struct regcache *regcache,
int regnum, const void *gregs_buf, size_t len)
{
- const gdb_byte *gregs = gregs_buf;
+ const gdb_byte *gregs = (const gdb_byte *) gregs_buf;
int regno;
static const gdb_byte zero_buf[4] = {0, 0, 0, 0};
const struct regcache *regcache,
int regnum, void *gregs_buf, size_t len)
{
- gdb_byte *gregs = gregs_buf;
+ gdb_byte *gregs = (gdb_byte *) gregs_buf;
int regno;
for (regno = NIOS2_Z_REGNUM; regno <= NIOS2_MPUACC_REGNUM; regno++)
}
/* Initialize a trad-frame cache corresponding to the tramp-frame.
- FUNC is the address of the instruction TRAMP[0] in memory. */
+ FUNC is the address of the instruction TRAMP[0] in memory.
+
+ This ABI is not documented. It corresponds to rt_setup_ucontext in
+ the kernel arch/nios2/kernel/signal.c file.
+
+ The key points are:
+ - The kernel creates a trampoline at the hard-wired address 0x1044.
+ - The stack pointer points to an object of type struct rt_sigframe.
+ The definition of this structure is not exported from the kernel.
+ The register save area is located at offset 152 bytes (as determined
+ by inspection of the stack contents in the debugger), and the
+ registers are saved as r1-r23, ra, fp, gp, ea, sp.
+
+ This interface was implemented with kernel version 3.19 (the first
+ official mainline kernel). Older unofficial kernel versions used
+ incompatible conventions; we do not support those here. */
+
+#define NIOS2_SIGRETURN_TRAMP_ADDR 0x1044
+#define NIOS2_SIGRETURN_REGSAVE_OFFSET 152
static void
nios2_linux_rt_sigreturn_init (const struct tramp_frame *self,
struct trad_frame_cache *this_cache,
CORE_ADDR func)
{
- CORE_ADDR base = func + 41 * 4;
+ CORE_ADDR sp = get_frame_register_unsigned (next_frame, NIOS2_SP_REGNUM);
+ CORE_ADDR base = sp + NIOS2_SIGRETURN_REGSAVE_OFFSET;
int i;
for (i = 0; i < 23; i++)
trad_frame_set_id (this_cache, frame_id_build (base, func));
}
-static struct tramp_frame nios2_linux_rt_sigreturn_tramp_frame =
+/* Trampoline for sigreturn. This has the form
+ movi r2, __NR_rt_sigreturn
+ trap 0
+ appropriately encoded for R1 or R2. */
+
+static struct tramp_frame nios2_r1_linux_rt_sigreturn_tramp_frame =
+{
+ SIGTRAMP_FRAME,
+ 4,
+ {
+ { MATCH_R1_MOVI | SET_IW_I_B (2) | SET_IW_I_IMM16 (139), -1 },
+ { MATCH_R1_TRAP | SET_IW_R_IMM5 (0), -1},
+ { TRAMP_SENTINEL_INSN }
+ },
+ nios2_linux_rt_sigreturn_init
+};
+
+static struct tramp_frame nios2_r2_linux_rt_sigreturn_tramp_frame =
{
SIGTRAMP_FRAME,
4,
{
- { 0x00800004 | (139 << 6), -1 }, /* movi r2,__NR_rt_sigreturn */
- { 0x003b683a, -1 }, /* trap */
+ { MATCH_R2_MOVI | SET_IW_F2I16_B (2) | SET_IW_F2I16_IMM16 (139), -1 },
+ { MATCH_R2_TRAP | SET_IW_X2L5_IMM5 (0), -1},
{ TRAMP_SENTINEL_INSN }
},
nios2_linux_rt_sigreturn_init
instruction to be executed. */
static CORE_ADDR
-nios2_linux_syscall_next_pc (struct frame_info *frame)
+nios2_linux_syscall_next_pc (struct frame_info *frame,
+ const struct nios2_opcode *op)
{
CORE_ADDR pc = get_frame_pc (frame);
ULONGEST syscall_nr = get_frame_register_unsigned (frame, NIOS2_R2_REGNUM);
if (syscall_nr == 139 /* rt_sigreturn */)
return frame_unwind_caller_pc (frame);
- return pc + NIOS2_OPCODE_SIZE;
+ return pc + op->size;
}
/* Hook function for gdbarch_register_osabi. */
set_gdbarch_iterate_over_regset_sections
(gdbarch, nios2_iterate_over_regset_sections);
/* Linux signal frame unwinders. */
- tramp_frame_prepend_unwinder (gdbarch,
- &nios2_linux_rt_sigreturn_tramp_frame);
+ if (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_nios2r2)
+ tramp_frame_prepend_unwinder (gdbarch,
+ &nios2_r2_linux_rt_sigreturn_tramp_frame);
+ else
+ tramp_frame_prepend_unwinder (gdbarch,
+ &nios2_r1_linux_rt_sigreturn_tramp_frame);
tdep->syscall_next_pc = nios2_linux_syscall_next_pc;
void
_initialize_nios2_linux_tdep (void)
{
- gdbarch_register_osabi (bfd_arch_nios2, 0, GDB_OSABI_LINUX,
- nios2_linux_init_abi);
+
+ const struct bfd_arch_info *arch_info;
+
+ for (arch_info = bfd_lookup_arch (bfd_arch_nios2, 0);
+ arch_info != NULL;
+ arch_info = arch_info->next)
+ gdbarch_register_osabi (bfd_arch_nios2, arch_info->mach,
+ GDB_OSABI_LINUX, nios2_linux_init_abi);
initialize_tdesc_nios2_linux ();
}