[PATCH]: Use gdbarch_tdep for 68hc11 specific data (stack_correction global)
Stephane Carrez
Stephane.Carrez@worldnet.fr
Fri Nov 24 13:00:00 GMT 2000
Hi!
Andrew Cagney <ac131313@cygnus.com> wrote:
> Can I encourage you to create ``struct gdbarch_tdep'' object and put
> this value in there. Eventually gdb is going to have more than one
> active GDB architecture and when that happens static variables just
> won't work :-(
As suggested by Andrew, I've commited the patch below to move the
'stack_correction' static variable in the gdbarch_tdep structure.
Stephane
2000-11-24 Stephane Carrez <Stephane.Carrez@worldnet.fr>
* m68hc11-tdep.c (gdbarch_tdep): Move stack_correction global to here.
(STACK_CORRECTION): Get stack correction using gdbarch_tdep.
(m68hc11_saved_pc_after_call): Use STACK_CORRECTION.
(m68hc11_frame_chain): Likewise.
(m68hc11_frame_init_saved_regs): Likewise.
(m68hc11_init_extra_frame_info): Likewise.
(m68hc11_push_arguments): Likewise.
(m68hc11_push_arguments): Likewise.
(m68hc11_store_struct_return): Likewise.
(m68hc11_push_return_address): Likewise.
(m68hc11_gdbarch_init): Setup stack_correction according to arch.
Index: m68hc11-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/m68hc11-tdep.c,v
retrieving revision 1.6
diff -p -r1.6 m68hc11-tdep.c
*** m68hc11-tdep.c 2000/09/06 19:39:10 1.6
--- m68hc11-tdep.c 2000/11/24 20:55:39
*************** struct gdbarch_tdep
*** 81,88 ****
--- 81,97 ----
{
/* from the elf header */
int elf_flags;
+
+ /* Stack pointer correction value. For 68hc11, the stack pointer points
+ to the next push location. An offset of 1 must be applied to obtain
+ the address where the last value is saved. For 68hc12, the stack
+ pointer points to the last value pushed. No offset is necessary. */
+ int stack_correction;
};
+ #define M6811_TDEP gdbarch_tdep (current_gdbarch)
+ #define STACK_CORRECTION (M6811_TDEP->stack_correction)
+
struct frame_extra_info
{
int frame_reg;
*************** static int soft_min_addr;
*** 120,131 ****
static int soft_max_addr;
static int soft_reg_initialized = 0;
- /* Stack pointer correction value. For 68hc11, the stack pointer points
- to the next push location. An offset of 1 must be applied to obtain
- the address where the last value is saved. For 68hc12, the stack
- pointer points to the last value pushed. No offset is necessary. */
- static int stack_correction = 1;
-
/* Look in the symbol table for the address of a pseudo register
in memory. If we don't find it, pretend the register is not used
and not available. */
--- 129,134 ----
*************** m68hc11_saved_pc_after_call (struct fram
*** 281,287 ****
{
CORE_ADDR addr;
! addr = read_register (HARD_SP_REGNUM) + stack_correction;
addr &= 0x0ffff;
return read_memory_integer (addr, 2) & 0x0FFFF;
}
--- 284,290 ----
{
CORE_ADDR addr;
! addr = read_register (HARD_SP_REGNUM) + STACK_CORRECTION;
addr &= 0x0ffff;
return read_memory_integer (addr, 2) & 0x0FFFF;
}
*************** m68hc11_frame_chain (struct frame_info *
*** 634,640 ****
return (CORE_ADDR) 0;
}
! addr = frame->frame + frame->extra_info->size + stack_correction - 2;
addr = read_memory_unsigned_integer (addr, 2) & 0x0FFFF;
if (addr == 0)
{
--- 637,643 ----
return (CORE_ADDR) 0;
}
! addr = frame->frame + frame->extra_info->size + STACK_CORRECTION - 2;
addr = read_memory_unsigned_integer (addr, 2) & 0x0FFFF;
if (addr == 0)
{
*************** m68hc11_frame_init_saved_regs (struct fr
*** 664,670 ****
m68hc11_guess_from_prologue (pc, fi->frame, &pc, &fi->extra_info->size,
fi->saved_regs);
! addr = fi->frame + fi->extra_info->size + stack_correction;
fi->saved_regs[SOFT_FP_REGNUM] = addr - 2;
fi->saved_regs[HARD_SP_REGNUM] = addr;
fi->saved_regs[HARD_PC_REGNUM] = fi->saved_regs[HARD_SP_REGNUM];
--- 667,673 ----
m68hc11_guess_from_prologue (pc, fi->frame, &pc, &fi->extra_info->size,
fi->saved_regs);
! addr = fi->frame + fi->extra_info->size + STACK_CORRECTION;
fi->saved_regs[SOFT_FP_REGNUM] = addr - 2;
fi->saved_regs[HARD_SP_REGNUM] = addr;
fi->saved_regs[HARD_PC_REGNUM] = fi->saved_regs[HARD_SP_REGNUM];
*************** m68hc11_init_extra_frame_info (int froml
*** 689,695 ****
}
else
{
! addr = fi->frame + fi->extra_info->size + stack_correction;
addr = read_memory_unsigned_integer (addr, 2) & 0x0ffff;
fi->extra_info->return_pc = addr;
#if 0
--- 692,698 ----
}
else
{
! addr = fi->frame + fi->extra_info->size + STACK_CORRECTION;
addr = read_memory_unsigned_integer (addr, 2) & 0x0ffff;
fi->extra_info->return_pc = addr;
#if 0
*************** m68hc11_push_arguments (int nargs,
*** 777,783 ****
/* 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);
}
else if (nargs > 0)
{
--- 780,786 ----
/* 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);
}
else if (nargs > 0)
{
*************** m68hc11_push_arguments (int nargs,
*** 804,810 ****
}
sp -= stack_alloc;
! stack_offset = stack_correction;
for (argnum = first_stack_argnum; argnum < nargs; argnum++)
{
type = VALUE_TYPE (args[argnum]);
--- 807,813 ----
}
sp -= stack_alloc;
! stack_offset = STACK_CORRECTION;
for (argnum = first_stack_argnum; argnum < nargs; argnum++)
{
type = VALUE_TYPE (args[argnum]);
*************** m68hc11_store_struct_return (CORE_ADDR a
*** 845,851 ****
/* The struct address computed by gdb is on the stack.
It uses the stack pointer so we must apply the stack
correction offset. */
! write_register (HARD_D_REGNUM, addr + stack_correction);
}
static void
--- 848,854 ----
/* The struct address computed by gdb is on the stack.
It uses the stack pointer so we must apply the stack
correction offset. */
! write_register (HARD_D_REGNUM, addr + STACK_CORRECTION);
}
static void
*************** m68hc11_push_return_address (CORE_ADDR p
*** 944,950 ****
pc = CALL_DUMMY_ADDRESS ();
sp -= 2;
store_unsigned_integer (valbuf, 2, pc);
! write_memory (sp + stack_correction, valbuf, 2);
return sp;
}
--- 947,953 ----
pc = CALL_DUMMY_ADDRESS ();
sp -= 2;
store_unsigned_integer (valbuf, 2, pc);
! write_memory (sp + STACK_CORRECTION, valbuf, 2);
return sp;
}
*************** m68hc11_gdbarch_init (struct gdbarch_inf
*** 993,999 ****
--- 996,1015 ----
tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
gdbarch = gdbarch_alloc (&info, tdep);
tdep->elf_flags = elf_flags;
+ switch (info.bfd_arch_info->arch)
+ {
+ case bfd_arch_m68hc11:
+ tdep->stack_correction = 1;
+ break;
+ case bfd_arch_m68hc12:
+ tdep->stack_correction = 0;
+ break;
+
+ default:
+ break;
+ }
+
/* Initially set everything according to the ABI. */
set_gdbarch_short_bit (gdbarch, 16);
set_gdbarch_int_bit (gdbarch, 32);
More information about the Gdb-patches
mailing list