Remove regcache_cooked_write
[deliverable/binutils-gdb.git] / gdb / i386-tdep.c
index 9ce329eb20978c42981730c2a8e778a96407da56..158344f2309bfbbdbcc7f082a650f2c367be0839 100644 (file)
@@ -47,6 +47,7 @@
 #include "i386-tdep.h"
 #include "i387-tdep.h"
 #include "x86-xstate.h"
+#include "x86-tdep.h"
 
 #include "record.h"
 #include "record-full.h"
@@ -2754,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,
@@ -2801,7 +2802,7 @@ 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);
+      regcache->raw_read (I386_ST0_REGNUM, buf);
       target_float_convert (buf, i387_ext_type (gdbarch), valbuf, type);
     }
   else
@@ -2811,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
@@ -2858,7 +2859,7 @@ i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
         not exactly how it would happen on the target itself, but
         it is the best we can do.  */
       target_float_convert (valbuf, type, buf, i387_ext_type (gdbarch));
-      regcache_raw_write (regcache, I386_ST0_REGNUM, buf);
+      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
@@ -2879,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__,
@@ -3248,7 +3249,7 @@ 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 (regcache->arch ());
   int mmxreg, fpreg;
@@ -3256,7 +3257,7 @@ i386_mmx_regnum_to_fp_regnum (struct regcache *regcache, int regnum)
   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;
 
@@ -3269,7 +3270,7 @@ 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)
 {
@@ -3282,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)));
@@ -3297,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
@@ -3321,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
@@ -3336,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
@@ -3356,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
@@ -3377,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
@@ -3390,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
@@ -3410,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
@@ -3431,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)));
@@ -3444,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)));
@@ -3460,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;
@@ -3485,11 +3474,11 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
       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
     {
@@ -3507,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;
 
@@ -3517,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))
        {
@@ -3537,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"));
@@ -4433,6 +4398,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
@@ -4459,6 +4433,9 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
                                      i386_stap_is_single_operand);
   set_gdbarch_stap_parse_special_token (gdbarch,
                                        i386_stap_parse_special_token);
+
+  set_gdbarch_in_indirect_branch_thunk (gdbarch,
+                                       i386_in_indirect_branch_thunk);
 }
 
 /* System V Release 4 (SVR4).  */
@@ -7129,6 +7106,7 @@ Do you want to stop the program?"),
              else if (ir.rm == 1)
                break;
            }
+         /* Fall through.  */
        case 3:  /* lidt */
          if (ir.mod == 3)
            {
@@ -8123,7 +8101,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;
 
@@ -8156,15 +8134,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;
     }
 }
@@ -8345,6 +8323,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.  */
 
@@ -8403,7 +8406,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
This page took 0.031836 seconds and 4 git commands to generate.