aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@linux-m68k.org>2003-07-07 15:06:11 +0000
committerAndreas Schwab <schwab@linux-m68k.org>2003-07-07 15:06:11 +0000
commit8de307e0c2449f3cfeecab1cbd149f5322e84eba (patch)
tree650ad02c1f7eb716ef439fa38e303549b9dc9281
parent2705e97210f696dc3ac667f7796644abad7d21e1 (diff)
downloadgdb-8de307e0c2449f3cfeecab1cbd149f5322e84eba.zip
gdb-8de307e0c2449f3cfeecab1cbd149f5322e84eba.tar.gz
gdb-8de307e0c2449f3cfeecab1cbd149f5322e84eba.tar.bz2
* Makefile.in (m68k-tdep.o, m68klinux-tdep.o): Update
dependencies. * m68k-tdep.c (NUM_FREGS): Delete. (SIG_PC_FP_OFFSET): Delete. (TARGET_M68K): Delete. (P_MOVEAL_SP_FP, P_ADDAW_SP, P_ADDAL_SP, P_SUBQW_SP, P_SUBQL_SP, P_LEA_SP_SP, P_LEA_PC_A5, P_FMOVEMX_SP, P_MOVEL_SP, P_MOVEML_SP): Define. (P_MOVL_SP_FP, P_MOVL, P_JSR, P_BSR, P_LEAL, P_MOVML, P_FMOVM, P_TRAP): Delete. (m68k_register_raw_size): Delete. (m68k_register_virtual_size): Delete. (m68k_register_type): Renamed from m68k_register_virtual_type and add gdbarch argument. (m68k_store_struct_return): Delete. (m68k_deprecated_extract_return_value): Delete. (m68k_deprecated_extract_struct_value_address): Delete. (m68k_frame_chain): Delete. (m68k_frame_saved_pc): Delete. (m68k_fix_call_dummy): Delete. (m68k_push_dummy_frame): Delete. (m68k_pop_frame): Delete. (m68k_extract_return_value): New function. (m68k_store_return_value): Rewrite using regcache. (m68k_extract_struct_value_address): Rewrite using regcache. (m68k_push_dummy_call): New function. (struct m68k_frame_cache): Define. (m68k_alloc_frame_cache): New function. (m68k_analyze_frame_setup): New function. (m68k_analyze_register_saves): New function. (m68k_analyze_prologue): New function. (m68k_skip_prologue): Rewrite using above functions. (m68k_unwind_pc): New function. (m68k_frame_cache): New function. (m68k_frame_this_id): New function. (m68k_frame_prev_register): New function. (m68k_frame_unwind): New variable. (m68k_frame_p): New function. (m68k_sigtramp_frame_cache): New function. (m68k_sigtramp_frame_this_id): New function. (m68k_sigtramp_frame_prev_register): New function. (m68k_sigtramp_frame_unwind): New variable. (m68k_sigtramp_frame_p): New function. (m68k_frame_base_address): New function. (m68k_frame_base): New function. (m68k_unwind_dummy_id): New function. (fill_gregset): Use regcache_collect. (fill_fpregset): Likewise. (m68k_saved_pc_after_call): Only define if SYSCALL_TRAP is defined. (m68k_gdbarch_init): Don't define call_dummy_words. Don't set deprecated_init_frame_pc, deprecated_store_struct_return, deprecated_extract_return_value, deprecated_store_return_value, deprecated_frame_chain, deprecated_frame_saved_pc, deprecated_frame_init_saved_regs, deprecated_register_raw_size, deprecated_register_virtual_size, deprecated_max_register_raw_size, deprecated_max_register_virtual_size, deprecated_register_virtual_type, deprecated_register_size, deprecated_register_byte, deprecated_register_bytes, deprecated_fp_regnum, deprecated_use_generic_dummy_frames, call_dummy_location, deprecated_call_dummy_breakpoint_offset, deprecated_pc_in_call_dummy, deprecated_call_dummy_length, deprecated_call_dummy_start_offset, deprecated_call_dummy_words, deprecated_sizeof_call_dummy_words, deprecated_fix_call_dummy, deprecated_push_dummy_frame, deprecated_pop_frame, deprecated_dummy_write_sp. Set deprecated_saved_pc_after_call only if SYSCALL_TRAP is defined. Set extract_return_value, store_return_value, extract_struct_value_address, register_type, push_dummy_call, unwind_dummy_id, unwind_pc. Add two frame unwind predicates. * m68k-tdep.h (M68K_D1_REGNUM, M68K_NUM_REGS, M68K_MAX_REGISTER_SIZE): Define. (struct m68k_sigtramp_info): Define. (struct gdbarch_tdep): Add get_sigtramp_info. * m68klinux-nat.c (fetch_register): Use register_size instead of REGISTER_RAW_SIZE. Don't put assignment in if. (store_register): Likewise. (fetch_inferior_registers): Likewise. (store_inferior_registers): Likewise. * m68klinux-tdep.c (m68k_linux_sigtramp_saved_pc): Delete. (m68k_linux_frame_saved_pc): Delete. (m68k_linux_sigcontext_reg_offset, m68k_linux_ucontext_reg_offset): Define. (m68k_linux_get_sigtramp_info): New function. (m68k_linux_extract_return_value): Rewrite using regcache. (m68k_linux_store_return_value): Likewise. (m68k_linux_extract_struct_value_address): Likewise. (m68k_linux_init_abi): Set get_sigtramp_info in tdep structure. Don't set deprecated_frame_saved_pc, deprecated_extract_return_value, deprecated_store_return_value, deprecated_extract_struct_value_address. Set extract_return_value, store_return_value, extract_struct_value_address.
-rw-r--r--gdb/ChangeLog97
-rw-r--r--gdb/Makefile.in13
-rw-r--r--gdb/m68k-tdep.c1061
-rw-r--r--gdb/m68k-tdep.h20
-rw-r--r--gdb/m68klinux-nat.c26
-rw-r--r--gdb/m68klinux-tdep.c249
6 files changed, 918 insertions, 548 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e3f6e38..c42797b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,100 @@
+2003-07-07 Andreas Schwab <schwab@suse.de>
+
+ * Makefile.in (m68k-tdep.o, m68klinux-tdep.o): Update
+ dependencies.
+ * m68k-tdep.c (NUM_FREGS): Delete.
+ (SIG_PC_FP_OFFSET): Delete.
+ (TARGET_M68K): Delete.
+ (P_MOVEAL_SP_FP, P_ADDAW_SP, P_ADDAL_SP, P_SUBQW_SP,
+ P_SUBQL_SP, P_LEA_SP_SP, P_LEA_PC_A5, P_FMOVEMX_SP,
+ P_MOVEL_SP, P_MOVEML_SP): Define.
+ (P_MOVL_SP_FP, P_MOVL, P_JSR, P_BSR, P_LEAL, P_MOVML, P_FMOVM,
+ P_TRAP): Delete.
+ (m68k_register_raw_size): Delete.
+ (m68k_register_virtual_size): Delete.
+ (m68k_register_type): Renamed from m68k_register_virtual_type and
+ add gdbarch argument.
+ (m68k_store_struct_return): Delete.
+ (m68k_deprecated_extract_return_value): Delete.
+ (m68k_deprecated_extract_struct_value_address): Delete.
+ (m68k_frame_chain): Delete.
+ (m68k_frame_saved_pc): Delete.
+ (m68k_fix_call_dummy): Delete.
+ (m68k_push_dummy_frame): Delete.
+ (m68k_pop_frame): Delete.
+ (m68k_extract_return_value): New function.
+ (m68k_store_return_value): Rewrite using regcache.
+ (m68k_extract_struct_value_address): Rewrite using regcache.
+ (m68k_push_dummy_call): New function.
+ (struct m68k_frame_cache): Define.
+ (m68k_alloc_frame_cache): New function.
+ (m68k_analyze_frame_setup): New function.
+ (m68k_analyze_register_saves): New function.
+ (m68k_analyze_prologue): New function.
+ (m68k_skip_prologue): Rewrite using above functions.
+ (m68k_unwind_pc): New function.
+ (m68k_frame_cache): New function.
+ (m68k_frame_this_id): New function.
+ (m68k_frame_prev_register): New function.
+ (m68k_frame_unwind): New variable.
+ (m68k_frame_p): New function.
+ (m68k_sigtramp_frame_cache): New function.
+ (m68k_sigtramp_frame_this_id): New function.
+ (m68k_sigtramp_frame_prev_register): New function.
+ (m68k_sigtramp_frame_unwind): New variable.
+ (m68k_sigtramp_frame_p): New function.
+ (m68k_frame_base_address): New function.
+ (m68k_frame_base): New function.
+ (m68k_unwind_dummy_id): New function.
+ (fill_gregset): Use regcache_collect.
+ (fill_fpregset): Likewise.
+ (m68k_saved_pc_after_call): Only define if SYSCALL_TRAP is
+ defined.
+ (m68k_gdbarch_init): Don't define call_dummy_words. Don't set
+ deprecated_init_frame_pc, deprecated_store_struct_return,
+ deprecated_extract_return_value, deprecated_store_return_value,
+ deprecated_frame_chain, deprecated_frame_saved_pc,
+ deprecated_frame_init_saved_regs, deprecated_register_raw_size,
+ deprecated_register_virtual_size,
+ deprecated_max_register_raw_size,
+ deprecated_max_register_virtual_size,
+ deprecated_register_virtual_type, deprecated_register_size,
+ deprecated_register_byte, deprecated_register_bytes,
+ deprecated_fp_regnum, deprecated_use_generic_dummy_frames,
+ call_dummy_location, deprecated_call_dummy_breakpoint_offset,
+ deprecated_pc_in_call_dummy, deprecated_call_dummy_length,
+ deprecated_call_dummy_start_offset, deprecated_call_dummy_words,
+ deprecated_sizeof_call_dummy_words, deprecated_fix_call_dummy,
+ deprecated_push_dummy_frame, deprecated_pop_frame,
+ deprecated_dummy_write_sp. Set deprecated_saved_pc_after_call
+ only if SYSCALL_TRAP is defined. Set extract_return_value,
+ store_return_value, extract_struct_value_address, register_type,
+ push_dummy_call, unwind_dummy_id, unwind_pc. Add two frame unwind
+ predicates.
+ * m68k-tdep.h (M68K_D1_REGNUM, M68K_NUM_REGS,
+ M68K_MAX_REGISTER_SIZE): Define.
+ (struct m68k_sigtramp_info): Define.
+ (struct gdbarch_tdep): Add get_sigtramp_info.
+ * m68klinux-nat.c (fetch_register): Use register_size instead of
+ REGISTER_RAW_SIZE. Don't put assignment in if.
+ (store_register): Likewise.
+ (fetch_inferior_registers): Likewise.
+ (store_inferior_registers): Likewise.
+ * m68klinux-tdep.c (m68k_linux_sigtramp_saved_pc): Delete.
+ (m68k_linux_frame_saved_pc): Delete.
+ (m68k_linux_sigcontext_reg_offset,
+ m68k_linux_ucontext_reg_offset): Define.
+ (m68k_linux_get_sigtramp_info): New function.
+ (m68k_linux_extract_return_value): Rewrite using regcache.
+ (m68k_linux_store_return_value): Likewise.
+ (m68k_linux_extract_struct_value_address): Likewise.
+ (m68k_linux_init_abi): Set get_sigtramp_info in tdep structure.
+ Don't set deprecated_frame_saved_pc,
+ deprecated_extract_return_value, deprecated_store_return_value,
+ deprecated_extract_struct_value_address. Set
+ extract_return_value, store_return_value,
+ extract_struct_value_address.
+
2003-07-07 Andrew Cagney <cagney@redhat.com>
* expprint.c: Include "user-regs.h" instead of "frame.h".
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 28f8583..3f83118 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1950,15 +1950,16 @@ m68hc11-tdep.o: m68hc11-tdep.c $(defs_h) $(frame_h) $(symtab_h) \
$(arch_utils_h) $(regcache_h) $(target_h) $(opcode_m68hc11_h) \
$(elf_m68hc11_h) $(elf_bfd_h)
m68k-stub.o: m68k-stub.c
-m68k-tdep.o: m68k-tdep.c $(defs_h) $(frame_h) $(symtab_h) $(gdbcore_h) \
- $(value_h) $(gdb_string_h) $(inferior_h) $(regcache_h) \
- $(arch_utils_h) $(gregset_h) $(osabi_h) $(m68k_tdep_h)
+m68k-tdep.o: m68k-tdep.c $(defs_h) $(frame_h) $(frame_base_h) \
+ $(frame_unwind_h) $(symtab_h) $(gdbcore_h) $(value_h) $(gdb_string_h) \
+ $(gdb_assert_h) $(inferior_h) $(regcache_h) $(arch_utils_h) \
+ $(gregset_h) $(osabi_h) $(m68k_tdep_h)
m68klinux-nat.o: m68klinux-nat.c $(defs_h) $(frame_h) $(inferior_h) \
$(language_h) $(gdbcore_h) $(gdb_string_h) $(regcache_h) \
$(m68k_tdep_h) $(gdb_stat_h) $(floatformat_h) $(target_h)
-m68klinux-tdep.o: m68klinux-tdep.c $(defs_h) $(gdbcore_h) $(frame_h) \
- $(target_h) $(gdb_string_h) $(gdbtypes_h) $(osabi_h) $(regcache_h) \
- $(objfiles_h) $(symtab_h) $(m68k_tdep_t)
+m68klinux-tdep.o: m68klinux-tdep.c $(defs_h) $(gdbcore_h) $(doublest) \
+ $(floatformat_h) $(frame_h) $(target_h) $(gdb_string_h) $(gdbtypes_h) \
+ $(osabi_h) $(regcache_h) $(objfiles_h) $(symtab_h) $(m68k_tdep_t)
m68knbsd-nat.o: m68knbsd-nat.c $(defs_h) $(inferior_h) $(gdbcore_h) \
$(regcache_h)
m68knbsd-tdep.o: m68knbsd-tdep.c $(defs_h) $(gdbtypes_h) $(regcache_h)
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index c8158c4..2a675e0 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -22,10 +22,13 @@
#include "defs.h"
#include "frame.h"
+#include "frame-base.h"
+#include "frame-unwind.h"
#include "symtab.h"
#include "gdbcore.h"
#include "value.h"
#include "gdb_string.h"
+#include "gdb_assert.h"
#include "inferior.h"
#include "regcache.h"
#include "arch-utils.h"
@@ -37,37 +40,24 @@
#define P_LINKL_FP 0x480e
#define P_LINKW_FP 0x4e56
#define P_PEA_FP 0x4856
-#define P_MOVL_SP_FP 0x2c4f
-#define P_MOVL 0x207c
-#define P_JSR 0x4eb9
-#define P_BSR 0x61ff
-#define P_LEAL 0x43fb
-#define P_MOVML 0x48ef
-#define P_FMOVM 0xf237
-#define P_TRAP 0x4e40
+#define P_MOVEAL_SP_FP 0x2c4f
+#define P_ADDAW_SP 0xdefc
+#define P_ADDAL_SP 0xdffc
+#define P_SUBQW_SP 0x514f
+#define P_SUBQL_SP 0x518f
+#define P_LEA_SP_SP 0x4fef
+#define P_LEA_PC_A5 0x4bfb0170
+#define P_FMOVEMX_SP 0xf227
+#define P_MOVEL_SP 0x2f00
+#define P_MOVEML_SP 0x48e7
#define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4)
#define REGISTER_BYTES_NOFP (16*4 + 8)
-#define NUM_FREGS (NUM_REGS-24)
-
/* Offset from SP to first arg on stack at first instruction of a function */
-
#define SP_ARG0 (1 * 4)
-/* This was determined by experimentation on hp300 BSD 4.3. Perhaps
- it corresponds to some offset in /usr/include/sys/user.h or
- something like that. Using some system include file would
- have the advantage of probably being more robust in the face
- of OS upgrades, but the disadvantage of being wrong for
- cross-debugging. */
-
-#define SIG_PC_FP_OFFSET 530
-
-#define TARGET_M68K
-
-
#if !defined (BPT_VECTOR)
#define BPT_VECTOR 0xf
#endif
@@ -77,9 +67,6 @@
#endif
-static void m68k_frame_init_saved_regs (struct frame_info *frame_info);
-
-
/* gdbarch_breakpoint_from_pc is set to m68k_local_breakpoint_from_pc
so m68k_remote_breakpoint_from_pc is currently not used. */
@@ -107,26 +94,6 @@ m68k_register_bytes_ok (long numbytes)
|| (numbytes == REGISTER_BYTES_NOFP));
}
-/* Number of bytes of storage in the actual machine representation
- for register regnum. On the 68000, all regs are 4 bytes
- except the floating point regs which are 12 bytes. */
-
-static int
-m68k_register_raw_size (int regnum)
-{
- return (regnum >= FP0_REGNUM && regnum < FP0_REGNUM + 8 ? 12 : 4);
-}
-
-/* Number of bytes of storage in the program's representation
- for register regnum. On the 68000, all regs are 4 bytes
- except the floating point regs which are 12-byte long doubles. */
-
-static int
-m68k_register_virtual_size (int regnum)
-{
- return (regnum >= FP0_REGNUM && regnum < FP0_REGNUM + 8 ? 12 : 4);
-}
-
/* Return the GDB type object for the "standard" data type of data in
register N. This should be int for D0-D7, SR, FPCONTROL and
FPSTATUS, long double for FP0-FP7, and void pointer for all others
@@ -136,7 +103,7 @@ m68k_register_virtual_size (int regnum)
address. */
static struct type *
-m68k_register_virtual_type (int regnum)
+m68k_register_type (struct gdbarch *gdbarch, int regnum)
{
if (regnum >= FP0_REGNUM && regnum <= FP0_REGNUM + 7)
return builtin_type_m68881_ext;
@@ -189,71 +156,83 @@ m68k_register_byte (int regnum)
else
return (regnum * 4);
}
-
-/* Store the address of the place in which to copy the structure the
- subroutine will return. This is called from call_function. */
-
-static void
-m68k_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
-{
- write_register (M68K_A1_REGNUM, addr);
-}
-
-/* Extract from an array regbuf containing the (raw) register state
- a function return value of type type, and copy that, in virtual format,
- into valbuf. This is assuming that floating point values are returned
- as doubles in d0/d1. */
+
+/* Extract from an array REGBUF containing the (raw) register state, a
+ function return value of TYPE, and copy that, in virtual format,
+ into VALBUF. */
static void
-m68k_deprecated_extract_return_value (struct type *type, char *regbuf,
- char *valbuf)
+m68k_extract_return_value (struct type *type, struct regcache *regcache,
+ void *valbuf)
{
- int offset = 0;
- int typeLength = TYPE_LENGTH (type);
+ int len = TYPE_LENGTH (type);
+ char buf[M68K_MAX_REGISTER_SIZE];
- if (typeLength < 4)
- offset = 4 - typeLength;
-
- memcpy (valbuf, regbuf + offset, typeLength);
-}
+ if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ && TYPE_NFIELDS (type) == 1)
+ {
+ m68k_extract_return_value (TYPE_FIELD_TYPE (type, 0), regcache, valbuf);
+ return;
+ }
-static CORE_ADDR
-m68k_deprecated_extract_struct_value_address (char *regbuf)
-{
- return (*(CORE_ADDR *) (regbuf));
+ if (len <= 4)
+ {
+ regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
+ memcpy (valbuf, buf + (4 - len), len);
+ }
+ else if (len <= 8)
+ {
+ regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
+ memcpy (valbuf, buf + (8 - len), len - 4);
+ regcache_raw_read (regcache, M68K_D1_REGNUM,
+ (char *) valbuf + (len - 4));
+ }
+ else
+ internal_error (__FILE__, __LINE__,
+ "Cannot extract return value of %d bytes long.", len);
}
-/* Write into appropriate registers a function return value
- of type TYPE, given in virtual format. Assumes floats are passed
- in d0/d1. */
+/* Write into the appropriate registers a function return value stored
+ in VALBUF of type TYPE, given in virtual format. */
static void
-m68k_store_return_value (struct type *type, char *valbuf)
+m68k_store_return_value (struct type *type, struct regcache *regcache,
+ const void *valbuf)
{
- deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (type));
-}
+ int len = TYPE_LENGTH (type);
-/* Describe the pointer in each stack frame to the previous stack frame
- (its caller). */
+ if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ && TYPE_NFIELDS (type) == 1)
+ {
+ m68k_store_return_value (TYPE_FIELD_TYPE (type, 0), regcache, valbuf);
+ return;
+ }
-/* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and produces
- the frame's chain-pointer. In the case of the 68000, the frame's
- nominal address is the address of a 4-byte word containing the
- calling frame's address. */
+ if (len <= 4)
+ regcache_raw_write_part (regcache, M68K_D0_REGNUM, 4 - len, len, valbuf);
+ else if (len <= 8)
+ {
+ regcache_raw_write_part (regcache, M68K_D1_REGNUM, 8 - len,
+ len - 4, valbuf);
+ regcache_raw_write (regcache, M68K_D0_REGNUM,
+ (char *) valbuf + (len - 4));
+ }
+ else
+ internal_error (__FILE__, __LINE__,
+ "Cannot store return value of %d bytes long.", len);
+}
-/* If we are chaining from sigtramp, then manufacture a sigtramp frame
- (which isn't really on the stack. I'm not sure this is right for anything
- but BSD4.3 on an hp300. */
+/* Extract from REGCACHE, which contains the (raw) register state, the
+ address in which a function should return its structure value, as a
+ CORE_ADDR. */
static CORE_ADDR
-m68k_frame_chain (struct frame_info *thisframe)
+m68k_extract_struct_value_address (struct regcache *regcache)
{
- if (get_frame_type (thisframe) == SIGTRAMP_FRAME)
- return get_frame_base (thisframe);
- else if (!inside_entry_file (get_frame_pc (thisframe)))
- return read_memory_unsigned_integer (get_frame_base (thisframe), 4);
- else
- return 0;
+ char buf[4];
+
+ regcache_cooked_read (regcache, M68K_D0_REGNUM, buf);
+ return extract_unsigned_integer (buf, 4);
}
/* A function that tells us whether the function invocation represented
@@ -269,23 +248,6 @@ m68k_frameless_function_invocation (struct frame_info *fi)
return frameless_look_for_prologue (fi);
}
-static CORE_ADDR
-m68k_frame_saved_pc (struct frame_info *frame)
-{
- if (get_frame_type (frame) == SIGTRAMP_FRAME)
- {
- if (get_next_frame (frame))
- return read_memory_unsigned_integer (get_frame_base (get_next_frame (frame))
- + SIG_PC_FP_OFFSET, 4);
- else
- return read_memory_unsigned_integer (read_register (SP_REGNUM)
- + SIG_PC_FP_OFFSET - 8, 4);
- }
- else
- return read_memory_unsigned_integer (get_frame_base (frame) + 4, 4);
-}
-
-
int
delta68_in_sigtramp (CORE_ADDR pc, char *name)
{
@@ -343,339 +305,578 @@ delta68_frame_num_args (struct frame_info *fi)
return val;
}
-/* Insert the specified number of args and function address
- into a call sequence of the above form stored at DUMMYNAME.
- We use the BFD routines to store a big-endian value of known size. */
-
-static void
-m68k_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
- struct value **args, struct type *type, int gcc_p)
+static CORE_ADDR
+m68k_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
+ struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
+ struct value **args, CORE_ADDR sp, int struct_return,
+ CORE_ADDR struct_addr)
{
- bfd_putb32 (fun, (unsigned char *) dummy + DEPRECATED_CALL_DUMMY_START_OFFSET + 2);
- bfd_putb32 (nargs * 4,
- (unsigned char *) dummy + DEPRECATED_CALL_DUMMY_START_OFFSET + 8);
+ char buf[4];
+ int i;
+
+ /* Push arguments in reverse order. */
+ for (i = nargs - 1; i >= 0; i--)
+ {
+ int len = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (args[i]));
+ int container_len = (len + 3) & ~3;
+ int offset = container_len - len;
+
+ sp -= container_len;
+ write_memory (sp + offset, VALUE_CONTENTS_ALL (args[i]), len);
+ }
+
+ /* Push value address. */
+ if (struct_return)
+ {
+ sp -= 4;
+ store_unsigned_integer (buf, 4, struct_addr);
+ write_memory (sp, buf, 4);
+ }
+
+ /* Store return address. */
+ sp -= 4;
+ store_unsigned_integer (buf, 4, bp_addr);
+ write_memory (sp, buf, 4);
+
+ /* Finally, update the stack pointer... */
+ store_unsigned_integer (buf, 4, sp);
+ regcache_cooked_write (regcache, M68K_SP_REGNUM, buf);
+
+ /* ...and fake a frame pointer. */
+ regcache_cooked_write (regcache, M68K_FP_REGNUM, buf);
+
+ /* DWARF2/GCC uses the stack address *before* the function call as a
+ frame's CFA. */
+ return sp + 8;
}
+
+struct m68k_frame_cache
+{
+ /* Base address. */
+ CORE_ADDR base;
+ CORE_ADDR sp_offset;
+ CORE_ADDR pc;
+ /* Saved registers. */
+ CORE_ADDR saved_regs[M68K_NUM_REGS];
+ CORE_ADDR saved_sp;
-/* Push an empty stack frame, to record the current PC, etc. */
+ /* Stack space reserved for local variables. */
+ long locals;
+};
-static void
-m68k_push_dummy_frame (void)
+/* Allocate and initialize a frame cache. */
+
+static struct m68k_frame_cache *
+m68k_alloc_frame_cache (void)
{
- register CORE_ADDR sp = read_register (SP_REGNUM);
- register int regnum;
- char raw_buffer[12];
+ struct m68k_frame_cache *cache;
+ int i;
- sp = push_word (sp, read_register (PC_REGNUM));
- sp = push_word (sp, read_register (DEPRECATED_FP_REGNUM));
- write_register (DEPRECATED_FP_REGNUM, sp);
+ cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache);
- /* Always save the floating-point registers, whether they exist on
- this target or not. */
- for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
- {
- deprecated_read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12);
- sp = push_bytes (sp, raw_buffer, 12);
- }
+ /* Base address. */
+ cache->base = 0;
+ cache->sp_offset = -4;
+ cache->pc = 0;
- for (regnum = DEPRECATED_FP_REGNUM - 1; regnum >= 0; regnum--)
- {
- sp = push_word (sp, read_register (regnum));
- }
- sp = push_word (sp, read_register (PS_REGNUM));
- write_register (SP_REGNUM, sp);
+ /* Saved registers. We initialize these to -1 since zero is a valid
+ offset (that's where %fp is supposed to be stored). */
+ for (i = 0; i < M68K_NUM_REGS; i++)
+ cache->saved_regs[i] = -1;
+
+ /* Frameless until proven otherwise. */
+ cache->locals = -1;
+
+ return cache;
}
-/* Discard from the stack the innermost frame,
- restoring all saved registers. */
+/* Check whether PC points at a code that sets up a new stack frame.
+ If so, it updates CACHE and returns the address of the first
+ instruction after the sequence that sets removes the "hidden"
+ argument from the stack or CURRENT_PC, whichever is smaller.
+ Otherwise, return PC. */
-static void
-m68k_pop_frame (void)
+static CORE_ADDR
+m68k_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR current_pc,
+ struct m68k_frame_cache *cache)
{
- register struct frame_info *frame = get_current_frame ();
- register CORE_ADDR fp;
- register int regnum;
- char raw_buffer[12];
+ int op;
+
+ if (pc >= current_pc)
+ return current_pc;
- fp = get_frame_base (frame);
- m68k_frame_init_saved_regs (frame);
- for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
+ op = read_memory_unsigned_integer (pc, 2);
+
+ if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP)
{
- if (get_frame_saved_regs (frame)[regnum])
+ cache->saved_regs[M68K_FP_REGNUM] = 0;
+ cache->sp_offset += 4;
+ if (op == P_LINKW_FP)
+ {
+ /* link.w %fp, #-N */
+ /* link.w %fp, #0; adda.l #-N, %sp */
+ cache->locals = -read_memory_integer (pc + 2, 2);
+
+ if (pc + 4 < current_pc && cache->locals == 0)
+ {
+ op = read_memory_unsigned_integer (pc + 4, 2);
+ if (op == P_ADDAL_SP)
+ {
+ cache->locals = read_memory_integer (pc + 6, 4);
+ return pc + 10;
+ }
+ }
+
+ return pc + 4;
+ }
+ else if (op == P_LINKL_FP)
{
- read_memory (get_frame_saved_regs (frame)[regnum], raw_buffer, 12);
- deprecated_write_register_bytes (REGISTER_BYTE (regnum), raw_buffer,
- 12);
+ /* link.l %fp, #-N */
+ cache->locals = -read_memory_integer (pc + 2, 4);
+ return pc + 6;
+ }
+ else
+ {
+ /* pea (%fp); movea.l %sp, %fp */
+ cache->locals = 0;
+
+ if (pc + 2 < current_pc)
+ {
+ op = read_memory_unsigned_integer (pc + 2, 2);
+
+ if (op == P_MOVEAL_SP_FP)
+ {
+ /* move.l %sp, %fp */
+ return pc + 4;
+ }
+ }
+
+ return pc + 2;
}
}
- for (regnum = DEPRECATED_FP_REGNUM - 1; regnum >= 0; regnum--)
+ else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
{
- if (get_frame_saved_regs (frame)[regnum])
+ /* subq.[wl] #N,%sp */
+ /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
+ cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
+ if (pc + 2 < current_pc)
{
- write_register (regnum,
- read_memory_integer (get_frame_saved_regs (frame)[regnum], 4));
+ op = read_memory_unsigned_integer (pc + 2, 2);
+ if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
+ {
+ cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
+ return pc + 4;
+ }
}
+ return pc + 2;
+ }
+ else if (op == P_ADDAW_SP || op == P_LEA_SP_SP)
+ {
+ /* adda.w #-N,%sp */
+ /* lea (-N,%sp),%sp */
+ cache->locals = -read_memory_integer (pc + 2, 2);
+ return pc + 4;
}
- if (get_frame_saved_regs (frame)[PS_REGNUM])
+ else if (op == P_ADDAL_SP)
{
- write_register (PS_REGNUM,
- read_memory_integer (get_frame_saved_regs (frame)[PS_REGNUM], 4));
+ /* adda.l #-N,%sp */
+ cache->locals = -read_memory_integer (pc + 2, 4);
+ return pc + 6;
}
- write_register (DEPRECATED_FP_REGNUM, read_memory_integer (fp, 4));
- write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
- write_register (SP_REGNUM, fp + 8);
- flush_cached_frames ();
+
+ return pc;
}
-
-/* Given an ip value corresponding to the start of a function,
- return the ip of the first instruction after the function
- prologue. This is the generic m68k support. Machines which
- require something different can override the SKIP_PROLOGUE
- macro to point elsewhere.
+/* Check whether PC points at code that saves registers on the stack.
+ If so, it updates CACHE and returns the address of the first
+ instruction after the register saves or CURRENT_PC, whichever is
+ smaller. Otherwise, return PC. */
- Some instructions which typically may appear in a function
- prologue include:
+static CORE_ADDR
+m68k_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
+ struct m68k_frame_cache *cache)
+{
+ if (cache->locals >= 0)
+ {
+ CORE_ADDR offset;
+ int op;
+ int i, mask, regno;
- A link instruction, word form:
+ offset = -4 - cache->locals;
+ while (pc < current_pc)
+ {
+ op = read_memory_unsigned_integer (pc, 2);
+ if (op == P_FMOVEMX_SP)
+ {
+ /* fmovem.x REGS,-(%sp) */
+ op = read_memory_unsigned_integer (pc + 2, 2);
+ if ((op & 0xff00) == 0xe000)
+ {
+ mask = op & 0xff;
+ for (i = 0; i < 16; i++, mask >>= 1)
+ {
+ if (mask & 1)
+ {
+ cache->saved_regs[i + M68K_FP0_REGNUM] = offset;
+ offset -= 12;
+ }
+ }
+ pc += 4;
+ }
+ else
+ break;
+ }
+ else if ((op & 0170677) == P_MOVEL_SP)
+ {
+ /* move.l %R,-(%sp) */
+ regno = ((op & 07000) >> 9) | ((op & 0100) >> 3);
+ cache->saved_regs[regno] = offset;
+ offset -= 4;
+ pc += 2;
+ }
+ else if (op == P_MOVEML_SP)
+ {
+ /* movem.l REGS,-(%sp) */
+ mask = read_memory_unsigned_integer (pc + 2, 2);
+ for (i = 0; i < 16; i++, mask >>= 1)
+ {
+ if (mask & 1)
+ {
+ cache->saved_regs[15 - i] = offset;
+ offset -= 4;
+ }
+ }
+ pc += 4;
+ }
+ else
+ break;
+ }
+ }
+
+ return pc;
+}
- link.w %a6,&0 4e56 XXXX
- A link instruction, long form:
+/* Do a full analysis of the prologue at PC and update CACHE
+ accordingly. Bail out early if CURRENT_PC is reached. Return the
+ address where the analysis stopped.
- link.l %fp,&F%1 480e XXXX XXXX
+ We handle all cases that can be generated by gcc.
- A movm instruction to preserve integer regs:
+ For allocating a stack frame:
- movm.l &M%1,(4,%sp) 48ef XXXX XXXX
+ link.w %a6,#-N
+ link.l %a6,#-N
+ pea (%fp); move.l %sp,%fp
+ link.w %a6,#0; add.l #-N,%sp
+ subq.l #N,%sp
+ subq.w #N,%sp
+ subq.w #8,%sp; subq.w #N-8,%sp
+ add.w #-N,%sp
+ lea (-N,%sp),%sp
+ add.l #-N,%sp
- A fmovm instruction to preserve float regs:
+ For saving registers:
- fmovm &FPM%1,(FPO%1,%sp) f237 XXXX XXXX XXXX XXXX
+ fmovem.x REGS,-(%sp)
+ move.l R1,-(%sp)
+ move.l R1,-(%sp); move.l R2,-(%sp)
+ movem.l REGS,-(%sp)
- Some profiling setup code (FIXME, not recognized yet):
+ For setting up the PIC register:
- lea.l (.L3,%pc),%a1 43fb XXXX XXXX XXXX
- bsr _mcount 61ff XXXX XXXX
+ lea (%pc,N),%a5
- */
+ */
static CORE_ADDR
-m68k_skip_prologue (CORE_ADDR ip)
+m68k_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
+ struct m68k_frame_cache *cache)
{
- register CORE_ADDR limit;
- struct symtab_and_line sal;
- register int op;
+ unsigned int op;
- /* Find out if there is a known limit for the extent of the prologue.
- If so, ensure we don't go past it. If not, assume "infinity". */
+ pc = m68k_analyze_frame_setup (pc, current_pc, cache);
+ pc = m68k_analyze_register_saves (pc, current_pc, cache);
+ if (pc >= current_pc)
+ return current_pc;
- sal = find_pc_line (ip, 0);
- limit = (sal.end) ? sal.end : (CORE_ADDR) ~0;
-
- while (ip < limit)
+ /* Check for GOT setup. */
+ op = read_memory_unsigned_integer (pc, 4);
+ if (op == P_LEA_PC_A5)
{
- op = read_memory_unsigned_integer (ip, 2);
-
- if (op == P_LINKW_FP)
- ip += 4; /* Skip link.w */
- else if (op == P_PEA_FP)
- ip += 2; /* Skip pea %fp */
- else if (op == P_MOVL_SP_FP)
- ip += 2; /* Skip move.l %sp, %fp */
- else if (op == P_LINKL_FP)
- ip += 6; /* Skip link.l */
- else if (op == P_MOVML)
- ip += 6; /* Skip movm.l */
- else if (op == P_FMOVM)
- ip += 10; /* Skip fmovm */
- else
- break; /* Found unknown code, bail out. */
+ /* lea (%pc,N),%a5 */
+ return pc + 6;
}
- return (ip);
+
+ return pc;
}
-/* Store the addresses of the saved registers of the frame described by
- FRAME_INFO in its saved_regs field.
- This includes special registers such as pc and fp saved in special
- ways in the stack frame. sp is even more special:
- the address we return for it IS the sp for the next frame. */
+/* Return PC of first real instruction. */
-static void
-m68k_frame_init_saved_regs (struct frame_info *frame_info)
+static CORE_ADDR
+m68k_skip_prologue (CORE_ADDR start_pc)
{
- register int regnum;
- register int regmask;
- register CORE_ADDR next_addr;
- register CORE_ADDR pc;
+ struct m68k_frame_cache cache;
+ CORE_ADDR pc;
+ int op;
- /* First possible address for a pc in a call dummy for this frame. */
- CORE_ADDR possible_call_dummy_start =
- get_frame_base (frame_info) - 28 - DEPRECATED_FP_REGNUM * 4 - 4 - 8 * 12;
+ cache.locals = -1;
+ pc = m68k_analyze_prologue (start_pc, (CORE_ADDR) -1, &cache);
+ if (cache.locals < 0)
+ return start_pc;
+ return pc;
+}
- int nextinsn;
+static CORE_ADDR
+m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
+{
+ char buf[8];
- if (get_frame_saved_regs (frame_info))
- return;
+ frame_unwind_register (next_frame, PC_REGNUM, buf);
+ return extract_typed_address (buf, builtin_type_void_func_ptr);
+}
+
+/* Normal frames. */
- frame_saved_regs_zalloc (frame_info);
+static struct m68k_frame_cache *
+m68k_frame_cache (struct frame_info *next_frame, void **this_cache)
+{
+ struct m68k_frame_cache *cache;
+ char buf[4];
+ int i;
+
+ if (*this_cache)
+ return *this_cache;
+
+ cache = m68k_alloc_frame_cache ();
+ *this_cache = cache;
+
+ /* In principle, for normal frames, %fp holds the frame pointer,
+ which holds the base address for the current stack frame.
+ However, for functions that don't need it, the frame pointer is
+ optional. For these "frameless" functions the frame pointer is
+ actually the frame pointer of the calling frame. Signal
+ trampolines are just a special case of a "frameless" function.
+ They (usually) share their frame pointer with the frame that was
+ in progress when the signal occurred. */
+
+ frame_unwind_register (next_frame, M68K_FP_REGNUM, buf);
+ cache->base = extract_unsigned_integer (buf, 4);
+ if (cache->base == 0)
+ return cache;
+
+ /* For normal frames, %pc is stored at 4(%fp). */
+ cache->saved_regs[M68K_PC_REGNUM] = 4;
+
+ cache->pc = frame_func_unwind (next_frame);
+ if (cache->pc != 0)
+ m68k_analyze_prologue (cache->pc, frame_pc_unwind (next_frame), cache);
+
+ if (cache->locals < 0)
+ {
+ /* We didn't find a valid frame, which means that CACHE->base
+ currently holds the frame pointer for our calling frame. If
+ we're at the start of a function, or somewhere half-way its
+ prologue, the function's frame probably hasn't been fully
+ setup yet. Try to reconstruct the base address for the stack
+ frame by looking at the stack pointer. For truly "frameless"
+ functions this might work too. */
+
+ frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
+ cache->base = extract_unsigned_integer (buf, 4) + cache->sp_offset;
+ }
- memset (get_frame_saved_regs (frame_info), 0, SIZEOF_FRAME_SAVED_REGS);
+ /* Now that we have the base address for the stack frame we can
+ calculate the value of %sp in the calling frame. */
+ cache->saved_sp = cache->base + 8;
- if (get_frame_pc (frame_info) >= possible_call_dummy_start
- && get_frame_pc (frame_info) <= get_frame_base (frame_info))
- {
+ /* Adjust all the saved registers such that they contain addresses
+ instead of offsets. */
+ for (i = 0; i < M68K_NUM_REGS; i++)
+ if (cache->saved_regs[i] != -1)
+ cache->saved_regs[i] += cache->base;
- /* It is a call dummy. We could just stop now, since we know
- what the call dummy saves and where. But this code proceeds
- to parse the "prologue" which is part of the call dummy.
- This is needlessly complex and confusing. FIXME. */
+ return cache;
+}
- next_addr = get_frame_base (frame_info);
- pc = possible_call_dummy_start;
- }
- else
- {
- pc = get_frame_func (frame_info);
+static void
+m68k_frame_this_id (struct frame_info *next_frame, void **this_cache,
+ struct frame_id *this_id)
+{
+ struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
- nextinsn = read_memory_unsigned_integer (pc, 2);
- if (P_PEA_FP == nextinsn
- && P_MOVL_SP_FP == read_memory_unsigned_integer (pc + 2, 2))
- {
- /* pea %fp
- move.l %sp, %fp */
- next_addr = get_frame_base (frame_info);
- pc += 4;
- }
- else if (P_LINKL_FP == nextinsn)
- /* link.l %fp */
- /* Find the address above the saved
- regs using the amount of storage from the link instruction. */
- {
- next_addr = get_frame_base (frame_info) + read_memory_integer (pc + 2, 4);
- pc += 6;
- }
- else if (P_LINKW_FP == nextinsn)
- /* link.w %fp */
- /* Find the address above the saved
- regs using the amount of storage from the link instruction. */
- {
- next_addr = get_frame_base (frame_info) + read_memory_integer (pc + 2, 2);
- pc += 4;
- }
- else
- goto lose;
+ /* This marks the outermost frame. */
+ if (cache->base == 0)
+ return;
- /* If have an addal #-n, sp next, adjust next_addr. */
- if (read_memory_unsigned_integer (pc, 2) == 0157774)
- next_addr += read_memory_integer (pc += 2, 4), pc += 4;
- }
+ /* See the end of m68k_push_dummy_call. */
+ *this_id = frame_id_build (cache->base + 8, cache->pc);
+}
- for (;;)
+static void
+m68k_frame_prev_register (struct frame_info *next_frame, void **this_cache,
+ int regnum, int *optimizedp,
+ enum lval_type *lvalp, CORE_ADDR *addrp,
+ int *realnump, void *valuep)
+{
+ struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
+
+ gdb_assert (regnum >= 0);
+
+ if (regnum == M68K_SP_REGNUM && cache->saved_sp)
{
- nextinsn = read_memory_unsigned_integer (pc, 2);
- regmask = read_memory_unsigned_integer (pc + 2, 2);
- /* fmovemx to -(sp) */
- if (0xf227 == nextinsn && (regmask & 0xff00) == 0xe000)
+ *optimizedp = 0;
+ *lvalp = not_lval;
+ *addrp = 0;
+ *realnump = -1;
+ if (valuep)
{
- /* Regmask's low bit is for register fp7, the first pushed */
- for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
- if (regmask & 1)
- get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 12);
- pc += 4;
+ /* Store the value. */
+ store_unsigned_integer (valuep, 4, cache->saved_sp);
}
- /* fmovemx to (fp + displacement) */
- else if (0171056 == nextinsn && (regmask & 0xff00) == 0xf000)
- {
- register CORE_ADDR addr;
-
- addr = get_frame_base (frame_info) + read_memory_integer (pc + 4, 2);
- /* Regmask's low bit is for register fp7, the first pushed */
- for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
- if (regmask & 1)
- {
- get_frame_saved_regs (frame_info)[regnum] = addr;
- addr += 12;
- }
- pc += 6;
- }
- /* moveml to (sp) */
- else if (0044327 == nextinsn)
- {
- /* Regmask's low bit is for register 0, the first written */
- for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
- if (regmask & 1)
- {
- get_frame_saved_regs (frame_info)[regnum] = next_addr;
- next_addr += 4;
- }
- pc += 4;
- }
- /* moveml to (fp + displacement) */
- else if (0044356 == nextinsn)
- {
- register CORE_ADDR addr;
-
- addr = get_frame_base (frame_info) + read_memory_integer (pc + 4, 2);
- /* Regmask's low bit is for register 0, the first written */
- for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
- if (regmask & 1)
- {
- get_frame_saved_regs (frame_info)[regnum] = addr;
- addr += 4;
- }
- pc += 6;
- }
- /* moveml to -(sp) */
- else if (0044347 == nextinsn)
- {
- /* Regmask's low bit is for register 15, the first pushed */
- for (regnum = 16; --regnum >= 0; regmask >>= 1)
- if (regmask & 1)
- get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 4);
- pc += 4;
- }
- /* movl r,-(sp) */
- else if (0x2f00 == (0xfff0 & nextinsn))
- {
- regnum = 0xf & nextinsn;
- get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 4);
- pc += 2;
- }
- /* fmovemx to index of sp */
- else if (0xf236 == nextinsn && (regmask & 0xff00) == 0xf000)
- {
- /* Regmask's low bit is for register fp0, the first written */
- for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
- if (regmask & 1)
- {
- get_frame_saved_regs (frame_info)[regnum] = next_addr;
- next_addr += 12;
- }
- pc += 10;
- }
- /* clrw -(sp); movw ccr,-(sp) */
- else if (0x4267 == nextinsn && 0x42e7 == regmask)
+ return;
+ }
+
+ if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1)
+ {
+ *optimizedp = 0;
+ *lvalp = lval_memory;
+ *addrp = cache->saved_regs[regnum];
+ *realnump = -1;
+ if (valuep)
{
- get_frame_saved_regs (frame_info)[PS_REGNUM] = (next_addr -= 4);
- pc += 4;
+ /* Read the value in from memory. */
+ read_memory (*addrp, valuep,
+ register_size (current_gdbarch, regnum));
}
- else
- break;
+ return;
}
-lose:;
- get_frame_saved_regs (frame_info)[SP_REGNUM] = get_frame_base (frame_info) + 8;
- get_frame_saved_regs (frame_info)[DEPRECATED_FP_REGNUM] = get_frame_base (frame_info);
- get_frame_saved_regs (frame_info)[PC_REGNUM] = get_frame_base (frame_info) + 4;
-#ifdef SIG_SP_FP_OFFSET
- /* Adjust saved SP_REGNUM for fake _sigtramp frames. */
- if ((get_frame_type (frame_info) == SIGTRAMP_FRAME) && frame_info->next)
- frame_info->saved_regs[SP_REGNUM] =
- frame_info->next->frame + SIG_SP_FP_OFFSET;
-#endif
+
+ frame_register_unwind (next_frame, regnum,
+ optimizedp, lvalp, addrp, realnump, valuep);
+}
+
+static const struct frame_unwind m68k_frame_unwind =
+{
+ NORMAL_FRAME,
+ m68k_frame_this_id,
+ m68k_frame_prev_register
+};
+
+static const struct frame_unwind *
+m68k_frame_p (CORE_ADDR pc)
+{
+ return &m68k_frame_unwind;
+}
+
+/* Signal trampolines. */
+
+static struct m68k_frame_cache *
+m68k_sigtramp_frame_cache (struct frame_info *next_frame, void **this_cache)
+{
+ struct m68k_frame_cache *cache;
+ struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+ struct m68k_sigtramp_info info;
+ char buf[4];
+ int i;
+
+ if (*this_cache)
+ return *this_cache;
+
+ cache = m68k_alloc_frame_cache ();
+
+ frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
+ cache->base = extract_unsigned_integer (buf, 4) - 4;
+
+ info = tdep->get_sigtramp_info (next_frame);
+
+ for (i = 0; i < M68K_NUM_REGS; i++)
+ if (info.sc_reg_offset[i] != -1)
+ cache->saved_regs[i] = info.sigcontext_addr + info.sc_reg_offset[i];
+
+ *this_cache = cache;
+ return cache;
+}
+
+static void
+m68k_sigtramp_frame_this_id (struct frame_info *next_frame, void **this_cache,
+ struct frame_id *this_id)
+{
+ struct m68k_frame_cache *cache =
+ m68k_sigtramp_frame_cache (next_frame, this_cache);
+
+ /* See the end of m68k_push_dummy_call. */
+ *this_id = frame_id_build (cache->base + 8, frame_pc_unwind (next_frame));
+}
+
+static void
+m68k_sigtramp_frame_prev_register (struct frame_info *next_frame,
+ void **this_cache,
+ int regnum, int *optimizedp,
+ enum lval_type *lvalp, CORE_ADDR *addrp,
+ int *realnump, void *valuep)
+{
+ /* Make sure we've initialized the cache. */
+ m68k_sigtramp_frame_cache (next_frame, this_cache);
+
+ m68k_frame_prev_register (next_frame, this_cache, regnum,
+ optimizedp, lvalp, addrp, realnump, valuep);
+}
+
+static const struct frame_unwind m68k_sigtramp_frame_unwind =
+{
+ SIGTRAMP_FRAME,
+ m68k_sigtramp_frame_this_id,
+ m68k_sigtramp_frame_prev_register
+};
+
+static const struct frame_unwind *
+m68k_sigtramp_frame_p (CORE_ADDR pc)
+{
+ char *name;
+
+ /* We shouldn't even bother to try if the OSABI didn't register
+ a get_sigtramp_info handler. */
+ if (!gdbarch_tdep (current_gdbarch)->get_sigtramp_info)
+ return NULL;
+
+ find_pc_partial_function (pc, &name, NULL, NULL);
+ if (PC_IN_SIGTRAMP (pc, name))
+ return &m68k_sigtramp_frame_unwind;
+
+ return NULL;
}
+
+static CORE_ADDR
+m68k_frame_base_address (struct frame_info *next_frame, void **this_cache)
+{
+ struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
+
+ return cache->base;
+}
+
+static const struct frame_base m68k_frame_base =
+{
+ &m68k_frame_unwind,
+ m68k_frame_base_address,
+ m68k_frame_base_address,
+ m68k_frame_base_address
+};
+
+static struct frame_id
+m68k_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
+{
+ char buf[4];
+ CORE_ADDR fp;
+ frame_unwind_register (next_frame, M68K_FP_REGNUM, buf);
+ fp = extract_unsigned_integer (buf, 4);
+ /* See the end of m68k_push_dummy_call. */
+ return frame_id_build (fp + 8, frame_pc_unwind (next_frame));
+}
+
#ifdef USE_PROC_FS /* Target dependent support for /proc */
#include <sys/procfs.h>
@@ -745,19 +946,13 @@ fill_gregset (gregset_t *gregsetp, int regno)
for (regi = 0; regi < R_PC; regi++)
{
- if ((regno == -1) || (regno == regi))
- {
- *(regp + regi) = *(int *) &deprecated_registers[REGISTER_BYTE (regi)];
- }
- }
- if ((regno == -1) || (regno == PS_REGNUM))
- {
- *(regp + R_PS) = *(int *) &deprecated_registers[REGISTER_BYTE (PS_REGNUM)];
- }
- if ((regno == -1) || (regno == PC_REGNUM))
- {
- *(regp + R_PC) = *(int *) &deprecated_registers[REGISTER_BYTE (PC_REGNUM)];
+ if (regno == -1 || regno == regi)
+ regcache_collect (regi, regp + regi);
}
+ if (regno == -1 || regno == PS_REGNUM)
+ regcache_collect (PS_REGNUM, regp + R_PS);
+ if (regno == -1 || regno == PC_REGNUM)
+ regcache_collect (PC_REGNUM, regp + R_PC);
}
#if defined (FP0_REGNUM)
@@ -791,30 +986,18 @@ void
fill_fpregset (fpregset_t *fpregsetp, int regno)
{
int regi;
- char *to;
- char *from;
for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++)
{
- if ((regno == -1) || (regno == regi))
- {
- from = (char *) &deprecated_registers[REGISTER_BYTE (regi)];
- to = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
- memcpy (to, from, REGISTER_RAW_SIZE (regi));
- }
- }
- if ((regno == -1) || (regno == M68K_FPC_REGNUM))
- {
- fpregsetp->f_pcr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPC_REGNUM)];
- }
- if ((regno == -1) || (regno == M68K_FPS_REGNUM))
- {
- fpregsetp->f_psr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPS_REGNUM)];
- }
- if ((regno == -1) || (regno == M68K_FPI_REGNUM))
- {
- fpregsetp->f_fpiaddr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPI_REGNUM)];
+ if (regno == -1 || regno == regi)
+ regcache_collect (regi, &fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
}
+ if (regno == -1 || regno == M68K_FPC_REGNUM)
+ regcache_collect (M68K_FPC_REGNUM, &fpregsetp->f_pcr);
+ if (regno == -1 || regno == M68K_FPS_REGNUM)
+ regcache_collect (M68K_FPS_REGNUM, &fpregsetp->f_psr);
+ if (regno == -1 || regno == M68K_FPI_REGNUM)
+ regcache_collect (M68K_FPI_REGNUM, &fpregsetp->f_fpiaddr);
}
#endif /* defined (FP0_REGNUM) */
@@ -857,6 +1040,7 @@ m68k_get_longjmp_target (CORE_ADDR *pc)
return 1;
}
+#ifdef SYSCALL_TRAP
/* Immediately after a function call, return the saved pc before the frame
is setup. For sun3's, we check for the common case of being inside of a
system call, and if so, we know that Sun pushes the call # on the stack
@@ -865,7 +1049,6 @@ m68k_get_longjmp_target (CORE_ADDR *pc)
static CORE_ADDR
m68k_saved_pc_after_call (struct frame_info *frame)
{
-#ifdef SYSCALL_TRAP
int op;
op = read_memory_unsigned_integer (frame->pc - SYSCALL_TRAP_OFFSET, 2);
@@ -873,9 +1056,9 @@ m68k_saved_pc_after_call (struct frame_info *frame)
if (op == SYSCALL_TRAP)
return read_memory_unsigned_integer (read_register (SP_REGNUM) + 4, 4);
else
-#endif /* SYSCALL_TRAP */
return read_memory_unsigned_integer (read_register (SP_REGNUM), 4);
}
+#endif /* SYSCALL_TRAP */
/* Function: m68k_gdbarch_init
Initializer function for the m68k gdbarch vector.
@@ -884,10 +1067,6 @@ m68k_saved_pc_after_call (struct frame_info *frame)
static struct gdbarch *
m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
- static LONGEST call_dummy_words[7] = { 0xf227e0ff, 0x48e7fffc, 0x426742e7,
- 0x4eb93232, 0x3232dffc, 0x69696969,
- (0x4e404e71 | (BPT_VECTOR << 16))
- };
struct gdbarch_tdep *tdep = NULL;
struct gdbarch *gdbarch;
@@ -899,17 +1078,15 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
tdep = xmalloc (sizeof (struct gdbarch_tdep));
gdbarch = gdbarch_alloc (&info, tdep);
- /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
- ready to unwind the PC first (see frame.c:get_prev_frame()). */
- set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default);
-
set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext);
set_gdbarch_long_double_bit (gdbarch, 96);
set_gdbarch_function_start_offset (gdbarch, 0);
set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
+#ifdef SYSCALL_TRAP
set_gdbarch_deprecated_saved_pc_after_call (gdbarch, m68k_saved_pc_after_call);
+#endif
set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
/* Stack grows down. */
@@ -919,50 +1096,25 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_believe_pcc_promotion (gdbarch, 1);
set_gdbarch_decr_pc_after_break (gdbarch, 2);
- set_gdbarch_deprecated_store_struct_return (gdbarch, m68k_store_struct_return);
- set_gdbarch_deprecated_extract_return_value (gdbarch,
- m68k_deprecated_extract_return_value);
- set_gdbarch_deprecated_store_return_value (gdbarch, m68k_store_return_value);
+ set_gdbarch_extract_return_value (gdbarch, m68k_extract_return_value);
+ set_gdbarch_store_return_value (gdbarch, m68k_store_return_value);
+ set_gdbarch_extract_struct_value_address (gdbarch,
+ m68k_extract_struct_value_address);
- set_gdbarch_deprecated_frame_chain (gdbarch, m68k_frame_chain);
- set_gdbarch_deprecated_frame_saved_pc (gdbarch, m68k_frame_saved_pc);
- set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, m68k_frame_init_saved_regs);
set_gdbarch_frameless_function_invocation (gdbarch,
m68k_frameless_function_invocation);
set_gdbarch_frame_args_skip (gdbarch, 8);
- set_gdbarch_deprecated_register_raw_size (gdbarch, m68k_register_raw_size);
- set_gdbarch_deprecated_register_virtual_size (gdbarch, m68k_register_virtual_size);
- set_gdbarch_deprecated_max_register_raw_size (gdbarch, 12);
- set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 12);
- set_gdbarch_deprecated_register_virtual_type (gdbarch, m68k_register_virtual_type);
+ set_gdbarch_register_type (gdbarch, m68k_register_type);
set_gdbarch_register_name (gdbarch, m68k_register_name);
- set_gdbarch_deprecated_register_size (gdbarch, 4);
- set_gdbarch_deprecated_register_byte (gdbarch, m68k_register_byte);
set_gdbarch_num_regs (gdbarch, 29);
set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok);
- set_gdbarch_deprecated_register_bytes (gdbarch, (16 * 4 + 8 + 8 * 12 + 3 * 4));
set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
- set_gdbarch_deprecated_fp_regnum (gdbarch, M68K_FP_REGNUM);
set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
- set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch, 0);
- set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
- set_gdbarch_deprecated_call_dummy_breakpoint_offset (gdbarch, 24);
- set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_on_stack);
- set_gdbarch_deprecated_call_dummy_length (gdbarch, 28);
- set_gdbarch_deprecated_call_dummy_start_offset (gdbarch, 12);
-
- set_gdbarch_deprecated_call_dummy_words (gdbarch, call_dummy_words);
- set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, sizeof (call_dummy_words));
- set_gdbarch_deprecated_fix_call_dummy (gdbarch, m68k_fix_call_dummy);
- set_gdbarch_deprecated_push_dummy_frame (gdbarch, m68k_push_dummy_frame);
- set_gdbarch_deprecated_pop_frame (gdbarch, m68k_pop_frame);
-
- /* Should be using push_dummy_call. */
- set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
+ set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call);
/* Disassembler. */
set_gdbarch_print_insn (gdbarch, print_insn_m68k);
@@ -973,6 +1125,12 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
#else
tdep->jb_pc = -1;
#endif
+ tdep->get_sigtramp_info = NULL;
+
+ /* Frame unwinder. */
+ set_gdbarch_unwind_dummy_id (gdbarch, m68k_unwind_dummy_id);
+ set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc);
+ frame_base_set_default (gdbarch, &m68k_frame_base);
/* Hook in ABI-specific overrides, if they have been registered. */
gdbarch_init_osabi (info, gdbarch);
@@ -983,6 +1141,9 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
if (tdep->jb_pc >= 0)
set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target);
+ frame_unwind_append_predicate (gdbarch, m68k_sigtramp_frame_p);
+ frame_unwind_append_predicate (gdbarch, m68k_frame_p);
+
return gdbarch;
}
diff --git a/gdb/m68k-tdep.h b/gdb/m68k-tdep.h
index 7c499a7..a81cc8c 100644
--- a/gdb/m68k-tdep.h
+++ b/gdb/m68k-tdep.h
@@ -22,6 +22,8 @@
#ifndef M68K_TDEP_H
#define M68K_TDEP_H
+struct frame_info;
+
/* Register numbers of various important registers.
Note that some of these values are "real" register numbers,
and correspond to the general registers of the machine,
@@ -32,6 +34,7 @@
enum
{
M68K_D0_REGNUM = 0,
+ M68K_D1_REGNUM = 1,
M68K_A0_REGNUM = 8,
M68K_A1_REGNUM = 9,
M68K_FP_REGNUM = 14, /* Contains address of executing stack frame */
@@ -44,6 +47,20 @@ enum
M68K_FPI_REGNUM = 28
};
+#define M68K_NUM_REGS (M68K_FPI_REGNUM + 1)
+
+/* Size of the largest register. */
+#define M68K_MAX_REGISTER_SIZE 12
+
+struct m68k_sigtramp_info
+{
+ /* Address of sigcontext. */
+ CORE_ADDR sigcontext_addr;
+
+ /* Offset of registers in `struct sigcontext'. */
+ int *sc_reg_offset;
+};
+
/* Target-dependent structure in gdbarch. */
struct gdbarch_tdep
{
@@ -52,6 +69,9 @@ struct gdbarch_tdep
int jb_pc;
/* The size of each entry in the jump buffer. */
size_t jb_elt_size;
+
+ /* Get info about sigtramp. */
+ struct m68k_sigtramp_info (*get_sigtramp_info) (struct frame_info *);
};
#endif /* M68K_TDEP_H */
diff --git a/gdb/m68klinux-nat.c b/gdb/m68klinux-nat.c
index 86e22b7..cfe9dab 100644
--- a/gdb/m68klinux-nat.c
+++ b/gdb/m68klinux-nat.c
@@ -140,23 +140,25 @@ fetch_register (int regno)
if (CANNOT_FETCH_REGISTER (regno))
{
- memset (buf, '\0', REGISTER_RAW_SIZE (regno)); /* Supply zeroes */
+ memset (buf, '\0', register_size (current_gdbarch, regno)); /* Supply zeroes */
supply_register (regno, buf);
return;
}
/* Overload thread id onto process id */
- if ((tid = TIDGET (inferior_ptid)) == 0)
+ tid = TIDGET (inferior_ptid);
+ if (tid == 0)
tid = PIDGET (inferior_ptid); /* no thread id, just use process id */
offset = U_REGS_OFFSET;
regaddr = register_addr (regno, offset);
- for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
+ for (i = 0; i < register_size (current_gdbarch, regno);
+ i += sizeof (PTRACE_XFER_TYPE))
{
errno = 0;
- *(PTRACE_XFER_TYPE *) & buf[i] = ptrace (PT_READ_U, tid,
- (PTRACE_ARG3_TYPE) regaddr, 0);
+ *(PTRACE_XFER_TYPE *) &buf[i] = ptrace (PT_READ_U, tid,
+ (PTRACE_ARG3_TYPE) regaddr, 0);
regaddr += sizeof (PTRACE_XFER_TYPE);
if (errno != 0)
{
@@ -207,7 +209,8 @@ store_register (int regno)
}
/* Overload thread id onto process id */
- if ((tid = TIDGET (inferior_ptid)) == 0)
+ tid = TIDGET (inferior_ptid);
+ if (tid == 0)
tid = PIDGET (inferior_ptid); /* no thread id, just use process id */
offset = U_REGS_OFFSET;
@@ -218,7 +221,8 @@ store_register (int regno)
regcache_collect (regno, buf);
/* Store the local buffer into the inferior a chunk at the time. */
- for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE))
+ for (i = 0; i < register_size (current_gdbarch, regno);
+ i += sizeof (PTRACE_XFER_TYPE))
{
errno = 0;
ptrace (PT_WRITE_U, tid, (PTRACE_ARG3_TYPE) regaddr,
@@ -293,7 +297,7 @@ fill_gregset (elf_gregset_t *gregsetp, int regno)
int i;
for (i = 0; i < NUM_GREGS; i++)
- if ((regno == -1 || regno == i))
+ if (regno == -1 || regno == i)
regcache_collect (i, regp + regmap[i]);
}
@@ -450,7 +454,8 @@ fetch_inferior_registers (int regno)
}
/* GNU/Linux LWP ID's are process ID's. */
- if ((tid = TIDGET (inferior_ptid)) == 0)
+ tid = TIDGET (inferior_ptid);
+ if (tid == 0)
tid = PIDGET (inferior_ptid); /* Not a threaded program. */
/* Use the PTRACE_GETFPXREGS request whenever possible, since it
@@ -505,7 +510,8 @@ store_inferior_registers (int regno)
}
/* GNU/Linux LWP ID's are process ID's. */
- if ((tid = TIDGET (inferior_ptid)) == 0)
+ tid = TIDGET (inferior_ptid);
+ if (tid == 0)
tid = PIDGET (inferior_ptid); /* Not a threaded program. */
/* Use the PTRACE_SETFPREGS requests whenever possible, since it
diff --git a/gdb/m68klinux-tdep.c b/gdb/m68klinux-tdep.c
index 1fa9f74..422f9af 100644
--- a/gdb/m68klinux-tdep.c
+++ b/gdb/m68klinux-tdep.c
@@ -22,6 +22,8 @@
#include "defs.h"
#include "gdbcore.h"
+#include "doublest.h"
+#include "floatformat.h"
#include "frame.h"
#include "target.h"
#include "gdb_string.h"
@@ -51,9 +53,9 @@
/* moveq #82,d0; notb d0; trap #0 */ \
|| (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
-/* Return non-zero if PC points into the signal trampoline. For the sake
- of m68k_linux_frame_saved_pc we also distinguish between non-RT and RT
- signal trampolines. */
+/* Return non-zero if PC points into the signal trampoline. For the
+ sake of m68k_linux_get_sigtramp_info we also distinguish between
+ non-RT and RT signal trampolines. */
static int
m68k_linux_pc_in_sigtramp (CORE_ADDR pc, char *name)
@@ -87,100 +89,183 @@ m68k_linux_pc_in_sigtramp (CORE_ADDR pc, char *name)
return 0;
}
-/* Offset to saved PC in sigcontext, from <asm/sigcontext.h>. */
-#define SIGCONTEXT_PC_OFFSET 26
-
-/* Offset to saved PC in ucontext, from <asm/ucontext.h>. */
-#define UCONTEXT_PC_OFFSET 88
-
-/* Get saved user PC for sigtramp from sigcontext or ucontext. */
-
-static CORE_ADDR
-m68k_linux_sigtramp_saved_pc (struct frame_info *frame)
+/* From <asm/sigcontext.h>. */
+static int m68k_linux_sigcontext_reg_offset[M68K_NUM_REGS] =
{
- CORE_ADDR sigcontext_addr;
- char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
- int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
- int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
+ 2 * 4, /* %d0 */
+ 3 * 4, /* %d1 */
+ -1, /* %d2 */
+ -1, /* %d3 */
+ -1, /* %d4 */
+ -1, /* %d5 */
+ -1, /* %d6 */
+ -1, /* %d7 */
+ 4 * 4, /* %a0 */
+ 5 * 4, /* %a1 */
+ -1, /* %a2 */
+ -1, /* %a3 */
+ -1, /* %a4 */
+ -1, /* %a5 */
+ -1, /* %fp */
+ 1 * 4, /* %sp */
+ 5 * 4 + 2, /* %sr */
+ 6 * 4 + 2, /* %pc */
+ 8 * 4, /* %fp0 */
+ 11 * 4, /* %fp1 */
+ -1, /* %fp2 */
+ -1, /* %fp3 */
+ -1, /* %fp4 */
+ -1, /* %fp5 */
+ -1, /* %fp6 */
+ -1, /* %fp7 */
+ 14 * 4, /* %fpcr */
+ 15 * 4, /* %fpsr */
+ 16 * 4 /* %fpiaddr */
+};
+
+/* From <asm/ucontext.h>. */
+static int m68k_linux_ucontext_reg_offset[M68K_NUM_REGS] =
+{
+ 6 * 4, /* %d0 */
+ 7 * 4, /* %d1 */
+ 8 * 4, /* %d2 */
+ 9 * 4, /* %d3 */
+ 10 * 4, /* %d4 */
+ 11 * 4, /* %d5 */
+ 12 * 4, /* %d6 */
+ 13 * 4, /* %d7 */
+ 14 * 4, /* %a0 */
+ 15 * 4, /* %a1 */
+ 16 * 4, /* %a2 */
+ 17 * 4, /* %a3 */
+ 18 * 4, /* %a4 */
+ 19 * 4, /* %a5 */
+ 20 * 4, /* %fp */
+ 21 * 4, /* %sp */
+ 23 * 4, /* %sr */
+ 22 * 4, /* %pc */
+ 27 * 4, /* %fp0 */
+ 30 * 4, /* %fp1 */
+ 33 * 4, /* %fp2 */
+ 36 * 4, /* %fp3 */
+ 39 * 4, /* %fp4 */
+ 42 * 4, /* %fp5 */
+ 45 * 4, /* %fp6 */
+ 48 * 4, /* %fp7 */
+ 24 * 4, /* %fpcr */
+ 25 * 4, /* %fpsr */
+ 26 * 4 /* %fpiaddr */
+};
+
+
+/* Get info about saved registers in sigtramp. */
+
+static struct m68k_sigtramp_info
+m68k_linux_get_sigtramp_info (struct frame_info *next_frame)
+{
+ CORE_ADDR sp;
+ char buf[4];
+ struct m68k_sigtramp_info info;
+
+ frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
+ sp = extract_unsigned_integer (buf, 4);
/* Get sigcontext address, it is the third parameter on the stack. */
- if (get_next_frame (frame))
- sigcontext_addr
- = read_memory_unsigned_integer (get_frame_base (get_next_frame (frame))
- + FRAME_ARGS_SKIP
- + sigcontext_offs,
- ptrbytes);
- else
- sigcontext_addr
- = read_memory_unsigned_integer (read_register (SP_REGNUM)
- + sigcontext_offs,
- ptrbytes);
-
- /* Don't cause a memory_error when accessing sigcontext in case the
- stack layout has changed or the stack is corrupt. */
- if (m68k_linux_pc_in_sigtramp (get_frame_pc (frame), 0) == 2)
- target_read_memory (sigcontext_addr + UCONTEXT_PC_OFFSET, buf, ptrbytes);
+ info.sigcontext_addr = read_memory_unsigned_integer (sp + 8, 4);
+
+ if (m68k_linux_pc_in_sigtramp (frame_pc_unwind (next_frame), 0) == 2)
+ info.sc_reg_offset = m68k_linux_ucontext_reg_offset;
else
- target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
- return extract_unsigned_integer (buf, ptrbytes);
+ info.sc_reg_offset = m68k_linux_sigcontext_reg_offset;
+ return info;
}
-/* Return the saved program counter for FRAME. */
+/* Extract from an array REGBUF containing the (raw) register state, a
+ function return value of TYPE, and copy that, in virtual format,
+ into VALBUF. */
-static CORE_ADDR
-m68k_linux_frame_saved_pc (struct frame_info *frame)
+static void
+m68k_linux_extract_return_value (struct type *type, struct regcache *regcache,
+ void *valbuf)
{
- if (get_frame_type (frame) == SIGTRAMP_FRAME)
- return m68k_linux_sigtramp_saved_pc (frame);
-
- return read_memory_unsigned_integer (get_frame_base (frame) + 4, 4);
-}
+ int len = TYPE_LENGTH (type);
+ char buf[M68K_MAX_REGISTER_SIZE];
-/* The following definitions are appropriate when using the ELF
- format, where floating point values are returned in fp0, pointer
- values in a0 and other values in d0. */
-
-/* Extract from an array REGBUF containing the (raw) register state a
- function return value of type TYPE, and copy that, in virtual
- format, into VALBUF. */
+ if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ && TYPE_NFIELDS (type) == 1)
+ {
+ m68k_linux_extract_return_value (TYPE_FIELD_TYPE (type, 0), regcache,
+ valbuf);
+ return;
+ }
-static void
-m68k_linux_extract_return_value (struct type *type, char *regbuf, char *valbuf)
-{
if (TYPE_CODE (type) == TYPE_CODE_FLT)
{
- DEPRECATED_REGISTER_CONVERT_TO_VIRTUAL (FP0_REGNUM, type,
- regbuf + REGISTER_BYTE (FP0_REGNUM),
- valbuf);
+ regcache_raw_read (regcache, M68K_FP0_REGNUM, buf);
+ convert_typed_floating (buf, builtin_type_m68881_ext, valbuf, type);
}
else if (TYPE_CODE (type) == TYPE_CODE_PTR)
- memcpy (valbuf, regbuf + REGISTER_BYTE (M68K_A0_REGNUM),
- TYPE_LENGTH (type));
+ regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf);
else
- memcpy (valbuf,
- regbuf + (TYPE_LENGTH (type) >= 4 ? 0 : 4 - TYPE_LENGTH (type)),
- TYPE_LENGTH (type));
+ {
+ if (len <= 4)
+ {
+ regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
+ memcpy (valbuf, buf + (4 - len), len);
+ }
+ else if (len <= 8)
+ {
+ regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
+ memcpy (valbuf, buf + (8 - len), len - 4);
+ regcache_raw_read (regcache, M68K_D1_REGNUM,
+ (char *) valbuf + (len - 4));
+ }
+ else
+ internal_error (__FILE__, __LINE__,
+ "Cannot extract return value of %d bytes long.", len);
+ }
}
-/* Write into appropriate registers a function return value of type
- TYPE, given in virtual format. */
+/* Write into the appropriate registers a function return value stored
+ in VALBUF of type TYPE, given in virtual format. */
static void
-m68k_linux_store_return_value (struct type *type, char *valbuf)
+m68k_linux_store_return_value (struct type *type, struct regcache *regcache,
+ const void *valbuf)
{
+ int len = TYPE_LENGTH (type);
+
+ if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ && TYPE_NFIELDS (type) == 1)
+ {
+ m68k_linux_store_return_value (TYPE_FIELD_TYPE (type, 0), regcache,
+ valbuf);
+ return;
+ }
+
if (TYPE_CODE (type) == TYPE_CODE_FLT)
{
- char raw_buffer[REGISTER_RAW_SIZE (FP0_REGNUM)];
- DEPRECATED_REGISTER_CONVERT_TO_RAW (type, FP0_REGNUM, valbuf, raw_buffer);
- deprecated_write_register_bytes (REGISTER_BYTE (FP0_REGNUM),
- raw_buffer, TYPE_LENGTH (type));
+ char buf[M68K_MAX_REGISTER_SIZE];
+ convert_typed_floating (valbuf, type, buf, builtin_type_m68881_ext);
+ regcache_raw_write (regcache, M68K_FP0_REGNUM, buf);
}
+ else if (TYPE_CODE (type) == TYPE_CODE_PTR)
+ regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf);
else
{
- if (TYPE_CODE (type) == TYPE_CODE_PTR)
- deprecated_write_register_bytes (REGISTER_BYTE (M68K_A0_REGNUM),
- valbuf, TYPE_LENGTH (type));
- deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (type));
+ if (len <= 4)
+ regcache_raw_write_part (regcache, M68K_D0_REGNUM,
+ 4 - len, len, valbuf);
+ else if (len <= 8)
+ {
+ regcache_raw_write_part (regcache, M68K_D1_REGNUM, 8 - len,
+ len - 4, valbuf);
+ regcache_raw_write (regcache, M68K_D0_REGNUM,
+ (char *) valbuf + (len - 4));
+ }
+ else
+ internal_error (__FILE__, __LINE__,
+ "Cannot store return value of %d bytes long.", len);
}
}
@@ -189,9 +274,12 @@ m68k_linux_store_return_value (struct type *type, char *valbuf)
as a CORE_ADDR. */
static CORE_ADDR
-m68k_linux_extract_struct_value_address (char *regbuf)
+m68k_linux_extract_struct_value_address (struct regcache *regcache)
{
- return *(CORE_ADDR *) (regbuf + REGISTER_BYTE (M68K_A0_REGNUM));
+ char buf[4];
+
+ regcache_cooked_read (regcache, M68K_A0_REGNUM, buf);
+ return extract_unsigned_integer (buf, 4);
}
static void
@@ -201,15 +289,12 @@ m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
tdep->jb_pc = M68K_LINUX_JB_PC;
tdep->jb_elt_size = M68K_LINUX_JB_ELEMENT_SIZE;
+ tdep->get_sigtramp_info = m68k_linux_get_sigtramp_info;
- set_gdbarch_deprecated_frame_saved_pc (gdbarch,
- m68k_linux_frame_saved_pc);
- set_gdbarch_deprecated_extract_return_value (gdbarch,
- m68k_linux_extract_return_value);
- set_gdbarch_deprecated_store_return_value (gdbarch,
- m68k_linux_store_return_value);
- set_gdbarch_deprecated_extract_struct_value_address (gdbarch,
- m68k_linux_extract_struct_value_address);
+ set_gdbarch_extract_return_value (gdbarch, m68k_linux_extract_return_value);
+ set_gdbarch_store_return_value (gdbarch, m68k_linux_store_return_value);
+ set_gdbarch_extract_struct_value_address (gdbarch,
+ m68k_linux_extract_struct_value_address);
set_gdbarch_pc_in_sigtramp (gdbarch, m68k_linux_pc_in_sigtramp);