This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH]: Convert m6811 to push_dummy_call (frame + regcache)
- From: Stephane Carrez <stcarrez at nerim dot fr>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 27 Jul 2003 22:30:16 +0200
- Subject: [PATCH]: Convert m6811 to push_dummy_call (frame + regcache)
Hi!
I've converted the HC11/HC12 to use the regcache and the new frame unwind mechanism.
The testsuite showed no regression and even solved few problems. So, I'm committing the
changes to mainline and 6_0. This is a first part (hopefully self contained?).
This patch converts the push_arguments to the new push_dummy_frame().
I've followed more or less m68k and i386. There is still a limitation (that existed before)
where calling a function which uses paged-memory calling convention will not work.
Committed on mainline and 6_0.
Stephane
2003-07-27 Stephane Carrez <stcarrez@nerim.fr>
* m68hc11-tdep.c (m68hc11_push_dummy_call): New function adapted
from m68hc11_push_arguments.
(m68hc11_push_arguments): Remove.
(m68hc11_push_return_address): Remove.
(m68hc11_gdbarch_init): Install the above; remove above deprecated
handlers; remove deprecated_extra_stack_alignment_needed.
Index: m68hc11-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/m68hc11-tdep.c,v
retrieving revision 1.83
diff -u -p -r1.83 m68hc11-tdep.c
--- m68hc11-tdep.c 26 Jul 2003 22:49:15 -0000 1.83
+++ m68hc11-tdep.c 27 Jul 2003 20:11:46 -0000
@@ -1094,72 +1094,81 @@ m68hc11_stack_align (CORE_ADDR addr)
}
static CORE_ADDR
-m68hc11_push_arguments (int nargs,
- struct value **args,
- CORE_ADDR sp,
- int struct_return,
- CORE_ADDR struct_addr)
+m68hc11_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)
{
- int stack_alloc;
int argnum;
int first_stack_argnum;
- int stack_offset;
struct type *type;
char *val;
int len;
+ char buf[2];
- stack_alloc = 0;
first_stack_argnum = 0;
if (struct_return)
{
/* The struct is allocated on the stack and gdb used the stack
pointer for the address of that struct. We must apply the
stack offset on the address. */
- write_register (HARD_D_REGNUM, struct_addr + STACK_CORRECTION);
+ regcache_cooked_write_unsigned (regcache, HARD_D_REGNUM,
+ struct_addr + STACK_CORRECTION);
}
else if (nargs > 0)
{
type = VALUE_TYPE (args[0]);
len = TYPE_LENGTH (type);
-
+
/* First argument is passed in D and X registers. */
if (len <= 4)
{
- LONGEST v = extract_unsigned_integer (VALUE_CONTENTS (args[0]), len);
+ ULONGEST v;
+
+ v = extract_unsigned_integer (VALUE_CONTENTS (args[0]), len);
first_stack_argnum = 1;
- write_register (HARD_D_REGNUM, v);
+
+ regcache_cooked_write_unsigned (regcache, HARD_D_REGNUM, v);
if (len > 2)
{
v >>= 16;
- write_register (HARD_X_REGNUM, v);
+ regcache_cooked_write_unsigned (regcache, HARD_X_REGNUM, v);
}
}
}
- for (argnum = first_stack_argnum; argnum < nargs; argnum++)
- {
- type = VALUE_TYPE (args[argnum]);
- stack_alloc += (TYPE_LENGTH (type) + 1) & -2;
- }
- sp -= stack_alloc;
- stack_offset = STACK_CORRECTION;
- for (argnum = first_stack_argnum; argnum < nargs; argnum++)
+ for (argnum = nargs - 1; argnum >= first_stack_argnum; argnum--)
{
type = VALUE_TYPE (args[argnum]);
len = TYPE_LENGTH (type);
- val = (char*) VALUE_CONTENTS (args[argnum]);
- write_memory (sp + stack_offset, val, len);
- stack_offset += len;
if (len & 1)
{
static char zero = 0;
- write_memory (sp + stack_offset, &zero, 1);
- stack_offset++;
+ sp--;
+ write_memory (sp, &zero, 1);
}
+ val = (char*) VALUE_CONTENTS (args[argnum]);
+ sp -= len;
+ write_memory (sp, val, len);
}
- return sp;
+
+ /* Store return address. */
+ sp -= 2;
+ store_unsigned_integer (buf, 2, bp_addr);
+ write_memory (sp, buf, 2);
+
+ /* Finally, update the stack pointer... */
+ sp -= STACK_CORRECTION;
+ regcache_cooked_write_unsigned (regcache, HARD_SP_REGNUM, sp);
+
+ /* ...and fake a frame pointer. */
+ regcache_cooked_write_unsigned (regcache, SOFT_FP_REGNUM, sp);
+
+ /* DWARF2/GCC uses the stack address *before* the function call as a
+ frame's CFA. */
+ return sp + 2;
}
@@ -1281,22 +1290,6 @@ m68hc11_extract_struct_value_address (st
return extract_unsigned_integer (buf, M68HC11_REG_SIZE);
}
-/* Function: push_return_address (pc)
- Set up the return address for the inferior function call.
- Needed for targets where we don't actually execute a JSR/BSR instruction */
-
-static CORE_ADDR
-m68hc11_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
-{
- char valbuf[2];
-
- pc = CALL_DUMMY_ADDRESS ();
- sp -= 2;
- store_unsigned_integer (valbuf, 2, pc);
- write_memory (sp + STACK_CORRECTION, valbuf, 2);
- return sp;
-}
-
/* Test whether the ELF symbol corresponds to a function using rtc or
rti to return. */
@@ -1385,8 +1378,6 @@ static struct gdbarch *
m68hc11_gdbarch_init (struct gdbarch_info info,
struct gdbarch_list *arches)
{
- static LONGEST m68hc11_call_dummy_words[] =
- {0};
struct gdbarch *gdbarch;
struct gdbarch_tdep *tdep;
int elf_flags;
@@ -1482,12 +1473,10 @@ m68hc11_gdbarch_init (struct gdbarch_inf
set_gdbarch_pseudo_register_read (gdbarch, m68hc11_pseudo_register_read);
set_gdbarch_pseudo_register_write (gdbarch, m68hc11_pseudo_register_write);
- set_gdbarch_deprecated_call_dummy_words (gdbarch, m68hc11_call_dummy_words);
- set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, sizeof (m68hc11_call_dummy_words));
+ set_gdbarch_push_dummy_call (gdbarch, m68hc11_push_dummy_call);
+
set_gdbarch_deprecated_get_saved_register (gdbarch, deprecated_generic_get_saved_register);
set_gdbarch_extract_return_value (gdbarch, m68hc11_extract_return_value);
- set_gdbarch_deprecated_push_arguments (gdbarch, m68hc11_push_arguments);
- set_gdbarch_deprecated_push_return_address (gdbarch, m68hc11_push_return_address);
set_gdbarch_return_value_on_stack (gdbarch, m68hc11_return_value_on_stack);
set_gdbarch_deprecated_store_struct_return (gdbarch, m68hc11_store_struct_return);
@@ -1513,7 +1502,6 @@ m68hc11_gdbarch_init (struct gdbarch_inf
set_gdbarch_function_start_offset (gdbarch, 0);
set_gdbarch_breakpoint_from_pc (gdbarch, m68hc11_breakpoint_from_pc);
set_gdbarch_stack_align (gdbarch, m68hc11_stack_align);
- set_gdbarch_deprecated_extra_stack_alignment_needed (gdbarch, 1);
set_gdbarch_print_insn (gdbarch, gdb_print_insn_m68hc11);
m68hc11_add_reggroups (gdbarch);