gdb/
[deliverable/binutils-gdb.git] / gdb / xtensa-tdep.c
index 200ad2665a30a64aedac510dede4846edf337969..ff683faaf0e80b53d5c0b79215b3dd351657036e 100644 (file)
@@ -1,6 +1,7 @@
 /* Target-dependent code for the Xtensa port of GDB, the GNU debugger.
 
-   Copyright (C) 2003, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005, 2006, 2007, 2008, 2009
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -164,6 +165,7 @@ windowing_enabled (CORE_ADDR ps)
 static int
 extract_call_winsize (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int winsize = 4;
   int insn;
   gdb_byte buf[4];
@@ -172,7 +174,7 @@ extract_call_winsize (struct gdbarch *gdbarch, CORE_ADDR pc)
 
   /* Read the previous instruction (should be a call[x]{4|8|12}.  */
   read_memory (pc-3, buf, 3);
-  insn = extract_unsigned_integer (buf, 3);
+  insn = extract_unsigned_integer (buf, 3, byte_order);
 
   /* Decode call instruction:
      Little Endian
@@ -182,7 +184,7 @@ extract_call_winsize (struct gdbarch *gdbarch, CORE_ADDR pc)
        call{0,4,8,12}   0101 || {00,01,10,11} || OFFSET
        callx{0,4,8,12}  0000 || {00,01,10,11} || 11 || OFFSET.  */
 
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
+  if (byte_order == BFD_ENDIAN_LITTLE)
     {
       if (((insn & 0xf) == 0x5) || ((insn & 0xcf) == 0xc0))
        winsize = (insn & 0x30) >> 2;   /* 0, 4, 8, 12.  */
@@ -211,44 +213,29 @@ xtensa_register_name (struct gdbarch *gdbarch, int regnum)
   return 0;
 }
 
-static unsigned long
-xtensa_read_register (int regnum)
-{
-  ULONGEST value;
-
-  regcache_raw_read_unsigned (get_current_regcache (), regnum, &value);
-  return (unsigned long) value;
-}
-
 /* Return the type of a register.  Create a new type, if necessary.  */
 
-static struct ctype_cache
-{
-  struct ctype_cache *next;
-  int size;
-  struct type *virtual_type;
-} *type_entries = NULL;
-
 static struct type *
 xtensa_register_type (struct gdbarch *gdbarch, int regnum)
 {
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
   /* Return signed integer for ARx and Ax registers.  */
-  if ((regnum >= gdbarch_tdep (gdbarch)->ar_base
-      && regnum < gdbarch_tdep (gdbarch)->ar_base
-                   + gdbarch_tdep (gdbarch)->num_aregs)
-      || (regnum >= gdbarch_tdep (gdbarch)->a0_base
-      && regnum < gdbarch_tdep (gdbarch)->a0_base + 16))
-    return builtin_type_int;
+  if ((regnum >= tdep->ar_base
+       && regnum < tdep->ar_base + tdep->num_aregs)
+      || (regnum >= tdep->a0_base
+         && regnum < tdep->a0_base + 16))
+    return builtin_type (gdbarch)->builtin_int;
 
   if (regnum == gdbarch_pc_regnum (gdbarch)
-      || regnum == gdbarch_tdep (gdbarch)->a0_base + 1)
-    return lookup_pointer_type (builtin_type_void);
+      || regnum == tdep->a0_base + 1)
+    return builtin_type (gdbarch)->builtin_data_ptr;
 
   /* Return the stored type for all other registers.  */
   else if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)
                                   + gdbarch_num_pseudo_regs (gdbarch))
     {
-      xtensa_register_t* reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
+      xtensa_register_t* reg = &tdep->regmap[regnum];
 
       /* Set ctype for this register (only the first time).  */
 
@@ -262,27 +249,27 @@ xtensa_register_type (struct gdbarch *gdbarch, int regnum)
          switch (size)
            {
            case 1:
-             reg->ctype = builtin_type_uint8;
+             reg->ctype = builtin_type (gdbarch)->builtin_uint8;
              break;
 
            case 2:
-             reg->ctype = builtin_type_uint16;
+             reg->ctype = builtin_type (gdbarch)->builtin_uint16;
              break;
 
            case 4:
-             reg->ctype = builtin_type_uint32;
+             reg->ctype = builtin_type (gdbarch)->builtin_uint32;
              break;
 
            case 8:
-             reg->ctype = builtin_type_uint64;
+             reg->ctype = builtin_type (gdbarch)->builtin_uint64;
              break;
 
            case 16:
-             reg->ctype = builtin_type_uint128;
+             reg->ctype = builtin_type (gdbarch)->builtin_uint128;
              break;
 
            default:
-             for (tp = type_entries; tp != NULL; tp = tp->next)
+             for (tp = tdep->type_entries; tp != NULL; tp = tp->next)
                if (tp->size == size)
                  break;
 
@@ -290,14 +277,13 @@ xtensa_register_type (struct gdbarch *gdbarch, int regnum)
                {
                  char *name = xmalloc (16);
                  tp = xmalloc (sizeof (struct ctype_cache));
-                 tp->next = type_entries;
-                 type_entries = tp;
+                 tp->next = tdep->type_entries;
+                 tdep->type_entries = tp;
                  tp->size = size;
 
                  sprintf (name, "int%d", size * 8);
-                 tp->virtual_type = init_type (TYPE_CODE_INT, size,
-                                               TYPE_FLAG_UNSIGNED, name,
-                                               NULL);
+                 tp->virtual_type
+                   = arch_integer_type (gdbarch, size * 8, 1, xstrdup (name));
                }
 
              reg->ctype = tp->virtual_type;
@@ -517,6 +503,8 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
                             int regnum,
                             gdb_byte *buffer)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
   DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
              regnum, xtensa_register_name (gdbarch, regnum));
 
@@ -533,7 +521,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
 
       regcache_raw_read (regcache, gdbarch_tdep (gdbarch)->wb_regnum, buf);
       regnum = arreg_number (gdbarch, regnum,
-                            extract_unsigned_integer (buf, 4));
+                            extract_unsigned_integer (buf, 4, byte_order));
     }
 
   /* We can always read non-pseudo registers.  */
@@ -613,6 +601,8 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
                              int regnum,
                              const gdb_byte *buffer)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
   DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
              regnum, xtensa_register_name (gdbarch, regnum));
 
@@ -631,7 +621,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
       regcache_raw_read (regcache,
                         gdbarch_tdep (gdbarch)->wb_regnum, buf);
       regnum = arreg_number (gdbarch, regnum,
-                            extract_unsigned_integer (buf, 4));
+                            extract_unsigned_integer (buf, 4, byte_order));
     }
 
   /* We can always write 'core' registers.
@@ -959,7 +949,7 @@ typedef struct xtensa_frame_cache
   CORE_ADDR base;      /* Stack pointer of this frame.  */
   CORE_ADDR pc;                /* PC at the entry point to the function.  */
   CORE_ADDR ra;                /* The raw return address (without CALLINC).  */
-  CORE_ADDR ps;                /* The PS register of the previous frame.  */
+  CORE_ADDR ps;                /* The PS register of this frame.  */
   CORE_ADDR prev_sp;   /* Stack Pointer of the previous frame.  */
   int call0;           /* It's a call0 framework (else windowed).  */
   union
@@ -1024,30 +1014,30 @@ static CORE_ADDR
 xtensa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
 {
   gdb_byte buf[8];
+  CORE_ADDR pc;
 
-  DEBUGTRACE ("xtensa_unwind_pc (next_frame = %p)\n", next_frame);
+  DEBUGTRACE ("xtensa_unwind_pc (next_frame = %s)\n", 
+               host_address_to_string (next_frame));
 
   frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
+  pc = extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
 
-  DEBUGINFO ("[xtensa_unwind_pc] pc = 0x%08x\n", (unsigned int)
-            extract_typed_address (buf, builtin_type_void_func_ptr));
+  DEBUGINFO ("[xtensa_unwind_pc] pc = 0x%08x\n", (unsigned int) pc);
 
-  return extract_typed_address (buf, builtin_type_void_func_ptr);
+  return pc;
 }
 
 
 static struct frame_id
-xtensa_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
+xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
 {
   CORE_ADDR pc, fp;
 
-  /* next_frame->prev is a dummy frame.  Return a frame ID of that frame.  */
+  /* THIS-FRAME is a dummy frame.  Return a frame ID of that frame.  */
 
-  DEBUGTRACE ("xtensa_unwind_dummy_id ()\n");
-
-  pc = frame_pc_unwind (next_frame);
-  fp = frame_unwind_register_unsigned
-        (next_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
+  pc = get_frame_pc (this_frame);
+  fp = get_frame_register_unsigned
+        (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
 
   /* Make dummy frame ID unique by adding a constant.  */
   return frame_id_build (fp + SP_ALIGNMENT, pc);
@@ -1178,61 +1168,54 @@ done:
 */
 
 static void
-call0_frame_cache (struct frame_info *next_frame,
+call0_frame_cache (struct frame_info *this_frame,
                   xtensa_frame_cache_t *cache,
-                  CORE_ADDR pc);
+                  CORE_ADDR pc, CORE_ADDR litbase);
 
 static struct xtensa_frame_cache *
-xtensa_frame_cache (struct frame_info *next_frame, void **this_cache)
+xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   xtensa_frame_cache_t *cache;
   CORE_ADDR ra, wb, ws, pc, sp, ps;
-  struct gdbarch *gdbarch = get_frame_arch (next_frame);
-  unsigned int ps_regnum = gdbarch_ps_regnum (gdbarch);
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int fp_regnum;
   char op1;
   int  windowed;
 
-  DEBUGTRACE ("xtensa_frame_cache (next_frame %p, *this_cache %p)\n",
-             next_frame, this_cache ? *this_cache : (void*)0xdeadbeef);
-
   if (*this_cache)
     return *this_cache;
 
-  windowed = windowing_enabled (xtensa_read_register (ps_regnum));
+  ps = get_frame_register_unsigned (this_frame, gdbarch_ps_regnum (gdbarch));
+  windowed = windowing_enabled (ps);
 
   /* Get pristine xtensa-frame.  */
   cache = xtensa_alloc_frame_cache (windowed);
   *this_cache = cache;
 
-  pc = frame_unwind_register_unsigned (next_frame,
-                                      gdbarch_pc_regnum (gdbarch));
+  pc = get_frame_register_unsigned (this_frame, gdbarch_pc_regnum (gdbarch));
 
   if (windowed)
     {
       /* Get WINDOWBASE, WINDOWSTART, and PS registers.  */
-      wb = frame_unwind_register_unsigned
-            (next_frame, gdbarch_tdep (gdbarch)->wb_regnum);
-      ws = frame_unwind_register_unsigned
-            (next_frame, gdbarch_tdep (gdbarch)->ws_regnum);
-      ps = frame_unwind_register_unsigned (next_frame, ps_regnum);
+      wb = get_frame_register_unsigned (this_frame, 
+                                       gdbarch_tdep (gdbarch)->wb_regnum);
+      ws = get_frame_register_unsigned (this_frame,
+                                       gdbarch_tdep (gdbarch)->ws_regnum);
 
-      op1 = read_memory_integer (pc, 1);
+      op1 = read_memory_integer (pc, 1, byte_order);
       if (XTENSA_IS_ENTRY (gdbarch, op1))
        {
          int callinc = CALLINC (ps);
-         ra = frame_unwind_register_unsigned
-           (next_frame, gdbarch_tdep (gdbarch)->a0_base + callinc * 4);
-         
-         DEBUGINFO("[xtensa_frame_cache] 'entry' at 0x%08x\n (callinc = %d)",
-                   (int)pc, callinc);
+         ra = get_frame_register_unsigned
+           (this_frame, gdbarch_tdep (gdbarch)->a0_base + callinc * 4);
          
          /* ENTRY hasn't been executed yet, therefore callsize is still 0.  */
          cache->wd.callsize = 0;
          cache->wd.wb = wb;
          cache->wd.ws = ws;
-         cache->prev_sp = frame_unwind_register_unsigned
-                            (next_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
+         cache->prev_sp = get_frame_register_unsigned
+                            (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
 
          /* This only can be the outermost frame since we are
             just about to execute ENTRY.  SP hasn't been set yet.
@@ -1250,15 +1233,15 @@ xtensa_frame_cache (struct frame_info *next_frame, void **this_cache)
       else
        {
          fp_regnum = xtensa_scan_prologue (gdbarch, pc);
-         ra = frame_unwind_register_unsigned
-                (next_frame, gdbarch_tdep (gdbarch)->a0_base);
+         ra = get_frame_register_unsigned (this_frame,
+                                           gdbarch_tdep (gdbarch)->a0_base);
          cache->wd.callsize = WINSIZE (ra);
          cache->wd.wb = (wb - cache->wd.callsize / 4)
                          & (gdbarch_tdep (gdbarch)->num_aregs / 4 - 1);
          cache->wd.ws = ws & ~(1 << wb);
 
-         cache->pc = frame_func_unwind (next_frame, NORMAL_FRAME);
-         cache->ra = (cache->pc & 0xc0000000) | (ra & 0x3fffffff);
+         cache->pc = get_frame_func (this_frame);
+         cache->ra = (pc & 0xc0000000) | (ra & 0x3fffffff);
          cache->ps = (ps & ~PS_CALLINC_MASK)
            | ((WINSIZE(ra)/4) << PS_CALLINC_SHIFT);
        }
@@ -1268,8 +1251,8 @@ xtensa_frame_cache (struct frame_info *next_frame, void **this_cache)
          int i;
 
          /* Set A0...A3.  */
-         sp = frame_unwind_register_unsigned
-                (next_frame, gdbarch_tdep (gdbarch)->a0_base + 1) - 16;
+         sp = get_frame_register_unsigned
+           (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1) - 16;
          
          for (i = 0; i < 4; i++, sp += 4)
            {
@@ -1281,8 +1264,8 @@ xtensa_frame_cache (struct frame_info *next_frame, void **this_cache)
              /* Set A4...A7/A11.  */
              /* Get the SP of the frame previous to the previous one.
                 To achieve this, we have to dereference SP twice.  */
-             sp = (CORE_ADDR) read_memory_integer (sp - 12, 4);
-             sp = (CORE_ADDR) read_memory_integer (sp - 12, 4);
+             sp = (CORE_ADDR) read_memory_integer (sp - 12, 4, byte_order);
+             sp = (CORE_ADDR) read_memory_integer (sp - 12, 4, byte_order);
              sp -= cache->wd.callsize * 4;
 
              for ( i = 4; i < cache->wd.callsize; i++, sp += 4)
@@ -1300,9 +1283,9 @@ xtensa_frame_cache (struct frame_info *next_frame, void **this_cache)
            {
              /* Register window overflow already happened.
                 We can read caller's SP from the proper spill loction.  */
-             sp = frame_unwind_register_unsigned (next_frame,
-                    gdbarch_tdep (gdbarch)->a0_base + 1);
-             cache->prev_sp = read_memory_integer (sp - 12, 4); 
+             sp = get_frame_register_unsigned
+               (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
+             cache->prev_sp = read_memory_integer (sp - 12, 4, byte_order);
            }
          else
            {
@@ -1311,116 +1294,52 @@ xtensa_frame_cache (struct frame_info *next_frame, void **this_cache)
                             (gdbarch, gdbarch_tdep (gdbarch)->a0_base + 1,
                              cache->wd.wb);
 
-             cache->prev_sp = xtensa_read_register (regnum);
+             cache->prev_sp = get_frame_register_unsigned (this_frame, regnum);
            }
        }
     }
   else /* Call0 framework.  */
     {
-      call0_frame_cache (next_frame, cache, pc);
+      unsigned int litbase_regnum = gdbarch_tdep (gdbarch)->litbase_regnum;
+      CORE_ADDR litbase = (litbase_regnum == -1)
+       ? 0 : get_frame_register_unsigned (this_frame, litbase_regnum);
+
+      call0_frame_cache (this_frame, cache, pc, litbase);
       fp_regnum = cache->c0.fp_regnum;
     }
 
-  cache->base = frame_unwind_register_unsigned (next_frame, fp_regnum);
+  cache->base = get_frame_register_unsigned (this_frame, fp_regnum);
 
   return cache;
 }
 
 static void
-xtensa_frame_this_id (struct frame_info *next_frame,
+xtensa_frame_this_id (struct frame_info *this_frame,
                      void **this_cache,
                      struct frame_id *this_id)
 {
   struct xtensa_frame_cache *cache =
-    xtensa_frame_cache (next_frame, this_cache);
-  struct frame_id id;
-
-  DEBUGTRACE ("xtensa_frame_this_id (next 0x%lx, *this 0x%lx)\n",
-             (unsigned long) next_frame, (unsigned long) *this_cache);
+    xtensa_frame_cache (this_frame, this_cache);
 
   if (cache->prev_sp == 0)
     return;
 
-  id = frame_id_build (cache->prev_sp, cache->pc);
-  if (frame_id_eq (id, get_frame_id(next_frame)))
-    {
-      warning(_("\
-Frame stack is corrupted. That could happen because of \
-setting register(s) from GDB or stopping execution \
-inside exception handler. Frame backtracing has stopped. \
-It can make some GDB commands work inappropriately.\n"));
-      cache->prev_sp = 0;
-      return;
-    }
-  (*this_id) = id;
+  (*this_id) = frame_id_build (cache->prev_sp, cache->pc);
 }
 
-static int
-call0_frame_get_reg_at_entry (struct frame_info *next_frame,
-                             struct xtensa_frame_cache *cache,
-                             int regnum, 
-                             CORE_ADDR *addrp,
-                             enum lval_type *lval,
-                             gdb_byte *valuep)
-{
-  CORE_ADDR fp, spe;
-  int stkofs;
-  struct gdbarch *gdbarch = get_frame_arch (next_frame);
-  int reg = (regnum >= gdbarch_tdep (gdbarch)->ar_base
-           && regnum <= (gdbarch_tdep (gdbarch)->ar_base + C0_NREGS))
-             ? regnum - gdbarch_tdep (gdbarch)->ar_base : regnum;
-
-  /* Determine stack pointer on entry to this function, based on FP.  */
-  spe = cache->c0.c0_fp - cache->c0.c0_rt[cache->c0.fp_regnum].fr_ofs;
-
-  /* If register was saved to the stack frame in the prologue, retrieve it.  */
-  stkofs = cache->c0.c0_rt[reg].to_stk;
-  if (stkofs != C0_NOSTK)
-    {
-      *lval = lval_memory;
-      *addrp = spe + stkofs;
-
-      if (valuep)
-       read_memory (*addrp, valuep, register_size (gdbarch, regnum));
-
-      return 1;
-    }
-
-  /* If not callee-saved or if known to have been overwritten, give up.  */
-  if (reg < C0_CLESV 
-      || cache->c0.c0_rt[reg].fr_reg != reg
-      || cache->c0.c0_rt[reg].fr_ofs != 0)
-    return 0;
-
-  if (get_frame_type (next_frame) != NORMAL_FRAME)
-    /* TODO: Do we need a special case for DUMMY_FRAME here?  */
-    return 0;
-
-  return call0_frame_get_reg_at_entry (get_next_frame(next_frame),
-                                      cache, regnum, addrp, lval, valuep);
-}
-
-static void
-xtensa_frame_prev_register (struct frame_info *next_frame,
+static struct value *
+xtensa_frame_prev_register (struct frame_info *this_frame,
                            void **this_cache,
-                           int regnum,
-                           int *optimizedp,
-                           enum lval_type *lvalp,
-                           CORE_ADDR *addrp,
-                           int *realnump,
-                           gdb_byte *valuep)
+                           int regnum)
 {
-  struct gdbarch *gdbarch = get_frame_arch (next_frame);
-  struct xtensa_frame_cache *cache =
-    xtensa_frame_cache (next_frame, this_cache);
-  CORE_ADDR saved_reg = 0;
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  struct xtensa_frame_cache *cache;
+  ULONGEST saved_reg = 0;
   int done = 1;
 
-  DEBUGTRACE ("xtensa_frame_prev_register (next 0x%lx, "
-             "*this 0x%lx, regnum %d (%s), ...)\n",
-             (unsigned long) next_frame,
-             *this_cache ? (unsigned long) *this_cache : 0, regnum,
-             xtensa_register_name (gdbarch, regnum));
+  if (*this_cache == NULL)
+    *this_cache = xtensa_frame_cache (this_frame, this_cache);
+  cache = *this_cache;
 
   if (regnum ==gdbarch_pc_regnum (gdbarch))
     saved_reg = cache->ra;
@@ -1441,16 +1360,7 @@ xtensa_frame_prev_register (struct frame_info *next_frame,
     done = 0;
 
   if (done)
-    {
-      *optimizedp = 0;
-      *lvalp = not_lval;
-      *addrp = 0;
-      *realnump = -1;
-      if (valuep)
-       store_unsigned_integer (valuep, 4, saved_reg);
-
-      return;
-    }
+    return frame_unwind_got_constant (this_frame, regnum, saved_reg);
 
   if (!cache->call0) /* Windowed ABI.  */
     {
@@ -1470,19 +1380,8 @@ xtensa_frame_prev_register (struct frame_info *next_frame,
          if (areg >= 0
              && areg < XTENSA_NUM_SAVED_AREGS
              && cache->wd.aregs[areg] != -1)
-           {
-             *optimizedp = 0;
-             *lvalp = lval_memory;
-             *addrp = cache->wd.aregs[areg];
-             *realnump = -1;
-
-             if (valuep)
-               read_memory (*addrp, valuep,
-                            register_size (gdbarch, regnum));
-
-             DEBUGINFO ("[xtensa_frame_prev_register] register on stack\n");
-             return;
-           }
+           return frame_unwind_got_memory (this_frame, regnum,
+                                           cache->wd.aregs[areg]);
        }
     }
   else /* Call0 ABI.  */
@@ -1504,17 +1403,8 @@ xtensa_frame_prev_register (struct frame_info *next_frame,
              /* Determine SP on entry based on FP.  */
              spe = cache->c0.c0_fp
                - cache->c0.c0_rt[cache->c0.fp_regnum].fr_ofs;
-             *optimizedp = 0;
-             *lvalp = lval_memory;
-             *addrp = spe + stkofs;
-             *realnump = -1;
-         
-             if (valuep)
-               read_memory (*addrp, valuep,
-                            register_size (gdbarch, regnum));
-         
-             DEBUGINFO ("[xtensa_frame_prev_register] register on stack\n");
-             return;
+
+             return frame_unwind_got_memory (this_frame, regnum, spe + stkofs);
            }
        }
     }
@@ -1522,34 +1412,25 @@ xtensa_frame_prev_register (struct frame_info *next_frame,
   /* All other registers have been either saved to
      the stack or are still alive in the processor.  */
 
-  *optimizedp = 0;
-  *lvalp = lval_register;
-  *addrp = 0;
-  *realnump = regnum;
-  if (valuep)
-    frame_unwind_register (next_frame, (*realnump), valuep);
+  return frame_unwind_got_register (this_frame, regnum, regnum);
 }
 
 
 static const struct frame_unwind
-xtensa_frame_unwind =
+xtensa_unwind =
 {
   NORMAL_FRAME,
   xtensa_frame_this_id,
-  xtensa_frame_prev_register
+  xtensa_frame_prev_register,
+  NULL,
+  default_frame_sniffer
 };
 
-static const struct frame_unwind *
-xtensa_frame_sniffer (struct frame_info *next_frame)
-{
-  return &xtensa_frame_unwind;
-}
-
 static CORE_ADDR
-xtensa_frame_base_address (struct frame_info *next_frame, void **this_cache)
+xtensa_frame_base_address (struct frame_info *this_frame, void **this_cache)
 {
   struct xtensa_frame_cache *cache =
-    xtensa_frame_cache (next_frame, this_cache);
+    xtensa_frame_cache (this_frame, this_cache);
 
   return cache->base;
 }
@@ -1557,7 +1438,7 @@ xtensa_frame_base_address (struct frame_info *next_frame, void **this_cache)
 static const struct frame_base
 xtensa_frame_base =
 {
-  &xtensa_frame_unwind,
+  &xtensa_unwind,
   xtensa_frame_base_address,
   xtensa_frame_base_address,
   xtensa_frame_base_address
@@ -1716,6 +1597,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
                        int struct_return,
                        CORE_ADDR struct_addr)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i;
   int size, onstack_size;
   gdb_byte *buf = (gdb_byte *) alloca (16);
@@ -1798,9 +1680,10 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
        case TYPE_CODE_ENUM:
 
          /* Cast argument to long if necessary as the mask does it too.  */
-         if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
+         if (TYPE_LENGTH (arg_type)
+             < TYPE_LENGTH (builtin_type (gdbarch)->builtin_long))
            {
-             arg_type = builtin_type_long;
+             arg_type = builtin_type (gdbarch)->builtin_long;
              arg = value_cast (arg_type, arg);
            }
          /* Aligment is equal to the type length for the basic types.  */
@@ -1810,15 +1693,16 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
        case TYPE_CODE_FLT:
 
          /* Align doubles correctly.  */
-         if (TYPE_LENGTH (arg_type) == TYPE_LENGTH (builtin_type_double))
-           info->align = TYPE_LENGTH (builtin_type_double);
+         if (TYPE_LENGTH (arg_type)
+             == TYPE_LENGTH (builtin_type (gdbarch)->builtin_double))
+           info->align = TYPE_LENGTH (builtin_type (gdbarch)->builtin_double);
          else
-           info->align = TYPE_LENGTH (builtin_type_long);
+           info->align = TYPE_LENGTH (builtin_type (gdbarch)->builtin_long);
          break;
 
        case TYPE_CODE_STRUCT:
        default:
-         info->align = TYPE_LENGTH (builtin_type_long);
+         info->align = TYPE_LENGTH (builtin_type (gdbarch)->builtin_long);
          break;
        }
       info->length = TYPE_LENGTH (arg_type);
@@ -1857,7 +1741,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 
   if (struct_return)
     {
-      store_unsigned_integer (buf, REGISTER_SIZE, struct_addr);
+      store_unsigned_integer (buf, REGISTER_SIZE, byte_order, struct_addr);
       regcache_cooked_write (regcache, ARG_1ST (gdbarch), buf);
     }
 
@@ -1893,13 +1777,13 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
             than REGISTER_SIZE; for larger odd-sized structures the excess
             will be left-aligned in the register on both endiannesses.  */
 
-         if (n < REGISTER_SIZE
-             && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+         if (n < REGISTER_SIZE && byte_order == BFD_ENDIAN_BIG)
            {
-             ULONGEST v = extract_unsigned_integer (cp, REGISTER_SIZE);
+             ULONGEST v;
+             v = extract_unsigned_integer (cp, REGISTER_SIZE, byte_order);
              v = v >> ((REGISTER_SIZE - n) * TARGET_CHAR_BIT);
 
-             store_unsigned_integer (buf, REGISTER_SIZE, v);
+             store_unsigned_integer (buf, REGISTER_SIZE, byte_order, v);
              regcache_cooked_write (regcache, r, buf);
 
              cp += REGISTER_SIZE;
@@ -1926,7 +1810,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
     {
       ra = (bp_addr & 0x3fffffff) | 0x40000000;
       regcache_raw_read (regcache, gdbarch_ps_regnum (gdbarch), buf);
-      ps = extract_unsigned_integer (buf, 4) & ~0x00030000;
+      ps = extract_unsigned_integer (buf, 4, byte_order) & ~0x00030000;
       regcache_cooked_write_unsigned
        (regcache, gdbarch_tdep (gdbarch)->a0_base + 4, ra);
       regcache_cooked_write_unsigned (regcache,
@@ -1939,9 +1823,9 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
         is only one register window corresponding to WINDOWEBASE.  */
 
       regcache_raw_read (regcache, gdbarch_tdep (gdbarch)->wb_regnum, buf);
-      regcache_cooked_write_unsigned (regcache,
-                                     gdbarch_tdep (gdbarch)->ws_regnum,
-                                     1 << extract_unsigned_integer (buf, 4));
+      regcache_cooked_write_unsigned
+       (regcache, gdbarch_tdep (gdbarch)->ws_regnum,
+        1 << extract_unsigned_integer (buf, 4, byte_order));
     }
   else
     {
@@ -2093,11 +1977,13 @@ call0_classify_opcode (xtensa_isa isa, xtensa_opcode opc)
    the stack frame.  */
 
 static void
-call0_track_op (xtensa_c0reg_t dst[], xtensa_c0reg_t src[],
+call0_track_op (struct gdbarch *gdbarch,
+               xtensa_c0reg_t dst[], xtensa_c0reg_t src[],
                xtensa_insn_kind opclass, int nods, unsigned odv[],
-               CORE_ADDR pc, int spreg)
+               CORE_ADDR pc, CORE_ADDR litbase, int spreg)
 {
-  unsigned litbase, litaddr, litval;
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  unsigned litaddr, litval;
 
   switch (opclass)
     {
@@ -2147,14 +2033,10 @@ call0_track_op (xtensa_c0reg_t dst[], xtensa_c0reg_t src[],
     case c0opc_l32r:
       /* 2 operands: dst, literal offset.  */
       gdb_assert (nods == 2);
-      /* litbase = xtensa_get_litbase (pc); can be also used.  */
-      litbase = (gdbarch_tdep (current_gdbarch)->litbase_regnum == -1)
-       ? 0 : xtensa_read_register
-               (gdbarch_tdep (current_gdbarch)->litbase_regnum);
       litaddr = litbase & 1
                  ? (litbase & ~1) + (signed)odv[1]
                  : (pc + 3  + (signed)odv[1]) & ~3;
-      litval = read_memory_integer(litaddr, 4);
+      litval = read_memory_integer (litaddr, 4, byte_order);
       dst[odv[0]].fr_reg = C0_CONST;
       dst[odv[0]].fr_ofs = litval;
       break;
@@ -2207,14 +2089,14 @@ call0_track_op (xtensa_c0reg_t dst[], xtensa_c0reg_t src[],
       because they begin with default assumptions that analysis may change.  */
 
 static CORE_ADDR
-call0_analyze_prologue (CORE_ADDR start, CORE_ADDR pc,
+call0_analyze_prologue (struct gdbarch *gdbarch,
+                       CORE_ADDR start, CORE_ADDR pc, CORE_ADDR litbase,
                        int nregs, xtensa_c0reg_t rt[], int *call0)
 {
   CORE_ADDR ia;                    /* Current insn address in prologue.  */
   CORE_ADDR ba = 0;        /* Current address at base of insn buffer.  */
   CORE_ADDR bt;                    /* Current address at top+1 of insn buffer.  */
-  #define BSZ 32           /* Instruction buffer size.  */
-  char ibuf[BSZ];          /* Instruction buffer for decoding prologue.  */
+  char ibuf[XTENSA_ISA_BSZ];/* Instruction buffer for decoding prologue.  */
   xtensa_isa isa;          /* libisa ISA handle.  */
   xtensa_insnbuf ins, slot; /* libisa handle to decoded insn, slot.  */
   xtensa_format ifmt;      /* libisa instruction format.  */
@@ -2274,7 +2156,7 @@ call0_analyze_prologue (CORE_ADDR start, CORE_ADDR pc,
   if (!xtensa_default_isa)
     xtensa_default_isa = xtensa_isa_init (0, 0);
   isa = xtensa_default_isa;
-  gdb_assert (BSZ >= xtensa_isa_maxlength (isa));
+  gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
   ins = xtensa_insnbuf_alloc (isa);
   slot = xtensa_insnbuf_alloc (isa);
 
@@ -2287,7 +2169,7 @@ call0_analyze_prologue (CORE_ADDR start, CORE_ADDR pc,
       if (ia + xtensa_isa_maxlength (isa) > bt)
         {
          ba = ia;
-         bt = (ba + BSZ) < body_pc ? ba + BSZ : body_pc;
+         bt = (ba + XTENSA_ISA_BSZ) < body_pc ? ba + XTENSA_ISA_BSZ : body_pc;
          read_memory (ba, ibuf, bt - ba);
        }
 
@@ -2399,7 +2281,8 @@ call0_analyze_prologue (CORE_ADDR start, CORE_ADDR pc,
            }
 
          /* Track register movement and modification for this operation.  */
-         call0_track_op (rt, rtmp, opclass, nods, odv, ia, 1);
+         call0_track_op (gdbarch, rt, rtmp, opclass,
+                         nods, odv, ia, litbase, 1);
        }
     }
 done:
@@ -2410,15 +2293,14 @@ done:
   return fail ? 0 : ia;
 }
 
-/* Initialize frame cache for the current frame.  The "next_frame" is the next
-   one relative to current frame.  "cache" is the pointer to the data structure
-   we have to initialize.  "pc" is curretnt PC.  */
+/* Initialize frame cache for the current frame in CALL0 ABI.  */
 
 static void
-call0_frame_cache (struct frame_info *next_frame,
-                  xtensa_frame_cache_t *cache, CORE_ADDR pc)
+call0_frame_cache (struct frame_info *this_frame,
+                  xtensa_frame_cache_t *cache, CORE_ADDR pc, CORE_ADDR litbase)
 {
-  struct gdbarch *gdbarch = get_frame_arch (next_frame);
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR start_pc;          /* The beginning of the function.  */
   CORE_ADDR body_pc=UINT_MAX;  /* PC, where prologue analysis stopped.  */
   CORE_ADDR sp, fp, ra;
@@ -2429,13 +2311,14 @@ call0_frame_cache (struct frame_info *next_frame,
 
   if (find_pc_partial_function (pc, NULL, &start_pc, NULL))
     {
-      body_pc = call0_analyze_prologue (start_pc, pc, C0_NREGS,
+      body_pc = call0_analyze_prologue (gdbarch, start_pc, pc, litbase,
+                                       C0_NREGS,
                                        &cache->c0.c0_rt[0],
                                        &cache->call0);
     }
   
-  sp = frame_unwind_register_unsigned
-        (next_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
+  sp = get_frame_register_unsigned
+    (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
   fp = sp; /* Assume FP == SP until proven otherwise.  */
 
   /* Get the frame information and FP (if used) at the current PC.
@@ -2470,7 +2353,7 @@ call0_frame_cache (struct frame_info *next_frame,
      alloca() and other dynamic allocations.  Adjust frame size by FP - SP.  */
   if (c0_hasfp)
     {
-      fp = frame_unwind_register_unsigned (next_frame, fp_regnum);
+      fp = get_frame_register_unsigned (this_frame, fp_regnum);
 
       /* Recalculate previous SP.  */
       prev_sp = fp + c0_frmsz;
@@ -2484,7 +2367,8 @@ call0_frame_cache (struct frame_info *next_frame,
   to_stk = cache->c0.c0_rt[C0_RA].to_stk;
   if (to_stk != C0_NOSTK)
     ra = (CORE_ADDR) 
-      read_memory_integer (sp + c0_frmsz + cache->c0.c0_rt[C0_RA].to_stk, 4);
+      read_memory_integer (sp + c0_frmsz + cache->c0.c0_rt[C0_RA].to_stk,
+                          4, byte_order);
 
   else if (cache->c0.c0_rt[C0_RA].fr_reg == C0_CONST
           && cache->c0.c0_rt[C0_RA].fr_ofs == 0)
@@ -2512,11 +2396,11 @@ call0_frame_cache (struct frame_info *next_frame,
           ++i);
       if (i >= C0_NREGS && cache->c0.c0_rt[C0_RA].fr_reg == C0_RA)
        i = C0_RA;
-      if (i < C0_NREGS) /* Read from the next_frame.  */
+      if (i < C0_NREGS)
        {
-         ra = frame_unwind_register_unsigned
-                (next_frame,
-                 gdbarch_tdep (gdbarch)->a0_base + cache->c0.c0_rt[i].fr_reg);
+         ra = get_frame_register_unsigned
+           (this_frame,
+            gdbarch_tdep (gdbarch)->a0_base + cache->c0.c0_rt[i].fr_reg);
        }
       else ra = 0;
     }
@@ -2569,7 +2453,7 @@ call0_frame_cache (struct frame_info *next_frame,
 
 /* #define DONT_SKIP_PROLOGUE  */
 
-CORE_ADDR
+static CORE_ADDR
 xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 {
   struct symtab_and_line prologue_sal;
@@ -2603,7 +2487,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
     }
 
   /* No debug line info.  Analyze prologue for Call0 or simply skip ENTRY.  */
-  body_pc = call0_analyze_prologue(start_pc, 0, 0, NULL, NULL);
+  body_pc = call0_analyze_prologue (gdbarch, start_pc, 0, 0, 0, NULL, NULL);
   return body_pc != 0 ? body_pc : start_pc;
 }
 
@@ -2658,7 +2542,7 @@ xtensa_verify_config (struct gdbarch *gdbarch)
 
 /* Derive specific register numbers from the array of registers.  */
 
-void
+static void
 xtensa_derive_tdep (struct gdbarch_tdep *tdep)
 {
   xtensa_register_t* rmap;
@@ -2766,9 +2650,8 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_pc_regnum (gdbarch, tdep->pc_regnum);
   set_gdbarch_ps_regnum (gdbarch, tdep->ps_regnum);
 
-  /* Renumber registers for known formats (stab, dwarf, and dwarf2).  */
+  /* Renumber registers for known formats (stabs and dwarf2).  */
   set_gdbarch_stab_reg_to_regnum (gdbarch, xtensa_reg_to_regnum);
-  set_gdbarch_dwarf_reg_to_regnum (gdbarch, xtensa_reg_to_regnum);
   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, xtensa_reg_to_regnum);
 
   /* We provide our own function to get register information.  */
@@ -2802,11 +2685,12 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_frame_align (gdbarch, xtensa_frame_align);
 
-  set_gdbarch_unwind_dummy_id (gdbarch, xtensa_unwind_dummy_id);
+  set_gdbarch_dummy_id (gdbarch, xtensa_dummy_id);
 
   /* Frame handling.  */
   frame_base_set_default (gdbarch, &xtensa_frame_base);
-  frame_unwind_append_sniffer (gdbarch, xtensa_frame_sniffer);
+  frame_unwind_append_unwinder (gdbarch, &xtensa_unwind);
+  dwarf2_append_unwinders (gdbarch);
 
   set_gdbarch_print_insn (gdbarch, print_insn_xtensa);
 
@@ -2830,6 +2714,9 @@ xtensa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
   error (_("xtensa_dump_tdep(): not implemented"));
 }
 
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_xtensa_tdep;
+
 void
 _initialize_xtensa_tdep (void)
 {
This page took 0.035993 seconds and 4 git commands to generate.