* sparc64-tdep.h (stryct_frame_info, struct trad_frame_saved_reg):
[deliverable/binutils-gdb.git] / gdb / amd64fbsd-nat.c
index 7880e58c48c2bb14bd391e9acbf26b6317153dab..edab8b567093b4e74e9b3378f37784c9c2339362 100644 (file)
@@ -1,5 +1,6 @@
 /* Native-dependent code for FreeBSD/amd64.
-   Copyright 2003 Free Software Foundation, Inc.
+
+   Copyright 2003, 2004 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -44,13 +45,14 @@ typedef struct fpreg fpregset_t;
 
 #include "gregset.h"
 #include "x86-64-tdep.h"
+#include "amd64-nat.h"
 \f
 
 /* Offset to the gregset_t location where REG is stored.  */
 #define REG_OFFSET(reg) offsetof (gregset_t, reg)
 
-/* At reg_offset[REGNO] you'll find the offset to the gregset_t
-   location where the GDB register REGNO is stored.  Unsupported
+/* At reg_offset[REGNUM] you'll find the offset to the gregset_t
+   location where the GDB register REGNUM is stored.  Unsupported
    registers are marked with `-1'.  */
 static int reg_offset[] =
 {
@@ -72,17 +74,34 @@ static int reg_offset[] =
   REG_OFFSET (r_r15),
   REG_OFFSET (r_rip),
   REG_OFFSET (r_rflags),
+  REG_OFFSET (r_cs),
+  REG_OFFSET (r_ss),
   -1,
   -1,
   -1,
   -1
 };
+\f
+
+/* Mapping between the general-purpose registers in FreeBSD/amd64
+   `struct reg' format and GDB's register cache layout for
+   FreeBSD/i386.
 
-#define REG_ADDR(regset, regno) ((char *) (regset) + reg_offset[regno])
+   Note that most FreeBSD/amd64 registers are 64-bit, while the
+   FreeBSD/i386 registers are all 32-bit, but since we're
+   little-endian we get away with that.  */
 
-/* Macro to determine if a register is fetched with PT_GETREGS.  */
-#define GETREGS_SUPPLIES(regno) \
-  ((0 <= (regno) && (regno) < X86_64_NUM_GREGS))
+/* From <machine/reg.h>.  */
+static int amd64fbsd32_r_reg_offset[I386_NUM_GREGS] =
+{
+  14 * 8, 13 * 8,              /* %eax, %ecx */
+  12 * 8, 11 * 8,              /* %edx, %ebx */
+  20 * 8, 10 * 8,              /* %esp, %ebp */
+  9 * 8, 8 * 8,                        /* %esi, %edi */
+  17 * 8, 19 * 8,              /* %eip, %eflags */
+  18 * 8, 21 * 8,              /* %cs, %ss */
+  -1, -1, -1, -1               /* %ds, %es, %fs, %gs */
+};
 \f
 
 /* Transfering the registers between GDB, inferiors and core files.  */
@@ -93,29 +112,17 @@ static int reg_offset[] =
 void
 supply_gregset (gregset_t *gregsetp)
 {
-  int i;
-
-  for (i = 0; i < X86_64_NUM_GREGS; i++)
-    {
-      if (reg_offset[i] == -1)
-       supply_register (i, NULL);
-      else
-       supply_register (i, REG_ADDR (gregsetp, i));
-    }
+  amd64_supply_native_gregset (current_regcache, gregsetp, -1);
 }
 
-/* Fill register REGNO (if it is a general-purpose register) in
-   *GREGSETPS with the value in GDB's register array.  If REGNO is -1,
+/* Fill register REGNUM (if it is a general-purpose register) in
+   *GREGSETPS with the value in GDB's register array.  If REGNUM is -1,
    do this for all registers.  */
 
 void
-fill_gregset (gregset_t *gregsetp, int regno)
+fill_gregset (gregset_t *gregsetp, int regnum)
 {
-  int i;
-
-  for (i = 0; i < X86_64_NUM_GREGS; i++)
-    if ((regno == -1 || regno == i) && reg_offset[i] != -1)
-      regcache_collect (i, REG_ADDR (gregsetp, i));
+  amd64_collect_native_gregset (current_regcache, gregsetp, regnum);
 }
 
 /* Fill GDB's register array with the floating-point register values
@@ -124,88 +131,17 @@ fill_gregset (gregset_t *gregsetp, int regno)
 void
 supply_fpregset (fpregset_t *fpregsetp)
 {
-  x86_64_supply_fxsave ((char *) fpregsetp);
+  x86_64_supply_fxsave (current_regcache, -1, fpregsetp);
 }
 
-/* Fill register REGNO (if it is a floating-point register) in
-   *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
+/* Fill register REGNUM (if it is a floating-point register) in
+   *FPREGSETP with the value in GDB's register array.  If REGNUM is -1,
    do this for all registers.  */
 
 void
-fill_fpregset (fpregset_t *fpregsetp, int regno)
+fill_fpregset (fpregset_t *fpregsetp, int regnum)
 {
-  x86_64_fill_fxsave ((char *) fpregsetp, regno);
-}
-
-/* Fetch register REGNO from the inferior.  If REGNO is -1, do this
-   for all registers (including the floating point registers).  */
-
-void
-fetch_inferior_registers (int regno)
-{
-  if (regno == -1 || GETREGS_SUPPLIES (regno))
-    {
-      gregset_t gregs;
-
-      if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
-                 (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
-       perror_with_name ("Couldn't get registers");
-
-      supply_gregset (&gregs);
-      if (regno != -1)
-       return;
-    }
-
-  if (regno == -1 || regno >= FP0_REGNUM)
-    {
-      fpregset_t fpregs;
-
-      if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
-                 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
-       perror_with_name ("Couldn't get floating point status");
-
-      supply_fpregset (&fpregs);
-    }
-}
-
-/* Store register REGNO back into the inferior.  If REGNO is -1, do
-   this for all registers (including the floating point registers).  */
-
-void
-store_inferior_registers (int regno)
-{
-  if (regno == -1 || GETREGS_SUPPLIES (regno))
-    {
-      gregset_t gregs;
-
-      if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
-                  (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
-        perror_with_name ("Couldn't get registers");
-
-      fill_gregset (&gregs, regno);
-
-      if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
-                 (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
-        perror_with_name ("Couldn't write registers");
-
-      if (regno != -1)
-       return;
-    }
-
-  if (regno == -1 || regno >= FP0_REGNUM)
-    {
-      fpregset_t fpregs;
-
-      if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
-                 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
-       perror_with_name ("Couldn't get floating point status");
-
-      fill_fpregset (&fpregs, regno);
-  
-      if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
-                 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
-       perror_with_name ("Couldn't write floating point status");
-    }
+  x86_64_fill_fxsave ((char *) fpregsetp, regnum);
 }
 \f
 
@@ -213,17 +149,19 @@ store_inferior_registers (int regno)
 void _initialize_amd64fbsd_nat (void);
 
 void
-_initialize_am64fbsd_nat (void)
+_initialize_amd64fbsd_nat (void)
 {
   int offset;
 
+  amd64_native_gregset32_reg_offset = amd64fbsd32_r_reg_offset;
+  amd64_native_gregset64_reg_offset = reg_offset;
+
   /* To support the recognition of signal handlers, i386bsd-tdep.c
      hardcodes some constants.  Inclusion of this file means that we
      are compiling a native debugger, which means that we can use the
      system header files and sysctl(3) to get at the relevant
      information.  */
 
-  extern int amd64fbsd_sc_reg_offset[];
 #define SC_REG_OFFSET amd64fbsd_sc_reg_offset
 
   /* We only check the program counter, stack pointer and frame
@@ -282,12 +220,9 @@ Please report this to <bug-gdb@gnu.org>.",
      environment can be found.  */
   {
     int mib[2];
-    int ps_strings;
+    long ps_strings;
     size_t len;
 
-    extern CORE_ADDR amd64fbsd_sigtramp_start;
-    extern CORE_ADDR amd64fbsd_sigtramp_end;
-
     mib[0] = CTL_KERN;
     mib[1] = KERN_PS_STRINGS;
     len = sizeof (ps_strings);
This page took 0.042653 seconds and 4 git commands to generate.