More updated translations
[binutils-gdb.git] / gdb / xtensa-tdep.c
blobc87940c1cfcf301042aadc36388e9f3ed436e02e
1 /* Target-dependent code for the Xtensa port of GDB, the GNU debugger.
3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "extract-store-integer.h"
21 #include "frame.h"
22 #include "solib-svr4.h"
23 #include "symtab.h"
24 #include "gdbtypes.h"
25 #include "gdbcore.h"
26 #include "value.h"
27 #include "osabi.h"
28 #include "regcache.h"
29 #include "reggroups.h"
30 #include "regset.h"
32 #include "dwarf2/frame.h"
33 #include "frame-base.h"
34 #include "frame-unwind.h"
36 #include "arch-utils.h"
37 #include "gdbarch.h"
39 #include "command.h"
40 #include "cli/cli-cmds.h"
42 #include "xtensa-isa.h"
43 #include "xtensa-tdep.h"
44 #include "xtensa-config.h"
45 #include <algorithm>
48 static unsigned int xtensa_debug_level = 0;
50 #define DEBUGWARN(args...) \
51 if (xtensa_debug_level > 0) \
52 gdb_printf (gdb_stdlog, "(warn ) " args)
54 #define DEBUGINFO(args...) \
55 if (xtensa_debug_level > 1) \
56 gdb_printf (gdb_stdlog, "(info ) " args)
58 #define DEBUGTRACE(args...) \
59 if (xtensa_debug_level > 2) \
60 gdb_printf (gdb_stdlog, "(trace) " args)
62 #define DEBUGVERB(args...) \
63 if (xtensa_debug_level > 3) \
64 gdb_printf (gdb_stdlog, "(verb ) " args)
67 /* According to the ABI, the SP must be aligned to 16-byte boundaries. */
68 #define SP_ALIGNMENT 16
71 /* On Windowed ABI, we use a6 through a11 for passing arguments
72 to a function called by GDB because CALL4 is used. */
73 #define ARGS_NUM_REGS 6
74 #define REGISTER_SIZE 4
77 /* Extract the call size from the return address or PS register. */
78 #define PS_CALLINC_SHIFT 16
79 #define PS_CALLINC_MASK 0x00030000
80 #define CALLINC(ps) (((ps) & PS_CALLINC_MASK) >> PS_CALLINC_SHIFT)
81 #define WINSIZE(ra) (4 * (( (ra) >> 30) & 0x3))
83 /* On TX, hardware can be configured without Exception Option.
84 There is no PS register in this case. Inside XT-GDB, let us treat
85 it as a virtual read-only register always holding the same value. */
86 #define TX_PS 0x20
88 /* ABI-independent macros. */
89 #define ARG_NOF(tdep) \
90 (tdep->call_abi \
91 == CallAbiCall0Only ? C0_NARGS : (ARGS_NUM_REGS))
92 #define ARG_1ST(tdep) \
93 (tdep->call_abi == CallAbiCall0Only \
94 ? (tdep->a0_base + C0_ARGS) \
95 : (tdep->a0_base + 6))
97 /* XTENSA_IS_ENTRY tests whether the first byte of an instruction
98 indicates that the instruction is an ENTRY instruction. */
100 #define XTENSA_IS_ENTRY(gdbarch, op1) \
101 ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) \
102 ? ((op1) == 0x6c) : ((op1) == 0x36))
104 #define XTENSA_ENTRY_LENGTH 3
106 /* windowing_enabled() returns true, if windowing is enabled.
107 WOE must be set to 1; EXCM to 0.
108 Note: We assume that EXCM is always 0 for XEA1. */
110 #define PS_WOE (1<<18)
111 #define PS_EXC (1<<4)
113 /* Big enough to hold the size of the largest register in bytes. */
114 #define XTENSA_MAX_REGISTER_SIZE 64
116 static int
117 windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
119 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
121 /* If we know CALL0 ABI is set explicitly, say it is Call0. */
122 if (tdep->call_abi == CallAbiCall0Only)
123 return 0;
125 return ((ps & PS_EXC) == 0 && (ps & PS_WOE) != 0);
128 /* Convert a live A-register number to the corresponding AR-register
129 number. */
130 static int
131 arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
133 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
134 int arreg;
136 arreg = a_regnum - tdep->a0_base;
137 arreg += (wb & ((tdep->num_aregs - 1) >> 2)) << WB_SHIFT;
138 arreg &= tdep->num_aregs - 1;
140 return arreg + tdep->ar_base;
143 /* Convert a live AR-register number to the corresponding A-register order
144 number in a range [0..15]. Return -1, if AR_REGNUM is out of WB window. */
145 static int
146 areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
148 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
149 int areg;
151 areg = ar_regnum - tdep->ar_base;
152 if (areg < 0 || areg >= tdep->num_aregs)
153 return -1;
154 areg = (areg - wb * 4) & (tdep->num_aregs - 1);
155 return (areg > 15) ? -1 : areg;
158 /* Read Xtensa register directly from the hardware. */
159 static unsigned long
160 xtensa_read_register (int regnum)
162 ULONGEST value;
164 regcache_raw_read_unsigned (get_thread_regcache (inferior_thread ()), regnum,
165 &value);
166 return (unsigned long) value;
169 /* Write Xtensa register directly to the hardware. */
170 static void
171 xtensa_write_register (int regnum, ULONGEST value)
173 regcache_raw_write_unsigned (get_thread_regcache (inferior_thread ()), regnum,
174 value);
177 /* Return the window size of the previous call to the function from which we
178 have just returned.
180 This function is used to extract the return value after a called function
181 has returned to the caller. On Xtensa, the register that holds the return
182 value (from the perspective of the caller) depends on what call
183 instruction was used. For now, we are assuming that the call instruction
184 precedes the current address, so we simply analyze the call instruction.
185 If we are in a dummy frame, we simply return 4 as we used a 'pseudo-call4'
186 method to call the inferior function. */
188 static int
189 extract_call_winsize (struct gdbarch *gdbarch, CORE_ADDR pc)
191 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
192 int winsize = 4;
193 int insn;
194 gdb_byte buf[4];
196 DEBUGTRACE ("extract_call_winsize (pc = 0x%08x)\n", (int) pc);
198 /* Read the previous instruction (should be a call[x]{4|8|12}. */
199 read_memory (pc-3, buf, 3);
200 insn = extract_unsigned_integer (buf, 3, byte_order);
202 /* Decode call instruction:
203 Little Endian
204 call{0,4,8,12} OFFSET || {00,01,10,11} || 0101
205 callx{0,4,8,12} OFFSET || 11 || {00,01,10,11} || 0000
206 Big Endian
207 call{0,4,8,12} 0101 || {00,01,10,11} || OFFSET
208 callx{0,4,8,12} 0000 || {00,01,10,11} || 11 || OFFSET. */
210 if (byte_order == BFD_ENDIAN_LITTLE)
212 if (((insn & 0xf) == 0x5) || ((insn & 0xcf) == 0xc0))
213 winsize = (insn & 0x30) >> 2; /* 0, 4, 8, 12. */
215 else
217 if (((insn >> 20) == 0x5) || (((insn >> 16) & 0xf3) == 0x03))
218 winsize = (insn >> 16) & 0xc; /* 0, 4, 8, 12. */
220 return winsize;
224 /* REGISTER INFORMATION */
226 /* Find register by name. */
227 static int
228 xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
230 int i;
231 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
233 for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
234 if (strcasecmp (tdep->regmap[i].name, name) == 0)
235 return i;
237 return -1;
240 /* Returns the name of a register. */
241 static const char *
242 xtensa_register_name (struct gdbarch *gdbarch, int regnum)
244 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
246 /* Return the name stored in the register map. */
247 return tdep->regmap[regnum].name;
250 /* Return the type of a register. Create a new type, if necessary. */
252 static struct type *
253 xtensa_register_type (struct gdbarch *gdbarch, int regnum)
255 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
257 /* Return signed integer for ARx and Ax registers. */
258 if ((regnum >= tdep->ar_base
259 && regnum < tdep->ar_base + tdep->num_aregs)
260 || (regnum >= tdep->a0_base
261 && regnum < tdep->a0_base + 16))
262 return builtin_type (gdbarch)->builtin_int;
264 if (regnum == gdbarch_pc_regnum (gdbarch)
265 || regnum == tdep->a0_base + 1)
266 return builtin_type (gdbarch)->builtin_data_ptr;
268 /* Return the stored type for all other registers. */
269 else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
271 xtensa_register_t* reg = &tdep->regmap[regnum];
273 /* Set ctype for this register (only the first time). */
275 if (reg->ctype == 0)
277 struct ctype_cache *tp;
278 int size = reg->byte_size;
280 /* We always use the memory representation,
281 even if the register width is smaller. */
282 switch (size)
284 case 1:
285 reg->ctype = builtin_type (gdbarch)->builtin_uint8;
286 break;
288 case 2:
289 reg->ctype = builtin_type (gdbarch)->builtin_uint16;
290 break;
292 case 4:
293 reg->ctype = builtin_type (gdbarch)->builtin_uint32;
294 break;
296 case 8:
297 reg->ctype = builtin_type (gdbarch)->builtin_uint64;
298 break;
300 case 16:
301 reg->ctype = builtin_type (gdbarch)->builtin_uint128;
302 break;
304 default:
305 for (tp = tdep->type_entries; tp != NULL; tp = tp->next)
306 if (tp->size == size)
307 break;
309 if (tp == NULL)
311 std::string name = string_printf ("int%d", size * 8);
313 tp = XNEW (struct ctype_cache);
314 tp->next = tdep->type_entries;
315 tdep->type_entries = tp;
316 tp->size = size;
317 type_allocator alloc (gdbarch);
318 tp->virtual_type
319 = init_integer_type (alloc, size * 8, 1, name.c_str ());
322 reg->ctype = tp->virtual_type;
325 return reg->ctype;
328 internal_error (_("invalid register number %d"), regnum);
329 return 0;
333 /* Return the 'local' register number for stubs, dwarf2, etc.
334 The debugging information enumerates registers starting from 0 for A0
335 to n for An. So, we only have to add the base number for A0. */
337 static int
338 xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
340 int i;
341 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
343 if (regnum >= 0 && regnum < 16)
344 return tdep->a0_base + regnum;
346 for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
347 if (regnum == tdep->regmap[i].target_number)
348 return i;
350 return -1;
354 /* Write the bits of a masked register to the various registers.
355 Only the masked areas of these registers are modified; the other
356 fields are untouched. The size of masked registers is always less
357 than or equal to 32 bits. */
359 static void
360 xtensa_register_write_masked (struct regcache *regcache,
361 xtensa_register_t *reg, const gdb_byte *buffer)
363 unsigned int value[(XTENSA_MAX_REGISTER_SIZE + 3) / 4];
364 const xtensa_mask_t *mask = reg->mask;
366 int shift = 0; /* Shift for next mask (mod 32). */
367 int start, size; /* Start bit and size of current mask. */
369 unsigned int *ptr = value;
370 unsigned int regval, m, mem = 0;
372 int bytesize = reg->byte_size;
373 int bitsize = bytesize * 8;
374 int i, r;
376 DEBUGTRACE ("xtensa_register_write_masked ()\n");
378 /* Copy the masked register to host byte-order. */
379 if (gdbarch_byte_order (regcache->arch ()) == BFD_ENDIAN_BIG)
380 for (i = 0; i < bytesize; i++)
382 mem >>= 8;
383 mem |= (buffer[bytesize - i - 1] << 24);
384 if ((i & 3) == 3)
385 *ptr++ = mem;
387 else
388 for (i = 0; i < bytesize; i++)
390 mem >>= 8;
391 mem |= (buffer[i] << 24);
392 if ((i & 3) == 3)
393 *ptr++ = mem;
396 /* We might have to shift the final value:
397 bytesize & 3 == 0 -> nothing to do, we use the full 32 bits,
398 bytesize & 3 == x -> shift (4-x) * 8. */
400 *ptr = mem >> (((0 - bytesize) & 3) * 8);
401 ptr = value;
402 mem = *ptr;
404 /* Write the bits to the masked areas of the other registers. */
405 for (i = 0; i < mask->count; i++)
407 start = mask->mask[i].bit_start;
408 size = mask->mask[i].bit_size;
409 regval = mem >> shift;
411 if ((shift += size) > bitsize)
412 error (_("size of all masks is larger than the register"));
414 if (shift >= 32)
416 mem = *(++ptr);
417 shift -= 32;
418 bitsize -= 32;
420 if (shift > 0)
421 regval |= mem << (size - shift);
424 /* Make sure we have a valid register. */
425 r = mask->mask[i].reg_num;
426 if (r >= 0 && size > 0)
428 /* Don't overwrite the unmasked areas. */
429 ULONGEST old_val;
430 regcache_cooked_read_unsigned (regcache, r, &old_val);
431 m = 0xffffffff >> (32 - size) << start;
432 regval <<= start;
433 regval = (regval & m) | (old_val & ~m);
434 regcache_cooked_write_unsigned (regcache, r, regval);
440 /* Read a tie state or mapped registers. Read the masked areas
441 of the registers and assemble them into a single value. */
443 static enum register_status
444 xtensa_register_read_masked (readable_regcache *regcache,
445 xtensa_register_t *reg, gdb_byte *buffer)
447 unsigned int value[(XTENSA_MAX_REGISTER_SIZE + 3) / 4];
448 const xtensa_mask_t *mask = reg->mask;
450 int shift = 0;
451 int start, size;
453 unsigned int *ptr = value;
454 unsigned int regval, mem = 0;
456 int bytesize = reg->byte_size;
457 int bitsize = bytesize * 8;
458 int i;
460 DEBUGTRACE ("xtensa_register_read_masked (reg \"%s\", ...)\n",
461 reg->name == 0 ? "" : reg->name);
463 /* Assemble the register from the masked areas of other registers. */
464 for (i = 0; i < mask->count; i++)
466 int r = mask->mask[i].reg_num;
467 if (r >= 0)
469 enum register_status status;
470 ULONGEST val;
472 status = regcache->cooked_read (r, &val);
473 if (status != REG_VALID)
474 return status;
475 regval = (unsigned int) val;
477 else
478 regval = 0;
480 start = mask->mask[i].bit_start;
481 size = mask->mask[i].bit_size;
483 regval >>= start;
485 if (size < 32)
486 regval &= (0xffffffff >> (32 - size));
488 mem |= regval << shift;
490 if ((shift += size) > bitsize)
491 error (_("size of all masks is larger than the register"));
493 if (shift >= 32)
495 *ptr++ = mem;
496 bitsize -= 32;
497 shift -= 32;
499 if (shift == 0)
500 mem = 0;
501 else
502 mem = regval >> (size - shift);
506 if (shift > 0)
507 *ptr = mem;
509 /* Copy value to target byte order. */
510 ptr = value;
511 mem = *ptr;
513 if (gdbarch_byte_order (regcache->arch ()) == BFD_ENDIAN_BIG)
514 for (i = 0; i < bytesize; i++)
516 if ((i & 3) == 0)
517 mem = *ptr++;
518 buffer[bytesize - i - 1] = mem & 0xff;
519 mem >>= 8;
521 else
522 for (i = 0; i < bytesize; i++)
524 if ((i & 3) == 0)
525 mem = *ptr++;
526 buffer[i] = mem & 0xff;
527 mem >>= 8;
530 return REG_VALID;
534 /* Read pseudo registers. */
536 static enum register_status
537 xtensa_pseudo_register_read (struct gdbarch *gdbarch,
538 readable_regcache *regcache,
539 int regnum,
540 gdb_byte *buffer)
542 DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
543 regnum, xtensa_register_name (gdbarch, regnum));
544 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
546 /* Read aliases a0..a15, if this is a Windowed ABI. */
547 if (tdep->isa_use_windowed_registers
548 && (regnum >= tdep->a0_base)
549 && (regnum <= tdep->a0_base + 15))
551 ULONGEST value;
552 enum register_status status;
554 status = regcache->raw_read (tdep->wb_regnum,
555 &value);
556 if (status != REG_VALID)
557 return status;
558 regnum = arreg_number (gdbarch, regnum, value);
561 /* We can always read non-pseudo registers. */
562 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
563 return regcache->raw_read (regnum, buffer);
565 /* We have to find out how to deal with privileged registers.
566 Let's treat them as pseudo-registers, but we cannot read/write them. */
568 else if (tdep->call_abi == CallAbiCall0Only
569 || regnum < tdep->a0_base)
571 buffer[0] = (gdb_byte)0;
572 buffer[1] = (gdb_byte)0;
573 buffer[2] = (gdb_byte)0;
574 buffer[3] = (gdb_byte)0;
575 return REG_VALID;
577 /* Pseudo registers. */
578 else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
580 xtensa_register_t *reg = &tdep->regmap[regnum];
581 xtensa_register_type_t type = reg->type;
582 int flags = tdep->target_flags;
584 /* We cannot read Unknown or Unmapped registers. */
585 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
587 if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
589 warning (_("cannot read register %s"),
590 xtensa_register_name (gdbarch, regnum));
591 return REG_VALID;
595 /* Some targets cannot read TIE register files. */
596 else if (type == xtRegisterTypeTieRegfile)
598 /* Use 'fetch' to get register? */
599 if (flags & xtTargetFlagsUseFetchStore)
601 warning (_("cannot read register"));
602 return REG_VALID;
605 /* On some targets (esp. simulators), we can always read the reg. */
606 else if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
608 warning (_("cannot read register"));
609 return REG_VALID;
613 /* We can always read mapped registers. */
614 else if (type == xtRegisterTypeMapped || type == xtRegisterTypeTieState)
615 return xtensa_register_read_masked (regcache, reg, buffer);
617 /* Assume that we can read the register. */
618 return regcache->raw_read (regnum, buffer);
620 else
621 internal_error (_("invalid register number %d"), regnum);
625 /* Write pseudo registers. */
627 static void
628 xtensa_pseudo_register_write (struct gdbarch *gdbarch,
629 struct regcache *regcache,
630 int regnum,
631 const gdb_byte *buffer)
633 DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
634 regnum, xtensa_register_name (gdbarch, regnum));
635 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
637 /* Renumber register, if aliases a0..a15 on Windowed ABI. */
638 if (tdep->isa_use_windowed_registers
639 && (regnum >= tdep->a0_base)
640 && (regnum <= tdep->a0_base + 15))
642 ULONGEST value;
643 regcache_raw_read_unsigned (regcache,
644 tdep->wb_regnum, &value);
645 regnum = arreg_number (gdbarch, regnum, value);
648 /* We can always write 'core' registers.
649 Note: We might have converted Ax->ARy. */
650 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
651 regcache->raw_write (regnum, buffer);
653 /* We have to find out how to deal with privileged registers.
654 Let's treat them as pseudo-registers, but we cannot read/write them. */
656 else if (regnum < tdep->a0_base)
658 return;
660 /* Pseudo registers. */
661 else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
663 xtensa_register_t *reg = &tdep->regmap[regnum];
664 xtensa_register_type_t type = reg->type;
665 int flags = tdep->target_flags;
667 /* On most targets, we cannot write registers
668 of type "Unknown" or "Unmapped". */
669 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
671 if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
673 warning (_("cannot write register %s"),
674 xtensa_register_name (gdbarch, regnum));
675 return;
679 /* Some targets cannot read TIE register files. */
680 else if (type == xtRegisterTypeTieRegfile)
682 /* Use 'store' to get register? */
683 if (flags & xtTargetFlagsUseFetchStore)
685 warning (_("cannot write register"));
686 return;
689 /* On some targets (esp. simulators), we can always write
690 the register. */
691 else if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
693 warning (_("cannot write register"));
694 return;
698 /* We can always write mapped registers. */
699 else if (type == xtRegisterTypeMapped || type == xtRegisterTypeTieState)
701 xtensa_register_write_masked (regcache, reg, buffer);
702 return;
705 /* Assume that we can write the register. */
706 regcache->raw_write (regnum, buffer);
708 else
709 internal_error (_("invalid register number %d"), regnum);
712 static const reggroup *xtensa_ar_reggroup;
713 static const reggroup *xtensa_user_reggroup;
714 static const reggroup *xtensa_vectra_reggroup;
715 static const reggroup *xtensa_cp[XTENSA_MAX_COPROCESSOR];
717 static void
718 xtensa_init_reggroups (void)
720 int i;
722 xtensa_ar_reggroup = reggroup_new ("ar", USER_REGGROUP);
723 xtensa_user_reggroup = reggroup_new ("user", USER_REGGROUP);
724 xtensa_vectra_reggroup = reggroup_new ("vectra", USER_REGGROUP);
726 for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
727 xtensa_cp[i] = reggroup_new (xstrprintf ("cp%d", i).release (),
728 USER_REGGROUP);
731 static void
732 xtensa_add_reggroups (struct gdbarch *gdbarch)
734 /* Xtensa-specific groups. */
735 reggroup_add (gdbarch, xtensa_ar_reggroup);
736 reggroup_add (gdbarch, xtensa_user_reggroup);
737 reggroup_add (gdbarch, xtensa_vectra_reggroup);
739 for (int i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
740 reggroup_add (gdbarch, xtensa_cp[i]);
743 static int
744 xtensa_coprocessor_register_group (const struct reggroup *group)
746 int i;
748 for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
749 if (group == xtensa_cp[i])
750 return i;
752 return -1;
755 #define SAVE_REST_FLAGS (XTENSA_REGISTER_FLAGS_READABLE \
756 | XTENSA_REGISTER_FLAGS_WRITABLE \
757 | XTENSA_REGISTER_FLAGS_VOLATILE)
759 #define SAVE_REST_VALID (XTENSA_REGISTER_FLAGS_READABLE \
760 | XTENSA_REGISTER_FLAGS_WRITABLE)
762 static int
763 xtensa_register_reggroup_p (struct gdbarch *gdbarch,
764 int regnum,
765 const struct reggroup *group)
767 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
768 xtensa_register_t* reg = &tdep->regmap[regnum];
769 xtensa_register_type_t type = reg->type;
770 xtensa_register_group_t rg = reg->group;
771 int cp_number;
773 if (group == save_reggroup)
774 /* Every single register should be included into the list of registers
775 to be watched for changes while using -data-list-changed-registers. */
776 return 1;
778 /* First, skip registers that are not visible to this target
779 (unknown and unmapped registers when not using ISS). */
781 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
782 return 0;
783 if (group == all_reggroup)
784 return 1;
785 if (group == xtensa_ar_reggroup)
786 return rg & xtRegisterGroupAddrReg;
787 if (group == xtensa_user_reggroup)
788 return rg & xtRegisterGroupUser;
789 if (group == float_reggroup)
790 return rg & xtRegisterGroupFloat;
791 if (group == general_reggroup)
792 return rg & xtRegisterGroupGeneral;
793 if (group == system_reggroup)
794 return rg & xtRegisterGroupState;
795 if (group == vector_reggroup || group == xtensa_vectra_reggroup)
796 return rg & xtRegisterGroupVectra;
797 if (group == restore_reggroup)
798 return (regnum < gdbarch_num_regs (gdbarch)
799 && (reg->flags & SAVE_REST_FLAGS) == SAVE_REST_VALID);
800 cp_number = xtensa_coprocessor_register_group (group);
801 if (cp_number >= 0)
802 return rg & (xtRegisterGroupCP0 << cp_number);
803 else
804 return 1;
808 /* Supply register REGNUM from the buffer specified by GREGS and LEN
809 in the general-purpose register set REGSET to register cache
810 REGCACHE. If REGNUM is -1 do this for all registers in REGSET. */
812 static void
813 xtensa_supply_gregset (const struct regset *regset,
814 struct regcache *rc,
815 int regnum,
816 const void *gregs,
817 size_t len)
819 const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
820 struct gdbarch *gdbarch = rc->arch ();
821 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
822 int i;
824 DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
826 if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
827 rc->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &regs->pc);
828 if (regnum == gdbarch_ps_regnum (gdbarch) || regnum == -1)
829 rc->raw_supply (gdbarch_ps_regnum (gdbarch), (char *) &regs->ps);
830 if (regnum == tdep->wb_regnum || regnum == -1)
831 rc->raw_supply (tdep->wb_regnum,
832 (char *) &regs->windowbase);
833 if (regnum == tdep->ws_regnum || regnum == -1)
834 rc->raw_supply (tdep->ws_regnum,
835 (char *) &regs->windowstart);
836 if (regnum == tdep->lbeg_regnum || regnum == -1)
837 rc->raw_supply (tdep->lbeg_regnum,
838 (char *) &regs->lbeg);
839 if (regnum == tdep->lend_regnum || regnum == -1)
840 rc->raw_supply (tdep->lend_regnum,
841 (char *) &regs->lend);
842 if (regnum == tdep->lcount_regnum || regnum == -1)
843 rc->raw_supply (tdep->lcount_regnum,
844 (char *) &regs->lcount);
845 if (regnum == tdep->sar_regnum || regnum == -1)
846 rc->raw_supply (tdep->sar_regnum,
847 (char *) &regs->sar);
848 if (regnum >=tdep->ar_base
849 && regnum < tdep->ar_base
850 + tdep->num_aregs)
851 rc->raw_supply
852 (regnum, (char *) &regs->ar[regnum - tdep->ar_base]);
853 else if (regnum == -1)
855 for (i = 0; i < tdep->num_aregs; ++i)
856 rc->raw_supply (tdep->ar_base + i,
857 (char *) &regs->ar[i]);
862 /* Xtensa register set. */
864 static struct regset
865 xtensa_gregset =
867 NULL,
868 xtensa_supply_gregset
872 /* Iterate over supported core file register note sections. */
874 static void
875 xtensa_iterate_over_regset_sections (struct gdbarch *gdbarch,
876 iterate_over_regset_sections_cb *cb,
877 void *cb_data,
878 const struct regcache *regcache)
880 DEBUGTRACE ("xtensa_iterate_over_regset_sections\n");
882 cb (".reg", sizeof (xtensa_elf_gregset_t), sizeof (xtensa_elf_gregset_t),
883 &xtensa_gregset, NULL, cb_data);
887 /* Handling frames. */
889 /* Number of registers to save in case of Windowed ABI. */
890 #define XTENSA_NUM_SAVED_AREGS 12
892 /* Frame cache part for Windowed ABI. */
893 typedef struct xtensa_windowed_frame_cache
895 int wb; /* WINDOWBASE of the previous frame. */
896 int callsize; /* Call size of this frame. */
897 int ws; /* WINDOWSTART of the previous frame. It keeps track of
898 life windows only. If there is no bit set for the
899 window, that means it had been already spilled
900 because of window overflow. */
902 /* Addresses of spilled A-registers.
903 AREGS[i] == -1, if corresponding AR is alive. */
904 CORE_ADDR aregs[XTENSA_NUM_SAVED_AREGS];
905 } xtensa_windowed_frame_cache_t;
907 /* Call0 ABI Definitions. */
909 #define C0_MAXOPDS 3 /* Maximum number of operands for prologue
910 analysis. */
911 #define C0_CLESV 12 /* Callee-saved registers are here and up. */
912 #define C0_SP 1 /* Register used as SP. */
913 #define C0_FP 15 /* Register used as FP. */
914 #define C0_RA 0 /* Register used as return address. */
915 #define C0_ARGS 2 /* Register used as first arg/retval. */
916 #define C0_NARGS 6 /* Number of A-regs for args/retvals. */
918 /* Each element of xtensa_call0_frame_cache.c0_rt[] describes for each
919 A-register where the current content of the reg came from (in terms
920 of an original reg and a constant). Negative values of c0_rt[n].fp_reg
921 mean that the original content of the register was saved to the stack.
922 c0_rt[n].fr.ofs is NOT the offset from the frame base because we don't
923 know where SP will end up until the entire prologue has been analyzed. */
925 #define C0_CONST -1 /* fr_reg value if register contains a constant. */
926 #define C0_INEXP -2 /* fr_reg value if inexpressible as reg + offset. */
927 #define C0_NOSTK -1 /* to_stk value if register has not been stored. */
929 extern xtensa_isa xtensa_default_isa;
931 typedef struct xtensa_c0reg
933 int fr_reg; /* original register from which register content
934 is derived, or C0_CONST, or C0_INEXP. */
935 int fr_ofs; /* constant offset from reg, or immediate value. */
936 int to_stk; /* offset from original SP to register (4-byte aligned),
937 or C0_NOSTK if register has not been saved. */
938 } xtensa_c0reg_t;
940 /* Frame cache part for Call0 ABI. */
941 typedef struct xtensa_call0_frame_cache
943 int c0_frmsz; /* Stack frame size. */
944 int c0_hasfp; /* Current frame uses frame pointer. */
945 int fp_regnum; /* A-register used as FP. */
946 int c0_fp; /* Actual value of frame pointer. */
947 int c0_fpalign; /* Dynamic adjustment for the stack
948 pointer. It's an AND mask. Zero,
949 if alignment was not adjusted. */
950 int c0_old_sp; /* In case of dynamic adjustment, it is
951 a register holding unaligned sp.
952 C0_INEXP, when undefined. */
953 int c0_sp_ofs; /* If "c0_old_sp" was spilled it's a
954 stack offset. C0_NOSTK otherwise. */
956 xtensa_c0reg_t c0_rt[C0_NREGS]; /* Register tracking information. */
957 } xtensa_call0_frame_cache_t;
959 typedef struct xtensa_frame_cache
961 CORE_ADDR base; /* Stack pointer of this frame. */
962 CORE_ADDR pc; /* PC of this frame at the function entry point. */
963 CORE_ADDR ra; /* The raw return address of this frame. */
964 CORE_ADDR ps; /* The PS register of the previous (older) frame. */
965 CORE_ADDR prev_sp; /* Stack Pointer of the previous (older) frame. */
966 int call0; /* It's a call0 framework (else windowed). */
967 union
969 xtensa_windowed_frame_cache_t wd; /* call0 == false. */
970 xtensa_call0_frame_cache_t c0; /* call0 == true. */
972 } xtensa_frame_cache_t;
975 static struct xtensa_frame_cache *
976 xtensa_alloc_frame_cache (int windowed)
978 xtensa_frame_cache_t *cache;
979 int i;
981 DEBUGTRACE ("xtensa_alloc_frame_cache ()\n");
983 cache = FRAME_OBSTACK_ZALLOC (xtensa_frame_cache_t);
985 cache->base = 0;
986 cache->pc = 0;
987 cache->ra = 0;
988 cache->ps = 0;
989 cache->prev_sp = 0;
990 cache->call0 = !windowed;
991 if (cache->call0)
993 cache->c0.c0_frmsz = -1;
994 cache->c0.c0_hasfp = 0;
995 cache->c0.fp_regnum = -1;
996 cache->c0.c0_fp = -1;
997 cache->c0.c0_fpalign = 0;
998 cache->c0.c0_old_sp = C0_INEXP;
999 cache->c0.c0_sp_ofs = C0_NOSTK;
1001 for (i = 0; i < C0_NREGS; i++)
1003 cache->c0.c0_rt[i].fr_reg = i;
1004 cache->c0.c0_rt[i].fr_ofs = 0;
1005 cache->c0.c0_rt[i].to_stk = C0_NOSTK;
1008 else
1010 cache->wd.wb = 0;
1011 cache->wd.ws = 0;
1012 cache->wd.callsize = -1;
1014 for (i = 0; i < XTENSA_NUM_SAVED_AREGS; i++)
1015 cache->wd.aregs[i] = -1;
1017 return cache;
1021 static CORE_ADDR
1022 xtensa_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
1024 return address & ~15;
1028 static CORE_ADDR
1029 xtensa_unwind_pc (struct gdbarch *gdbarch, const frame_info_ptr &next_frame)
1031 gdb_byte buf[8];
1032 CORE_ADDR pc;
1034 DEBUGTRACE ("xtensa_unwind_pc (next_frame = %s)\n",
1035 host_address_to_string (next_frame.get ()));
1037 frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
1038 pc = extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
1040 DEBUGINFO ("[xtensa_unwind_pc] pc = 0x%08x\n", (unsigned int) pc);
1042 return pc;
1046 static struct frame_id
1047 xtensa_dummy_id (struct gdbarch *gdbarch, const frame_info_ptr &this_frame)
1049 CORE_ADDR pc, fp;
1050 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1052 /* THIS-FRAME is a dummy frame. Return a frame ID of that frame. */
1054 pc = get_frame_pc (this_frame);
1055 fp = get_frame_register_unsigned
1056 (this_frame, tdep->a0_base + 1);
1058 /* Make dummy frame ID unique by adding a constant. */
1059 return frame_id_build (fp + SP_ALIGNMENT, pc);
1062 /* Returns true, if instruction to execute next is unique to Xtensa Window
1063 Interrupt Handlers. It can only be one of L32E, S32E, RFWO, or RFWU. */
1065 static int
1066 xtensa_window_interrupt_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
1068 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1069 unsigned int insn = read_memory_integer (pc, 4, byte_order);
1070 unsigned int code;
1072 if (byte_order == BFD_ENDIAN_BIG)
1074 /* Check, if this is L32E or S32E. */
1075 code = insn & 0xf000ff00;
1076 if ((code == 0x00009000) || (code == 0x00009400))
1077 return 1;
1078 /* Check, if this is RFWU or RFWO. */
1079 code = insn & 0xffffff00;
1080 return ((code == 0x00430000) || (code == 0x00530000));
1082 else
1084 /* Check, if this is L32E or S32E. */
1085 code = insn & 0x00ff000f;
1086 if ((code == 0x090000) || (code == 0x490000))
1087 return 1;
1088 /* Check, if this is RFWU or RFWO. */
1089 code = insn & 0x00ffffff;
1090 return ((code == 0x00003400) || (code == 0x00003500));
1094 /* Returns the best guess about which register is a frame pointer
1095 for the function containing CURRENT_PC. */
1097 #define XTENSA_ISA_BSZ 32 /* Instruction buffer size. */
1098 #define XTENSA_ISA_BADPC ((CORE_ADDR)0) /* Bad PC value. */
1100 static unsigned int
1101 xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
1103 #define RETURN_FP goto done
1105 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1106 unsigned int fp_regnum = tdep->a0_base + 1;
1107 CORE_ADDR start_addr;
1108 xtensa_isa isa;
1109 xtensa_insnbuf ins, slot;
1110 gdb_byte ibuf[XTENSA_ISA_BSZ];
1111 CORE_ADDR ia, bt, ba;
1112 xtensa_format ifmt;
1113 int ilen, islots, is;
1114 xtensa_opcode opc;
1115 const char *opcname;
1117 find_pc_partial_function (current_pc, NULL, &start_addr, NULL);
1118 if (start_addr == 0)
1119 return fp_regnum;
1121 isa = xtensa_default_isa;
1122 gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
1123 ins = xtensa_insnbuf_alloc (isa);
1124 slot = xtensa_insnbuf_alloc (isa);
1125 ba = 0;
1127 for (ia = start_addr, bt = ia; ia < current_pc ; ia += ilen)
1129 if (ia + xtensa_isa_maxlength (isa) > bt)
1131 ba = ia;
1132 bt = (ba + XTENSA_ISA_BSZ) < current_pc
1133 ? ba + XTENSA_ISA_BSZ : current_pc;
1134 if (target_read_memory (ba, ibuf, bt - ba) != 0)
1135 RETURN_FP;
1138 xtensa_insnbuf_from_chars (isa, ins, &ibuf[ia-ba], 0);
1139 ifmt = xtensa_format_decode (isa, ins);
1140 if (ifmt == XTENSA_UNDEFINED)
1141 RETURN_FP;
1142 ilen = xtensa_format_length (isa, ifmt);
1143 if (ilen == XTENSA_UNDEFINED)
1144 RETURN_FP;
1145 islots = xtensa_format_num_slots (isa, ifmt);
1146 if (islots == XTENSA_UNDEFINED)
1147 RETURN_FP;
1149 for (is = 0; is < islots; ++is)
1151 if (xtensa_format_get_slot (isa, ifmt, is, ins, slot))
1152 RETURN_FP;
1154 opc = xtensa_opcode_decode (isa, ifmt, is, slot);
1155 if (opc == XTENSA_UNDEFINED)
1156 RETURN_FP;
1158 opcname = xtensa_opcode_name (isa, opc);
1160 if (strcasecmp (opcname, "mov.n") == 0
1161 || strcasecmp (opcname, "or") == 0)
1163 unsigned int register_operand;
1165 /* Possible candidate for setting frame pointer
1166 from A1. This is what we are looking for. */
1168 if (xtensa_operand_get_field (isa, opc, 1, ifmt,
1169 is, slot, &register_operand) != 0)
1170 RETURN_FP;
1171 if (xtensa_operand_decode (isa, opc, 1, &register_operand) != 0)
1172 RETURN_FP;
1173 if (register_operand == 1) /* Mov{.n} FP A1. */
1175 if (xtensa_operand_get_field (isa, opc, 0, ifmt, is, slot,
1176 &register_operand) != 0)
1177 RETURN_FP;
1178 if (xtensa_operand_decode (isa, opc, 0,
1179 &register_operand) != 0)
1180 RETURN_FP;
1182 fp_regnum
1183 = tdep->a0_base + register_operand;
1184 RETURN_FP;
1188 if (
1189 /* We have problems decoding the memory. */
1190 opcname == NULL
1191 || strcasecmp (opcname, "ill") == 0
1192 || strcasecmp (opcname, "ill.n") == 0
1193 /* Hit planted breakpoint. */
1194 || strcasecmp (opcname, "break") == 0
1195 || strcasecmp (opcname, "break.n") == 0
1196 /* Flow control instructions finish prologue. */
1197 || xtensa_opcode_is_branch (isa, opc) > 0
1198 || xtensa_opcode_is_jump (isa, opc) > 0
1199 || xtensa_opcode_is_loop (isa, opc) > 0
1200 || xtensa_opcode_is_call (isa, opc) > 0
1201 || strcasecmp (opcname, "simcall") == 0
1202 || strcasecmp (opcname, "syscall") == 0)
1203 /* Can not continue analysis. */
1204 RETURN_FP;
1207 done:
1208 xtensa_insnbuf_free(isa, slot);
1209 xtensa_insnbuf_free(isa, ins);
1210 return fp_regnum;
1213 /* The key values to identify the frame using "cache" are
1215 cache->base = SP (or best guess about FP) of this frame;
1216 cache->pc = entry-PC (entry point of the frame function);
1217 cache->prev_sp = SP of the previous frame. */
1219 static void
1220 call0_frame_cache (const frame_info_ptr &this_frame,
1221 xtensa_frame_cache_t *cache, CORE_ADDR pc);
1223 static void
1224 xtensa_window_interrupt_frame_cache (const frame_info_ptr &this_frame,
1225 xtensa_frame_cache_t *cache,
1226 CORE_ADDR pc);
1228 static struct xtensa_frame_cache *
1229 xtensa_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
1231 xtensa_frame_cache_t *cache;
1232 CORE_ADDR ra, wb, ws, pc, sp, ps;
1233 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1234 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1235 unsigned int fp_regnum;
1236 int windowed, ps_regnum;
1238 if (*this_cache)
1239 return (struct xtensa_frame_cache *) *this_cache;
1241 pc = get_frame_register_unsigned (this_frame, gdbarch_pc_regnum (gdbarch));
1242 ps_regnum = gdbarch_ps_regnum (gdbarch);
1243 ps = (ps_regnum >= 0
1244 ? get_frame_register_unsigned (this_frame, ps_regnum) : TX_PS);
1246 windowed = windowing_enabled (gdbarch, ps);
1248 /* Get pristine xtensa-frame. */
1249 cache = xtensa_alloc_frame_cache (windowed);
1250 *this_cache = cache;
1252 if (windowed)
1254 LONGEST op1;
1255 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1257 /* Get WINDOWBASE, WINDOWSTART, and PS registers. */
1258 wb = get_frame_register_unsigned (this_frame,
1259 tdep->wb_regnum);
1260 ws = get_frame_register_unsigned (this_frame,
1261 tdep->ws_regnum);
1263 if (safe_read_memory_integer (pc, 1, byte_order, &op1)
1264 && XTENSA_IS_ENTRY (gdbarch, op1))
1266 int callinc = CALLINC (ps);
1267 ra = get_frame_register_unsigned
1268 (this_frame, tdep->a0_base + callinc * 4);
1270 /* ENTRY hasn't been executed yet, therefore callsize is still 0. */
1271 cache->wd.callsize = 0;
1272 cache->wd.wb = wb;
1273 cache->wd.ws = ws;
1274 cache->prev_sp = get_frame_register_unsigned
1275 (this_frame, tdep->a0_base + 1);
1277 /* This only can be the outermost frame since we are
1278 just about to execute ENTRY. SP hasn't been set yet.
1279 We can assume any frame size, because it does not
1280 matter, and, let's fake frame base in cache. */
1281 cache->base = cache->prev_sp - 16;
1283 cache->pc = pc;
1284 cache->ra = (cache->pc & 0xc0000000) | (ra & 0x3fffffff);
1285 cache->ps = (ps & ~PS_CALLINC_MASK)
1286 | ((WINSIZE(ra)/4) << PS_CALLINC_SHIFT);
1288 return cache;
1290 else
1292 fp_regnum = xtensa_scan_prologue (gdbarch, pc);
1293 ra = get_frame_register_unsigned (this_frame,
1294 tdep->a0_base);
1295 cache->wd.callsize = WINSIZE (ra);
1296 cache->wd.wb = (wb - cache->wd.callsize / 4)
1297 & (tdep->num_aregs / 4 - 1);
1298 cache->wd.ws = ws & ~(1 << wb);
1300 cache->pc = get_frame_func (this_frame);
1301 cache->ra = (pc & 0xc0000000) | (ra & 0x3fffffff);
1302 cache->ps = (ps & ~PS_CALLINC_MASK)
1303 | ((WINSIZE(ra)/4) << PS_CALLINC_SHIFT);
1306 if (cache->wd.ws == 0)
1308 int i;
1310 /* Set A0...A3. */
1311 sp = get_frame_register_unsigned
1312 (this_frame, tdep->a0_base + 1) - 16;
1314 for (i = 0; i < 4; i++, sp += 4)
1316 cache->wd.aregs[i] = sp;
1319 if (cache->wd.callsize > 4)
1321 /* Set A4...A7/A11. */
1322 /* Get the SP of the frame previous to the previous one.
1323 To achieve this, we have to dereference SP twice. */
1324 sp = (CORE_ADDR) read_memory_integer (sp - 12, 4, byte_order);
1325 sp = (CORE_ADDR) read_memory_integer (sp - 12, 4, byte_order);
1326 sp -= cache->wd.callsize * 4;
1328 for ( i = 4; i < cache->wd.callsize; i++, sp += 4)
1330 cache->wd.aregs[i] = sp;
1335 if ((cache->prev_sp == 0) && ( ra != 0 ))
1336 /* If RA is equal to 0 this frame is an outermost frame. Leave
1337 cache->prev_sp unchanged marking the boundary of the frame stack. */
1339 if ((cache->wd.ws & (1 << cache->wd.wb)) == 0)
1341 /* Register window overflow already happened.
1342 We can read caller's SP from the proper spill location. */
1343 sp = get_frame_register_unsigned
1344 (this_frame, tdep->a0_base + 1);
1345 cache->prev_sp = read_memory_integer (sp - 12, 4, byte_order);
1347 else
1349 /* Read caller's frame SP directly from the previous window. */
1350 int regnum = arreg_number
1351 (gdbarch, tdep->a0_base + 1,
1352 cache->wd.wb);
1354 cache->prev_sp = xtensa_read_register (regnum);
1358 else if (xtensa_window_interrupt_insn (gdbarch, pc))
1360 /* Execution stopped inside Xtensa Window Interrupt Handler. */
1362 xtensa_window_interrupt_frame_cache (this_frame, cache, pc);
1363 /* Everything was set already, including cache->base. */
1364 return cache;
1366 else /* Call0 framework. */
1368 call0_frame_cache (this_frame, cache, pc);
1369 fp_regnum = cache->c0.fp_regnum;
1372 cache->base = get_frame_register_unsigned (this_frame, fp_regnum);
1374 return cache;
1377 static int xtensa_session_once_reported = 1;
1379 /* Report a problem with prologue analysis while doing backtracing.
1380 But, do it only once to avoid annoying repeated messages. */
1382 static void
1383 warning_once (void)
1385 if (xtensa_session_once_reported == 0)
1386 warning (_("\
1387 \nUnrecognised function prologue. Stack trace cannot be resolved. \
1388 This message will not be repeated in this session.\n"));
1390 xtensa_session_once_reported = 1;
1394 static void
1395 xtensa_frame_this_id (const frame_info_ptr &this_frame,
1396 void **this_cache,
1397 struct frame_id *this_id)
1399 struct xtensa_frame_cache *cache =
1400 xtensa_frame_cache (this_frame, this_cache);
1402 if (cache->prev_sp == 0)
1403 return;
1405 (*this_id) = frame_id_build (cache->prev_sp, cache->pc);
1408 static struct value *
1409 xtensa_frame_prev_register (const frame_info_ptr &this_frame,
1410 void **this_cache,
1411 int regnum)
1413 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1414 struct xtensa_frame_cache *cache;
1415 ULONGEST saved_reg = 0;
1416 int done = 1;
1417 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1419 if (*this_cache == NULL)
1420 *this_cache = xtensa_frame_cache (this_frame, this_cache);
1421 cache = (struct xtensa_frame_cache *) *this_cache;
1423 if (regnum ==gdbarch_pc_regnum (gdbarch))
1424 saved_reg = cache->ra;
1425 else if (regnum == tdep->a0_base + 1)
1426 saved_reg = cache->prev_sp;
1427 else if (!cache->call0)
1429 if (regnum == tdep->ws_regnum)
1430 saved_reg = cache->wd.ws;
1431 else if (regnum == tdep->wb_regnum)
1432 saved_reg = cache->wd.wb;
1433 else if (regnum == gdbarch_ps_regnum (gdbarch))
1434 saved_reg = cache->ps;
1435 else
1436 done = 0;
1438 else
1439 done = 0;
1441 if (done)
1442 return frame_unwind_got_constant (this_frame, regnum, saved_reg);
1444 if (!cache->call0) /* Windowed ABI. */
1446 /* Convert A-register numbers to AR-register numbers,
1447 if we deal with A-register. */
1448 if (regnum >= tdep->a0_base
1449 && regnum <= tdep->a0_base + 15)
1450 regnum = arreg_number (gdbarch, regnum, cache->wd.wb);
1452 /* Check, if we deal with AR-register saved on stack. */
1453 if (regnum >= tdep->ar_base
1454 && regnum <= (tdep->ar_base
1455 + tdep->num_aregs))
1457 int areg = areg_number (gdbarch, regnum, cache->wd.wb);
1459 if (areg >= 0
1460 && areg < XTENSA_NUM_SAVED_AREGS
1461 && cache->wd.aregs[areg] != -1)
1462 return frame_unwind_got_memory (this_frame, regnum,
1463 cache->wd.aregs[areg]);
1466 else /* Call0 ABI. */
1468 int reg = (regnum >= tdep->ar_base
1469 && regnum <= (tdep->ar_base
1470 + C0_NREGS))
1471 ? regnum - tdep->ar_base : regnum;
1473 if (reg < C0_NREGS)
1475 CORE_ADDR spe;
1476 int stkofs;
1478 /* If register was saved in the prologue, retrieve it. */
1479 stkofs = cache->c0.c0_rt[reg].to_stk;
1480 if (stkofs != C0_NOSTK)
1482 /* Determine SP on entry based on FP. */
1483 spe = cache->c0.c0_fp
1484 - cache->c0.c0_rt[cache->c0.fp_regnum].fr_ofs;
1486 return frame_unwind_got_memory (this_frame, regnum,
1487 spe + stkofs);
1492 /* All other registers have been either saved to
1493 the stack or are still alive in the processor. */
1495 return frame_unwind_got_register (this_frame, regnum, regnum);
1499 static const struct frame_unwind_legacy xtensa_unwind (
1500 "xtensa prologue",
1501 NORMAL_FRAME,
1502 FRAME_UNWIND_ARCH,
1503 default_frame_unwind_stop_reason,
1504 xtensa_frame_this_id,
1505 xtensa_frame_prev_register,
1506 NULL,
1507 default_frame_sniffer
1510 static CORE_ADDR
1511 xtensa_frame_base_address (const frame_info_ptr &this_frame, void **this_cache)
1513 struct xtensa_frame_cache *cache =
1514 xtensa_frame_cache (this_frame, this_cache);
1516 return cache->base;
1519 static const struct frame_base
1520 xtensa_frame_base =
1522 &xtensa_unwind,
1523 xtensa_frame_base_address,
1524 xtensa_frame_base_address,
1525 xtensa_frame_base_address
1529 static void
1530 xtensa_extract_return_value (struct type *type,
1531 struct regcache *regcache,
1532 void *dst)
1534 struct gdbarch *gdbarch = regcache->arch ();
1535 bfd_byte *valbuf = (bfd_byte *) dst;
1536 int len = type->length ();
1537 ULONGEST pc, wb;
1538 int callsize, areg;
1539 int offset = 0;
1541 DEBUGTRACE ("xtensa_extract_return_value (...)\n");
1543 gdb_assert(len > 0);
1545 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1546 if (tdep->call_abi != CallAbiCall0Only)
1548 /* First, we have to find the caller window in the register file. */
1549 regcache_raw_read_unsigned (regcache, gdbarch_pc_regnum (gdbarch), &pc);
1550 callsize = extract_call_winsize (gdbarch, pc);
1552 /* On Xtensa, we can return up to 4 words (or 2 for call12). */
1553 if (len > (callsize > 8 ? 8 : 16))
1554 internal_error (_("cannot extract return value of %d bytes long"),
1555 len);
1557 /* Get the register offset of the return
1558 register (A2) in the caller window. */
1559 regcache_raw_read_unsigned
1560 (regcache, tdep->wb_regnum, &wb);
1561 areg = arreg_number (gdbarch,
1562 tdep->a0_base + 2 + callsize, wb);
1564 else
1566 /* No windowing hardware - Call0 ABI. */
1567 areg = tdep->a0_base + C0_ARGS;
1570 DEBUGINFO ("[xtensa_extract_return_value] areg %d len %d\n", areg, len);
1572 if (len < 4 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1573 offset = 4 - len;
1575 for (; len > 0; len -= 4, areg++, valbuf += 4)
1577 if (len < 4)
1578 regcache->raw_read_part (areg, offset, len, valbuf);
1579 else
1580 regcache->raw_read (areg, valbuf);
1585 static void
1586 xtensa_store_return_value (struct type *type,
1587 struct regcache *regcache,
1588 const void *dst)
1590 struct gdbarch *gdbarch = regcache->arch ();
1591 const bfd_byte *valbuf = (const bfd_byte *) dst;
1592 unsigned int areg;
1593 ULONGEST pc, wb;
1594 int callsize;
1595 int len = type->length ();
1596 int offset = 0;
1598 DEBUGTRACE ("xtensa_store_return_value (...)\n");
1600 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1601 if (tdep->call_abi != CallAbiCall0Only)
1603 regcache_raw_read_unsigned
1604 (regcache, tdep->wb_regnum, &wb);
1605 regcache_raw_read_unsigned (regcache, gdbarch_pc_regnum (gdbarch), &pc);
1606 callsize = extract_call_winsize (gdbarch, pc);
1608 if (len > (callsize > 8 ? 8 : 16))
1609 internal_error (_("unimplemented for this length: %s"),
1610 pulongest (type->length ()));
1611 areg = arreg_number (gdbarch,
1612 tdep->a0_base + 2 + callsize, wb);
1614 DEBUGTRACE ("[xtensa_store_return_value] callsize %d wb %d\n",
1615 callsize, (int) wb);
1617 else
1619 areg = tdep->a0_base + C0_ARGS;
1622 if (len < 4 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1623 offset = 4 - len;
1625 for (; len > 0; len -= 4, areg++, valbuf += 4)
1627 if (len < 4)
1628 regcache->raw_write_part (areg, offset, len, valbuf);
1629 else
1630 regcache->raw_write (areg, valbuf);
1635 static enum return_value_convention
1636 xtensa_return_value (struct gdbarch *gdbarch,
1637 struct value *function,
1638 struct type *valtype,
1639 struct regcache *regcache,
1640 gdb_byte *readbuf,
1641 const gdb_byte *writebuf)
1643 /* Structures up to 16 bytes are returned in registers. */
1645 int struct_return = ((valtype->code () == TYPE_CODE_STRUCT
1646 || valtype->code () == TYPE_CODE_UNION
1647 || valtype->code () == TYPE_CODE_ARRAY)
1648 && valtype->length () > 16);
1650 if (struct_return)
1651 return RETURN_VALUE_STRUCT_CONVENTION;
1653 DEBUGTRACE ("xtensa_return_value(...)\n");
1655 if (writebuf != NULL)
1657 xtensa_store_return_value (valtype, regcache, writebuf);
1660 if (readbuf != NULL)
1662 gdb_assert (!struct_return);
1663 xtensa_extract_return_value (valtype, regcache, readbuf);
1665 return RETURN_VALUE_REGISTER_CONVENTION;
1669 /* DUMMY FRAME */
1671 static CORE_ADDR
1672 xtensa_push_dummy_call (struct gdbarch *gdbarch,
1673 struct value *function,
1674 struct regcache *regcache,
1675 CORE_ADDR bp_addr,
1676 int nargs,
1677 struct value **args,
1678 CORE_ADDR sp,
1679 function_call_return_method return_method,
1680 CORE_ADDR struct_addr)
1682 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1683 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1684 int size, onstack_size;
1685 gdb_byte *buf = (gdb_byte *) alloca (16);
1686 CORE_ADDR ra, ps;
1687 struct argument_info
1689 const bfd_byte *contents;
1690 int length;
1691 int onstack; /* onstack == 0 => in reg */
1692 int align; /* alignment */
1693 union
1695 int offset; /* stack offset if on stack. */
1696 int regno; /* regno if in register. */
1697 } u;
1700 struct argument_info *arg_info =
1701 (struct argument_info *) alloca (nargs * sizeof (struct argument_info));
1703 CORE_ADDR osp = sp;
1705 DEBUGTRACE ("xtensa_push_dummy_call (...)\n");
1707 if (xtensa_debug_level > 3)
1709 DEBUGINFO ("[xtensa_push_dummy_call] nargs = %d\n", nargs);
1710 DEBUGINFO ("[xtensa_push_dummy_call] sp=0x%x, return_method=%d, "
1711 "struct_addr=0x%x\n",
1712 (int) sp, (int) return_method, (int) struct_addr);
1714 for (int i = 0; i < nargs; i++)
1716 struct value *arg = args[i];
1717 struct type *arg_type = check_typedef (arg->type ());
1718 gdb_printf (gdb_stdlog, "%2d: %s %3s ", i,
1719 host_address_to_string (arg),
1720 pulongest (arg_type->length ()));
1721 switch (arg_type->code ())
1723 case TYPE_CODE_INT:
1724 gdb_printf (gdb_stdlog, "int");
1725 break;
1726 case TYPE_CODE_STRUCT:
1727 gdb_printf (gdb_stdlog, "struct");
1728 break;
1729 default:
1730 gdb_printf (gdb_stdlog, "%3d", arg_type->code ());
1731 break;
1733 gdb_printf (gdb_stdlog, " %s\n",
1734 host_address_to_string (arg->contents ().data ()));
1738 /* First loop: collect information.
1739 Cast into type_long. (This shouldn't happen often for C because
1740 GDB already does this earlier.) It's possible that GDB could
1741 do it all the time but it's harmless to leave this code here. */
1743 size = 0;
1744 onstack_size = 0;
1746 if (return_method == return_method_struct)
1747 size = REGISTER_SIZE;
1749 for (int i = 0; i < nargs; i++)
1751 struct argument_info *info = &arg_info[i];
1752 struct value *arg = args[i];
1753 struct type *arg_type = check_typedef (arg->type ());
1755 switch (arg_type->code ())
1757 case TYPE_CODE_INT:
1758 case TYPE_CODE_BOOL:
1759 case TYPE_CODE_CHAR:
1760 case TYPE_CODE_RANGE:
1761 case TYPE_CODE_ENUM:
1763 /* Cast argument to long if necessary as the mask does it too. */
1764 if (arg_type->length ()
1765 < builtin_type (gdbarch)->builtin_long->length ())
1767 arg_type = builtin_type (gdbarch)->builtin_long;
1768 arg = value_cast (arg_type, arg);
1770 /* Aligment is equal to the type length for the basic types. */
1771 info->align = arg_type->length ();
1772 break;
1774 case TYPE_CODE_FLT:
1776 /* Align doubles correctly. */
1777 if (arg_type->length ()
1778 == builtin_type (gdbarch)->builtin_double->length ())
1779 info->align = builtin_type (gdbarch)->builtin_double->length ();
1780 else
1781 info->align = builtin_type (gdbarch)->builtin_long->length ();
1782 break;
1784 case TYPE_CODE_STRUCT:
1785 default:
1786 info->align = builtin_type (gdbarch)->builtin_long->length ();
1787 break;
1789 info->length = arg_type->length ();
1790 info->contents = arg->contents ().data ();
1792 /* Align size and onstack_size. */
1793 size = (size + info->align - 1) & ~(info->align - 1);
1794 onstack_size = (onstack_size + info->align - 1) & ~(info->align - 1);
1796 if (size + info->length > REGISTER_SIZE * ARG_NOF (tdep))
1798 info->onstack = 1;
1799 info->u.offset = onstack_size;
1800 onstack_size += info->length;
1802 else
1804 info->onstack = 0;
1805 info->u.regno = ARG_1ST (tdep) + size / REGISTER_SIZE;
1807 size += info->length;
1810 /* Adjust the stack pointer and align it. */
1811 sp = align_down (sp - onstack_size, SP_ALIGNMENT);
1813 /* Simulate MOVSP, if Windowed ABI. */
1814 if ((tdep->call_abi != CallAbiCall0Only)
1815 && (sp != osp))
1817 read_memory (osp - 16, buf, 16);
1818 write_memory (sp - 16, buf, 16);
1821 /* Second Loop: Load arguments. */
1823 if (return_method == return_method_struct)
1825 store_unsigned_integer (buf, REGISTER_SIZE, byte_order, struct_addr);
1826 regcache->cooked_write (ARG_1ST (tdep), buf);
1829 for (int i = 0; i < nargs; i++)
1831 struct argument_info *info = &arg_info[i];
1833 if (info->onstack)
1835 int n = info->length;
1836 CORE_ADDR offset = sp + info->u.offset;
1838 /* Odd-sized structs are aligned to the lower side of a memory
1839 word in big-endian mode and require a shift. This only
1840 applies for structures smaller than one word. */
1842 if (n < REGISTER_SIZE
1843 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1844 offset += (REGISTER_SIZE - n);
1846 write_memory (offset, info->contents, info->length);
1849 else
1851 int n = info->length;
1852 const bfd_byte *cp = info->contents;
1853 int r = info->u.regno;
1855 /* Odd-sized structs are aligned to the lower side of registers in
1856 big-endian mode and require a shift. The odd-sized leftover will
1857 be at the end. Note that this is only true for structures smaller
1858 than REGISTER_SIZE; for larger odd-sized structures the excess
1859 will be left-aligned in the register on both endiannesses. */
1861 if (n < REGISTER_SIZE && byte_order == BFD_ENDIAN_BIG)
1863 ULONGEST v;
1864 v = extract_unsigned_integer (cp, REGISTER_SIZE, byte_order);
1865 v = v >> ((REGISTER_SIZE - n) * TARGET_CHAR_BIT);
1867 store_unsigned_integer (buf, REGISTER_SIZE, byte_order, v);
1868 regcache->cooked_write (r, buf);
1870 cp += REGISTER_SIZE;
1871 n -= REGISTER_SIZE;
1872 r++;
1874 else
1875 while (n > 0)
1877 regcache->cooked_write (r, cp);
1879 cp += REGISTER_SIZE;
1880 n -= REGISTER_SIZE;
1881 r++;
1886 /* Set the return address of dummy frame to the dummy address.
1887 The return address for the current function (in A0) is
1888 saved in the dummy frame, so we can safely overwrite A0 here. */
1890 if (tdep->call_abi != CallAbiCall0Only)
1892 ULONGEST val;
1894 ra = (bp_addr & 0x3fffffff) | 0x40000000;
1895 regcache_raw_read_unsigned (regcache, gdbarch_ps_regnum (gdbarch), &val);
1896 ps = (unsigned long) val & ~0x00030000;
1897 regcache_cooked_write_unsigned
1898 (regcache, tdep->a0_base + 4, ra);
1899 regcache_cooked_write_unsigned (regcache,
1900 gdbarch_ps_regnum (gdbarch),
1901 ps | 0x00010000);
1903 /* All the registers have been saved. After executing
1904 dummy call, they all will be restored. So it's safe
1905 to modify WINDOWSTART register to make it look like there
1906 is only one register window corresponding to WINDOWEBASE. */
1908 regcache->raw_read (tdep->wb_regnum, buf);
1909 regcache_cooked_write_unsigned
1910 (regcache, tdep->ws_regnum,
1911 1 << extract_unsigned_integer (buf, 4, byte_order));
1913 else
1915 /* Simulate CALL0: write RA into A0 register. */
1916 regcache_cooked_write_unsigned
1917 (regcache, tdep->a0_base, bp_addr);
1920 /* Set new stack pointer and return it. */
1921 regcache_cooked_write_unsigned (regcache,
1922 tdep->a0_base + 1, sp);
1923 /* Make dummy frame ID unique by adding a constant. */
1924 return sp + SP_ALIGNMENT;
1927 /* Implement the breakpoint_kind_from_pc gdbarch method. */
1929 static int
1930 xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
1932 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1934 if (tdep->isa_use_density_instructions)
1935 return 2;
1936 else
1937 return 4;
1940 /* Return a breakpoint for the current location of PC. We always use
1941 the density version if we have density instructions (regardless of the
1942 current instruction at PC), and use regular instructions otherwise. */
1944 #define BIG_BREAKPOINT { 0x00, 0x04, 0x00 }
1945 #define LITTLE_BREAKPOINT { 0x00, 0x40, 0x00 }
1946 #define DENSITY_BIG_BREAKPOINT { 0xd2, 0x0f }
1947 #define DENSITY_LITTLE_BREAKPOINT { 0x2d, 0xf0 }
1949 /* Implement the sw_breakpoint_from_kind gdbarch method. */
1951 static const gdb_byte *
1952 xtensa_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
1954 *size = kind;
1956 if (kind == 4)
1958 static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
1959 static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
1961 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1962 return big_breakpoint;
1963 else
1964 return little_breakpoint;
1966 else
1968 static unsigned char density_big_breakpoint[] = DENSITY_BIG_BREAKPOINT;
1969 static unsigned char density_little_breakpoint[]
1970 = DENSITY_LITTLE_BREAKPOINT;
1972 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1973 return density_big_breakpoint;
1974 else
1975 return density_little_breakpoint;
1979 /* Call0 ABI support routines. */
1981 /* Return true, if PC points to "ret" or "ret.n". */
1983 static int
1984 call0_ret (CORE_ADDR start_pc, CORE_ADDR finish_pc)
1986 #define RETURN_RET goto done
1987 xtensa_isa isa;
1988 xtensa_insnbuf ins, slot;
1989 gdb_byte ibuf[XTENSA_ISA_BSZ];
1990 CORE_ADDR ia, bt, ba;
1991 xtensa_format ifmt;
1992 int ilen, islots, is;
1993 xtensa_opcode opc;
1994 const char *opcname;
1995 int found_ret = 0;
1997 isa = xtensa_default_isa;
1998 gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
1999 ins = xtensa_insnbuf_alloc (isa);
2000 slot = xtensa_insnbuf_alloc (isa);
2001 ba = 0;
2003 for (ia = start_pc, bt = ia; ia < finish_pc ; ia += ilen)
2005 if (ia + xtensa_isa_maxlength (isa) > bt)
2007 ba = ia;
2008 bt = (ba + XTENSA_ISA_BSZ) < finish_pc
2009 ? ba + XTENSA_ISA_BSZ : finish_pc;
2010 if (target_read_memory (ba, ibuf, bt - ba) != 0 )
2011 RETURN_RET;
2014 xtensa_insnbuf_from_chars (isa, ins, &ibuf[ia-ba], 0);
2015 ifmt = xtensa_format_decode (isa, ins);
2016 if (ifmt == XTENSA_UNDEFINED)
2017 RETURN_RET;
2018 ilen = xtensa_format_length (isa, ifmt);
2019 if (ilen == XTENSA_UNDEFINED)
2020 RETURN_RET;
2021 islots = xtensa_format_num_slots (isa, ifmt);
2022 if (islots == XTENSA_UNDEFINED)
2023 RETURN_RET;
2025 for (is = 0; is < islots; ++is)
2027 if (xtensa_format_get_slot (isa, ifmt, is, ins, slot))
2028 RETURN_RET;
2030 opc = xtensa_opcode_decode (isa, ifmt, is, slot);
2031 if (opc == XTENSA_UNDEFINED)
2032 RETURN_RET;
2034 opcname = xtensa_opcode_name (isa, opc);
2036 if ((strcasecmp (opcname, "ret.n") == 0)
2037 || (strcasecmp (opcname, "ret") == 0))
2039 found_ret = 1;
2040 RETURN_RET;
2044 done:
2045 xtensa_insnbuf_free(isa, slot);
2046 xtensa_insnbuf_free(isa, ins);
2047 return found_ret;
2050 /* Call0 opcode class. Opcodes are preclassified according to what they
2051 mean for Call0 prologue analysis, and their number of significant operands.
2052 The purpose of this is to simplify prologue analysis by separating
2053 instruction decoding (libisa) from the semantics of prologue analysis. */
2055 enum xtensa_insn_kind
2057 c0opc_illegal, /* Unknown to libisa (invalid) or 'ill' opcode. */
2058 c0opc_uninteresting, /* Not interesting for Call0 prologue analysis. */
2059 c0opc_flow, /* Flow control insn. */
2060 c0opc_entry, /* ENTRY indicates non-Call0 prologue. */
2061 c0opc_break, /* Debugger software breakpoints. */
2062 c0opc_add, /* Adding two registers. */
2063 c0opc_addi, /* Adding a register and an immediate. */
2064 c0opc_and, /* Bitwise "and"-ing two registers. */
2065 c0opc_sub, /* Subtracting a register from a register. */
2066 c0opc_mov, /* Moving a register to a register. */
2067 c0opc_movi, /* Moving an immediate to a register. */
2068 c0opc_l32r, /* Loading a literal. */
2069 c0opc_s32i, /* Storing word at fixed offset from a base register. */
2070 c0opc_rwxsr, /* RSR, WRS, or XSR instructions. */
2071 c0opc_l32e, /* L32E instruction. */
2072 c0opc_s32e, /* S32E instruction. */
2073 c0opc_rfwo, /* RFWO instruction. */
2074 c0opc_rfwu, /* RFWU instruction. */
2075 c0opc_NrOf /* Number of opcode classifications. */
2078 /* Return true, if OPCNAME is RSR, WRS, or XSR instruction. */
2080 static int
2081 rwx_special_register (const char *opcname)
2083 char ch = *opcname++;
2085 if ((ch != 'r') && (ch != 'w') && (ch != 'x'))
2086 return 0;
2087 if (*opcname++ != 's')
2088 return 0;
2089 if (*opcname++ != 'r')
2090 return 0;
2091 if (*opcname++ != '.')
2092 return 0;
2094 return 1;
2097 /* Classify an opcode based on what it means for Call0 prologue analysis. */
2099 static xtensa_insn_kind
2100 call0_classify_opcode (xtensa_isa isa, xtensa_opcode opc)
2102 const char *opcname;
2103 xtensa_insn_kind opclass = c0opc_uninteresting;
2105 DEBUGTRACE ("call0_classify_opcode (..., opc = %d)\n", opc);
2107 /* Get opcode name and handle special classifications. */
2109 opcname = xtensa_opcode_name (isa, opc);
2111 if (opcname == NULL
2112 || strcasecmp (opcname, "ill") == 0
2113 || strcasecmp (opcname, "ill.n") == 0)
2114 opclass = c0opc_illegal;
2115 else if (strcasecmp (opcname, "break") == 0
2116 || strcasecmp (opcname, "break.n") == 0)
2117 opclass = c0opc_break;
2118 else if (strcasecmp (opcname, "entry") == 0)
2119 opclass = c0opc_entry;
2120 else if (strcasecmp (opcname, "rfwo") == 0)
2121 opclass = c0opc_rfwo;
2122 else if (strcasecmp (opcname, "rfwu") == 0)
2123 opclass = c0opc_rfwu;
2124 else if (xtensa_opcode_is_branch (isa, opc) > 0
2125 || xtensa_opcode_is_jump (isa, opc) > 0
2126 || xtensa_opcode_is_loop (isa, opc) > 0
2127 || xtensa_opcode_is_call (isa, opc) > 0
2128 || strcasecmp (opcname, "simcall") == 0
2129 || strcasecmp (opcname, "syscall") == 0)
2130 opclass = c0opc_flow;
2132 /* Also, classify specific opcodes that need to be tracked. */
2133 else if (strcasecmp (opcname, "add") == 0
2134 || strcasecmp (opcname, "add.n") == 0)
2135 opclass = c0opc_add;
2136 else if (strcasecmp (opcname, "and") == 0)
2137 opclass = c0opc_and;
2138 else if (strcasecmp (opcname, "addi") == 0
2139 || strcasecmp (opcname, "addi.n") == 0
2140 || strcasecmp (opcname, "addmi") == 0)
2141 opclass = c0opc_addi;
2142 else if (strcasecmp (opcname, "sub") == 0)
2143 opclass = c0opc_sub;
2144 else if (strcasecmp (opcname, "mov.n") == 0
2145 || strcasecmp (opcname, "or") == 0) /* Could be 'mov' asm macro. */
2146 opclass = c0opc_mov;
2147 else if (strcasecmp (opcname, "movi") == 0
2148 || strcasecmp (opcname, "movi.n") == 0)
2149 opclass = c0opc_movi;
2150 else if (strcasecmp (opcname, "l32r") == 0)
2151 opclass = c0opc_l32r;
2152 else if (strcasecmp (opcname, "s32i") == 0
2153 || strcasecmp (opcname, "s32i.n") == 0)
2154 opclass = c0opc_s32i;
2155 else if (strcasecmp (opcname, "l32e") == 0)
2156 opclass = c0opc_l32e;
2157 else if (strcasecmp (opcname, "s32e") == 0)
2158 opclass = c0opc_s32e;
2159 else if (rwx_special_register (opcname))
2160 opclass = c0opc_rwxsr;
2162 return opclass;
2165 /* Tracks register movement/mutation for a given operation, which may
2166 be within a bundle. Updates the destination register tracking info
2167 accordingly. The pc is needed only for pc-relative load instructions
2168 (eg. l32r). The SP register number is needed to identify stores to
2169 the stack frame. Returns 0, if analysis was successful, non-zero
2170 otherwise. */
2172 static int
2173 call0_track_op (struct gdbarch *gdbarch, xtensa_c0reg_t dst[], xtensa_c0reg_t src[],
2174 xtensa_insn_kind opclass, int nods, unsigned odv[],
2175 CORE_ADDR pc, int spreg, xtensa_frame_cache_t *cache)
2177 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2178 unsigned litbase, litaddr, litval;
2179 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
2181 switch (opclass)
2183 case c0opc_addi:
2184 /* 3 operands: dst, src, imm. */
2185 gdb_assert (nods == 3);
2186 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
2187 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs + odv[2];
2188 break;
2189 case c0opc_add:
2190 /* 3 operands: dst, src1, src2. */
2191 gdb_assert (nods == 3);
2192 if (src[odv[1]].fr_reg == C0_CONST)
2194 dst[odv[0]].fr_reg = src[odv[2]].fr_reg;
2195 dst[odv[0]].fr_ofs = src[odv[2]].fr_ofs + src[odv[1]].fr_ofs;
2197 else if (src[odv[2]].fr_reg == C0_CONST)
2199 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
2200 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs + src[odv[2]].fr_ofs;
2202 else dst[odv[0]].fr_reg = C0_INEXP;
2203 break;
2204 case c0opc_and:
2205 /* 3 operands: dst, src1, src2. */
2206 gdb_assert (nods == 3);
2207 if (cache->c0.c0_fpalign == 0)
2209 /* Handle dynamic stack alignment. */
2210 if ((src[odv[0]].fr_reg == spreg) && (src[odv[1]].fr_reg == spreg))
2212 if (src[odv[2]].fr_reg == C0_CONST)
2213 cache->c0.c0_fpalign = src[odv[2]].fr_ofs;
2214 break;
2216 else if ((src[odv[0]].fr_reg == spreg)
2217 && (src[odv[2]].fr_reg == spreg))
2219 if (src[odv[1]].fr_reg == C0_CONST)
2220 cache->c0.c0_fpalign = src[odv[1]].fr_ofs;
2221 break;
2223 /* else fall through. */
2225 if (src[odv[1]].fr_reg == C0_CONST)
2227 dst[odv[0]].fr_reg = src[odv[2]].fr_reg;
2228 dst[odv[0]].fr_ofs = src[odv[2]].fr_ofs & src[odv[1]].fr_ofs;
2230 else if (src[odv[2]].fr_reg == C0_CONST)
2232 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
2233 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs & src[odv[2]].fr_ofs;
2235 else dst[odv[0]].fr_reg = C0_INEXP;
2236 break;
2237 case c0opc_sub:
2238 /* 3 operands: dst, src1, src2. */
2239 gdb_assert (nods == 3);
2240 if (src[odv[2]].fr_reg == C0_CONST)
2242 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
2243 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs - src[odv[2]].fr_ofs;
2245 else dst[odv[0]].fr_reg = C0_INEXP;
2246 break;
2247 case c0opc_mov:
2248 /* 2 operands: dst, src [, src]. */
2249 gdb_assert (nods == 2);
2250 /* First, check if it's a special case of saving unaligned SP
2251 to a spare register in case of dynamic stack adjustment.
2252 But, only do it one time. The second time could be initializing
2253 frame pointer. We don't want to overwrite the first one. */
2254 if ((odv[1] == spreg) && (cache->c0.c0_old_sp == C0_INEXP))
2255 cache->c0.c0_old_sp = odv[0];
2257 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
2258 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs;
2259 break;
2260 case c0opc_movi:
2261 /* 2 operands: dst, imm. */
2262 gdb_assert (nods == 2);
2263 dst[odv[0]].fr_reg = C0_CONST;
2264 dst[odv[0]].fr_ofs = odv[1];
2265 break;
2266 case c0opc_l32r:
2267 /* 2 operands: dst, literal offset. */
2268 gdb_assert (nods == 2);
2269 /* litbase = xtensa_get_litbase (pc); can be also used. */
2270 litbase = (tdep->litbase_regnum == -1)
2271 ? 0 : xtensa_read_register
2272 (tdep->litbase_regnum);
2273 litaddr = litbase & 1
2274 ? (litbase & ~1) + (signed)odv[1]
2275 : (pc + 3 + (signed)odv[1]) & ~3;
2276 litval = read_memory_integer (litaddr, 4, byte_order);
2277 dst[odv[0]].fr_reg = C0_CONST;
2278 dst[odv[0]].fr_ofs = litval;
2279 break;
2280 case c0opc_s32i:
2281 /* 3 operands: value, base, offset. */
2282 gdb_assert (nods == 3 && spreg >= 0 && spreg < C0_NREGS);
2283 /* First, check if it's a spill for saved unaligned SP,
2284 when dynamic stack adjustment was applied to this frame. */
2285 if ((cache->c0.c0_fpalign != 0) /* Dynamic stack adjustment. */
2286 && (odv[1] == spreg) /* SP usage indicates spill. */
2287 && (odv[0] == cache->c0.c0_old_sp)) /* Old SP register spilled. */
2288 cache->c0.c0_sp_ofs = odv[2];
2290 if (src[odv[1]].fr_reg == spreg /* Store to stack frame. */
2291 && (src[odv[1]].fr_ofs & 3) == 0 /* Alignment preserved. */
2292 && src[odv[0]].fr_reg >= 0 /* Value is from a register. */
2293 && src[odv[0]].fr_ofs == 0 /* Value hasn't been modified. */
2294 && src[src[odv[0]].fr_reg].to_stk == C0_NOSTK) /* First time. */
2296 /* ISA encoding guarantees alignment. But, check it anyway. */
2297 gdb_assert ((odv[2] & 3) == 0);
2298 dst[src[odv[0]].fr_reg].to_stk = src[odv[1]].fr_ofs + odv[2];
2300 break;
2301 /* If we end up inside Window Overflow / Underflow interrupt handler
2302 report an error because these handlers should have been handled
2303 already in a different way. */
2304 case c0opc_l32e:
2305 case c0opc_s32e:
2306 case c0opc_rfwo:
2307 case c0opc_rfwu:
2308 return 1;
2309 default:
2310 return 1;
2312 return 0;
2315 /* Analyze prologue of the function at start address to determine if it uses
2316 the Call0 ABI, and if so track register moves and linear modifications
2317 in the prologue up to the PC or just beyond the prologue, whichever is
2318 first. An 'entry' instruction indicates non-Call0 ABI and the end of the
2319 prologue. The prologue may overlap non-prologue instructions but is
2320 guaranteed to end by the first flow-control instruction (jump, branch,
2321 call or return). Since an optimized function may move information around
2322 and change the stack frame arbitrarily during the prologue, the information
2323 is guaranteed valid only at the point in the function indicated by the PC.
2324 May be used to skip the prologue or identify the ABI, w/o tracking.
2326 Returns: Address of first instruction after prologue, or PC (whichever
2327 is first), or 0, if decoding failed (in libisa).
2328 Input args:
2329 start Start address of function/prologue.
2330 pc Program counter to stop at. Use 0 to continue to end of prologue.
2331 If 0, avoids infinite run-on in corrupt code memory by bounding
2332 the scan to the end of the function if that can be determined.
2333 nregs Number of general registers to track.
2334 InOut args:
2335 cache Xtensa frame cache.
2337 Note that these may produce useful results even if decoding fails
2338 because they begin with default assumptions that analysis may change. */
2340 static CORE_ADDR
2341 call0_analyze_prologue (struct gdbarch *gdbarch,
2342 CORE_ADDR start, CORE_ADDR pc,
2343 int nregs, xtensa_frame_cache_t *cache)
2345 CORE_ADDR ia; /* Current insn address in prologue. */
2346 CORE_ADDR ba = 0; /* Current address at base of insn buffer. */
2347 CORE_ADDR bt; /* Current address at top+1 of insn buffer. */
2348 gdb_byte ibuf[XTENSA_ISA_BSZ];/* Instruction buffer for decoding prologue. */
2349 xtensa_isa isa; /* libisa ISA handle. */
2350 xtensa_insnbuf ins, slot; /* libisa handle to decoded insn, slot. */
2351 xtensa_format ifmt; /* libisa instruction format. */
2352 int ilen, islots, is; /* Instruction length, nbr slots, current slot. */
2353 xtensa_opcode opc; /* Opcode in current slot. */
2354 xtensa_insn_kind opclass; /* Opcode class for Call0 prologue analysis. */
2355 int nods; /* Opcode number of operands. */
2356 unsigned odv[C0_MAXOPDS]; /* Operand values in order provided by libisa. */
2357 xtensa_c0reg_t *rtmp; /* Register tracking info snapshot. */
2358 int j; /* General loop counter. */
2359 int fail = 0; /* Set non-zero and exit, if decoding fails. */
2360 CORE_ADDR body_pc; /* The PC for the first non-prologue insn. */
2361 CORE_ADDR end_pc; /* The PC for the lust function insn. */
2363 struct symtab_and_line prologue_sal;
2365 DEBUGTRACE ("call0_analyze_prologue (start = 0x%08x, pc = 0x%08x, ...)\n",
2366 (int)start, (int)pc);
2368 /* Try to limit the scan to the end of the function if a non-zero pc
2369 arg was not supplied to avoid probing beyond the end of valid memory.
2370 If memory is full of garbage that classifies as c0opc_uninteresting.
2371 If this fails (eg. if no symbols) pc ends up 0 as it was.
2372 Initialize the Call0 frame and register tracking info.
2373 Assume it's Call0 until an 'entry' instruction is encountered.
2374 Assume we may be in the prologue until we hit a flow control instr. */
2376 rtmp = NULL;
2377 body_pc = UINT_MAX;
2378 end_pc = 0;
2380 /* Find out, if we have an information about the prologue from DWARF. */
2381 prologue_sal = find_pc_line (start, 0);
2382 if (prologue_sal.line != 0) /* Found debug info. */
2383 body_pc = prologue_sal.end;
2385 /* If we are going to analyze the prologue in general without knowing about
2386 the current PC, make the best assumption for the end of the prologue. */
2387 if (pc == 0)
2389 find_pc_partial_function (start, 0, NULL, &end_pc);
2390 body_pc = std::min (end_pc, body_pc);
2392 else
2393 body_pc = std::min (pc, body_pc);
2395 cache->call0 = 1;
2396 rtmp = (xtensa_c0reg_t*) alloca(nregs * sizeof(xtensa_c0reg_t));
2398 isa = xtensa_default_isa;
2399 gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
2400 ins = xtensa_insnbuf_alloc (isa);
2401 slot = xtensa_insnbuf_alloc (isa);
2403 for (ia = start, bt = ia; ia < body_pc ; ia += ilen)
2405 /* (Re)fill instruction buffer from memory if necessary, but do not
2406 read memory beyond PC to be sure we stay within text section
2407 (this protection only works if a non-zero pc is supplied). */
2409 if (ia + xtensa_isa_maxlength (isa) > bt)
2411 ba = ia;
2412 bt = (ba + XTENSA_ISA_BSZ) < body_pc ? ba + XTENSA_ISA_BSZ : body_pc;
2413 if (target_read_memory (ba, ibuf, bt - ba) != 0 )
2414 error (_("Unable to read target memory ..."));
2417 /* Decode format information. */
2419 xtensa_insnbuf_from_chars (isa, ins, &ibuf[ia-ba], 0);
2420 ifmt = xtensa_format_decode (isa, ins);
2421 if (ifmt == XTENSA_UNDEFINED)
2423 fail = 1;
2424 goto done;
2426 ilen = xtensa_format_length (isa, ifmt);
2427 if (ilen == XTENSA_UNDEFINED)
2429 fail = 1;
2430 goto done;
2432 islots = xtensa_format_num_slots (isa, ifmt);
2433 if (islots == XTENSA_UNDEFINED)
2435 fail = 1;
2436 goto done;
2439 /* Analyze a bundle or a single instruction, using a snapshot of
2440 the register tracking info as input for the entire bundle so that
2441 register changes do not take effect within this bundle. */
2443 for (j = 0; j < nregs; ++j)
2444 rtmp[j] = cache->c0.c0_rt[j];
2446 for (is = 0; is < islots; ++is)
2448 /* Decode a slot and classify the opcode. */
2450 fail = xtensa_format_get_slot (isa, ifmt, is, ins, slot);
2451 if (fail)
2452 goto done;
2454 opc = xtensa_opcode_decode (isa, ifmt, is, slot);
2455 DEBUGVERB ("[call0_analyze_prologue] instr addr = 0x%08x, opc = %d\n",
2456 (unsigned)ia, opc);
2457 if (opc == XTENSA_UNDEFINED)
2458 opclass = c0opc_illegal;
2459 else
2460 opclass = call0_classify_opcode (isa, opc);
2462 /* Decide whether to track this opcode, ignore it, or bail out. */
2464 switch (opclass)
2466 case c0opc_illegal:
2467 case c0opc_break:
2468 fail = 1;
2469 goto done;
2471 case c0opc_uninteresting:
2472 continue;
2474 case c0opc_flow: /* Flow control instructions stop analysis. */
2475 case c0opc_rwxsr: /* RSR, WSR, XSR instructions stop analysis. */
2476 goto done;
2478 case c0opc_entry:
2479 cache->call0 = 0;
2480 ia += ilen; /* Skip over 'entry' insn. */
2481 goto done;
2483 default:
2484 cache->call0 = 1;
2487 /* Only expected opcodes should get this far. */
2489 /* Extract and decode the operands. */
2490 nods = xtensa_opcode_num_operands (isa, opc);
2491 if (nods == XTENSA_UNDEFINED)
2493 fail = 1;
2494 goto done;
2497 for (j = 0; j < nods && j < C0_MAXOPDS; ++j)
2499 fail = xtensa_operand_get_field (isa, opc, j, ifmt,
2500 is, slot, &odv[j]);
2501 if (fail)
2502 goto done;
2504 fail = xtensa_operand_decode (isa, opc, j, &odv[j]);
2505 if (fail)
2506 goto done;
2509 /* Check operands to verify use of 'mov' assembler macro. */
2510 if (opclass == c0opc_mov && nods == 3)
2512 if (odv[2] == odv[1])
2514 nods = 2;
2515 if ((odv[0] == 1) && (odv[1] != 1))
2516 /* OR A1, An, An , where n != 1.
2517 This means we are inside epilogue already. */
2518 goto done;
2520 else
2522 opclass = c0opc_uninteresting;
2523 continue;
2527 /* Track register movement and modification for this operation. */
2528 fail = call0_track_op (gdbarch, cache->c0.c0_rt, rtmp,
2529 opclass, nods, odv, ia, 1, cache);
2530 if (fail)
2531 goto done;
2534 done:
2535 DEBUGVERB ("[call0_analyze_prologue] stopped at instr addr 0x%08x, %s\n",
2536 (unsigned)ia, fail ? "failed" : "succeeded");
2537 xtensa_insnbuf_free(isa, slot);
2538 xtensa_insnbuf_free(isa, ins);
2539 return fail ? XTENSA_ISA_BADPC : ia;
2542 /* Initialize frame cache for the current frame in CALL0 ABI. */
2544 static void
2545 call0_frame_cache (const frame_info_ptr &this_frame,
2546 xtensa_frame_cache_t *cache, CORE_ADDR pc)
2548 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2549 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2550 CORE_ADDR start_pc; /* The beginning of the function. */
2551 CORE_ADDR body_pc=UINT_MAX; /* PC, where prologue analysis stopped. */
2552 CORE_ADDR sp, fp, ra;
2553 int fp_regnum = C0_SP, c0_hasfp = 0, c0_frmsz = 0, prev_sp = 0, to_stk;
2554 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
2556 sp = get_frame_register_unsigned
2557 (this_frame, tdep->a0_base + 1);
2558 fp = sp; /* Assume FP == SP until proven otherwise. */
2560 /* Find the beginning of the prologue of the function containing the PC
2561 and analyze it up to the PC or the end of the prologue. */
2563 if (find_pc_partial_function (pc, NULL, &start_pc, NULL))
2565 body_pc = call0_analyze_prologue (gdbarch, start_pc, pc, C0_NREGS, cache);
2567 if (body_pc == XTENSA_ISA_BADPC)
2569 warning_once ();
2570 ra = 0;
2571 goto finish_frame_analysis;
2575 /* Get the frame information and FP (if used) at the current PC.
2576 If PC is in the prologue, the prologue analysis is more reliable
2577 than DWARF info. We don't not know for sure, if PC is in the prologue,
2578 but we do know no calls have yet taken place, so we can almost
2579 certainly rely on the prologue analysis. */
2581 if (body_pc <= pc)
2583 /* Prologue analysis was successful up to the PC.
2584 It includes the cases when PC == START_PC. */
2585 c0_hasfp = cache->c0.c0_rt[C0_FP].fr_reg == C0_SP;
2586 /* c0_hasfp == true means there is a frame pointer because
2587 we analyzed the prologue and found that cache->c0.c0_rt[C0_FP]
2588 was derived from SP. Otherwise, it would be C0_FP. */
2589 fp_regnum = c0_hasfp ? C0_FP : C0_SP;
2590 c0_frmsz = - cache->c0.c0_rt[fp_regnum].fr_ofs;
2591 fp_regnum += tdep->a0_base;
2593 else /* No data from the prologue analysis. */
2595 c0_hasfp = 0;
2596 fp_regnum = tdep->a0_base + C0_SP;
2597 c0_frmsz = 0;
2598 start_pc = pc;
2601 if (cache->c0.c0_fpalign)
2603 /* This frame has a special prologue with a dynamic stack adjustment
2604 to force an alignment, which is bigger than standard 16 bytes. */
2606 CORE_ADDR unaligned_sp;
2608 if (cache->c0.c0_old_sp == C0_INEXP)
2609 /* This can't be. Prologue code should be consistent.
2610 Unaligned stack pointer should be saved in a spare register. */
2612 warning_once ();
2613 ra = 0;
2614 goto finish_frame_analysis;
2617 if (cache->c0.c0_sp_ofs == C0_NOSTK)
2618 /* Saved unaligned value of SP is kept in a register. */
2619 unaligned_sp = get_frame_register_unsigned
2620 (this_frame, tdep->a0_base + cache->c0.c0_old_sp);
2621 else
2622 /* Get the value from stack. */
2623 unaligned_sp = (CORE_ADDR)
2624 read_memory_integer (fp + cache->c0.c0_sp_ofs, 4, byte_order);
2626 prev_sp = unaligned_sp + c0_frmsz;
2628 else
2629 prev_sp = fp + c0_frmsz;
2631 /* Frame size from debug info or prologue tracking does not account for
2632 alloca() and other dynamic allocations. Adjust frame size by FP - SP. */
2633 if (c0_hasfp)
2635 fp = get_frame_register_unsigned (this_frame, fp_regnum);
2637 /* Update the stack frame size. */
2638 c0_frmsz += fp - sp;
2641 /* Get the return address (RA) from the stack if saved,
2642 or try to get it from a register. */
2644 to_stk = cache->c0.c0_rt[C0_RA].to_stk;
2645 if (to_stk != C0_NOSTK)
2646 ra = (CORE_ADDR)
2647 read_memory_integer (sp + c0_frmsz + cache->c0.c0_rt[C0_RA].to_stk,
2648 4, byte_order);
2650 else if (cache->c0.c0_rt[C0_RA].fr_reg == C0_CONST
2651 && cache->c0.c0_rt[C0_RA].fr_ofs == 0)
2653 /* Special case for terminating backtrace at a function that wants to
2654 be seen as the outermost one. Such a function will clear it's RA (A0)
2655 register to 0 in the prologue instead of saving its original value. */
2656 ra = 0;
2658 else
2660 /* RA was copied to another register or (before any function call) may
2661 still be in the original RA register. This is not always reliable:
2662 even in a leaf function, register tracking stops after prologue, and
2663 even in prologue, non-prologue instructions (not tracked) may overwrite
2664 RA or any register it was copied to. If likely in prologue or before
2665 any call, use retracking info and hope for the best (compiler should
2666 have saved RA in stack if not in a leaf function). If not in prologue,
2667 too bad. */
2669 int i;
2670 for (i = 0;
2671 (i < C0_NREGS)
2672 && (i == C0_RA || cache->c0.c0_rt[i].fr_reg != C0_RA);
2673 ++i);
2674 if (i >= C0_NREGS && cache->c0.c0_rt[C0_RA].fr_reg == C0_RA)
2675 i = C0_RA;
2676 if (i < C0_NREGS)
2678 ra = get_frame_register_unsigned
2679 (this_frame,
2680 tdep->a0_base + cache->c0.c0_rt[i].fr_reg);
2682 else ra = 0;
2685 finish_frame_analysis:
2686 cache->pc = start_pc;
2687 cache->ra = ra;
2688 /* RA == 0 marks the outermost frame. Do not go past it. */
2689 cache->prev_sp = (ra != 0) ? prev_sp : 0;
2690 cache->c0.fp_regnum = fp_regnum;
2691 cache->c0.c0_frmsz = c0_frmsz;
2692 cache->c0.c0_hasfp = c0_hasfp;
2693 cache->c0.c0_fp = fp;
2696 static CORE_ADDR a0_saved;
2697 static CORE_ADDR a7_saved;
2698 static CORE_ADDR a11_saved;
2699 static int a0_was_saved;
2700 static int a7_was_saved;
2701 static int a11_was_saved;
2703 /* Simulate L32E instruction: AT <-- ref (AS + offset). */
2704 static void
2705 execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
2707 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
2708 int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
2709 int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
2710 CORE_ADDR addr = xtensa_read_register (asreg) + offset;
2711 unsigned int spilled_value
2712 = read_memory_unsigned_integer (addr, 4, gdbarch_byte_order (gdbarch));
2714 if ((at == 0) && !a0_was_saved)
2716 a0_saved = xtensa_read_register (atreg);
2717 a0_was_saved = 1;
2719 else if ((at == 7) && !a7_was_saved)
2721 a7_saved = xtensa_read_register (atreg);
2722 a7_was_saved = 1;
2724 else if ((at == 11) && !a11_was_saved)
2726 a11_saved = xtensa_read_register (atreg);
2727 a11_was_saved = 1;
2730 xtensa_write_register (atreg, spilled_value);
2733 /* Simulate S32E instruction: AT --> ref (AS + offset). */
2734 static void
2735 execute_s32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
2737 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
2738 int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
2739 int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
2740 CORE_ADDR addr = xtensa_read_register (asreg) + offset;
2741 ULONGEST spilled_value = xtensa_read_register (atreg);
2743 write_memory_unsigned_integer (addr, 4,
2744 gdbarch_byte_order (gdbarch),
2745 spilled_value);
2748 #define XTENSA_MAX_WINDOW_INTERRUPT_HANDLER_LEN 200
2750 enum xtensa_exception_handler_t
2752 xtWindowOverflow,
2753 xtWindowUnderflow,
2754 xtNoExceptionHandler
2757 /* Execute instruction stream from current PC until hitting RFWU or RFWO.
2758 Return type of Xtensa Window Interrupt Handler on success. */
2759 static xtensa_exception_handler_t
2760 execute_code (struct gdbarch *gdbarch, CORE_ADDR current_pc, CORE_ADDR wb)
2762 xtensa_isa isa;
2763 xtensa_insnbuf ins, slot;
2764 gdb_byte ibuf[XTENSA_ISA_BSZ];
2765 CORE_ADDR ia, bt, ba;
2766 xtensa_format ifmt;
2767 int ilen, islots, is;
2768 xtensa_opcode opc;
2769 int insn_num = 0;
2770 void (*func) (struct gdbarch *, int, int, int, CORE_ADDR);
2771 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
2773 uint32_t at, as, offset;
2775 /* WindowUnderflow12 = true, when inside _WindowUnderflow12. */
2776 int WindowUnderflow12 = (current_pc & 0x1ff) >= 0x140;
2778 isa = xtensa_default_isa;
2779 gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
2780 ins = xtensa_insnbuf_alloc (isa);
2781 slot = xtensa_insnbuf_alloc (isa);
2782 ba = 0;
2783 ia = current_pc;
2784 bt = ia;
2786 a0_was_saved = 0;
2787 a7_was_saved = 0;
2788 a11_was_saved = 0;
2790 while (insn_num++ < XTENSA_MAX_WINDOW_INTERRUPT_HANDLER_LEN)
2792 if (ia + xtensa_isa_maxlength (isa) > bt)
2794 ba = ia;
2795 bt = (ba + XTENSA_ISA_BSZ);
2796 if (target_read_memory (ba, ibuf, bt - ba) != 0)
2797 return xtNoExceptionHandler;
2799 xtensa_insnbuf_from_chars (isa, ins, &ibuf[ia-ba], 0);
2800 ifmt = xtensa_format_decode (isa, ins);
2801 if (ifmt == XTENSA_UNDEFINED)
2802 return xtNoExceptionHandler;
2803 ilen = xtensa_format_length (isa, ifmt);
2804 if (ilen == XTENSA_UNDEFINED)
2805 return xtNoExceptionHandler;
2806 islots = xtensa_format_num_slots (isa, ifmt);
2807 if (islots == XTENSA_UNDEFINED)
2808 return xtNoExceptionHandler;
2809 for (is = 0; is < islots; ++is)
2811 if (xtensa_format_get_slot (isa, ifmt, is, ins, slot))
2812 return xtNoExceptionHandler;
2813 opc = xtensa_opcode_decode (isa, ifmt, is, slot);
2814 if (opc == XTENSA_UNDEFINED)
2815 return xtNoExceptionHandler;
2816 switch (call0_classify_opcode (isa, opc))
2818 case c0opc_illegal:
2819 case c0opc_flow:
2820 case c0opc_entry:
2821 case c0opc_break:
2822 /* We expect none of them here. */
2823 return xtNoExceptionHandler;
2824 case c0opc_l32e:
2825 func = execute_l32e;
2826 break;
2827 case c0opc_s32e:
2828 func = execute_s32e;
2829 break;
2830 case c0opc_rfwo: /* RFWO. */
2831 /* Here, we return from WindowOverflow handler and,
2832 if we stopped at the very beginning, which means
2833 A0 was saved, we have to restore it now. */
2834 if (a0_was_saved)
2836 int arreg = arreg_number (gdbarch,
2837 tdep->a0_base,
2838 wb);
2839 xtensa_write_register (arreg, a0_saved);
2841 return xtWindowOverflow;
2842 case c0opc_rfwu: /* RFWU. */
2843 /* Here, we return from WindowUnderflow handler.
2844 Let's see if either A7 or A11 has to be restored. */
2845 if (WindowUnderflow12)
2847 if (a11_was_saved)
2849 int arreg = arreg_number (gdbarch,
2850 tdep->a0_base + 11,
2851 wb);
2852 xtensa_write_register (arreg, a11_saved);
2855 else if (a7_was_saved)
2857 int arreg = arreg_number (gdbarch,
2858 tdep->a0_base + 7,
2859 wb);
2860 xtensa_write_register (arreg, a7_saved);
2862 return xtWindowUnderflow;
2863 default: /* Simply skip this insns. */
2864 continue;
2867 /* Decode arguments for L32E / S32E and simulate their execution. */
2868 if ( xtensa_opcode_num_operands (isa, opc) != 3 )
2869 return xtNoExceptionHandler;
2870 if (xtensa_operand_get_field (isa, opc, 0, ifmt, is, slot, &at))
2871 return xtNoExceptionHandler;
2872 if (xtensa_operand_decode (isa, opc, 0, &at))
2873 return xtNoExceptionHandler;
2874 if (xtensa_operand_get_field (isa, opc, 1, ifmt, is, slot, &as))
2875 return xtNoExceptionHandler;
2876 if (xtensa_operand_decode (isa, opc, 1, &as))
2877 return xtNoExceptionHandler;
2878 if (xtensa_operand_get_field (isa, opc, 2, ifmt, is, slot, &offset))
2879 return xtNoExceptionHandler;
2880 if (xtensa_operand_decode (isa, opc, 2, &offset))
2881 return xtNoExceptionHandler;
2883 (*func) (gdbarch, at, as, offset, wb);
2886 ia += ilen;
2888 return xtNoExceptionHandler;
2891 /* Handle Window Overflow / Underflow exception frames. */
2893 static void
2894 xtensa_window_interrupt_frame_cache (const frame_info_ptr &this_frame,
2895 xtensa_frame_cache_t *cache,
2896 CORE_ADDR pc)
2898 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2899 CORE_ADDR ps, wb, ws, ra;
2900 int epc1_regnum, i, regnum;
2901 xtensa_exception_handler_t eh_type;
2902 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
2904 /* Read PS, WB, and WS from the hardware. Note that PS register
2905 must be present, if Windowed ABI is supported. */
2906 ps = xtensa_read_register (gdbarch_ps_regnum (gdbarch));
2907 wb = xtensa_read_register (tdep->wb_regnum);
2908 ws = xtensa_read_register (tdep->ws_regnum);
2910 /* Execute all the remaining instructions from Window Interrupt Handler
2911 by simulating them on the remote protocol level. On return, set the
2912 type of Xtensa Window Interrupt Handler, or report an error. */
2913 eh_type = execute_code (gdbarch, pc, wb);
2914 if (eh_type == xtNoExceptionHandler)
2915 error (_("\
2916 Unable to decode Xtensa Window Interrupt Handler's code."));
2918 cache->ps = ps ^ PS_EXC; /* Clear the exception bit in PS. */
2919 cache->call0 = 0; /* It's Windowed ABI. */
2921 /* All registers for the cached frame will be alive. */
2922 for (i = 0; i < XTENSA_NUM_SAVED_AREGS; i++)
2923 cache->wd.aregs[i] = -1;
2925 if (eh_type == xtWindowOverflow)
2926 cache->wd.ws = ws ^ (1 << wb);
2927 else /* eh_type == xtWindowUnderflow. */
2928 cache->wd.ws = ws | (1 << wb);
2930 cache->wd.wb = (ps & 0xf00) >> 8; /* Set WB to OWB. */
2931 regnum = arreg_number (gdbarch, tdep->a0_base,
2932 cache->wd.wb);
2933 ra = xtensa_read_register (regnum);
2934 cache->wd.callsize = WINSIZE (ra);
2935 cache->prev_sp = xtensa_read_register (regnum + 1);
2936 /* Set regnum to a frame pointer of the frame being cached. */
2937 regnum = xtensa_scan_prologue (gdbarch, pc);
2938 regnum = arreg_number (gdbarch,
2939 tdep->a0_base + regnum,
2940 cache->wd.wb);
2941 cache->base = get_frame_register_unsigned (this_frame, regnum);
2943 /* Read PC of interrupted function from EPC1 register. */
2944 epc1_regnum = xtensa_find_register_by_name (gdbarch,"epc1");
2945 if (epc1_regnum < 0)
2946 error(_("Unable to read Xtensa register EPC1"));
2947 cache->ra = xtensa_read_register (epc1_regnum);
2948 cache->pc = get_frame_func (this_frame);
2952 /* Skip function prologue.
2954 Return the pc of the first instruction after prologue. GDB calls this to
2955 find the address of the first line of the function or (if there is no line
2956 number information) to skip the prologue for planting breakpoints on
2957 function entries. Use debug info (if present) or prologue analysis to skip
2958 the prologue to achieve reliable debugging behavior. For windowed ABI,
2959 only the 'entry' instruction is skipped. It is not strictly necessary to
2960 skip the prologue (Call0) or 'entry' (Windowed) because xt-gdb knows how to
2961 backtrace at any point in the prologue, however certain potential hazards
2962 are avoided and a more "normal" debugging experience is ensured by
2963 skipping the prologue (can be disabled by defining DONT_SKIP_PROLOG).
2964 For example, if we don't skip the prologue:
2965 - Some args may not yet have been saved to the stack where the debug
2966 info expects to find them (true anyway when only 'entry' is skipped);
2967 - Software breakpoints ('break' instrs) may not have been unplanted
2968 when the prologue analysis is done on initializing the frame cache,
2969 and breaks in the prologue will throw off the analysis.
2971 If we have debug info ( line-number info, in particular ) we simply skip
2972 the code associated with the first function line effectively skipping
2973 the prologue code. It works even in cases like
2975 int main()
2976 { int local_var = 1;
2977 ....
2980 because, for this source code, both Xtensa compilers will generate two
2981 separate entries ( with the same line number ) in dwarf line-number
2982 section to make sure there is a boundary between the prologue code and
2983 the rest of the function.
2985 If there is no debug info, we need to analyze the code. */
2987 /* #define DONT_SKIP_PROLOGUE */
2989 static CORE_ADDR
2990 xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
2992 struct symtab_and_line prologue_sal;
2993 CORE_ADDR body_pc;
2995 DEBUGTRACE ("xtensa_skip_prologue (start_pc = 0x%08x)\n", (int) start_pc);
2997 #if DONT_SKIP_PROLOGUE
2998 return start_pc;
2999 #endif
3001 /* Try to find first body line from debug info. */
3003 prologue_sal = find_pc_line (start_pc, 0);
3004 if (prologue_sal.line != 0) /* Found debug info. */
3006 /* In Call0, it is possible to have a function with only one instruction
3007 ('ret') resulting from a one-line optimized function that does nothing.
3008 In that case, prologue_sal.end may actually point to the start of the
3009 next function in the text section, causing a breakpoint to be set at
3010 the wrong place. Check, if the end address is within a different
3011 function, and if so return the start PC. We know we have symbol
3012 information. */
3014 CORE_ADDR end_func;
3016 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
3017 if ((tdep->call_abi == CallAbiCall0Only)
3018 && call0_ret (start_pc, prologue_sal.end))
3019 return start_pc;
3021 find_pc_partial_function (prologue_sal.end, NULL, &end_func, NULL);
3022 if (end_func != start_pc)
3023 return start_pc;
3025 return prologue_sal.end;
3028 /* No debug line info. Analyze prologue for Call0 or simply skip ENTRY. */
3029 body_pc = call0_analyze_prologue (gdbarch, start_pc, 0, 0,
3030 xtensa_alloc_frame_cache (0));
3031 return body_pc != 0 ? body_pc : start_pc;
3034 /* Verify the current configuration. */
3035 static void
3036 xtensa_verify_config (struct gdbarch *gdbarch)
3038 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
3039 string_file log;
3041 /* Verify that we got a reasonable number of AREGS. */
3042 if ((tdep->num_aregs & -tdep->num_aregs) != tdep->num_aregs)
3043 log.printf (_("\
3044 \n\tnum_aregs: Number of AR registers (%d) is not a power of two!"),
3045 tdep->num_aregs);
3047 /* Verify that certain registers exist. */
3049 if (tdep->pc_regnum == -1)
3050 log.printf (_("\n\tpc_regnum: No PC register"));
3051 if (tdep->isa_use_exceptions && tdep->ps_regnum == -1)
3052 log.printf (_("\n\tps_regnum: No PS register"));
3054 if (tdep->isa_use_windowed_registers)
3056 if (tdep->wb_regnum == -1)
3057 log.printf (_("\n\twb_regnum: No WB register"));
3058 if (tdep->ws_regnum == -1)
3059 log.printf (_("\n\tws_regnum: No WS register"));
3060 if (tdep->ar_base == -1)
3061 log.printf (_("\n\tar_base: No AR registers"));
3064 if (tdep->a0_base == -1)
3065 log.printf (_("\n\ta0_base: No Ax registers"));
3067 if (!log.empty ())
3068 internal_error (_("the following are invalid: %s"), log.c_str ());
3072 /* Derive specific register numbers from the array of registers. */
3074 static void
3075 xtensa_derive_tdep (xtensa_gdbarch_tdep *tdep)
3077 xtensa_register_t* rmap;
3078 int n, max_size = 4;
3080 tdep->num_regs = 0;
3081 tdep->num_nopriv_regs = 0;
3083 /* Special registers 0..255 (core). */
3084 #define XTENSA_DBREGN_SREG(n) (0x0200+(n))
3085 /* User registers 0..255. */
3086 #define XTENSA_DBREGN_UREG(n) (0x0300+(n))
3088 for (rmap = tdep->regmap, n = 0; rmap->target_number != -1; n++, rmap++)
3090 if (rmap->target_number == 0x0020)
3091 tdep->pc_regnum = n;
3092 else if (rmap->target_number == 0x0100)
3093 tdep->ar_base = n;
3094 else if (rmap->target_number == 0x0000)
3095 tdep->a0_base = n;
3096 else if (rmap->target_number == XTENSA_DBREGN_SREG(72))
3097 tdep->wb_regnum = n;
3098 else if (rmap->target_number == XTENSA_DBREGN_SREG(73))
3099 tdep->ws_regnum = n;
3100 else if (rmap->target_number == XTENSA_DBREGN_SREG(233))
3101 tdep->debugcause_regnum = n;
3102 else if (rmap->target_number == XTENSA_DBREGN_SREG(232))
3103 tdep->exccause_regnum = n;
3104 else if (rmap->target_number == XTENSA_DBREGN_SREG(238))
3105 tdep->excvaddr_regnum = n;
3106 else if (rmap->target_number == XTENSA_DBREGN_SREG(0))
3107 tdep->lbeg_regnum = n;
3108 else if (rmap->target_number == XTENSA_DBREGN_SREG(1))
3109 tdep->lend_regnum = n;
3110 else if (rmap->target_number == XTENSA_DBREGN_SREG(2))
3111 tdep->lcount_regnum = n;
3112 else if (rmap->target_number == XTENSA_DBREGN_SREG(3))
3113 tdep->sar_regnum = n;
3114 else if (rmap->target_number == XTENSA_DBREGN_SREG(5))
3115 tdep->litbase_regnum = n;
3116 else if (rmap->target_number == XTENSA_DBREGN_SREG(230))
3117 tdep->ps_regnum = n;
3118 else if (rmap->target_number == XTENSA_DBREGN_UREG(231))
3119 tdep->threadptr_regnum = n;
3120 #if 0
3121 else if (rmap->target_number == XTENSA_DBREGN_SREG(226))
3122 tdep->interrupt_regnum = n;
3123 else if (rmap->target_number == XTENSA_DBREGN_SREG(227))
3124 tdep->interrupt2_regnum = n;
3125 else if (rmap->target_number == XTENSA_DBREGN_SREG(224))
3126 tdep->cpenable_regnum = n;
3127 #endif
3129 if (rmap->byte_size > max_size)
3130 max_size = rmap->byte_size;
3131 if (rmap->mask != 0 && tdep->num_regs == 0)
3132 tdep->num_regs = n;
3133 if ((rmap->flags & XTENSA_REGISTER_FLAGS_PRIVILEGED) != 0
3134 && tdep->num_nopriv_regs == 0)
3135 tdep->num_nopriv_regs = n;
3137 if (tdep->num_regs == 0)
3138 tdep->num_regs = tdep->num_nopriv_regs;
3140 /* Number of pseudo registers. */
3141 tdep->num_pseudo_regs = n - tdep->num_regs;
3143 /* Empirically determined maximum sizes. */
3144 tdep->max_register_raw_size = max_size;
3145 tdep->max_register_virtual_size = max_size;
3148 /* Module "constructor" function. */
3150 extern xtensa_register_t xtensa_rmap[];
3152 static struct gdbarch *
3153 xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3155 DEBUGTRACE ("gdbarch_init()\n");
3157 if (!xtensa_default_isa)
3158 xtensa_default_isa = xtensa_isa_init (0, 0);
3160 /* We have to set the byte order before we call gdbarch_alloc. */
3161 info.byte_order = XCHAL_HAVE_BE ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
3163 gdbarch *gdbarch
3164 = gdbarch_alloc (&info,
3165 gdbarch_tdep_up (new xtensa_gdbarch_tdep (xtensa_rmap)));
3166 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
3167 xtensa_derive_tdep (tdep);
3169 /* Verify our configuration. */
3170 xtensa_verify_config (gdbarch);
3171 xtensa_session_once_reported = 0;
3173 set_gdbarch_wchar_bit (gdbarch, 2 * TARGET_CHAR_BIT);
3174 set_gdbarch_wchar_signed (gdbarch, 0);
3176 /* Pseudo-Register read/write. */
3177 set_gdbarch_pseudo_register_read (gdbarch, xtensa_pseudo_register_read);
3178 set_gdbarch_deprecated_pseudo_register_write (gdbarch,
3179 xtensa_pseudo_register_write);
3181 /* Set target information. */
3182 set_gdbarch_num_regs (gdbarch, tdep->num_regs);
3183 set_gdbarch_num_pseudo_regs (gdbarch, tdep->num_pseudo_regs);
3184 set_gdbarch_sp_regnum (gdbarch, tdep->a0_base + 1);
3185 set_gdbarch_pc_regnum (gdbarch, tdep->pc_regnum);
3186 set_gdbarch_ps_regnum (gdbarch, tdep->ps_regnum);
3188 /* Renumber registers for known formats (stabs and dwarf2). */
3189 set_gdbarch_stab_reg_to_regnum (gdbarch, xtensa_reg_to_regnum);
3190 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, xtensa_reg_to_regnum);
3192 /* We provide our own function to get register information. */
3193 set_gdbarch_register_name (gdbarch, xtensa_register_name);
3194 set_gdbarch_register_type (gdbarch, xtensa_register_type);
3196 /* To call functions from GDB using dummy frame. */
3197 set_gdbarch_push_dummy_call (gdbarch, xtensa_push_dummy_call);
3199 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
3201 set_gdbarch_return_value (gdbarch, xtensa_return_value);
3203 /* Advance PC across any prologue instructions to reach "real" code. */
3204 set_gdbarch_skip_prologue (gdbarch, xtensa_skip_prologue);
3206 /* Stack grows downward. */
3207 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
3209 /* Set breakpoints. */
3210 set_gdbarch_breakpoint_kind_from_pc (gdbarch,
3211 xtensa_breakpoint_kind_from_pc);
3212 set_gdbarch_sw_breakpoint_from_kind (gdbarch,
3213 xtensa_sw_breakpoint_from_kind);
3215 /* After breakpoint instruction or illegal instruction, pc still
3216 points at break instruction, so don't decrement. */
3217 set_gdbarch_decr_pc_after_break (gdbarch, 0);
3219 /* We don't skip args. */
3220 set_gdbarch_frame_args_skip (gdbarch, 0);
3222 set_gdbarch_unwind_pc (gdbarch, xtensa_unwind_pc);
3224 set_gdbarch_frame_align (gdbarch, xtensa_frame_align);
3226 set_gdbarch_dummy_id (gdbarch, xtensa_dummy_id);
3228 /* Frame handling. */
3229 frame_base_set_default (gdbarch, &xtensa_frame_base);
3230 frame_unwind_append_unwinder (gdbarch, &xtensa_unwind);
3231 dwarf2_append_unwinders (gdbarch);
3233 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
3235 xtensa_add_reggroups (gdbarch);
3236 set_gdbarch_register_reggroup_p (gdbarch, xtensa_register_reggroup_p);
3238 set_gdbarch_iterate_over_regset_sections
3239 (gdbarch, xtensa_iterate_over_regset_sections);
3241 set_solib_svr4_fetch_link_map_offsets
3242 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
3244 /* Hook in the ABI-specific overrides, if they have been registered. */
3245 gdbarch_init_osabi (info, gdbarch);
3247 return gdbarch;
3250 static void
3251 xtensa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3253 error (_("xtensa_dump_tdep(): not implemented"));
3256 void _initialize_xtensa_tdep ();
3257 void
3258 _initialize_xtensa_tdep ()
3260 gdbarch_register (bfd_arch_xtensa, xtensa_gdbarch_init, xtensa_dump_tdep);
3261 xtensa_init_reggroups ();
3263 add_setshow_zuinteger_cmd ("xtensa",
3264 class_maintenance,
3265 &xtensa_debug_level,
3266 _("Set Xtensa debugging."),
3267 _("Show Xtensa debugging."), _("\
3268 When non-zero, Xtensa-specific debugging is enabled.\n\
3269 Can be 1, 2, 3, or 4 indicating the level of debugging."),
3270 NULL,
3271 NULL,
3272 &setdebuglist, &showdebuglist);