Fix regression caused by recently added syscall restart code
[external/binutils.git] / gdb / nds32-tdep.c
index 05c48aa..801b2da 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for the NDS32 architecture, for GDB.
 
-   Copyright (C) 2013-2017 Free Software Foundation, Inc.
+   Copyright (C) 2013-2019 Free Software Foundation, Inc.
    Contributed by Andes Technology Corporation.
 
    This file is part of GDB.
@@ -55,8 +55,6 @@
 #define N32_FLDI_SP \
        N32_TYPE2 (LDC, 0, REG_SP, 0)
 
-extern void _initialize_nds32_tdep (void);
-
 /* Use an invalid address value as 'not available' marker.  */
 enum { REG_UNAVAIL = (CORE_ADDR) -1 };
 
@@ -439,17 +437,18 @@ nds32_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 
 static enum register_status
 nds32_pseudo_register_read (struct gdbarch *gdbarch,
-                           struct regcache *regcache, int regnum,
+                           readable_regcache *regcache, int regnum,
                            gdb_byte *buf)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
-  enum register_status status = REG_UNKNOWN;
+  enum register_status status;
 
-  /* Sanity check.  */
-  if (tdep->fpu_freg == -1 || tdep->use_pseudo_fsrs == 0)
-    return status;
+  /* This function is registered in nds32_gdbarch_init only after these are
+     set.  */
+  gdb_assert (tdep->fpu_freg != -1);
+  gdb_assert (tdep->use_pseudo_fsrs != 0);
 
   regnum -= gdbarch_num_regs (gdbarch);
 
@@ -463,12 +462,14 @@ nds32_pseudo_register_read (struct gdbarch *gdbarch,
        offset = (regnum & 1) ? 0 : 4;
 
       fdr_regnum = NDS32_FD0_REGNUM + (regnum >> 1);
-      status = regcache_raw_read (regcache, fdr_regnum, reg_buf);
+      status = regcache->raw_read (fdr_regnum, reg_buf);
       if (status == REG_VALID)
        memcpy (buf, reg_buf + offset, 4);
+
+      return status;
     }
 
-  return status;
+  gdb_assert_not_reached ("invalid pseudo register number");
 }
 
 /* Implement the "pseudo_register_write" gdbarch method.  */
@@ -482,9 +483,10 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
 
-  /* Sanity check.  */
-  if (tdep->fpu_freg == -1 || tdep->use_pseudo_fsrs == 0)
-    return;
+  /* This function is registered in nds32_gdbarch_init only after these are
+     set.  */
+  gdb_assert (tdep->fpu_freg != -1);
+  gdb_assert (tdep->use_pseudo_fsrs != 0);
 
   regnum -= gdbarch_num_regs (gdbarch);
 
@@ -498,10 +500,13 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
        offset = (regnum & 1) ? 0 : 4;
 
       fdr_regnum = NDS32_FD0_REGNUM + (regnum >> 1);
-      regcache_raw_read (regcache, fdr_regnum, reg_buf);
+      regcache->raw_read (fdr_regnum, reg_buf);
       memcpy (reg_buf + offset, buf, 4);
-      regcache_raw_write (regcache, fdr_regnum, reg_buf);
+      regcache->raw_write (fdr_regnum, reg_buf);
+      return;
     }
+
+  gdb_assert_not_reached ("invalid pseudo register number");
 }
 \f
 /* Helper function for NDS32 ABI.  Return true if FPRs can be used
@@ -1485,7 +1490,8 @@ static CORE_ADDR
 nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                       struct regcache *regcache, CORE_ADDR bp_addr,
                       int nargs, struct value **args, CORE_ADDR sp,
-                      int struct_return, CORE_ADDR struct_addr)
+                      function_call_return_method return_method,
+                      CORE_ADDR struct_addr)
 {
   const int REND = 6;          /* End for register offset.  */
   int goff = 0;                        /* Current gpr offset for argument.  */
@@ -1506,7 +1512,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* If STRUCT_RETURN is true, then the struct return address (in
      STRUCT_ADDR) will consume the first argument-passing register.
      Both adjust the register count and store that value.  */
-  if (struct_return)
+  if (return_method == return_method_struct)
     {
       regcache_cooked_write_unsigned (regcache, NDS32_R0_REGNUM, struct_addr);
       goff++;
@@ -1582,13 +1588,11 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
              switch (len)
                {
                case 4:
-                 regcache_cooked_write (regcache,
-                                        tdep->fs0_regnum + foff, val);
+                 regcache->cooked_write (tdep->fs0_regnum + foff, val);
                  foff++;
                  break;
                case 8:
-                 regcache_cooked_write (regcache,
-                                        NDS32_FD0_REGNUM + (foff >> 1), val);
+                 regcache->cooked_write (NDS32_FD0_REGNUM + (foff >> 1), val);
                  foff += 2;
                  break;
                default:
@@ -1735,9 +1739,9 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
   if (abi_use_fpr && calling_use_fpr)
     {
       if (len == 4)
-       regcache_cooked_read (regcache, tdep->fs0_regnum, valbuf);
+       regcache->cooked_read (tdep->fs0_regnum, valbuf);
       else if (len == 8)
-       regcache_cooked_read (regcache, NDS32_FD0_REGNUM, valbuf);
+       regcache->cooked_read (NDS32_FD0_REGNUM, valbuf);
       else
        internal_error (__FILE__, __LINE__,
                        _("Cannot extract return value of %d bytes "
@@ -1783,7 +1787,7 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
        }
       else if (len == 4)
        {
-         regcache_cooked_read (regcache, NDS32_R0_REGNUM, valbuf);
+         regcache->cooked_read (NDS32_R0_REGNUM, valbuf);
        }
       else if (len < 8)
        {
@@ -1800,8 +1804,8 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
        }
       else
        {
-         regcache_cooked_read (regcache, NDS32_R0_REGNUM, valbuf);
-         regcache_cooked_read (regcache, NDS32_R0_REGNUM + 1, valbuf + 4);
+         regcache->cooked_read (NDS32_R0_REGNUM, valbuf);
+         regcache->cooked_read (NDS32_R0_REGNUM + 1, valbuf + 4);
        }
     }
 }
@@ -1825,9 +1829,9 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
   if (abi_use_fpr && calling_use_fpr)
     {
       if (len == 4)
-       regcache_cooked_write (regcache, tdep->fs0_regnum, valbuf);
+       regcache->cooked_write (tdep->fs0_regnum, valbuf);
       else if (len == 8)
-       regcache_cooked_write (regcache, NDS32_FD0_REGNUM, valbuf);
+       regcache->cooked_write (NDS32_FD0_REGNUM, valbuf);
       else
        internal_error (__FILE__, __LINE__,
                        _("Cannot store return value of %d bytes "
@@ -1844,7 +1848,7 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
        }
       else if (len == 4)
        {
-         regcache_cooked_write (regcache, NDS32_R0_REGNUM, valbuf);
+         regcache->cooked_write (NDS32_R0_REGNUM, valbuf);
        }
       else if (len < 8)
        {
@@ -1862,8 +1866,8 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
        }
       else
        {
-         regcache_cooked_write (regcache, NDS32_R0_REGNUM, valbuf);
-         regcache_cooked_write (regcache, NDS32_R0_REGNUM + 1, valbuf + 4);
+         regcache->cooked_write (NDS32_R0_REGNUM, valbuf);
+         regcache->cooked_write (NDS32_R0_REGNUM + 1, valbuf + 4);
        }
     }
 }
@@ -2069,6 +2073,9 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   gdbarch = gdbarch_alloc (&info, tdep);
 
+  set_gdbarch_wchar_bit (gdbarch, 16);
+  set_gdbarch_wchar_signed (gdbarch, 0);
+
   if (fpu_freg == -1)
     num_regs = NDS32_NUM_REGS;
   else if (use_pseudo_fsrs == 1)
@@ -2093,7 +2100,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Add NDS32 register aliases.  To avoid search in user register name space,
      user_reg_map_name_to_regnum is not used.  */
-  maxregs = (gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch));
+  maxregs = gdbarch_num_cooked_regs (gdbarch);
   for (i = 0; i < ARRAY_SIZE (nds32_register_aliases); i++)
     {
       int regnum, j;
@@ -2124,7 +2131,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   nds32_add_reggroups (gdbarch);
 
   /* Hook in ABI-specific overrides, if they have been registered.  */
-  info.tdep_info = (void *) tdesc_data;
+  info.tdesc_data = tdesc_data;
   gdbarch_init_osabi (info, gdbarch);
 
   /* Override tdesc_register callbacks for system registers.  */
@@ -2151,8 +2158,6 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_frame_align (gdbarch, nds32_frame_align);
   frame_base_set_default (gdbarch, &nds32_frame_base);
 
-  set_gdbarch_print_insn (gdbarch, print_insn_nds32);
-
   /* Handle longjmp.  */
   set_gdbarch_get_longjmp_target (gdbarch, nds32_get_longjmp_target);