This is the third and final batch of makefile changes this round.
[deliverable/binutils-gdb.git] / gdb / i386-tdep.c
index d621fa3a2e2404ecd278f4acd015305a9f9f50de..ab56e62a7172877660b2490f7ef3e0e70b182d96 100644 (file)
@@ -1,65 +1,69 @@
-/* Intel 386 stuff.
-   Copyright (C) 1988, 1989 Free Software Foundation, Inc.
+/* Intel 386 target-dependent stuff.
+   Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
-GDB is free software; you can redistribute it and/or modify
+This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
-any later version.
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-GDB is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GDB; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-#include <stdio.h>
 #include "defs.h"
-#include "param.h"
 #include "frame.h"
 #include "inferior.h"
 #include "gdbcore.h"
 
-#ifdef USG
-#include <sys/types.h>
+#ifdef USE_PROC_FS     /* Target dependent support for /proc */
+#include <sys/procfs.h>
 #endif
 
-#include <sys/param.h>
-#include <sys/dir.h>
-#include <signal.h>
-#include <sys/user.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-
-#ifndef N_SET_MAGIC
-#ifdef COFF_FORMAT
-#define N_SET_MAGIC(exec, val) ((exec).magic = (val))
-#else
-#define N_SET_MAGIC(exec, val) ((exec).a_magic = (val))
-#endif
-#endif
+static long
+i386_get_frame_setup PARAMS ((int));
 
-#include <sys/file.h>
-#include <sys/stat.h>
+static void
+i386_follow_jump PARAMS ((void));
 
-/* I don't know whether this is right for cross-debugging even if you
-   do somehow manage to get the right include file.  */
-#if defined (USE_MACHINE_REG_H)
-#include <machine/reg.h>
-#else
-#include <sys/reg.h>
-#endif
+static void
+codestream_read PARAMS ((unsigned char *, int));
 
-/* helper functions for m-i386.h */
+static void
+codestream_seek PARAMS ((int));
 
-/* stdio style buffering to minimize calls to ptrace */
+static unsigned char 
+codestream_fill PARAMS ((int));
+
+/* helper functions for tm-i386.h */
+
+/* Stdio style buffering was used to minimize calls to ptrace, but this
+   buffering did not take into account that the code section being accessed
+   may not be an even number of buffers long (even if the buffer is only
+   sizeof(int) long).  In cases where the code section size happened to
+   be a non-integral number of buffers long, attempting to read the last
+   buffer would fail.  Simply using target_read_memory and ignoring errors,
+   rather than read_memory, is not the correct solution, since legitimate
+   access errors would then be totally ignored.  To properly handle this
+   situation and continue to use buffering would require that this code
+   be able to determine the minimum code section size granularity (not the
+   alignment of the section itself, since the actual failing case that
+   pointed out this problem had a section alignment of 4 but was not a
+   multiple of 4 bytes long), on a target by target basis, and then
+   adjust it's buffer size accordingly.  This is messy, but potentially
+   feasible.  It probably needs the bfd library's help and support.  For
+   now, the buffer size is set to 1.  (FIXME -fnf) */
+
+#define CODESTREAM_BUFSIZ 1    /* Was sizeof(int), see note above. */
 static CORE_ADDR codestream_next_addr;
 static CORE_ADDR codestream_addr;
-static unsigned char codestream_buf[sizeof (int)];
+static unsigned char codestream_buf[CODESTREAM_BUFSIZ];
 static int codestream_off;
 static int codestream_cnt;
 
@@ -71,14 +75,15 @@ static int codestream_cnt;
 
 static unsigned char 
 codestream_fill (peek_flag)
+    int peek_flag;
 {
   codestream_addr = codestream_next_addr;
-  codestream_next_addr += sizeof (int);
+  codestream_next_addr += CODESTREAM_BUFSIZ;
   codestream_off = 0;
-  codestream_cnt = sizeof (int);
+  codestream_cnt = CODESTREAM_BUFSIZ;
   read_memory (codestream_addr,
               (unsigned char *)codestream_buf,
-              sizeof (int));
+              CODESTREAM_BUFSIZ);
   
   if (peek_flag)
     return (codestream_peek());
@@ -88,8 +93,10 @@ codestream_fill (peek_flag)
 
 static void
 codestream_seek (place)
+    int place;
 {
-  codestream_next_addr = place & -sizeof (int);
+  codestream_next_addr = place / CODESTREAM_BUFSIZ;
+  codestream_next_addr *= CODESTREAM_BUFSIZ;
   codestream_cnt = 0;
   codestream_fill (1);
   while (codestream_tell() != place)
@@ -99,6 +106,7 @@ codestream_seek (place)
 static void
 codestream_read (buf, count)
      unsigned char *buf;
+     int count;
 {
   unsigned char *p;
   int i;
@@ -108,7 +116,8 @@ codestream_read (buf, count)
 }
 
 /* next instruction is a jump, move to target */
-static
+
+static void
 i386_follow_jump ()
 {
   int long_delta;
@@ -133,7 +142,9 @@ i386_follow_jump ()
       if (data16)
        {
          codestream_read ((unsigned char *)&short_delta, 2);
-         pos += short_delta + 3; /* include size of jmp inst */
+
+         /* include size of jmp inst (including the 0x66 prefix).  */
+         pos += short_delta + 4; 
        }
       else
        {
@@ -147,7 +158,7 @@ i386_follow_jump ()
       pos += byte_delta + 2;
       break;
     }
-  codestream_seek (pos + data16);
+  codestream_seek (pos);
 }
 
 /*
@@ -157,8 +168,10 @@ i386_follow_jump ()
  * if entry sequence doesn't make sense, return -1, and leave 
  * codestream pointer random
  */
+
 static long
 i386_get_frame_setup (pc)
+     int pc;
 {
   unsigned char op;
   
@@ -252,6 +265,7 @@ i386_get_frame_setup (pc)
            }
          /* subl with 32 bit immediate */
          codestream_read ((unsigned char *)&locals, 4);
+         SWAP_TARGET_AND_HOST (&locals, 4);
          return (locals);
        }
       else
@@ -264,6 +278,7 @@ i386_get_frame_setup (pc)
       /* enter instruction: arg is 16 bit unsigned immed */
       unsigned short slocals;
       codestream_read ((unsigned char *)&slocals, 2);
+      SWAP_TARGET_AND_HOST (&slocals, 2);
       codestream_get (); /* flush final byte of enter instruction */
       return (slocals);
     }
@@ -281,7 +296,7 @@ i386_get_frame_setup (pc)
 
 int
 i386_frame_num_args (fi)
-     struct frame_info fi;
+     struct frame_info *fi;
 {
   int retpc;                                           
   unsigned char op;                                    
@@ -296,7 +311,7 @@ i386_frame_num_args (fi)
        nameless arguments.  */
     return -1;
 
-  pfi = get_prev_frame_info ((fi));                    
+  pfi = get_prev_frame_info (fi);                      
   if (pfi == 0)
     {
       /* Note:  this can happen if we are looking at the frame for
@@ -367,6 +382,7 @@ i386_frame_num_args (fi)
  * next instruction will be a branch back to the start.
  */
 
+void
 i386_frame_find_saved_regs (fip, fsrp)
      struct frame_info *fip;
      struct frame_saved_regs *fsrp;
@@ -418,7 +434,10 @@ i386_frame_find_saved_regs (fip, fsrp)
 }
 
 /* return pc of first real instruction */
+
+int
 i386_skip_prologue (pc)
+     int pc;
 {
   unsigned char op;
   int i;
@@ -445,6 +464,7 @@ i386_skip_prologue (pc)
   return (codestream_tell ());
 }
 
+void
 i386_push_dummy_frame ()
 {
   CORE_ADDR sp = read_register (SP_REGNUM);
@@ -462,6 +482,7 @@ i386_push_dummy_frame ()
   write_register (SP_REGNUM, sp);
 }
 
+void
 i386_pop_frame ()
 {
   FRAME frame = get_current_frame ();
@@ -492,3 +513,134 @@ i386_pop_frame ()
   set_current_frame ( create_new_frame (read_register (FP_REGNUM),
                                        read_pc ()));
 }
+
+#ifdef USE_PROC_FS     /* Target dependent support for /proc */
+
+/*  The /proc interface divides the target machine's register set up into
+    two different sets, the general register set (gregset) and the floating
+    point register set (fpregset).  For each set, there is an ioctl to get
+    the current register set and another ioctl to set the current values.
+
+    The actual structure passed through the ioctl interface is, of course,
+    naturally machine dependent, and is different for each set of registers.
+    For the i386 for example, the general register set is typically defined
+    by:
+
+       typedef int gregset_t[19];              (in <sys/regset.h>)
+
+       #define GS      0                       (in <sys/reg.h>)
+       #define FS      1
+       ...
+       #define UESP    17
+       #define SS      18
+
+    and the floating point set by:
+
+       typedef struct fpregset
+         {
+           union
+             {
+               struct fpchip_state     // fp extension state //
+               {
+                 int state[27];        // 287/387 saved state //
+                 int status;           // status word saved at exception //
+               } fpchip_state;
+               struct fp_emul_space    // for emulators //
+               {
+                 char fp_emul[246];
+                 char fp_epad[2];
+               } fp_emul_space;
+               int f_fpregs[62];       // union of the above //
+             } fp_reg_set;
+           long f_wregs[33];           // saved weitek state //
+       } fpregset_t;
+
+    These routines provide the packing and unpacking of gregset_t and
+    fpregset_t formatted data.
+
+ */
+
+/* This is a duplicate of the table in i386-xdep.c. */
+
+static int regmap[] = 
+{
+  EAX, ECX, EDX, EBX,
+  UESP, EBP, ESI, EDI,
+  EIP, EFL, CS, SS,
+  DS, ES, FS, GS,
+};
+
+
+/*  Given a pointer to a general register set in /proc format (gregset_t *),
+    unpack the register contents and supply them as gdb's idea of the current
+    register values. */
+
+void
+supply_gregset (gregsetp)
+     gregset_t *gregsetp;
+{
+  register int regno;
+  register greg_t *regp = (greg_t *) gregsetp;
+  extern int regmap[];
+
+  for (regno = 0 ; regno < NUM_REGS ; regno++)
+    {
+      supply_register (regno, (char *) (regp + regmap[regno]));
+    }
+}
+
+void
+fill_gregset (gregsetp, regno)
+     gregset_t *gregsetp;
+     int regno;
+{
+  int regi;
+  register greg_t *regp = (greg_t *) gregsetp;
+  extern char registers[];
+  extern int regmap[];
+
+  for (regi = 0 ; regi < NUM_REGS ; regi++)
+    {
+      if ((regno == -1) || (regno == regi))
+       {
+         *(regp + regmap[regno]) = *(int *) &registers[REGISTER_BYTE (regi)];
+       }
+    }
+}
+
+#if defined (FP0_REGNUM)
+
+/*  Given a pointer to a floating point register set in /proc format
+    (fpregset_t *), unpack the register contents and supply them as gdb's
+    idea of the current floating point register values. */
+
+void 
+supply_fpregset (fpregsetp)
+     fpregset_t *fpregsetp;
+{
+  register int regno;
+  
+  /* FIXME: see m68k-tdep.c for an example, for the m68k. */
+}
+
+/*  Given a pointer to a floating point register set in /proc format
+    (fpregset_t *), update the register specified by REGNO from gdb's idea
+    of the current floating point register set.  If REGNO is -1, update
+    them all. */
+
+void
+fill_fpregset (fpregsetp, regno)
+     fpregset_t *fpregsetp;
+     int regno;
+{
+  int regi;
+  char *to;
+  char *from;
+  extern char registers[];
+
+  /* FIXME: see m68k-tdep.c for an example, for the m68k. */
+}
+
+#endif /* defined (FP0_REGNUM) */
+
+#endif  /* USE_PROC_FS */
This page took 0.02794 seconds and 4 git commands to generate.