Automatic date update in version.in
[binutils-gdb.git] / gdb / xtensa-tdep.c
blob2c3d468d8be934efb2d45b6cbca71c8bf9d10854
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 "frame.h"
21 #include "solib-svr4.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "gdbcore.h"
25 #include "value.h"
26 #include "osabi.h"
27 #include "regcache.h"
28 #include "reggroups.h"
29 #include "regset.h"
31 #include "dwarf2/frame.h"
32 #include "frame-base.h"
33 #include "frame-unwind.h"
35 #include "arch-utils.h"
36 #include "gdbarch.h"
38 #include "command.h"
39 #include "gdbcmd.h"
41 #include "xtensa-isa.h"
42 #include "xtensa-tdep.h"
43 #include "xtensa-config.h"
44 #include <algorithm>
47 static unsigned int xtensa_debug_level = 0;
49 #define DEBUGWARN(args...) \
50 if (xtensa_debug_level > 0) \
51 gdb_printf (gdb_stdlog, "(warn ) " args)
53 #define DEBUGINFO(args...) \
54 if (xtensa_debug_level > 1) \
55 gdb_printf (gdb_stdlog, "(info ) " args)
57 #define DEBUGTRACE(args...) \
58 if (xtensa_debug_level > 2) \
59 gdb_printf (gdb_stdlog, "(trace) " args)
61 #define DEBUGVERB(args...) \
62 if (xtensa_debug_level > 3) \
63 gdb_printf (gdb_stdlog, "(verb ) " args)
66 /* According to the ABI, the SP must be aligned to 16-byte boundaries. */
67 #define SP_ALIGNMENT 16
70 /* On Windowed ABI, we use a6 through a11 for passing arguments
71 to a function called by GDB because CALL4 is used. */
72 #define ARGS_NUM_REGS 6
73 #define REGISTER_SIZE 4
76 /* Extract the call size from the return address or PS register. */
77 #define PS_CALLINC_SHIFT 16
78 #define PS_CALLINC_MASK 0x00030000
79 #define CALLINC(ps) (((ps) & PS_CALLINC_MASK) >> PS_CALLINC_SHIFT)
80 #define WINSIZE(ra) (4 * (( (ra) >> 30) & 0x3))
82 /* On TX, hardware can be configured without Exception Option.
83 There is no PS register in this case. Inside XT-GDB, let us treat
84 it as a virtual read-only register always holding the same value. */
85 #define TX_PS 0x20
87 /* ABI-independent macros. */
88 #define ARG_NOF(tdep) \
89 (tdep->call_abi \
90 == CallAbiCall0Only ? C0_NARGS : (ARGS_NUM_REGS))
91 #define ARG_1ST(tdep) \
92 (tdep->call_abi == CallAbiCall0Only \
93 ? (tdep->a0_base + C0_ARGS) \
94 : (tdep->a0_base + 6))
96 /* XTENSA_IS_ENTRY tests whether the first byte of an instruction
97 indicates that the instruction is an ENTRY instruction. */
99 #define XTENSA_IS_ENTRY(gdbarch, op1) \
100 ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) \
101 ? ((op1) == 0x6c) : ((op1) == 0x36))
103 #define XTENSA_ENTRY_LENGTH 3
105 /* windowing_enabled() returns true, if windowing is enabled.
106 WOE must be set to 1; EXCM to 0.
107 Note: We assume that EXCM is always 0 for XEA1. */
109 #define PS_WOE (1<<18)
110 #define PS_EXC (1<<4)
112 /* Big enough to hold the size of the largest register in bytes. */
113 #define XTENSA_MAX_REGISTER_SIZE 64
115 static int
116 windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
118 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
120 /* If we know CALL0 ABI is set explicitly, say it is Call0. */
121 if (tdep->call_abi == CallAbiCall0Only)
122 return 0;
124 return ((ps & PS_EXC) == 0 && (ps & PS_WOE) != 0);
127 /* Convert a live A-register number to the corresponding AR-register
128 number. */
129 static int
130 arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
132 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
133 int arreg;
135 arreg = a_regnum - tdep->a0_base;
136 arreg += (wb & ((tdep->num_aregs - 1) >> 2)) << WB_SHIFT;
137 arreg &= tdep->num_aregs - 1;
139 return arreg + tdep->ar_base;
142 /* Convert a live AR-register number to the corresponding A-register order
143 number in a range [0..15]. Return -1, if AR_REGNUM is out of WB window. */
144 static int
145 areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
147 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
148 int areg;
150 areg = ar_regnum - tdep->ar_base;
151 if (areg < 0 || areg >= tdep->num_aregs)
152 return -1;
153 areg = (areg - wb * 4) & (tdep->num_aregs - 1);
154 return (areg > 15) ? -1 : areg;
157 /* Read Xtensa register directly from the hardware. */
158 static unsigned long
159 xtensa_read_register (int regnum)
161 ULONGEST value;
163 regcache_raw_read_unsigned (get_thread_regcache (inferior_thread ()), regnum,
164 &value);
165 return (unsigned long) value;
168 /* Write Xtensa register directly to the hardware. */
169 static void
170 xtensa_write_register (int regnum, ULONGEST value)
172 regcache_raw_write_unsigned (get_thread_regcache (inferior_thread ()), regnum,
173 value);
176 /* Return the window size of the previous call to the function from which we
177 have just returned.
179 This function is used to extract the return value after a called function
180 has returned to the caller. On Xtensa, the register that holds the return
181 value (from the perspective of the caller) depends on what call
182 instruction was used. For now, we are assuming that the call instruction
183 precedes the current address, so we simply analyze the call instruction.
184 If we are in a dummy frame, we simply return 4 as we used a 'pseudo-call4'
185 method to call the inferior function. */
187 static int
188 extract_call_winsize (struct gdbarch *gdbarch, CORE_ADDR pc)
190 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
191 int winsize = 4;
192 int insn;
193 gdb_byte buf[4];
195 DEBUGTRACE ("extract_call_winsize (pc = 0x%08x)\n", (int) pc);
197 /* Read the previous instruction (should be a call[x]{4|8|12}. */
198 read_memory (pc-3, buf, 3);
199 insn = extract_unsigned_integer (buf, 3, byte_order);
201 /* Decode call instruction:
202 Little Endian
203 call{0,4,8,12} OFFSET || {00,01,10,11} || 0101
204 callx{0,4,8,12} OFFSET || 11 || {00,01,10,11} || 0000
205 Big Endian
206 call{0,4,8,12} 0101 || {00,01,10,11} || OFFSET
207 callx{0,4,8,12} 0000 || {00,01,10,11} || 11 || OFFSET. */
209 if (byte_order == BFD_ENDIAN_LITTLE)
211 if (((insn & 0xf) == 0x5) || ((insn & 0xcf) == 0xc0))
212 winsize = (insn & 0x30) >> 2; /* 0, 4, 8, 12. */
214 else
216 if (((insn >> 20) == 0x5) || (((insn >> 16) & 0xf3) == 0x03))
217 winsize = (insn >> 16) & 0xc; /* 0, 4, 8, 12. */
219 return winsize;
223 /* REGISTER INFORMATION */
225 /* Find register by name. */
226 static int
227 xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
229 int i;
230 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
232 for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
233 if (strcasecmp (tdep->regmap[i].name, name) == 0)
234 return i;
236 return -1;
239 /* Returns the name of a register. */
240 static const char *
241 xtensa_register_name (struct gdbarch *gdbarch, int regnum)
243 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
245 /* Return the name stored in the register map. */
246 return tdep->regmap[regnum].name;
249 /* Return the type of a register. Create a new type, if necessary. */
251 static struct type *
252 xtensa_register_type (struct gdbarch *gdbarch, int regnum)
254 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
256 /* Return signed integer for ARx and Ax registers. */
257 if ((regnum >= tdep->ar_base
258 && regnum < tdep->ar_base + tdep->num_aregs)
259 || (regnum >= tdep->a0_base
260 && regnum < tdep->a0_base + 16))
261 return builtin_type (gdbarch)->builtin_int;
263 if (regnum == gdbarch_pc_regnum (gdbarch)
264 || regnum == tdep->a0_base + 1)
265 return builtin_type (gdbarch)->builtin_data_ptr;
267 /* Return the stored type for all other registers. */
268 else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
270 xtensa_register_t* reg = &tdep->regmap[regnum];
272 /* Set ctype for this register (only the first time). */
274 if (reg->ctype == 0)
276 struct ctype_cache *tp;
277 int size = reg->byte_size;
279 /* We always use the memory representation,
280 even if the register width is smaller. */
281 switch (size)
283 case 1:
284 reg->ctype = builtin_type (gdbarch)->builtin_uint8;
285 break;
287 case 2:
288 reg->ctype = builtin_type (gdbarch)->builtin_uint16;
289 break;
291 case 4:
292 reg->ctype = builtin_type (gdbarch)->builtin_uint32;
293 break;
295 case 8:
296 reg->ctype = builtin_type (gdbarch)->builtin_uint64;
297 break;
299 case 16:
300 reg->ctype = builtin_type (gdbarch)->builtin_uint128;
301 break;
303 default:
304 for (tp = tdep->type_entries; tp != NULL; tp = tp->next)
305 if (tp->size == size)
306 break;
308 if (tp == NULL)
310 std::string name = string_printf ("int%d", size * 8);
312 tp = XNEW (struct ctype_cache);
313 tp->next = tdep->type_entries;
314 tdep->type_entries = tp;
315 tp->size = size;
316 type_allocator alloc (gdbarch);
317 tp->virtual_type
318 = init_integer_type (alloc, size * 8, 1, name.c_str ());
321 reg->ctype = tp->virtual_type;
324 return reg->ctype;
327 internal_error (_("invalid register number %d"), regnum);
328 return 0;
332 /* Return the 'local' register number for stubs, dwarf2, etc.
333 The debugging information enumerates registers starting from 0 for A0
334 to n for An. So, we only have to add the base number for A0. */
336 static int
337 xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
339 int i;
340 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
342 if (regnum >= 0 && regnum < 16)
343 return tdep->a0_base + regnum;
345 for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
346 if (regnum == tdep->regmap[i].target_number)
347 return i;
349 return -1;
353 /* Write the bits of a masked register to the various registers.
354 Only the masked areas of these registers are modified; the other
355 fields are untouched. The size of masked registers is always less
356 than or equal to 32 bits. */
358 static void
359 xtensa_register_write_masked (struct regcache *regcache,
360 xtensa_register_t *reg, const gdb_byte *buffer)
362 unsigned int value[(XTENSA_MAX_REGISTER_SIZE + 3) / 4];
363 const xtensa_mask_t *mask = reg->mask;
365 int shift = 0; /* Shift for next mask (mod 32). */
366 int start, size; /* Start bit and size of current mask. */
368 unsigned int *ptr = value;
369 unsigned int regval, m, mem = 0;
371 int bytesize = reg->byte_size;
372 int bitsize = bytesize * 8;
373 int i, r;
375 DEBUGTRACE ("xtensa_register_write_masked ()\n");
377 /* Copy the masked register to host byte-order. */
378 if (gdbarch_byte_order (regcache->arch ()) == BFD_ENDIAN_BIG)
379 for (i = 0; i < bytesize; i++)
381 mem >>= 8;
382 mem |= (buffer[bytesize - i - 1] << 24);
383 if ((i & 3) == 3)
384 *ptr++ = mem;
386 else
387 for (i = 0; i < bytesize; i++)
389 mem >>= 8;
390 mem |= (buffer[i] << 24);
391 if ((i & 3) == 3)
392 *ptr++ = mem;
395 /* We might have to shift the final value:
396 bytesize & 3 == 0 -> nothing to do, we use the full 32 bits,
397 bytesize & 3 == x -> shift (4-x) * 8. */
399 *ptr = mem >> (((0 - bytesize) & 3) * 8);
400 ptr = value;
401 mem = *ptr;
403 /* Write the bits to the masked areas of the other registers. */
404 for (i = 0; i < mask->count; i++)
406 start = mask->mask[i].bit_start;
407 size = mask->mask[i].bit_size;
408 regval = mem >> shift;
410 if ((shift += size) > bitsize)
411 error (_("size of all masks is larger than the register"));
413 if (shift >= 32)
415 mem = *(++ptr);
416 shift -= 32;
417 bitsize -= 32;
419 if (shift > 0)
420 regval |= mem << (size - shift);
423 /* Make sure we have a valid register. */
424 r = mask->mask[i].reg_num;
425 if (r >= 0 && size > 0)
427 /* Don't overwrite the unmasked areas. */
428 ULONGEST old_val;
429 regcache_cooked_read_unsigned (regcache, r, &old_val);
430 m = 0xffffffff >> (32 - size) << start;
431 regval <<= start;
432 regval = (regval & m) | (old_val & ~m);
433 regcache_cooked_write_unsigned (regcache, r, regval);
439 /* Read a tie state or mapped registers. Read the masked areas
440 of the registers and assemble them into a single value. */
442 static enum register_status
443 xtensa_register_read_masked (readable_regcache *regcache,
444 xtensa_register_t *reg, gdb_byte *buffer)
446 unsigned int value[(XTENSA_MAX_REGISTER_SIZE + 3) / 4];
447 const xtensa_mask_t *mask = reg->mask;
449 int shift = 0;
450 int start, size;
452 unsigned int *ptr = value;
453 unsigned int regval, mem = 0;
455 int bytesize = reg->byte_size;
456 int bitsize = bytesize * 8;
457 int i;
459 DEBUGTRACE ("xtensa_register_read_masked (reg \"%s\", ...)\n",
460 reg->name == 0 ? "" : reg->name);
462 /* Assemble the register from the masked areas of other registers. */
463 for (i = 0; i < mask->count; i++)
465 int r = mask->mask[i].reg_num;
466 if (r >= 0)
468 enum register_status status;
469 ULONGEST val;
471 status = regcache->cooked_read (r, &val);
472 if (status != REG_VALID)
473 return status;
474 regval = (unsigned int) val;
476 else
477 regval = 0;
479 start = mask->mask[i].bit_start;
480 size = mask->mask[i].bit_size;
482 regval >>= start;
484 if (size < 32)
485 regval &= (0xffffffff >> (32 - size));
487 mem |= regval << shift;
489 if ((shift += size) > bitsize)
490 error (_("size of all masks is larger than the register"));
492 if (shift >= 32)
494 *ptr++ = mem;
495 bitsize -= 32;
496 shift -= 32;
498 if (shift == 0)
499 mem = 0;
500 else
501 mem = regval >> (size - shift);
505 if (shift > 0)
506 *ptr = mem;
508 /* Copy value to target byte order. */
509 ptr = value;
510 mem = *ptr;
512 if (gdbarch_byte_order (regcache->arch ()) == BFD_ENDIAN_BIG)
513 for (i = 0; i < bytesize; i++)
515 if ((i & 3) == 0)
516 mem = *ptr++;
517 buffer[bytesize - i - 1] = mem & 0xff;
518 mem >>= 8;
520 else
521 for (i = 0; i < bytesize; i++)
523 if ((i & 3) == 0)
524 mem = *ptr++;
525 buffer[i] = mem & 0xff;
526 mem >>= 8;
529 return REG_VALID;
533 /* Read pseudo registers. */
535 static enum register_status
536 xtensa_pseudo_register_read (struct gdbarch *gdbarch,
537 readable_regcache *regcache,
538 int regnum,
539 gdb_byte *buffer)
541 DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
542 regnum, xtensa_register_name (gdbarch, regnum));
543 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
545 /* Read aliases a0..a15, if this is a Windowed ABI. */
546 if (tdep->isa_use_windowed_registers
547 && (regnum >= tdep->a0_base)
548 && (regnum <= tdep->a0_base + 15))
550 ULONGEST value;
551 enum register_status status;
553 status = regcache->raw_read (tdep->wb_regnum,
554 &value);
555 if (status != REG_VALID)
556 return status;
557 regnum = arreg_number (gdbarch, regnum, value);
560 /* We can always read non-pseudo registers. */
561 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
562 return regcache->raw_read (regnum, buffer);
564 /* We have to find out how to deal with privileged registers.
565 Let's treat them as pseudo-registers, but we cannot read/write them. */
567 else if (tdep->call_abi == CallAbiCall0Only
568 || regnum < tdep->a0_base)
570 buffer[0] = (gdb_byte)0;
571 buffer[1] = (gdb_byte)0;
572 buffer[2] = (gdb_byte)0;
573 buffer[3] = (gdb_byte)0;
574 return REG_VALID;
576 /* Pseudo registers. */
577 else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
579 xtensa_register_t *reg = &tdep->regmap[regnum];
580 xtensa_register_type_t type = reg->type;
581 int flags = tdep->target_flags;
583 /* We cannot read Unknown or Unmapped registers. */
584 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
586 if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
588 warning (_("cannot read register %s"),
589 xtensa_register_name (gdbarch, regnum));
590 return REG_VALID;
594 /* Some targets cannot read TIE register files. */
595 else if (type == xtRegisterTypeTieRegfile)
597 /* Use 'fetch' to get register? */
598 if (flags & xtTargetFlagsUseFetchStore)
600 warning (_("cannot read register"));
601 return REG_VALID;
604 /* On some targets (esp. simulators), we can always read the reg. */
605 else if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
607 warning (_("cannot read register"));
608 return REG_VALID;
612 /* We can always read mapped registers. */
613 else if (type == xtRegisterTypeMapped || type == xtRegisterTypeTieState)
614 return xtensa_register_read_masked (regcache, reg, buffer);
616 /* Assume that we can read the register. */
617 return regcache->raw_read (regnum, buffer);
619 else
620 internal_error (_("invalid register number %d"), regnum);
624 /* Write pseudo registers. */
626 static void
627 xtensa_pseudo_register_write (struct gdbarch *gdbarch,
628 struct regcache *regcache,
629 int regnum,
630 const gdb_byte *buffer)
632 DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
633 regnum, xtensa_register_name (gdbarch, regnum));
634 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
636 /* Renumber register, if aliases a0..a15 on Windowed ABI. */
637 if (tdep->isa_use_windowed_registers
638 && (regnum >= tdep->a0_base)
639 && (regnum <= tdep->a0_base + 15))
641 ULONGEST value;
642 regcache_raw_read_unsigned (regcache,
643 tdep->wb_regnum, &value);
644 regnum = arreg_number (gdbarch, regnum, value);
647 /* We can always write 'core' registers.
648 Note: We might have converted Ax->ARy. */
649 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
650 regcache->raw_write (regnum, buffer);
652 /* We have to find out how to deal with privileged registers.
653 Let's treat them as pseudo-registers, but we cannot read/write them. */
655 else if (regnum < tdep->a0_base)
657 return;
659 /* Pseudo registers. */
660 else if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
662 xtensa_register_t *reg = &tdep->regmap[regnum];
663 xtensa_register_type_t type = reg->type;
664 int flags = tdep->target_flags;
666 /* On most targets, we cannot write registers
667 of type "Unknown" or "Unmapped". */
668 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
670 if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
672 warning (_("cannot write register %s"),
673 xtensa_register_name (gdbarch, regnum));
674 return;
678 /* Some targets cannot read TIE register files. */
679 else if (type == xtRegisterTypeTieRegfile)
681 /* Use 'store' to get register? */
682 if (flags & xtTargetFlagsUseFetchStore)
684 warning (_("cannot write register"));
685 return;
688 /* On some targets (esp. simulators), we can always write
689 the register. */
690 else if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
692 warning (_("cannot write register"));
693 return;
697 /* We can always write mapped registers. */
698 else if (type == xtRegisterTypeMapped || type == xtRegisterTypeTieState)
700 xtensa_register_write_masked (regcache, reg, buffer);
701 return;
704 /* Assume that we can write the register. */
705 regcache->raw_write (regnum, buffer);
707 else
708 internal_error (_("invalid register number %d"), regnum);
711 static const reggroup *xtensa_ar_reggroup;
712 static const reggroup *xtensa_user_reggroup;
713 static const reggroup *xtensa_vectra_reggroup;
714 static const reggroup *xtensa_cp[XTENSA_MAX_COPROCESSOR];
716 static void
717 xtensa_init_reggroups (void)
719 int i;
721 xtensa_ar_reggroup = reggroup_new ("ar", USER_REGGROUP);
722 xtensa_user_reggroup = reggroup_new ("user", USER_REGGROUP);
723 xtensa_vectra_reggroup = reggroup_new ("vectra", USER_REGGROUP);
725 for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
726 xtensa_cp[i] = reggroup_new (xstrprintf ("cp%d", i).release (),
727 USER_REGGROUP);
730 static void
731 xtensa_add_reggroups (struct gdbarch *gdbarch)
733 /* Xtensa-specific groups. */
734 reggroup_add (gdbarch, xtensa_ar_reggroup);
735 reggroup_add (gdbarch, xtensa_user_reggroup);
736 reggroup_add (gdbarch, xtensa_vectra_reggroup);
738 for (int i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
739 reggroup_add (gdbarch, xtensa_cp[i]);
742 static int
743 xtensa_coprocessor_register_group (const struct reggroup *group)
745 int i;
747 for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
748 if (group == xtensa_cp[i])
749 return i;
751 return -1;
754 #define SAVE_REST_FLAGS (XTENSA_REGISTER_FLAGS_READABLE \
755 | XTENSA_REGISTER_FLAGS_WRITABLE \
756 | XTENSA_REGISTER_FLAGS_VOLATILE)
758 #define SAVE_REST_VALID (XTENSA_REGISTER_FLAGS_READABLE \
759 | XTENSA_REGISTER_FLAGS_WRITABLE)
761 static int
762 xtensa_register_reggroup_p (struct gdbarch *gdbarch,
763 int regnum,
764 const struct reggroup *group)
766 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
767 xtensa_register_t* reg = &tdep->regmap[regnum];
768 xtensa_register_type_t type = reg->type;
769 xtensa_register_group_t rg = reg->group;
770 int cp_number;
772 if (group == save_reggroup)
773 /* Every single register should be included into the list of registers
774 to be watched for changes while using -data-list-changed-registers. */
775 return 1;
777 /* First, skip registers that are not visible to this target
778 (unknown and unmapped registers when not using ISS). */
780 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
781 return 0;
782 if (group == all_reggroup)
783 return 1;
784 if (group == xtensa_ar_reggroup)
785 return rg & xtRegisterGroupAddrReg;
786 if (group == xtensa_user_reggroup)
787 return rg & xtRegisterGroupUser;
788 if (group == float_reggroup)
789 return rg & xtRegisterGroupFloat;
790 if (group == general_reggroup)
791 return rg & xtRegisterGroupGeneral;
792 if (group == system_reggroup)
793 return rg & xtRegisterGroupState;
794 if (group == vector_reggroup || group == xtensa_vectra_reggroup)
795 return rg & xtRegisterGroupVectra;
796 if (group == restore_reggroup)
797 return (regnum < gdbarch_num_regs (gdbarch)
798 && (reg->flags & SAVE_REST_FLAGS) == SAVE_REST_VALID);
799 cp_number = xtensa_coprocessor_register_group (group);
800 if (cp_number >= 0)
801 return rg & (xtRegisterGroupCP0 << cp_number);
802 else
803 return 1;
807 /* Supply register REGNUM from the buffer specified by GREGS and LEN
808 in the general-purpose register set REGSET to register cache
809 REGCACHE. If REGNUM is -1 do this for all registers in REGSET. */
811 static void
812 xtensa_supply_gregset (const struct regset *regset,
813 struct regcache *rc,
814 int regnum,
815 const void *gregs,
816 size_t len)
818 const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
819 struct gdbarch *gdbarch = rc->arch ();
820 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
821 int i;
823 DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
825 if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
826 rc->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &regs->pc);
827 if (regnum == gdbarch_ps_regnum (gdbarch) || regnum == -1)
828 rc->raw_supply (gdbarch_ps_regnum (gdbarch), (char *) &regs->ps);
829 if (regnum == tdep->wb_regnum || regnum == -1)
830 rc->raw_supply (tdep->wb_regnum,
831 (char *) &regs->windowbase);
832 if (regnum == tdep->ws_regnum || regnum == -1)
833 rc->raw_supply (tdep->ws_regnum,
834 (char *) &regs->windowstart);
835 if (regnum == tdep->lbeg_regnum || regnum == -1)
836 rc->raw_supply (tdep->lbeg_regnum,
837 (char *) &regs->lbeg);
838 if (regnum == tdep->lend_regnum || regnum == -1)
839 rc->raw_supply (tdep->lend_regnum,
840 (char *) &regs->lend);
841 if (regnum == tdep->lcount_regnum || regnum == -1)
842 rc->raw_supply (tdep->lcount_regnum,
843 (char *) &regs->lcount);
844 if (regnum == tdep->sar_regnum || regnum == -1)
845 rc->raw_supply (tdep->sar_regnum,
846 (char *) &regs->sar);
847 if (regnum >=tdep->ar_base
848 && regnum < tdep->ar_base
849 + tdep->num_aregs)
850 rc->raw_supply
851 (regnum, (char *) &regs->ar[regnum - tdep->ar_base]);
852 else if (regnum == -1)
854 for (i = 0; i < tdep->num_aregs; ++i)
855 rc->raw_supply (tdep->ar_base + i,
856 (char *) &regs->ar[i]);
861 /* Xtensa register set. */
863 static struct regset
864 xtensa_gregset =
866 NULL,
867 xtensa_supply_gregset
871 /* Iterate over supported core file register note sections. */
873 static void
874 xtensa_iterate_over_regset_sections (struct gdbarch *gdbarch,
875 iterate_over_regset_sections_cb *cb,
876 void *cb_data,
877 const struct regcache *regcache)
879 DEBUGTRACE ("xtensa_iterate_over_regset_sections\n");
881 cb (".reg", sizeof (xtensa_elf_gregset_t), sizeof (xtensa_elf_gregset_t),
882 &xtensa_gregset, NULL, cb_data);
886 /* Handling frames. */
888 /* Number of registers to save in case of Windowed ABI. */
889 #define XTENSA_NUM_SAVED_AREGS 12
891 /* Frame cache part for Windowed ABI. */
892 typedef struct xtensa_windowed_frame_cache
894 int wb; /* WINDOWBASE of the previous frame. */
895 int callsize; /* Call size of this frame. */
896 int ws; /* WINDOWSTART of the previous frame. It keeps track of
897 life windows only. If there is no bit set for the
898 window, that means it had been already spilled
899 because of window overflow. */
901 /* Addresses of spilled A-registers.
902 AREGS[i] == -1, if corresponding AR is alive. */
903 CORE_ADDR aregs[XTENSA_NUM_SAVED_AREGS];
904 } xtensa_windowed_frame_cache_t;
906 /* Call0 ABI Definitions. */
908 #define C0_MAXOPDS 3 /* Maximum number of operands for prologue
909 analysis. */
910 #define C0_CLESV 12 /* Callee-saved registers are here and up. */
911 #define C0_SP 1 /* Register used as SP. */
912 #define C0_FP 15 /* Register used as FP. */
913 #define C0_RA 0 /* Register used as return address. */
914 #define C0_ARGS 2 /* Register used as first arg/retval. */
915 #define C0_NARGS 6 /* Number of A-regs for args/retvals. */
917 /* Each element of xtensa_call0_frame_cache.c0_rt[] describes for each
918 A-register where the current content of the reg came from (in terms
919 of an original reg and a constant). Negative values of c0_rt[n].fp_reg
920 mean that the original content of the register was saved to the stack.
921 c0_rt[n].fr.ofs is NOT the offset from the frame base because we don't
922 know where SP will end up until the entire prologue has been analyzed. */
924 #define C0_CONST -1 /* fr_reg value if register contains a constant. */
925 #define C0_INEXP -2 /* fr_reg value if inexpressible as reg + offset. */
926 #define C0_NOSTK -1 /* to_stk value if register has not been stored. */
928 extern xtensa_isa xtensa_default_isa;
930 typedef struct xtensa_c0reg
932 int fr_reg; /* original register from which register content
933 is derived, or C0_CONST, or C0_INEXP. */
934 int fr_ofs; /* constant offset from reg, or immediate value. */
935 int to_stk; /* offset from original SP to register (4-byte aligned),
936 or C0_NOSTK if register has not been saved. */
937 } xtensa_c0reg_t;
939 /* Frame cache part for Call0 ABI. */
940 typedef struct xtensa_call0_frame_cache
942 int c0_frmsz; /* Stack frame size. */
943 int c0_hasfp; /* Current frame uses frame pointer. */
944 int fp_regnum; /* A-register used as FP. */
945 int c0_fp; /* Actual value of frame pointer. */
946 int c0_fpalign; /* Dynamic adjustment for the stack
947 pointer. It's an AND mask. Zero,
948 if alignment was not adjusted. */
949 int c0_old_sp; /* In case of dynamic adjustment, it is
950 a register holding unaligned sp.
951 C0_INEXP, when undefined. */
952 int c0_sp_ofs; /* If "c0_old_sp" was spilled it's a
953 stack offset. C0_NOSTK otherwise. */
955 xtensa_c0reg_t c0_rt[C0_NREGS]; /* Register tracking information. */
956 } xtensa_call0_frame_cache_t;
958 typedef struct xtensa_frame_cache
960 CORE_ADDR base; /* Stack pointer of this frame. */
961 CORE_ADDR pc; /* PC of this frame at the function entry point. */
962 CORE_ADDR ra; /* The raw return address of this frame. */
963 CORE_ADDR ps; /* The PS register of the previous (older) frame. */
964 CORE_ADDR prev_sp; /* Stack Pointer of the previous (older) frame. */
965 int call0; /* It's a call0 framework (else windowed). */
966 union
968 xtensa_windowed_frame_cache_t wd; /* call0 == false. */
969 xtensa_call0_frame_cache_t c0; /* call0 == true. */
971 } xtensa_frame_cache_t;
974 static struct xtensa_frame_cache *
975 xtensa_alloc_frame_cache (int windowed)
977 xtensa_frame_cache_t *cache;
978 int i;
980 DEBUGTRACE ("xtensa_alloc_frame_cache ()\n");
982 cache = FRAME_OBSTACK_ZALLOC (xtensa_frame_cache_t);
984 cache->base = 0;
985 cache->pc = 0;
986 cache->ra = 0;
987 cache->ps = 0;
988 cache->prev_sp = 0;
989 cache->call0 = !windowed;
990 if (cache->call0)
992 cache->c0.c0_frmsz = -1;
993 cache->c0.c0_hasfp = 0;
994 cache->c0.fp_regnum = -1;
995 cache->c0.c0_fp = -1;
996 cache->c0.c0_fpalign = 0;
997 cache->c0.c0_old_sp = C0_INEXP;
998 cache->c0.c0_sp_ofs = C0_NOSTK;
1000 for (i = 0; i < C0_NREGS; i++)
1002 cache->c0.c0_rt[i].fr_reg = i;
1003 cache->c0.c0_rt[i].fr_ofs = 0;
1004 cache->c0.c0_rt[i].to_stk = C0_NOSTK;
1007 else
1009 cache->wd.wb = 0;
1010 cache->wd.ws = 0;
1011 cache->wd.callsize = -1;
1013 for (i = 0; i < XTENSA_NUM_SAVED_AREGS; i++)
1014 cache->wd.aregs[i] = -1;
1016 return cache;
1020 static CORE_ADDR
1021 xtensa_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
1023 return address & ~15;
1027 static CORE_ADDR
1028 xtensa_unwind_pc (struct gdbarch *gdbarch, const frame_info_ptr &next_frame)
1030 gdb_byte buf[8];
1031 CORE_ADDR pc;
1033 DEBUGTRACE ("xtensa_unwind_pc (next_frame = %s)\n",
1034 host_address_to_string (next_frame.get ()));
1036 frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
1037 pc = extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
1039 DEBUGINFO ("[xtensa_unwind_pc] pc = 0x%08x\n", (unsigned int) pc);
1041 return pc;
1045 static struct frame_id
1046 xtensa_dummy_id (struct gdbarch *gdbarch, const frame_info_ptr &this_frame)
1048 CORE_ADDR pc, fp;
1049 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1051 /* THIS-FRAME is a dummy frame. Return a frame ID of that frame. */
1053 pc = get_frame_pc (this_frame);
1054 fp = get_frame_register_unsigned
1055 (this_frame, tdep->a0_base + 1);
1057 /* Make dummy frame ID unique by adding a constant. */
1058 return frame_id_build (fp + SP_ALIGNMENT, pc);
1061 /* Returns true, if instruction to execute next is unique to Xtensa Window
1062 Interrupt Handlers. It can only be one of L32E, S32E, RFWO, or RFWU. */
1064 static int
1065 xtensa_window_interrupt_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
1067 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1068 unsigned int insn = read_memory_integer (pc, 4, byte_order);
1069 unsigned int code;
1071 if (byte_order == BFD_ENDIAN_BIG)
1073 /* Check, if this is L32E or S32E. */
1074 code = insn & 0xf000ff00;
1075 if ((code == 0x00009000) || (code == 0x00009400))
1076 return 1;
1077 /* Check, if this is RFWU or RFWO. */
1078 code = insn & 0xffffff00;
1079 return ((code == 0x00430000) || (code == 0x00530000));
1081 else
1083 /* Check, if this is L32E or S32E. */
1084 code = insn & 0x00ff000f;
1085 if ((code == 0x090000) || (code == 0x490000))
1086 return 1;
1087 /* Check, if this is RFWU or RFWO. */
1088 code = insn & 0x00ffffff;
1089 return ((code == 0x00003400) || (code == 0x00003500));
1093 /* Returns the best guess about which register is a frame pointer
1094 for the function containing CURRENT_PC. */
1096 #define XTENSA_ISA_BSZ 32 /* Instruction buffer size. */
1097 #define XTENSA_ISA_BADPC ((CORE_ADDR)0) /* Bad PC value. */
1099 static unsigned int
1100 xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
1102 #define RETURN_FP goto done
1104 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1105 unsigned int fp_regnum = tdep->a0_base + 1;
1106 CORE_ADDR start_addr;
1107 xtensa_isa isa;
1108 xtensa_insnbuf ins, slot;
1109 gdb_byte ibuf[XTENSA_ISA_BSZ];
1110 CORE_ADDR ia, bt, ba;
1111 xtensa_format ifmt;
1112 int ilen, islots, is;
1113 xtensa_opcode opc;
1114 const char *opcname;
1116 find_pc_partial_function (current_pc, NULL, &start_addr, NULL);
1117 if (start_addr == 0)
1118 return fp_regnum;
1120 isa = xtensa_default_isa;
1121 gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
1122 ins = xtensa_insnbuf_alloc (isa);
1123 slot = xtensa_insnbuf_alloc (isa);
1124 ba = 0;
1126 for (ia = start_addr, bt = ia; ia < current_pc ; ia += ilen)
1128 if (ia + xtensa_isa_maxlength (isa) > bt)
1130 ba = ia;
1131 bt = (ba + XTENSA_ISA_BSZ) < current_pc
1132 ? ba + XTENSA_ISA_BSZ : current_pc;
1133 if (target_read_memory (ba, ibuf, bt - ba) != 0)
1134 RETURN_FP;
1137 xtensa_insnbuf_from_chars (isa, ins, &ibuf[ia-ba], 0);
1138 ifmt = xtensa_format_decode (isa, ins);
1139 if (ifmt == XTENSA_UNDEFINED)
1140 RETURN_FP;
1141 ilen = xtensa_format_length (isa, ifmt);
1142 if (ilen == XTENSA_UNDEFINED)
1143 RETURN_FP;
1144 islots = xtensa_format_num_slots (isa, ifmt);
1145 if (islots == XTENSA_UNDEFINED)
1146 RETURN_FP;
1148 for (is = 0; is < islots; ++is)
1150 if (xtensa_format_get_slot (isa, ifmt, is, ins, slot))
1151 RETURN_FP;
1153 opc = xtensa_opcode_decode (isa, ifmt, is, slot);
1154 if (opc == XTENSA_UNDEFINED)
1155 RETURN_FP;
1157 opcname = xtensa_opcode_name (isa, opc);
1159 if (strcasecmp (opcname, "mov.n") == 0
1160 || strcasecmp (opcname, "or") == 0)
1162 unsigned int register_operand;
1164 /* Possible candidate for setting frame pointer
1165 from A1. This is what we are looking for. */
1167 if (xtensa_operand_get_field (isa, opc, 1, ifmt,
1168 is, slot, &register_operand) != 0)
1169 RETURN_FP;
1170 if (xtensa_operand_decode (isa, opc, 1, &register_operand) != 0)
1171 RETURN_FP;
1172 if (register_operand == 1) /* Mov{.n} FP A1. */
1174 if (xtensa_operand_get_field (isa, opc, 0, ifmt, is, slot,
1175 &register_operand) != 0)
1176 RETURN_FP;
1177 if (xtensa_operand_decode (isa, opc, 0,
1178 &register_operand) != 0)
1179 RETURN_FP;
1181 fp_regnum
1182 = tdep->a0_base + register_operand;
1183 RETURN_FP;
1187 if (
1188 /* We have problems decoding the memory. */
1189 opcname == NULL
1190 || strcasecmp (opcname, "ill") == 0
1191 || strcasecmp (opcname, "ill.n") == 0
1192 /* Hit planted breakpoint. */
1193 || strcasecmp (opcname, "break") == 0
1194 || strcasecmp (opcname, "break.n") == 0
1195 /* Flow control instructions finish prologue. */
1196 || xtensa_opcode_is_branch (isa, opc) > 0
1197 || xtensa_opcode_is_jump (isa, opc) > 0
1198 || xtensa_opcode_is_loop (isa, opc) > 0
1199 || xtensa_opcode_is_call (isa, opc) > 0
1200 || strcasecmp (opcname, "simcall") == 0
1201 || strcasecmp (opcname, "syscall") == 0)
1202 /* Can not continue analysis. */
1203 RETURN_FP;
1206 done:
1207 xtensa_insnbuf_free(isa, slot);
1208 xtensa_insnbuf_free(isa, ins);
1209 return fp_regnum;
1212 /* The key values to identify the frame using "cache" are
1214 cache->base = SP (or best guess about FP) of this frame;
1215 cache->pc = entry-PC (entry point of the frame function);
1216 cache->prev_sp = SP of the previous frame. */
1218 static void
1219 call0_frame_cache (const frame_info_ptr &this_frame,
1220 xtensa_frame_cache_t *cache, CORE_ADDR pc);
1222 static void
1223 xtensa_window_interrupt_frame_cache (const frame_info_ptr &this_frame,
1224 xtensa_frame_cache_t *cache,
1225 CORE_ADDR pc);
1227 static struct xtensa_frame_cache *
1228 xtensa_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
1230 xtensa_frame_cache_t *cache;
1231 CORE_ADDR ra, wb, ws, pc, sp, ps;
1232 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1233 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1234 unsigned int fp_regnum;
1235 int windowed, ps_regnum;
1237 if (*this_cache)
1238 return (struct xtensa_frame_cache *) *this_cache;
1240 pc = get_frame_register_unsigned (this_frame, gdbarch_pc_regnum (gdbarch));
1241 ps_regnum = gdbarch_ps_regnum (gdbarch);
1242 ps = (ps_regnum >= 0
1243 ? get_frame_register_unsigned (this_frame, ps_regnum) : TX_PS);
1245 windowed = windowing_enabled (gdbarch, ps);
1247 /* Get pristine xtensa-frame. */
1248 cache = xtensa_alloc_frame_cache (windowed);
1249 *this_cache = cache;
1251 if (windowed)
1253 LONGEST op1;
1254 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1256 /* Get WINDOWBASE, WINDOWSTART, and PS registers. */
1257 wb = get_frame_register_unsigned (this_frame,
1258 tdep->wb_regnum);
1259 ws = get_frame_register_unsigned (this_frame,
1260 tdep->ws_regnum);
1262 if (safe_read_memory_integer (pc, 1, byte_order, &op1)
1263 && XTENSA_IS_ENTRY (gdbarch, op1))
1265 int callinc = CALLINC (ps);
1266 ra = get_frame_register_unsigned
1267 (this_frame, tdep->a0_base + callinc * 4);
1269 /* ENTRY hasn't been executed yet, therefore callsize is still 0. */
1270 cache->wd.callsize = 0;
1271 cache->wd.wb = wb;
1272 cache->wd.ws = ws;
1273 cache->prev_sp = get_frame_register_unsigned
1274 (this_frame, tdep->a0_base + 1);
1276 /* This only can be the outermost frame since we are
1277 just about to execute ENTRY. SP hasn't been set yet.
1278 We can assume any frame size, because it does not
1279 matter, and, let's fake frame base in cache. */
1280 cache->base = cache->prev_sp - 16;
1282 cache->pc = pc;
1283 cache->ra = (cache->pc & 0xc0000000) | (ra & 0x3fffffff);
1284 cache->ps = (ps & ~PS_CALLINC_MASK)
1285 | ((WINSIZE(ra)/4) << PS_CALLINC_SHIFT);
1287 return cache;
1289 else
1291 fp_regnum = xtensa_scan_prologue (gdbarch, pc);
1292 ra = get_frame_register_unsigned (this_frame,
1293 tdep->a0_base);
1294 cache->wd.callsize = WINSIZE (ra);
1295 cache->wd.wb = (wb - cache->wd.callsize / 4)
1296 & (tdep->num_aregs / 4 - 1);
1297 cache->wd.ws = ws & ~(1 << wb);
1299 cache->pc = get_frame_func (this_frame);
1300 cache->ra = (pc & 0xc0000000) | (ra & 0x3fffffff);
1301 cache->ps = (ps & ~PS_CALLINC_MASK)
1302 | ((WINSIZE(ra)/4) << PS_CALLINC_SHIFT);
1305 if (cache->wd.ws == 0)
1307 int i;
1309 /* Set A0...A3. */
1310 sp = get_frame_register_unsigned
1311 (this_frame, tdep->a0_base + 1) - 16;
1313 for (i = 0; i < 4; i++, sp += 4)
1315 cache->wd.aregs[i] = sp;
1318 if (cache->wd.callsize > 4)
1320 /* Set A4...A7/A11. */
1321 /* Get the SP of the frame previous to the previous one.
1322 To achieve this, we have to dereference SP twice. */
1323 sp = (CORE_ADDR) read_memory_integer (sp - 12, 4, byte_order);
1324 sp = (CORE_ADDR) read_memory_integer (sp - 12, 4, byte_order);
1325 sp -= cache->wd.callsize * 4;
1327 for ( i = 4; i < cache->wd.callsize; i++, sp += 4)
1329 cache->wd.aregs[i] = sp;
1334 if ((cache->prev_sp == 0) && ( ra != 0 ))
1335 /* If RA is equal to 0 this frame is an outermost frame. Leave
1336 cache->prev_sp unchanged marking the boundary of the frame stack. */
1338 if ((cache->wd.ws & (1 << cache->wd.wb)) == 0)
1340 /* Register window overflow already happened.
1341 We can read caller's SP from the proper spill location. */
1342 sp = get_frame_register_unsigned
1343 (this_frame, tdep->a0_base + 1);
1344 cache->prev_sp = read_memory_integer (sp - 12, 4, byte_order);
1346 else
1348 /* Read caller's frame SP directly from the previous window. */
1349 int regnum = arreg_number
1350 (gdbarch, tdep->a0_base + 1,
1351 cache->wd.wb);
1353 cache->prev_sp = xtensa_read_register (regnum);
1357 else if (xtensa_window_interrupt_insn (gdbarch, pc))
1359 /* Execution stopped inside Xtensa Window Interrupt Handler. */
1361 xtensa_window_interrupt_frame_cache (this_frame, cache, pc);
1362 /* Everything was set already, including cache->base. */
1363 return cache;
1365 else /* Call0 framework. */
1367 call0_frame_cache (this_frame, cache, pc);
1368 fp_regnum = cache->c0.fp_regnum;
1371 cache->base = get_frame_register_unsigned (this_frame, fp_regnum);
1373 return cache;
1376 static int xtensa_session_once_reported = 1;
1378 /* Report a problem with prologue analysis while doing backtracing.
1379 But, do it only once to avoid annoying repeated messages. */
1381 static void
1382 warning_once (void)
1384 if (xtensa_session_once_reported == 0)
1385 warning (_("\
1386 \nUnrecognised function prologue. Stack trace cannot be resolved. \
1387 This message will not be repeated in this session.\n"));
1389 xtensa_session_once_reported = 1;
1393 static void
1394 xtensa_frame_this_id (const frame_info_ptr &this_frame,
1395 void **this_cache,
1396 struct frame_id *this_id)
1398 struct xtensa_frame_cache *cache =
1399 xtensa_frame_cache (this_frame, this_cache);
1401 if (cache->prev_sp == 0)
1402 return;
1404 (*this_id) = frame_id_build (cache->prev_sp, cache->pc);
1407 static struct value *
1408 xtensa_frame_prev_register (const frame_info_ptr &this_frame,
1409 void **this_cache,
1410 int regnum)
1412 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1413 struct xtensa_frame_cache *cache;
1414 ULONGEST saved_reg = 0;
1415 int done = 1;
1416 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
1418 if (*this_cache == NULL)
1419 *this_cache = xtensa_frame_cache (this_frame, this_cache);
1420 cache = (struct xtensa_frame_cache *) *this_cache;
1422 if (regnum ==gdbarch_pc_regnum (gdbarch))
1423 saved_reg = cache->ra;
1424 else if (regnum == tdep->a0_base + 1)
1425 saved_reg = cache->prev_sp;
1426 else if (!cache->call0)
1428 if (regnum == tdep->ws_regnum)
1429 saved_reg = cache->wd.ws;
1430 else if (regnum == tdep->wb_regnum)
1431 saved_reg = cache->wd.wb;
1432 else if (regnum == gdbarch_ps_regnum (gdbarch))
1433 saved_reg = cache->ps;
1434 else
1435 done = 0;
1437 else
1438 done = 0;
1440 if (done)
1441 return frame_unwind_got_constant (this_frame, regnum, saved_reg);
1443 if (!cache->call0) /* Windowed ABI. */
1445 /* Convert A-register numbers to AR-register numbers,
1446 if we deal with A-register. */
1447 if (regnum >= tdep->a0_base
1448 && regnum <= tdep->a0_base + 15)
1449 regnum = arreg_number (gdbarch, regnum, cache->wd.wb);
1451 /* Check, if we deal with AR-register saved on stack. */
1452 if (regnum >= tdep->ar_base
1453 && regnum <= (tdep->ar_base
1454 + tdep->num_aregs))
1456 int areg = areg_number (gdbarch, regnum, cache->wd.wb);
1458 if (areg >= 0
1459 && areg < XTENSA_NUM_SAVED_AREGS
1460 && cache->wd.aregs[areg] != -1)
1461 return frame_unwind_got_memory (this_frame, regnum,
1462 cache->wd.aregs[areg]);
1465 else /* Call0 ABI. */
1467 int reg = (regnum >= tdep->ar_base
1468 && regnum <= (tdep->ar_base
1469 + C0_NREGS))
1470 ? regnum - tdep->ar_base : regnum;
1472 if (reg < C0_NREGS)
1474 CORE_ADDR spe;
1475 int stkofs;
1477 /* If register was saved in the prologue, retrieve it. */
1478 stkofs = cache->c0.c0_rt[reg].to_stk;
1479 if (stkofs != C0_NOSTK)
1481 /* Determine SP on entry based on FP. */
1482 spe = cache->c0.c0_fp
1483 - cache->c0.c0_rt[cache->c0.fp_regnum].fr_ofs;
1485 return frame_unwind_got_memory (this_frame, regnum,
1486 spe + stkofs);
1491 /* All other registers have been either saved to
1492 the stack or are still alive in the processor. */
1494 return frame_unwind_got_register (this_frame, regnum, regnum);
1498 static const struct frame_unwind
1499 xtensa_unwind =
1501 "xtensa prologue",
1502 NORMAL_FRAME,
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. \
3269 Can be 1, 2, 3, or 4 indicating the level of debugging."),
3270 NULL,
3271 NULL,
3272 &setdebuglist, &showdebuglist);