2002-05-27 Martin M. Hunt <hunt@redhat.com>
[deliverable/binutils-gdb.git] / gdb / i386-tdep.c
index a5d3ef74f949616aefc23839a52f11cccf2da026..54746eeb8654a1473a551a940d98fd44b22d88ac 100644 (file)
@@ -1,7 +1,7 @@
 /* Intel 386 target-dependent stuff.
-   Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2001
-   Free Software Foundation, Inc.
+
+   Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
+   1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "command.h"
 #include "arch-utils.h"
 #include "regcache.h"
+#include "doublest.h"
+#include "value.h"
+#include "gdb_assert.h"
+
+#include "elf-bfd.h"
+
+#include "i386-tdep.h"
+
+/* Names of the registers.  The first 10 registers match the register
+   numbering scheme used by GCC for stabs and DWARF.  */
+static char *i386_register_names[] =
+{
+  "eax",   "ecx",    "edx",   "ebx",
+  "esp",   "ebp",    "esi",   "edi",
+  "eip",   "eflags", "cs",    "ss",
+  "ds",    "es",     "fs",    "gs",
+  "st0",   "st1",    "st2",   "st3",
+  "st4",   "st5",    "st6",   "st7",
+  "fctrl", "fstat",  "ftag",  "fiseg",
+  "fioff", "foseg",  "fooff", "fop",
+  "xmm0",  "xmm1",   "xmm2",  "xmm3",
+  "xmm4",  "xmm5",   "xmm6",  "xmm7",
+  "mxcsr"
+};
 
-/* i386_register_byte[i] is the offset into the register file of the
+/* i386_register_offset[i] is the offset into the register file of the
    start of register number i.  We initialize this from
-   i386_register_raw_size.  */
-int i386_register_byte[MAX_NUM_REGS];
+   i386_register_size.  */
+static int i386_register_offset[MAX_NUM_REGS];
 
-/* i386_register_raw_size[i] is the number of bytes of storage in
-   GDB's register array occupied by register i.  */
-int i386_register_raw_size[MAX_NUM_REGS] = {
+/* i386_register_size[i] is the number of bytes of storage in GDB's
+   register array occupied by register i.  */
+static int i386_register_size[MAX_NUM_REGS] = {
    4,  4,  4,  4,
    4,  4,  4,  4,
    4,  4,  4,  4,
@@ -54,9 +78,105 @@ int i386_register_raw_size[MAX_NUM_REGS] = {
    4
 };
 
-/* i386_register_virtual_size[i] is the size in bytes of the virtual
-   type of register i.  */
-int i386_register_virtual_size[MAX_NUM_REGS];
+/* Return the name of register REG.  */
+
+char *
+i386_register_name (int reg)
+{
+  if (reg < 0)
+    return NULL;
+  if (reg >= sizeof (i386_register_names) / sizeof (*i386_register_names))
+    return NULL;
+
+  return i386_register_names[reg];
+}
+
+/* Return the offset into the register array of the start of register
+   number REG.  */
+int
+i386_register_byte (int reg)
+{
+  return i386_register_offset[reg];
+}
+
+/* Return the number of bytes of storage in GDB's register array
+   occupied by register REG.  */
+
+int
+i386_register_raw_size (int reg)
+{
+  return i386_register_size[reg];
+}
+
+/* Return the size in bytes of the virtual type of register REG.  */
+
+int
+i386_register_virtual_size (int reg)
+{
+  return TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (reg));
+}
+
+/* Convert stabs register number REG to the appropriate register
+   number used by GDB.  */
+
+int
+i386_stab_reg_to_regnum (int reg)
+{
+  /* This implements what GCC calls the "default" register map.  */
+  if (reg >= 0 && reg <= 7)
+    {
+      /* General registers.  */
+      return reg;
+    }
+  else if (reg >= 12 && reg <= 19)
+    {
+      /* Floating-point registers.  */
+      return reg - 12 + FP0_REGNUM;
+    }
+  else if (reg >= 21 && reg <= 28)
+    {
+      /* SSE registers.  */
+      return reg - 21 + XMM0_REGNUM;
+    }
+  else if (reg >= 29 && reg <= 36)
+    {
+      /* MMX registers.  */
+      /* FIXME: kettenis/2001-07-28: Should we have the MMX registers
+         as pseudo-registers?  */
+      return reg - 29 + FP0_REGNUM;
+    }
+
+  /* This will hopefully provoke a warning.  */
+  return NUM_REGS + NUM_PSEUDO_REGS;
+}
+
+/* Convert Dwarf register number REG to the appropriate register
+   number used by GDB.  */
+
+int
+i386_dwarf_reg_to_regnum (int reg)
+{
+  /* The DWARF register numbering includes %eip and %eflags, and
+     numbers the floating point registers differently.  */
+  if (reg >= 0 && reg <= 9)
+    {
+      /* General registers.  */
+      return reg;
+    }
+  else if (reg >= 11 && reg <= 18)
+    {
+      /* Floating-point registers.  */
+      return reg - 11 + FP0_REGNUM;
+    }
+  else if (reg >= 21)
+    {
+      /* The SSE and MMX registers have identical numbers as in stabs.  */
+      return i386_stab_reg_to_regnum (reg);
+    }
+
+  /* This will hopefully provoke a warning.  */
+  return NUM_REGS + NUM_PSEUDO_REGS;
+}
 \f
 
 /* This is the variable that is set with "set disassembly-flavor", and
@@ -71,13 +191,6 @@ static const char *valid_flavors[] =
 };
 static const char *disassembly_flavor = att_flavor;
 
-/* This is used to keep the bfd arch_info in sync with the disassembly
-   flavor.  */
-static void set_disassembly_flavor_sfunc (char *, int,
-                                         struct cmd_list_element *);
-static void set_disassembly_flavor (void);
-\f
-
 /* 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
@@ -349,6 +462,66 @@ i386_get_frame_setup (CORE_ADDR pc)
   return (-1);
 }
 
+/* Return the chain-pointer for FRAME.  In the case of the i386, the
+   frame's nominal address is the address of a 4-byte word containing
+   the calling frame's address.  */
+
+CORE_ADDR
+i386_frame_chain (struct frame_info *frame)
+{
+  if (frame->signal_handler_caller)
+    return frame->frame;
+
+  if (! inside_entry_file (frame->pc))
+    return read_memory_unsigned_integer (frame->frame, 4);
+
+  return 0;
+}
+
+/* Determine whether the function invocation represented by FRAME does
+   not have a from on the stack associated with it.  If it does not,
+   return non-zero, otherwise return zero.  */
+
+int
+i386_frameless_function_invocation (struct frame_info *frame)
+{
+  if (frame->signal_handler_caller)
+    return 0;
+
+  return frameless_look_for_prologue (frame);
+}
+
+/* Return the saved program counter for FRAME.  */
+
+CORE_ADDR
+i386_frame_saved_pc (struct frame_info *frame)
+{
+  /* FIXME: kettenis/2001-05-09: Conditionalizing the next bit of code
+     on SIGCONTEXT_PC_OFFSET and I386V4_SIGTRAMP_SAVED_PC should be
+     considered a temporary hack.  I plan to come up with something
+     better when we go multi-arch.  */
+#if defined (SIGCONTEXT_PC_OFFSET) || defined (I386V4_SIGTRAMP_SAVED_PC)
+  if (frame->signal_handler_caller)
+    return sigtramp_saved_pc (frame);
+#endif
+
+  return read_memory_unsigned_integer (frame->frame + 4, 4);
+}
+
+CORE_ADDR
+i386go32_frame_saved_pc (struct frame_info *frame)
+{
+  return read_memory_integer (frame->frame + 4, 4);
+}
+
+/* Immediately after a function call, return the saved pc.  */
+
+CORE_ADDR
+i386_saved_pc_after_call (struct frame_info *frame)
+{
+  return read_memory_unsigned_integer (read_register (SP_REGNUM), 4);
+}
+
 /* Return number of args passed to a frame.
    Can return -1, meaning no way to tell.  */
 
@@ -596,18 +769,20 @@ void
 i386_push_dummy_frame (void)
 {
   CORE_ADDR sp = read_register (SP_REGNUM);
+  CORE_ADDR fp;
   int regnum;
   char regbuf[MAX_REGISTER_RAW_SIZE];
 
   sp = push_word (sp, read_register (PC_REGNUM));
   sp = push_word (sp, read_register (FP_REGNUM));
-  write_register (FP_REGNUM, sp);
+  fp = sp;
   for (regnum = 0; regnum < NUM_REGS; regnum++)
     {
       read_register_gen (regnum, regbuf);
       sp = push_bytes (sp, regbuf, REGISTER_RAW_SIZE (regnum));
     }
   write_register (SP_REGNUM, sp);
+  write_register (FP_REGNUM, fp);
 }
 
 /* Insert the (relative) function address into the call sequence
@@ -615,7 +790,7 @@ i386_push_dummy_frame (void)
 
 void
 i386_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
-                    value_ptr *args, struct type *type, int gcc_p)
+                    struct value **args, struct type *type, int gcc_p)
 {
   int from, to, delta, loc;
 
@@ -661,6 +836,16 @@ i386_pop_frame (void)
 
 #ifdef GET_LONGJMP_TARGET
 
+/* FIXME: Multi-arching does not set JB_PC and JB_ELEMENT_SIZE yet.  
+   Fill in with dummy value to enable compilation.  */
+#ifndef JB_PC
+#define JB_PC 0
+#endif /* JB_PC */
+
+#ifndef JB_ELEMENT_SIZE
+#define JB_ELEMENT_SIZE 4
+#endif /* JB_ELEMENT_SIZE */
+
 /* Figure out where the longjmp will land.  Slurp the args out of the
    stack.  We expect the first arg to be a pointer to the jmp_buf
    structure from which we extract the pc (JB_PC) that we will land
@@ -695,7 +880,7 @@ get_longjmp_target (CORE_ADDR *pc)
 \f
 
 CORE_ADDR
-i386_push_arguments (int nargs, value_ptr *args, CORE_ADDR sp,
+i386_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
                     int struct_return, CORE_ADDR struct_addr)
 {
   sp = default_push_arguments (nargs, args, sp, struct_return, struct_addr);
@@ -733,7 +918,14 @@ i386_extract_return_value (struct type *type, char *regbuf, char *valbuf)
 {
   int len = TYPE_LENGTH (type);
 
-  if (TYPE_CODE_FLT == TYPE_CODE (type))
+  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+      && TYPE_NFIELDS (type) == 1)
+    {
+      i386_extract_return_value (TYPE_FIELD_TYPE (type, 0), regbuf, valbuf);
+      return;
+    }
+
+  if (TYPE_CODE (type) == TYPE_CODE_FLT)
     {
       if (NUM_FREGS == 0)
        {
@@ -742,26 +934,12 @@ i386_extract_return_value (struct type *type, char *regbuf, char *valbuf)
          return;
        }
 
-      /* Floating-point return values can be found in %st(0).  */
-      if (len == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT
-         && TARGET_LONG_DOUBLE_FORMAT == &floatformat_i387_ext)
-       {
-         /* Copy straight over, but take care of the padding.  */
-         memcpy (valbuf, &regbuf[REGISTER_BYTE (FP0_REGNUM)],
-                 FPU_REG_RAW_SIZE);
-         memset (valbuf + FPU_REG_RAW_SIZE, 0, len - FPU_REG_RAW_SIZE);
-       }
-      else
-       {
-         /* Convert the extended floating-point number found in
-             %st(0) to the desired type.  This is probably not exactly
-             how it would happen on the target itself, but it is the
-             best we can do.  */
-         DOUBLEST val;
-         floatformat_to_doublest (&floatformat_i387_ext,
-                                  &regbuf[REGISTER_BYTE (FP0_REGNUM)], &val);
-         store_floating (valbuf, TYPE_LENGTH (type), val);
-       }
+      /* Floating-point return values can be found in %st(0).  Convert
+        its contents to the desired type.  This is probably not
+        exactly how it would happen on the target itself, but it is
+        the best we can do.  */
+      convert_typed_floating (&regbuf[REGISTER_BYTE (FP0_REGNUM)],
+                             builtin_type_i387_ext, valbuf, type);
     }
   else
     {
@@ -791,36 +969,48 @@ i386_store_return_value (struct type *type, char *valbuf)
 {
   int len = TYPE_LENGTH (type);
 
-  if (TYPE_CODE_FLT == TYPE_CODE (type))
+  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+      && TYPE_NFIELDS (type) == 1)
     {
+      i386_store_return_value (TYPE_FIELD_TYPE (type, 0), valbuf);
+      return;
+    }
+
+  if (TYPE_CODE (type) == TYPE_CODE_FLT)
+    {
+      unsigned int fstat;
+      char buf[FPU_REG_RAW_SIZE];
+
       if (NUM_FREGS == 0)
        {
          warning ("Cannot set floating-point return value.");
          return;
        }
 
-      /* Floating-point return values can be found in %st(0).  */
-      if (len == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT
-         && TARGET_LONG_DOUBLE_FORMAT == &floatformat_i387_ext)
-       {
-         /* Copy straight over.  */
-         write_register_bytes (REGISTER_BYTE (FP0_REGNUM), valbuf,
-                               FPU_REG_RAW_SIZE);
-       }
-      else
-       {
-         char buf[FPU_REG_RAW_SIZE];
-         DOUBLEST val;
-
-         /* Convert the value found in VALBUF to the extended
-             floating point format used by the FPU.  This is probably
-             not exactly how it would happen on the target itself, but
-             it is the best we can do.  */
-         val = extract_floating (valbuf, TYPE_LENGTH (type));
-         floatformat_from_doublest (&floatformat_i387_ext, &val, buf);
-         write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf,
-                               FPU_REG_RAW_SIZE);
-       }
+      /* Returning floating-point values is a bit tricky.  Apart from
+         storing the return value in %st(0), we have to simulate the
+         state of the FPU at function return point.  */
+
+      /* Convert the value found in VALBUF to the extended
+        floating-point format used by the FPU.  This is probably
+        not exactly how it would happen on the target itself, but
+        it is the best we can do.  */
+      convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext);
+      write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf,
+                           FPU_REG_RAW_SIZE);
+
+      /* Set the top of the floating-point register stack to 7.  The
+         actual value doesn't really matter, but 7 is what a normal
+         function return would end up with if the program started out
+         with a freshly initialized FPU.  */
+      fstat = read_register (FSTAT_REGNUM);
+      fstat |= (7 << 11);
+      write_register (FSTAT_REGNUM, fstat);
+
+      /* Mark %st(1) through %st(7) as empty.  Since we set the top of
+         the floating-point register stack to 7, the appropriate value
+         for the tag word is 0x3fff.  */
+      write_register (FTAG_REGNUM, 0x3fff);
     }
   else
     {
@@ -841,31 +1031,94 @@ i386_store_return_value (struct type *type, char *valbuf)
                        "Cannot store return value of %d bytes long.", len);
     }
 }
+
+/* Extract from an array REGBUF containing the (raw) register state
+   the address in which a function should return its structure value,
+   as a CORE_ADDR.  */
+
+CORE_ADDR
+i386_extract_struct_value_address (char *regbuf)
+{
+  return extract_address (&regbuf[REGISTER_BYTE (LOW_RETURN_REGNUM)],
+                         REGISTER_RAW_SIZE (LOW_RETURN_REGNUM));
+}
 \f
 
+/* Return the GDB type object for the "standard" data type of data in
+   register REGNUM.  Perhaps %esi and %edi should go here, but
+   potentially they could be used for things other than address.  */
+
+struct type *
+i386_register_virtual_type (int regnum)
+{
+  if (regnum == PC_REGNUM || regnum == FP_REGNUM || regnum == SP_REGNUM)
+    return lookup_pointer_type (builtin_type_void);
+
+  if (IS_FP_REGNUM (regnum))
+    return builtin_type_i387_ext;
+
+  if (IS_SSE_REGNUM (regnum))
+    return builtin_type_vec128i;
+
+  return builtin_type_int;
+}
+
+/* Return true iff register REGNUM's virtual format is different from
+   its raw format.  Note that this definition assumes that the host
+   supports IEEE 32-bit floats, since it doesn't say that SSE
+   registers need conversion.  Even if we can't find a counterexample,
+   this is still sloppy.  */
+
+int
+i386_register_convertible (int regnum)
+{
+  return IS_FP_REGNUM (regnum);
+}
+
 /* Convert data from raw format for register REGNUM in buffer FROM to
-   virtual format with type TYPE in buffer TO.  In principle both
-   formats are identical except that the virtual format has two extra
-   bytes appended that aren't used.  We set these to zero.  */
+   virtual format with type TYPE in buffer TO.  */
 
 void
 i386_register_convert_to_virtual (int regnum, struct type *type,
                                  char *from, char *to)
 {
-  /* Copy straight over, but take care of the padding.  */
-  memcpy (to, from, FPU_REG_RAW_SIZE);
-  memset (to + FPU_REG_RAW_SIZE, 0, TYPE_LENGTH (type) - FPU_REG_RAW_SIZE);
+  gdb_assert (IS_FP_REGNUM (regnum));
+
+  /* We only support floating-point values.  */
+  if (TYPE_CODE (type) != TYPE_CODE_FLT)
+    {
+      warning ("Cannot convert floating-point register value "
+              "to non-floating-point type.");
+      memset (to, 0, TYPE_LENGTH (type));
+      return;
+    }
+
+  /* Convert to TYPE.  This should be a no-op if TYPE is equivalent to
+     the extended floating-point format used by the FPU.  */
+  convert_typed_floating (from, builtin_type_i387_ext, to, type);
 }
 
 /* Convert data from virtual format with type TYPE in buffer FROM to
-   raw format for register REGNUM in buffer TO.  Simply omit the two
-   unused bytes.  */
+   raw format for register REGNUM in buffer TO.  */
 
 void
 i386_register_convert_to_raw (struct type *type, int regnum,
                              char *from, char *to)
 {
-  memcpy (to, from, FPU_REG_RAW_SIZE);
+  gdb_assert (IS_FP_REGNUM (regnum));
+
+  /* We only support floating-point values.  */
+  if (TYPE_CODE (type) != TYPE_CODE_FLT)
+    {
+      warning ("Cannot convert non-floating-point type "
+              "to floating-point register value.");
+      memset (to, 0, TYPE_LENGTH (type));
+      return;
+    }
+
+  /* Convert from TYPE.  This should be a no-op if TYPE is equivalent
+     to the extended floating-point format used by the FPU.  */
+  convert_typed_floating (from, type, to, builtin_type_i387_ext);
 }
 \f     
 
@@ -961,27 +1214,298 @@ gdb_print_insn_i386 (bfd_vma memaddr, disassemble_info *info)
   internal_error (__FILE__, __LINE__, "failed internal consistency check");
 }
 
-/* If the disassembly mode is intel, we have to also switch the bfd
-   mach_type.  This function is run in the set disassembly_flavor
-   command, and does that.  */
+\f
+/* This table matches the indices assigned to enum i386_abi.  Keep
+   them in sync.  */
+static const char * const i386_abi_names[] =
+{
+  "<unknown>",
+  "SVR4",
+  "NetBSD",
+  "GNU/Linux",
+  "GNU/Hurd",
+  "Solaris",
+  "FreeBSD",
+  NULL
+};
+
+
+#define ABI_TAG_OS_GNU_LINUX   I386_ABI_LINUX
+#define ABI_TAG_OS_GNU_HURD    I386_ABI_HURD
+#define ABI_TAG_OS_GNU_SOLARIS I386_ABI_INVALID
+#define ABI_TAG_OS_FREEBSD     I386_ABI_FREEBSD
+#define ABI_TAG_OS_NETBSD      I386_ABI_NETBSD
 
 static void
-set_disassembly_flavor_sfunc (char *args, int from_tty,
-                             struct cmd_list_element *c)
+process_note_sections (bfd *abfd, asection *sect, void *obj)
 {
-  set_disassembly_flavor ();
+  int *abi = obj;
+  const char *name;
+  unsigned int sectsize;
+
+  name = bfd_get_section_name (abfd, sect);
+  sectsize = bfd_section_size (abfd, sect);
+
+  if (strcmp (name, ".note.ABI-tag") == 0 && sectsize > 0)
+    {
+      unsigned int name_length, data_length, note_type;
+      char *note;
+
+      /* If the section is larger than this, it's probably not what we
+        are looking for.  */
+      if (sectsize > 128)
+       sectsize = 128;
+
+      note = alloca (sectsize);
+
+      bfd_get_section_contents (abfd, sect, note,
+                               (file_ptr) 0, (bfd_size_type) sectsize);
+
+      name_length = bfd_h_get_32 (abfd, note);
+      data_length = bfd_h_get_32 (abfd, note + 4);
+      note_type = bfd_h_get_32 (abfd, note + 8);
+
+      if (name_length == 4 && data_length == 16
+         && note_type == NT_GNU_ABI_TAG
+         && strcmp (note + 12, "GNU") == 0)
+       {
+         int abi_tag_os = bfd_h_get_32 (abfd, note + 16);
+
+         /* The case numbers are from abi-tags in glibc.  */
+         switch (abi_tag_os)
+           {
+           case GNU_ABI_TAG_LINUX:
+             *abi = ABI_TAG_OS_GNU_LINUX;
+             break;
+
+           case GNU_ABI_TAG_HURD:
+             *abi = ABI_TAG_OS_GNU_HURD;
+             break;
+
+           case GNU_ABI_TAG_SOLARIS:
+             *abi = ABI_TAG_OS_GNU_SOLARIS;
+             break;
+
+           default:
+             internal_error
+               (__FILE__, __LINE__,
+                "process_note_abi_sections: unknown ABI OS tag %d",
+                abi_tag_os);
+             break;
+           }
+       }
+      else if (name_length == 8 && data_length == 4
+              && note_type == NT_FREEBSD_ABI_TAG
+              && strcmp (note + 12, "FreeBSD") == 0)
+       *abi = ABI_TAG_OS_FREEBSD;
+    }
+  /* NetBSD uses a similar trick.  */
+  else if (strcmp (name, ".note.netbsd.ident") == 0 && sectsize > 0)
+    {
+      unsigned int name_length, desc_length, note_type;
+      char *note;
+
+      /* If the section is larger than this, it's probably not what we are
+         looking for.  */
+      if (sectsize > 128)
+       sectsize = 128;
+
+      note = alloca (sectsize);
+
+      bfd_get_section_contents (abfd, sect, note,
+                               (file_ptr) 0, (bfd_size_type) sectsize);
+
+      name_length = bfd_h_get_32 (abfd, note);
+      desc_length = bfd_h_get_32 (abfd, note + 4);
+      note_type = bfd_h_get_32 (abfd, note + 8);
+
+      if (name_length == 7 && desc_length == 4
+         && note_type == NT_NETBSD_IDENT
+         && strcmp (note + 12, "NetBSD") == 0)
+       *abi = ABI_TAG_OS_NETBSD;
+    }
 }
 
-static void
-set_disassembly_flavor (void)
+static int
+i386_elf_abi_from_note (bfd *abfd)
 {
-  if (disassembly_flavor == att_flavor)
-    set_architecture_from_arch_mach (bfd_arch_i386, bfd_mach_i386_i386);
-  else if (disassembly_flavor == intel_flavor)
-    set_architecture_from_arch_mach (bfd_arch_i386,
-                                    bfd_mach_i386_i386_intel_syntax);
+  enum i386_abi abi = I386_ABI_UNKNOWN;
+  
+  bfd_map_over_sections (abfd, process_note_sections, &abi);
+
+  return abi;
+}
+
+static enum i386_abi
+i386_elf_abi (bfd *abfd)
+{
+  int elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
+
+  /* The fact that the EI_OSABI byte is set to ELFOSABI_NONE doesn't
+     necessarily mean that this is a System V ELF binary.  To further
+     distinguish between binaries for differens operating systems,
+     check for vendor-specific note elements.  */
+  if (elfosabi == ELFOSABI_NONE)
+    {
+      enum i386_abi abi = i386_elf_abi_from_note (abfd);
+
+      if (abi != I386_ABI_UNKNOWN)
+       return abi;
+
+      /* FreeBSD folks are naughty; they stored the string "FreeBSD"
+        in the padding of the e_ident field of the ELF header.  */
+      if (strcmp (&elf_elfheader (abfd)->e_ident[8], "FreeBSD") == 0)
+       return I386_ABI_FREEBSD;
+    }
+
+  switch (elfosabi)
+    {
+    case ELFOSABI_NONE:
+      return I386_ABI_SVR4;
+    case ELFOSABI_FREEBSD:
+      return I386_ABI_FREEBSD;
+    }
+
+  return I386_ABI_UNKNOWN;
+}
+
+struct i386_abi_handler
+{
+  struct i386_abi_handler *next;
+  enum i386_abi abi;
+  void (*init_abi)(struct gdbarch_info, struct gdbarch *);
+};
+
+struct i386_abi_handler *i386_abi_handler_list = NULL;
+
+void
+i386_gdbarch_register_os_abi (enum i386_abi abi,
+                             void (*init_abi)(struct gdbarch_info,
+                                              struct gdbarch *))
+{
+  struct i386_abi_handler **handler_p;
+
+  for (handler_p = &i386_abi_handler_list; *handler_p != NULL;
+       handler_p = &(*handler_p)->next)
+    {
+      if ((*handler_p)->abi == abi)
+       {
+         internal_error
+           (__FILE__, __LINE__,
+            "i386_gdbarch_register_abi: A handler for this ABI variant "
+            "(%d) has already been registered", (int) abi);
+         /* If user wants to continue, override previous definition.  */
+         (*handler_p)->init_abi = init_abi;
+         return;
+       }
+    }
+  (*handler_p)
+    = (struct i386_abi_handler *) xmalloc (sizeof (struct i386_abi_handler));
+  (*handler_p)->next = NULL;
+  (*handler_p)->abi = abi;
+  (*handler_p)->init_abi = init_abi;
+}
+
+struct gdbarch *
+i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
+{
+  struct gdbarch_tdep *tdep;
+  struct gdbarch *gdbarch;
+  enum i386_abi abi = I386_ABI_UNKNOWN;
+  struct i386_abi_handler *abi_handler;
+
+  if (info.abfd != NULL)
+    {
+      switch (bfd_get_flavour (info.abfd))
+       {
+       case bfd_target_elf_flavour:
+         abi= i386_elf_abi (info.abfd);
+         break;
+
+       default:
+         /* Not sure what to do here, leave the ABI as unknown.  */
+         break;
+       }
+    }
+
+  /* Find a candidate among extant architectures.  */
+  for (arches = gdbarch_list_lookup_by_info (arches, &info);
+       arches != NULL;
+       arches = gdbarch_list_lookup_by_info (arches->next, &info))
+    {
+      /* Make sure the ABI selection matches.  */
+      tdep = gdbarch_tdep (arches->gdbarch);
+      if (tdep && tdep->abi == abi)
+        return arches->gdbarch;
+    }
+
+  /* Allocate space for the new architecture.  */
+  tdep = XMALLOC (struct gdbarch_tdep);
+  gdbarch = gdbarch_alloc (&info, tdep);
+
+  tdep->abi = abi;
+
+  /* FIXME: kettenis/2001-11-24: Although not all IA-32 processors
+     have the SSE registers, it's easier to set the default to 8.  */
+  tdep->num_xmm_regs = 8;
+
+  set_gdbarch_use_generic_dummy_frames (gdbarch, 0);
+
+  /* Call dummy code.  */
+  set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
+  set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 5);
+  set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
+  set_gdbarch_call_dummy_p (gdbarch, 1);
+  set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
+
+  set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register);
+  set_gdbarch_push_arguments (gdbarch, i386_push_arguments);
+
+  set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_on_stack);
+
+  /* NOTE: tm-i386nw.h and tm-i386v4.h override this.  */
+  set_gdbarch_frame_chain_valid (gdbarch, file_frame_chain_valid);
+
+  /* NOTE: tm-i386aix.h, tm-i386bsd.h, tm-i386os9k.h, tm-linux.h,
+     tm-ptx.h, tm-symmetry.h currently override this.  Sigh.  */
+  set_gdbarch_num_regs (gdbarch, NUM_GREGS + NUM_FREGS + NUM_SSE_REGS);
+
+  /* Hook in ABI-specific overrides, if they have been registered.  */
+  if (abi == I386_ABI_UNKNOWN)
+    {
+      /* Don't complain about not knowing the ABI variant if we don't
+        have an inferior.  */
+      if (info.abfd)
+       fprintf_filtered
+         (gdb_stderr, "GDB doesn't recognize the ABI of the inferior.  "
+          "Attempting to continue with the default i386 settings");
+    }
+  else
+    {
+      for (abi_handler = i386_abi_handler_list; abi_handler != NULL;
+          abi_handler = abi_handler->next)
+       if (abi_handler->abi == abi)
+         break;
+
+      if (abi_handler)
+       abi_handler->init_abi (info, gdbarch);
+      else
+       {
+         /* We assume that if GDB_MULTI_ARCH is less than
+            GDB_MULTI_ARCH_TM that an ABI variant can be supported by
+            overriding definitions in this file.  */
+         if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL)
+           fprintf_filtered
+             (gdb_stderr,
+              "A handler for the ABI variant \"%s\" is not built into this "
+              "configuration of GDB.  "
+              "Attempting to continue with the default i386 settings",
+              i386_abi_names[abi]);
+       }
+    }
+  
+  return gdbarch;
 }
-\f
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 void _initialize_i386_tdep (void);
@@ -989,6 +1513,8 @@ void _initialize_i386_tdep (void);
 void
 _initialize_i386_tdep (void)
 {
+  register_gdbarch_init (bfd_arch_i386, i386_gdbarch_init);
+
   /* Initialize the table saying where each register starts in the
      register file.  */
   {
@@ -997,19 +1523,11 @@ _initialize_i386_tdep (void)
     offset = 0;
     for (i = 0; i < MAX_NUM_REGS; i++)
       {
-       i386_register_byte[i] = offset;
-       offset += i386_register_raw_size[i];
+       i386_register_offset[i] = offset;
+       offset += i386_register_size[i];
       }
   }
 
-  /* Initialize the table of virtual register sizes.  */
-  {
-    int i;
-
-    for (i = 0; i < MAX_NUM_REGS; i++)
-      i386_register_virtual_size[i] = TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (i));
-  }
-
   tm_print_insn = gdb_print_insn_i386;
   tm_print_insn_info.mach = bfd_lookup_arch (bfd_arch_i386, 0)->mach;
 
@@ -1024,11 +1542,6 @@ _initialize_i386_tdep (void)
 Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
 and the default value is \"att\".",
                                &setlist);
-    new_cmd->function.sfunc = set_disassembly_flavor_sfunc;
     add_show_from_set (new_cmd, &showlist);
   }
-
-  /* Finally, initialize the disassembly flavor to the default given
-     in the disassembly_flavor variable.  */
-  set_disassembly_flavor ();
 }
This page took 0.031799 seconds and 4 git commands to generate.