Split size in regset section iterators
[deliverable/binutils-gdb.git] / gdb / i386-tdep.c
index f2917dbaed41f0daac4dbcbabd4e23bc00574c6a..a6994aaf1266ba4e47c06f694dad2d320c3c758f 100644 (file)
@@ -1,6 +1,6 @@
 /* Intel 386 target-dependent stuff.
 
-   Copyright (C) 1988-2017 Free Software Foundation, Inc.
+   Copyright (C) 1988-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -23,7 +23,6 @@
 #include "command.h"
 #include "dummy-frame.h"
 #include "dwarf2-frame.h"
-#include "doublest.h"
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
@@ -40,6 +39,7 @@
 #include "symfile.h"
 #include "symtab.h"
 #include "target.h"
+#include "target-float.h"
 #include "value.h"
 #include "dis-asm.h"
 #include "disasm.h"
 #include "i386-tdep.h"
 #include "i387-tdep.h"
 #include "x86-xstate.h"
+#include "x86-tdep.h"
 
 #include "record.h"
 #include "record-full.h"
-#include "features/i386/i386.c"
-#include "features/i386/i386-avx.c"
-#include "features/i386/i386-mpx.c"
-#include "features/i386/i386-avx-mpx.c"
-#include "features/i386/i386-avx-avx512.c"
-#include "features/i386/i386-avx-mpx-avx512-pku.c"
-#include "features/i386/i386-mmx.c"
+#include "target-descriptions.h"
+#include "arch/i386.h"
 
 #include "ax.h"
 #include "ax-gdb.h"
@@ -573,7 +569,7 @@ i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 /* Wrapper on i386_svr4_dwarf_reg_to_regnum to return
    num_regs + num_pseudo_regs for other debug formats.  */
 
-static int
+int
 i386_svr4_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
   int regnum = i386_svr4_dwarf_reg_to_regnum (gdbarch, reg);
@@ -799,8 +795,7 @@ i386_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
   return i386_jmp_p (insn);
 }
 
-/* Some kernels may run one past a syscall insn, so we have to cope.
-   Otherwise this is just simple_displaced_step_copy_insn.  */
+/* Some kernels may run one past a syscall insn, so we have to cope.  */
 
 struct displaced_step_closure *
 i386_displaced_step_copy_insn (struct gdbarch *gdbarch,
@@ -808,7 +803,8 @@ i386_displaced_step_copy_insn (struct gdbarch *gdbarch,
                               struct regcache *regs)
 {
   size_t len = gdbarch_max_insn_length (gdbarch);
-  gdb_byte *buf = (gdb_byte *) xmalloc (len);
+  i386_displaced_step_closure *closure = new i386_displaced_step_closure (len);
+  gdb_byte *buf = closure->buf.data ();
 
   read_memory (from, buf, len);
 
@@ -833,7 +829,7 @@ i386_displaced_step_copy_insn (struct gdbarch *gdbarch,
       displaced_step_dump_bytes (gdb_stdlog, buf, len);
     }
 
-  return (struct displaced_step_closure *) buf;
+  return closure;
 }
 
 /* Fix up the state of registers and memory after having single-stepped
@@ -841,7 +837,7 @@ i386_displaced_step_copy_insn (struct gdbarch *gdbarch,
 
 void
 i386_displaced_step_fixup (struct gdbarch *gdbarch,
-                           struct displaced_step_closure *closure,
+                           struct displaced_step_closure *closure_,
                            CORE_ADDR from, CORE_ADDR to,
                            struct regcache *regs)
 {
@@ -853,9 +849,9 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch,
      applying it.  */
   ULONGEST insn_offset = to - from;
 
-  /* Since we use simple_displaced_step_copy_insn, our closure is a
-     copy of the instruction.  */
-  gdb_byte *insn = (gdb_byte *) closure;
+  i386_displaced_step_closure *closure
+    = (i386_displaced_step_closure *) closure_;
+  gdb_byte *insn = closure->buf.data ();
   /* The start of the insn, needed in case we see some prefixes.  */
   gdb_byte *insn_start = insn;
 
@@ -2684,6 +2680,13 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int write_pass;
   int args_space = 0;
 
+  /* BND registers can be in arbitrary values at the moment of the
+     inferior call.  This can cause boundary violations that are not
+     due to a real bug or even desired by the user.  The best to be done
+     is set the BND registers to allow access to the whole memory, INIT
+     state, before pushing the inferior call.   */
+  i387_reset_bnd_regs (gdbarch, regcache);
+
   /* Determine the total space required for arguments and struct
      return address in a first pass (allowing for 16-byte-aligned
      arguments), then push arguments in a second pass.  */
@@ -2752,10 +2755,10 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 
   /* Finally, update the stack pointer...  */
   store_unsigned_integer (buf, 4, byte_order, sp);
-  regcache_cooked_write (regcache, I386_ESP_REGNUM, buf);
+  regcache->cooked_write (I386_ESP_REGNUM, buf);
 
   /* ...and fake a frame pointer.  */
-  regcache_cooked_write (regcache, I386_EBP_REGNUM, buf);
+  regcache->cooked_write (I386_EBP_REGNUM, buf);
 
   /* MarkK wrote: This "+ 8" is all over the place:
      (i386_frame_this_id, i386_sigtramp_frame_this_id,
@@ -2799,8 +2802,8 @@ i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
         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.  */
-      regcache_raw_read (regcache, I386_ST0_REGNUM, buf);
-      convert_typed_floating (buf, i387_ext_type (gdbarch), valbuf, type);
+      regcache->raw_read (I386_ST0_REGNUM, buf);
+      target_float_convert (buf, i387_ext_type (gdbarch), valbuf, type);
     }
   else
     {
@@ -2809,14 +2812,14 @@ i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 
       if (len <= low_size)
        {
-         regcache_raw_read (regcache, LOW_RETURN_REGNUM, buf);
+         regcache->raw_read (LOW_RETURN_REGNUM, buf);
          memcpy (valbuf, buf, len);
        }
       else if (len <= (low_size + high_size))
        {
-         regcache_raw_read (regcache, LOW_RETURN_REGNUM, buf);
+         regcache->raw_read (LOW_RETURN_REGNUM, buf);
          memcpy (valbuf, buf, low_size);
-         regcache_raw_read (regcache, HIGH_RETURN_REGNUM, buf);
+         regcache->raw_read (HIGH_RETURN_REGNUM, buf);
          memcpy (valbuf + low_size, buf, len - low_size);
        }
       else
@@ -2855,8 +2858,8 @@ i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
         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, i387_ext_type (gdbarch));
-      regcache_raw_write (regcache, I386_ST0_REGNUM, buf);
+      target_float_convert (valbuf, type, buf, i387_ext_type (gdbarch));
+      regcache->raw_write (I386_ST0_REGNUM, buf);
 
       /* Set the top of the floating-point register stack to 7.  The
          actual value doesn't really matter, but 7 is what a normal
@@ -2877,12 +2880,12 @@ i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
       int high_size = register_size (gdbarch, HIGH_RETURN_REGNUM);
 
       if (len <= low_size)
-       regcache_raw_write_part (regcache, LOW_RETURN_REGNUM, 0, len, valbuf);
+       regcache->raw_write_part (LOW_RETURN_REGNUM, 0, len, valbuf);
       else if (len <= (low_size + high_size))
        {
-         regcache_raw_write (regcache, LOW_RETURN_REGNUM, valbuf);
-         regcache_raw_write_part (regcache, HIGH_RETURN_REGNUM, 0,
-                                  len - low_size, valbuf + low_size);
+         regcache->raw_write (LOW_RETURN_REGNUM, valbuf);
+         regcache->raw_write_part (HIGH_RETURN_REGNUM, 0, len - low_size,
+                                   valbuf + low_size);
        }
       else
        internal_error (__FILE__, __LINE__,
@@ -3246,15 +3249,15 @@ i386_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
    the MMX registers need to be mapped onto floating point registers.  */
 
 static int
-i386_mmx_regnum_to_fp_regnum (struct regcache *regcache, int regnum)
+i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
+  struct gdbarch_tdep *tdep = gdbarch_tdep (regcache->arch ());
   int mmxreg, fpreg;
   ULONGEST fstat;
   int tos;
 
   mmxreg = regnum - tdep->mm0_regnum;
-  regcache_raw_read_unsigned (regcache, I387_FSTAT_REGNUM (tdep), &fstat);
+  regcache->raw_read (I387_FSTAT_REGNUM (tdep), &fstat);
   tos = (fstat >> 11) & 0x7;
   fpreg = (mmxreg + tos) % 8;
 
@@ -3267,11 +3270,11 @@ i386_mmx_regnum_to_fp_regnum (struct regcache *regcache, int regnum)
 
 void
 i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
-                                     struct regcache *regcache,
+                                     readable_regcache *regcache,
                                      int regnum,
                                      struct value *result_value)
 {
-  gdb_byte raw_buf[MAX_REGISTER_SIZE];
+  gdb_byte raw_buf[I386_MAX_REGISTER_SIZE];
   enum register_status status;
   gdb_byte *buf = value_contents_raw (result_value);
 
@@ -3280,7 +3283,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
       int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum);
 
       /* Extract (always little endian).  */
-      status = regcache_raw_read (regcache, fpnum, raw_buf);
+      status = regcache->raw_read (fpnum, raw_buf);
       if (status != REG_VALID)
        mark_value_bytes_unavailable (result_value, 0,
                                      TYPE_LENGTH (value_type (result_value)));
@@ -3295,9 +3298,8 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
          regnum -= tdep->bnd0_regnum;
 
          /* Extract (always little endian).  Read lower 128bits.  */
-         status = regcache_raw_read (regcache,
-                                     I387_BND0R_REGNUM (tdep) + regnum,
-                                     raw_buf);
+         status = regcache->raw_read (I387_BND0R_REGNUM (tdep) + regnum,
+                                      raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 0, 16);
          else
@@ -3319,9 +3321,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
          regnum -= tdep->k0_regnum;
 
          /* Extract (always little endian).  */
-         status = regcache_raw_read (regcache,
-                                     tdep->k0_regnum + regnum,
-                                     raw_buf);
+         status = regcache->raw_read (tdep->k0_regnum + regnum, raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 0, 8);
          else
@@ -3334,18 +3334,16 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
          if (regnum < num_lower_zmm_regs)
            {
              /* Extract (always little endian).  Read lower 128bits.  */
-             status = regcache_raw_read (regcache,
-                                         I387_XMM0_REGNUM (tdep) + regnum,
-                                         raw_buf);
+             status = regcache->raw_read (I387_XMM0_REGNUM (tdep) + regnum,
+                                          raw_buf);
              if (status != REG_VALID)
                mark_value_bytes_unavailable (result_value, 0, 16);
              else
                memcpy (buf, raw_buf, 16);
 
              /* Extract (always little endian).  Read upper 128bits.  */
-             status = regcache_raw_read (regcache,
-                                         tdep->ymm0h_regnum + regnum,
-                                         raw_buf);
+             status = regcache->raw_read (tdep->ymm0h_regnum + regnum,
+                                          raw_buf);
              if (status != REG_VALID)
                mark_value_bytes_unavailable (result_value, 16, 16);
              else
@@ -3354,20 +3352,18 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
          else
            {
              /* Extract (always little endian).  Read lower 128bits.  */
-             status = regcache_raw_read (regcache,
-                                         I387_XMM16_REGNUM (tdep) + regnum
-                                         - num_lower_zmm_regs,
-                                         raw_buf);
+             status = regcache->raw_read (I387_XMM16_REGNUM (tdep) + regnum
+                                          - num_lower_zmm_regs,
+                                          raw_buf);
              if (status != REG_VALID)
                mark_value_bytes_unavailable (result_value, 0, 16);
              else
                memcpy (buf, raw_buf, 16);
 
              /* Extract (always little endian).  Read upper 128bits.  */
-             status = regcache_raw_read (regcache,
-                                         I387_YMM16H_REGNUM (tdep) + regnum
-                                         - num_lower_zmm_regs,
-                                         raw_buf);
+             status = regcache->raw_read (I387_YMM16H_REGNUM (tdep) + regnum
+                                          - num_lower_zmm_regs,
+                                          raw_buf);
              if (status != REG_VALID)
                mark_value_bytes_unavailable (result_value, 16, 16);
              else
@@ -3375,9 +3371,8 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
            }
 
          /* Read upper 256bits.  */
-         status = regcache_raw_read (regcache,
-                                     tdep->zmm0h_regnum + regnum,
-                                     raw_buf);
+         status = regcache->raw_read (tdep->zmm0h_regnum + regnum,
+                                      raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 32, 32);
          else
@@ -3388,17 +3383,15 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
          regnum -= tdep->ymm0_regnum;
 
          /* Extract (always little endian).  Read lower 128bits.  */
-         status = regcache_raw_read (regcache,
-                                     I387_XMM0_REGNUM (tdep) + regnum,
-                                     raw_buf);
+         status = regcache->raw_read (I387_XMM0_REGNUM (tdep) + regnum,
+                                      raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 0, 16);
          else
            memcpy (buf, raw_buf, 16);
          /* Read upper 128bits.  */
-         status = regcache_raw_read (regcache,
-                                     tdep->ymm0h_regnum + regnum,
-                                     raw_buf);
+         status = regcache->raw_read (tdep->ymm0h_regnum + regnum,
+                                      raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 16, 32);
          else
@@ -3408,17 +3401,15 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
        {
          regnum -= tdep->ymm16_regnum;
          /* Extract (always little endian).  Read lower 128bits.  */
-         status = regcache_raw_read (regcache,
-                                     I387_XMM16_REGNUM (tdep) + regnum,
-                                     raw_buf);
+         status = regcache->raw_read (I387_XMM16_REGNUM (tdep) + regnum,
+                                      raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 0, 16);
          else
            memcpy (buf, raw_buf, 16);
          /* Read upper 128bits.  */
-         status = regcache_raw_read (regcache,
-                                     tdep->ymm16h_regnum + regnum,
-                                     raw_buf);
+         status = regcache->raw_read (tdep->ymm16h_regnum + regnum,
+                                      raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 16, 16);
          else
@@ -3429,7 +3420,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
          int gpnum = regnum - tdep->ax_regnum;
 
          /* Extract (always little endian).  */
-         status = regcache_raw_read (regcache, gpnum, raw_buf);
+         status = regcache->raw_read (gpnum, raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 0,
                                          TYPE_LENGTH (value_type (result_value)));
@@ -3442,7 +3433,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 
          /* Extract (always little endian).  We read both lower and
             upper registers.  */
-         status = regcache_raw_read (regcache, gpnum % 4, raw_buf);
+         status = regcache->raw_read (gpnum % 4, raw_buf);
          if (status != REG_VALID)
            mark_value_bytes_unavailable (result_value, 0,
                                          TYPE_LENGTH (value_type (result_value)));
@@ -3458,7 +3449,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
 
 static struct value *
 i386_pseudo_register_read_value (struct gdbarch *gdbarch,
-                                struct regcache *regcache,
+                                readable_regcache *regcache,
                                 int regnum)
 {
   struct value *result;
@@ -3476,18 +3467,18 @@ void
 i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
                            int regnum, const gdb_byte *buf)
 {
-  gdb_byte raw_buf[MAX_REGISTER_SIZE];
+  gdb_byte raw_buf[I386_MAX_REGISTER_SIZE];
 
   if (i386_mmx_regnum_p (gdbarch, regnum))
     {
       int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum);
 
       /* Read ...  */
-      regcache_raw_read (regcache, fpnum, raw_buf);
+      regcache->raw_read (fpnum, raw_buf);
       /* ... Modify ... (always little endian).  */
       memcpy (raw_buf, buf, register_size (gdbarch, regnum));
       /* ... Write.  */
-      regcache_raw_write (regcache, fpnum, raw_buf);
+      regcache->raw_write (fpnum, raw_buf);
     }
   else
     {
@@ -3505,9 +3496,8 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
          upper = extract_unsigned_integer (buf + size, size, byte_order);
 
          /* Fetching register buffer.  */
-         regcache_raw_read (regcache,
-                            I387_BND0R_REGNUM (tdep) + regnum,
-                            raw_buf);
+         regcache->raw_read (I387_BND0R_REGNUM (tdep) + regnum,
+                             raw_buf);
 
          upper = ~upper;
 
@@ -3515,18 +3505,13 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
          memcpy (raw_buf, &lower, 8);
          memcpy (raw_buf + 8, &upper, 8);
 
-
-         regcache_raw_write (regcache,
-                             I387_BND0R_REGNUM (tdep) + regnum,
-                             raw_buf);
+         regcache->raw_write (I387_BND0R_REGNUM (tdep) + regnum, raw_buf);
        }
       else if (i386_k_regnum_p (gdbarch, regnum))
        {
          regnum -= tdep->k0_regnum;
 
-         regcache_raw_write (regcache,
-                             tdep->k0_regnum + regnum,
-                             buf);
+         regcache->raw_write (tdep->k0_regnum + regnum, buf);
        }
       else if (i386_zmm_regnum_p (gdbarch, regnum))
        {
@@ -3535,82 +3520,64 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
          if (regnum < num_lower_zmm_regs)
            {
              /* Write lower 128bits.  */
-             regcache_raw_write (regcache,
-                                 I387_XMM0_REGNUM (tdep) + regnum,
-                                 buf);
+             regcache->raw_write (I387_XMM0_REGNUM (tdep) + regnum, buf);
              /* Write upper 128bits.  */
-             regcache_raw_write (regcache,
-                                 I387_YMM0_REGNUM (tdep) + regnum,
-                                 buf + 16);
+             regcache->raw_write (I387_YMM0_REGNUM (tdep) + regnum, buf + 16);
            }
          else
            {
              /* Write lower 128bits.  */
-             regcache_raw_write (regcache,
-                                 I387_XMM16_REGNUM (tdep) + regnum
-                                 - num_lower_zmm_regs,
-                                 buf);
+             regcache->raw_write (I387_XMM16_REGNUM (tdep) + regnum
+                                  - num_lower_zmm_regs, buf);
              /* Write upper 128bits.  */
-             regcache_raw_write (regcache,
-                                 I387_YMM16H_REGNUM (tdep) + regnum
-                                 - num_lower_zmm_regs,
-                                 buf + 16);
+             regcache->raw_write (I387_YMM16H_REGNUM (tdep) + regnum
+                                  - num_lower_zmm_regs, buf + 16);
            }
          /* Write upper 256bits.  */
-         regcache_raw_write (regcache,
-                             tdep->zmm0h_regnum + regnum,
-                             buf + 32);
+         regcache->raw_write (tdep->zmm0h_regnum + regnum, buf + 32);
        }
       else if (i386_ymm_regnum_p (gdbarch, regnum))
        {
          regnum -= tdep->ymm0_regnum;
 
          /* ... Write lower 128bits.  */
-         regcache_raw_write (regcache,
-                            I387_XMM0_REGNUM (tdep) + regnum,
-                            buf);
+         regcache->raw_write (I387_XMM0_REGNUM (tdep) + regnum, buf);
          /* ... Write upper 128bits.  */
-         regcache_raw_write (regcache,
-                            tdep->ymm0h_regnum + regnum,
-                            buf + 16);
+         regcache->raw_write (tdep->ymm0h_regnum + regnum, buf + 16);
        }
       else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
        {
          regnum -= tdep->ymm16_regnum;
 
          /* ... Write lower 128bits.  */
-         regcache_raw_write (regcache,
-                             I387_XMM16_REGNUM (tdep) + regnum,
-                             buf);
+         regcache->raw_write (I387_XMM16_REGNUM (tdep) + regnum, buf);
          /* ... Write upper 128bits.  */
-         regcache_raw_write (regcache,
-                             tdep->ymm16h_regnum + regnum,
-                             buf + 16);
+         regcache->raw_write (tdep->ymm16h_regnum + regnum, buf + 16);
        }
       else if (i386_word_regnum_p (gdbarch, regnum))
        {
          int gpnum = regnum - tdep->ax_regnum;
 
          /* Read ...  */
-         regcache_raw_read (regcache, gpnum, raw_buf);
+         regcache->raw_read (gpnum, raw_buf);
          /* ... Modify ... (always little endian).  */
          memcpy (raw_buf, buf, 2);
          /* ... Write.  */
-         regcache_raw_write (regcache, gpnum, raw_buf);
+         regcache->raw_write (gpnum, raw_buf);
        }
       else if (i386_byte_regnum_p (gdbarch, regnum))
        {
          int gpnum = regnum - tdep->al_regnum;
 
          /* Read ...  We read both lower and upper registers.  */
-         regcache_raw_read (regcache, gpnum % 4, raw_buf);
+         regcache->raw_read (gpnum % 4, raw_buf);
          /* ... Modify ... (always little endian).  */
          if (gpnum >= 4)
            memcpy (raw_buf + 1, buf, 1);
          else
            memcpy (raw_buf, buf, 1);
          /* ... Write.  */
-         regcache_raw_write (regcache, gpnum % 4, raw_buf);
+         regcache->raw_write (gpnum % 4, raw_buf);
        }
       else
        internal_error (__FILE__, __LINE__, _("invalid regnum"));
@@ -3837,7 +3804,7 @@ void
 i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
                     int regnum, const void *gregs, size_t len)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) gregs;
   int i;
@@ -3848,7 +3815,7 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
     {
       if ((regnum == i || regnum == -1)
          && tdep->gregset_reg_offset[i] != -1)
-       regcache_raw_supply (regcache, i, regs + tdep->gregset_reg_offset[i]);
+       regcache->raw_supply (i, regs + tdep->gregset_reg_offset[i]);
     }
 }
 
@@ -3862,7 +3829,7 @@ i386_collect_gregset (const struct regset *regset,
                      const struct regcache *regcache,
                      int regnum, void *gregs, size_t len)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   gdb_byte *regs = (gdb_byte *) gregs;
   int i;
@@ -3873,7 +3840,7 @@ i386_collect_gregset (const struct regset *regset,
     {
       if ((regnum == i || regnum == -1)
          && tdep->gregset_reg_offset[i] != -1)
-       regcache_raw_collect (regcache, i, regs + tdep->gregset_reg_offset[i]);
+       regcache->raw_collect (i, regs + tdep->gregset_reg_offset[i]);
     }
 }
 
@@ -3885,7 +3852,7 @@ static void
 i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
                      int regnum, const void *fpregs, size_t len)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
@@ -3908,7 +3875,7 @@ i386_collect_fpregset (const struct regset *regset,
                       const struct regcache *regcache,
                       int regnum, void *fpregs, size_t len)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
@@ -3943,9 +3910,11 @@ i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
-  cb (".reg", tdep->sizeof_gregset, &i386_gregset, NULL, cb_data);
+  cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
+      cb_data);
   if (tdep->sizeof_fpregset)
-    cb (".reg2", tdep->sizeof_fpregset, tdep->fpregset, NULL, cb_data);
+    cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, tdep->fpregset,
+       NULL, cb_data);
 }
 \f
 
@@ -4002,11 +3971,9 @@ i386_print_insn (bfd_vma pc, struct disassemble_info *info)
   gdb_assert (disassembly_flavor == att_flavor
              || disassembly_flavor == intel_flavor);
 
-  /* FIXME: kettenis/20020915: Until disassembler_options is properly
-     constified, cast to prevent a compiler warning.  */
-  info->disassembler_options = (char *) disassembly_flavor;
+  info->disassembler_options = disassembly_flavor;
 
-  return print_insn_i386 (pc, info);
+  return default_print_insn (pc, info);
 }
 \f
 
@@ -4433,6 +4400,15 @@ i386_gnu_triplet_regexp (struct gdbarch *gdbarch)
 
 \f
 
+/* Implement the "in_indirect_branch_thunk" gdbarch function.  */
+
+static bool
+i386_in_indirect_branch_thunk (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+  return x86_in_indirect_branch_thunk (pc, i386_register_names,
+                                      I386_EAX_REGNUM, I386_EIP_REGNUM);
+}
+
 /* Generic ELF.  */
 
 void
@@ -4460,7 +4436,8 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_stap_parse_special_token (gdbarch,
                                        i386_stap_parse_special_token);
 
-  set_gdbarch_gnu_triplet_regexp (gdbarch, i386_gnu_triplet_regexp);
+  set_gdbarch_in_indirect_branch_thunk (gdbarch,
+                                       i386_in_indirect_branch_thunk);
 }
 
 /* System V Release 4 (SVR4).  */
@@ -4484,33 +4461,6 @@ i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->jb_pc_offset = 20;
 }
 
-/* DJGPP.  */
-
-static void
-i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
-{
-  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
-
-  /* DJGPP doesn't have any special frames for signal handlers.  */
-  tdep->sigtramp_p = NULL;
-
-  tdep->jb_pc_offset = 36;
-
-  /* DJGPP does not support the SSE registers.  */
-  if (! tdesc_has_registers (info.target_desc))
-    tdep->tdesc = tdesc_i386_mmx;
-
-  /* Native compiler is GCC, which uses the SVR4 register numbering
-     even in COFF and STABS.  See the comment in i386_gdbarch_init,
-     before the calls to set_gdbarch_stab_reg_to_regnum and
-     set_gdbarch_sdb_reg_to_regnum.  */
-  set_gdbarch_stab_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
-  set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
-
-  set_gdbarch_has_dos_based_file_system (gdbarch, 1);
-
-  set_gdbarch_gnu_triplet_regexp (gdbarch, i386_gnu_triplet_regexp);
-}
 \f
 
 /* i386 register groups.  In addition to the normal groups, add "mmx"
@@ -4547,8 +4497,8 @@ i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
   const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
       ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
-      bndr_regnum_p, bnd_regnum_p, k_regnum_p, zmm_regnum_p, zmmh_regnum_p,
-      zmm_avx512_regnum_p, mpx_ctrl_regnum_p, xmm_avx512_regnum_p,
+      bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
+      mpx_ctrl_regnum_p, xmm_avx512_regnum_p,
       avx512_p, avx_p, sse_p, pkru_regnum_p;
 
   /* Don't include pseudo registers, except for MMX, in any register
@@ -5060,7 +5010,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
   uint32_t opcode;
   uint8_t opcode8;
   ULONGEST addr;
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte buf[I386_MAX_REGISTER_SIZE];
   struct i386_record_s ir;
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   uint8_t rex_w = -1;
@@ -7158,6 +7108,7 @@ Do you want to stop the program?"),
              else if (ir.rm == 1)
                break;
            }
+         /* Fall through.  */
        case 3:  /* lidt */
          if (ir.mod == 3)
            {
@@ -8152,7 +8103,7 @@ static const int i386_record_regmap[] =
 
 static int
 i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
-                              char **msg)
+                              std::string *msg)
 {
   int len, jumplen;
 
@@ -8185,15 +8136,15 @@ i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
       /* Return a bit of target-specific detail to add to the caller's
         generic failure message.  */
       if (msg)
-       *msg = xstrprintf (_("; instruction is only %d bytes long, "
-                            "need at least %d bytes for the jump"),
-                          len, jumplen);
+       *msg = string_printf (_("; instruction is only %d bytes long, "
+                               "need at least %d bytes for the jump"),
+                             len, jumplen);
       return 0;
     }
   else
     {
       if (msg)
-       *msg = NULL;
+       msg->clear ();
       return 1;
     }
 }
@@ -8374,6 +8325,31 @@ i386_validate_tdesc_p (struct gdbarch_tdep *tdep,
   return valid_p;
 }
 
+\f
+
+/* Implement the type_align gdbarch function.  */
+
+static ULONGEST
+i386_type_align (struct gdbarch *gdbarch, struct type *type)
+{
+  type = check_typedef (type);
+
+  if (gdbarch_ptr_bit (gdbarch) == 32)
+    {
+      if ((TYPE_CODE (type) == TYPE_CODE_INT
+          || TYPE_CODE (type) == TYPE_CODE_FLT)
+         && TYPE_LENGTH (type) > 4)
+       return 4;
+
+      /* Handle x86's funny long double.  */
+      if (TYPE_CODE (type) == TYPE_CODE_FLT
+         && gdbarch_long_double_bit (gdbarch) == TYPE_LENGTH (type) * 8)
+       return 4;
+    }
+
+  return TYPE_LENGTH (type);
+}
+
 \f
 /* Note: This is called for both i386 and amd64.  */
 
@@ -8432,7 +8408,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   tdep->record_regmap = i386_record_regmap;
 
-  set_gdbarch_long_long_align_bit (gdbarch, 32);
+  set_gdbarch_type_align (gdbarch, i386_type_align);
 
   /* The format used for `long double' on almost all i386 targets is
      the i387 extended floating-point format.  In fact, of all targets
@@ -8573,7 +8549,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Get the x86 target description from INFO.  */
   tdesc = info.target_desc;
   if (! tdesc_has_registers (tdesc))
-    tdesc = tdesc_i386;
+    tdesc = i386_target_description (X86_XSTATE_SSE_MASK);
   tdep->tdesc = tdesc;
 
   tdep->num_core_regs = I386_NUM_GREGS + I387_NUM_REGS;
@@ -8628,7 +8604,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Hook in ABI-specific overrides, if they have been registered.
      Note: If INFO specifies a 64 bit arch, this is where we turn
      a 32-bit i386 into a 64-bit amd64.  */
-  info.tdep_info = tdesc_data;
+  info.tdesc_data = tdesc_data;
   gdbarch_init_osabi (info, gdbarch);
 
   if (!i386_validate_tdesc_p (tdep, tdesc_data))
@@ -8735,15 +8711,6 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   return gdbarch;
 }
 
-static enum gdb_osabi
-i386_coff_osabi_sniffer (bfd *abfd)
-{
-  if (strcmp (bfd_get_target (abfd), "coff-go32-exe") == 0
-      || strcmp (bfd_get_target (abfd), "coff-go32") == 0)
-    return GDB_OSABI_GO32;
-
-  return GDB_OSABI_UNKNOWN;
-}
 \f
 
 /* Return the target description for a specified XSAVE feature mask.  */
@@ -8751,21 +8718,20 @@ i386_coff_osabi_sniffer (bfd *abfd)
 const struct target_desc *
 i386_target_description (uint64_t xcr0)
 {
-  switch (xcr0 & X86_XSTATE_ALL_MASK)
-    {
-    case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-      return tdesc_i386_avx_mpx_avx512_pku;
-    case X86_XSTATE_AVX_AVX512_MASK:
-      return tdesc_i386_avx_avx512;
-    case X86_XSTATE_AVX_MPX_MASK:
-      return tdesc_i386_avx_mpx;
-    case X86_XSTATE_MPX_MASK:
-      return tdesc_i386_mpx;
-    case X86_XSTATE_AVX_MASK:
-      return tdesc_i386_avx;
-    default:
-      return tdesc_i386;
-    }
+  static target_desc *i386_tdescs \
+    [2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {};
+  target_desc **tdesc;
+
+  tdesc = &i386_tdescs[(xcr0 & X86_XSTATE_SSE) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_AVX) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_MPX) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0];
+
+  if (*tdesc == NULL)
+    *tdesc = i386_create_target_description (xcr0, false);
+
+  return *tdesc;
 }
 
 #define MPX_BASE_MASK (~(ULONGEST) 0xfff)
@@ -8781,7 +8747,7 @@ i386_mpx_bd_base (void)
   enum register_status regstatus;
 
   rcache = get_current_regcache ();
-  tdep = gdbarch_tdep (get_regcache_arch (rcache));
+  tdep = gdbarch_tdep (rcache->arch ());
 
   regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
 
@@ -8913,7 +8879,7 @@ i386_mpx_print_bounds (const CORE_ADDR bt_entry[4])
 /* Implement the command "show mpx bound".  */
 
 static void
-i386_mpx_info_bounds (char *args, int from_tty)
+i386_mpx_info_bounds (const char *args, int from_tty)
 {
   CORE_ADDR bd_base = 0;
   CORE_ADDR addr;
@@ -8955,7 +8921,7 @@ i386_mpx_info_bounds (char *args, int from_tty)
 /* Implement the command "set mpx bound".  */
 
 static void
-i386_mpx_set_bounds (char *args, int from_tty)
+i386_mpx_set_bounds (const char *args, int from_tty)
 {
   CORE_ADDR bd_base = 0;
   CORE_ADDR addr, lower, upper;
@@ -9010,7 +8976,7 @@ static struct cmd_list_element *mpx_set_cmdlist, *mpx_show_cmdlist;
 /* Helper function for the CLI commands.  */
 
 static void
-set_mpx_cmd (char *args, int from_tty)
+set_mpx_cmd (const char *args, int from_tty)
 {
   help_list (mpx_set_cmdlist, "set mpx ", all_commands, gdb_stdout);
 }
@@ -9018,14 +8984,11 @@ set_mpx_cmd (char *args, int from_tty)
 /* Helper function for the CLI commands.  */
 
 static void
-show_mpx_cmd (char *args, int from_tty)
+show_mpx_cmd (const char *args, int from_tty)
 {
   cmd_show_list (mpx_show_cmdlist, from_tty, "");
 }
 
-/* Provide a prototype to silence -Wmissing-prototypes.  */
-void _initialize_i386_tdep (void);
-
 void
 _initialize_i386_tdep (void)
 {
@@ -9081,26 +9044,36 @@ Show Intel Memory Protection Extensions specific variables."),
  in the bound table.",
           &mpx_set_cmdlist);
 
-  gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
-                                 i386_coff_osabi_sniffer);
-
   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SVR4,
                          i386_svr4_init_abi);
-  gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_GO32,
-                         i386_go32_init_abi);
 
   /* Initialize the i386-specific register groups.  */
   i386_init_reggroups ();
 
-  /* Initialize the standard target descriptions.  */
-  initialize_tdesc_i386 ();
-  initialize_tdesc_i386_mmx ();
-  initialize_tdesc_i386_avx ();
-  initialize_tdesc_i386_mpx ();
-  initialize_tdesc_i386_avx_mpx ();
-  initialize_tdesc_i386_avx_avx512 ();
-  initialize_tdesc_i386_avx_mpx_avx512_pku ();
-
   /* Tell remote stub that we support XML target description.  */
   register_remote_support_xml ("i386");
+
+#if GDB_SELF_TEST
+  struct
+  {
+    const char *xml;
+    uint64_t mask;
+  } xml_masks[] = {
+    { "i386/i386.xml", X86_XSTATE_SSE_MASK },
+    { "i386/i386-mmx.xml", X86_XSTATE_X87_MASK },
+    { "i386/i386-avx.xml", X86_XSTATE_AVX_MASK },
+    { "i386/i386-mpx.xml", X86_XSTATE_MPX_MASK },
+    { "i386/i386-avx-mpx.xml", X86_XSTATE_AVX_MPX_MASK },
+    { "i386/i386-avx-avx512.xml", X86_XSTATE_AVX_AVX512_MASK },
+    { "i386/i386-avx-mpx-avx512-pku.xml",
+      X86_XSTATE_AVX_MPX_AVX512_PKU_MASK },
+  };
+
+  for (auto &a : xml_masks)
+    {
+      auto tdesc = i386_target_description (a.mask);
+
+      selftests::record_xml_tdesc (a.xml, tdesc);
+    }
+#endif /* GDB_SELF_TEST */
 }
This page took 0.048575 seconds and 4 git commands to generate.