+\f
+/* Return the address of a system call's alternative return
+ address. */
+
+static CORE_ADDR
+sparc64_linux_step_trap (struct frame_info *frame, unsigned long insn)
+{
+ if (insn == 0x91d0206d)
+ {
+ struct gdbarch *gdbarch = get_frame_arch (frame);
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
+ ULONGEST sp = get_frame_register_unsigned (frame, SPARC_SP_REGNUM);
+ if (sp & 1)
+ sp += BIAS;
+
+ /* The kernel puts the sigreturn registers on the stack,
+ and this is where the signal unwinding state is take from
+ when returning from a signal.
+
+ A siginfo_t sits 192 bytes from the base of the stack. This
+ siginfo_t is 128 bytes, and is followed by the sigreturn
+ register save area. The saved PC sits at a 136 byte offset
+ into there. */
+
+ return read_memory_unsigned_integer (sp + 192 + 128 + 136,
+ 8, byte_order);
+ }
+
+ return 0;
+}
+\f
+
+const struct sparc_gregset sparc64_linux_core_gregset =
+{
+ 32 * 8, /* %tstate */
+ 33 * 8, /* %tpc */
+ 34 * 8, /* %tnpc */
+ 35 * 8, /* %y */
+ -1, /* %wim */
+ -1, /* %tbr */
+ 1 * 8, /* %g1 */
+ 16 * 8, /* %l0 */
+ 8, /* y size */
+};
+\f
+
+static void
+sparc64_linux_supply_core_gregset (const struct regset *regset,
+ struct regcache *regcache,
+ int regnum, const void *gregs, size_t len)
+{
+ sparc64_supply_gregset (&sparc64_linux_core_gregset,
+ regcache, regnum, gregs);
+}
+
+static void
+sparc64_linux_collect_core_gregset (const struct regset *regset,
+ const struct regcache *regcache,
+ int regnum, void *gregs, size_t len)
+{
+ sparc64_collect_gregset (&sparc64_linux_core_gregset,
+ regcache, regnum, gregs);
+}
+
+static void
+sparc64_linux_supply_core_fpregset (const struct regset *regset,
+ struct regcache *regcache,
+ int regnum, const void *fpregs, size_t len)
+{
+ sparc64_supply_fpregset (&sparc64_bsd_fpregset, regcache, regnum, fpregs);
+}
+
+static void
+sparc64_linux_collect_core_fpregset (const struct regset *regset,
+ const struct regcache *regcache,
+ int regnum, void *fpregs, size_t len)
+{
+ sparc64_collect_fpregset (&sparc64_bsd_fpregset, regcache, regnum, fpregs);
+}
+
+/* Set the program counter for process PTID to PC. */
+
+#define TSTATE_SYSCALL 0x0000000000000020ULL
+
+static void
+sparc64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
+{
+ struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
+ ULONGEST state;
+
+ regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
+ regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
+
+ /* Clear the "in syscall" bit to prevent the kernel from
+ messing with the PCs we just installed, if we happen to be
+ within an interrupted system call that the kernel wants to
+ restart.
+
+ Note that after we return from the dummy call, the TSTATE et al.
+ registers will be automatically restored, and the kernel
+ continues to restart the system call at this point. */
+ regcache_cooked_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
+ state &= ~TSTATE_SYSCALL;
+ regcache_cooked_write_unsigned (regcache, SPARC64_STATE_REGNUM, state);
+}
+
+static LONGEST
+sparc64_linux_get_syscall_number (struct gdbarch *gdbarch,
+ ptid_t ptid)
+{
+ struct regcache *regcache = get_thread_regcache (ptid);
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ /* The content of a register. */
+ gdb_byte buf[8];
+ /* The result. */
+ LONGEST ret;
+
+ /* Getting the system call number from the register.
+ When dealing with the sparc architecture, this information
+ is stored at the %g1 register. */
+ regcache_cooked_read (regcache, SPARC_G1_REGNUM, buf);
+
+ ret = extract_signed_integer (buf, 8, byte_order);
+
+ return ret;
+}
+