2009-01-30 Julian Brown <julian@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / xtensa-tdep.c
CommitLineData
ca3bf3bd
DJ
1/* Target-dependent code for the Xtensa port of GDB, the GNU debugger.
2
0fb0cc75
JB
3 Copyright (C) 2003, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
ca3bf3bd
DJ
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
ca3bf3bd
DJ
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
ca3bf3bd
DJ
20
21#include "defs.h"
22#include "frame.h"
ee967b5f 23#include "solib-svr4.h"
ca3bf3bd
DJ
24#include "symtab.h"
25#include "symfile.h"
26#include "objfiles.h"
27#include "gdbtypes.h"
28#include "gdbcore.h"
29#include "value.h"
30#include "dis-asm.h"
31#include "inferior.h"
32#include "floatformat.h"
33#include "regcache.h"
34#include "reggroups.h"
35#include "regset.h"
36
37#include "dummy-frame.h"
38#include "elf/dwarf2.h"
39#include "dwarf2-frame.h"
40#include "dwarf2loc.h"
41#include "frame.h"
42#include "frame-base.h"
43#include "frame-unwind.h"
44
45#include "arch-utils.h"
46#include "gdbarch.h"
47#include "remote.h"
48#include "serial.h"
49
50#include "command.h"
51#include "gdbcmd.h"
52#include "gdb_assert.h"
53
bdb4c075 54#include "xtensa-isa.h"
ca3bf3bd 55#include "xtensa-tdep.h"
94a0e877 56#include "xtensa-config.h"
ca3bf3bd
DJ
57
58
59static int xtensa_debug_level = 0;
60
61#define DEBUGWARN(args...) \
62 if (xtensa_debug_level > 0) \
63 fprintf_unfiltered (gdb_stdlog, "(warn ) " args)
64
65#define DEBUGINFO(args...) \
66 if (xtensa_debug_level > 1) \
67 fprintf_unfiltered (gdb_stdlog, "(info ) " args)
68
69#define DEBUGTRACE(args...) \
70 if (xtensa_debug_level > 2) \
71 fprintf_unfiltered (gdb_stdlog, "(trace) " args)
72
73#define DEBUGVERB(args...) \
74 if (xtensa_debug_level > 3) \
75 fprintf_unfiltered (gdb_stdlog, "(verb ) " args)
76
77
78/* According to the ABI, the SP must be aligned to 16-byte boundaries. */
ca3bf3bd
DJ
79#define SP_ALIGNMENT 16
80
81
bdb4c075
MG
82/* On Windowed ABI, we use a6 through a11 for passing arguments
83 to a function called by GDB because CALL4 is used. */
bdb4c075
MG
84#define ARGS_NUM_REGS 6
85#define REGISTER_SIZE 4
ca3bf3bd 86
ca3bf3bd 87
bdb4c075
MG
88/* Extract the call size from the return address or PS register. */
89#define PS_CALLINC_SHIFT 16
90#define PS_CALLINC_MASK 0x00030000
91#define CALLINC(ps) (((ps) & PS_CALLINC_MASK) >> PS_CALLINC_SHIFT)
92#define WINSIZE(ra) (4 * (( (ra) >> 30) & 0x3))
ca3bf3bd 93
bdb4c075 94/* ABI-independent macros. */
91d8eb23
MD
95#define ARG_NOF(gdbarch) \
96 (gdbarch_tdep (gdbarch)->call_abi \
97 == CallAbiCall0Only ? C0_NARGS : (ARGS_NUM_REGS))
98#define ARG_1ST(gdbarch) \
99 (gdbarch_tdep (gdbarch)->call_abi == CallAbiCall0Only \
94a0e877 100 ? (gdbarch_tdep (gdbarch)->a0_base + C0_ARGS) \
91d8eb23 101 : (gdbarch_tdep (gdbarch)->a0_base + 6))
ca3bf3bd 102
ca3bf3bd
DJ
103/* XTENSA_IS_ENTRY tests whether the first byte of an instruction
104 indicates that the instruction is an ENTRY instruction. */
105
91d8eb23
MD
106#define XTENSA_IS_ENTRY(gdbarch, op1) \
107 ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) \
4c6b5505 108 ? ((op1) == 0x6c) : ((op1) == 0x36))
ca3bf3bd 109
bdb4c075 110#define XTENSA_ENTRY_LENGTH 3
ca3bf3bd
DJ
111
112/* windowing_enabled() returns true, if windowing is enabled.
113 WOE must be set to 1; EXCM to 0.
114 Note: We assume that EXCM is always 0 for XEA1. */
115
bdb4c075
MG
116#define PS_WOE (1<<18)
117#define PS_EXC (1<<4)
118
ee967b5f 119/* Convert a live A-register number to the corresponding AR-register number. */
91d8eb23 120static int
ee967b5f 121arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
91d8eb23
MD
122{
123 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
ee967b5f 124 int arreg;
91d8eb23 125
ee967b5f
MG
126 arreg = a_regnum - tdep->a0_base;
127 arreg += (wb & ((tdep->num_aregs - 1) >> 2)) << WB_SHIFT;
128 arreg &= tdep->num_aregs - 1;
91d8eb23 129
ee967b5f
MG
130 return arreg + tdep->ar_base;
131}
132
133/* Convert a live AR-register number to the corresponding A-register order
134 number in a range [0..15]. Return -1, if AR_REGNUM is out of WB window. */
135static int
136areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
137{
138 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
139 int areg;
140
141 areg = ar_regnum - tdep->ar_base;
142 if (areg < 0 || areg >= tdep->num_aregs)
143 return -1;
144 areg = (areg - wb * 4) & (tdep->num_aregs - 1);
145 return (areg > 15) ? -1 : areg;
91d8eb23
MD
146}
147
ca3bf3bd
DJ
148static inline int
149windowing_enabled (CORE_ADDR ps)
150{
bdb4c075 151 return ((ps & PS_EXC) == 0 && (ps & PS_WOE) != 0);
ca3bf3bd
DJ
152}
153
154/* Return the window size of the previous call to the function from which we
155 have just returned.
156
157 This function is used to extract the return value after a called function
bdb4c075 158 has returned to the caller. On Xtensa, the register that holds the return
ca3bf3bd
DJ
159 value (from the perspective of the caller) depends on what call
160 instruction was used. For now, we are assuming that the call instruction
161 precedes the current address, so we simply analyze the call instruction.
162 If we are in a dummy frame, we simply return 4 as we used a 'pseudo-call4'
163 method to call the inferior function. */
164
165static int
91d8eb23 166extract_call_winsize (struct gdbarch *gdbarch, CORE_ADDR pc)
ca3bf3bd 167{
bdb4c075 168 int winsize = 4;
ca3bf3bd 169 int insn;
ff7a4c00 170 gdb_byte buf[4];
ca3bf3bd
DJ
171
172 DEBUGTRACE ("extract_call_winsize (pc = 0x%08x)\n", (int) pc);
173
174 /* Read the previous instruction (should be a call[x]{4|8|12}. */
175 read_memory (pc-3, buf, 3);
176 insn = extract_unsigned_integer (buf, 3);
177
178 /* Decode call instruction:
179 Little Endian
180 call{0,4,8,12} OFFSET || {00,01,10,11} || 0101
181 callx{0,4,8,12} OFFSET || 11 || {00,01,10,11} || 0000
182 Big Endian
183 call{0,4,8,12} 0101 || {00,01,10,11} || OFFSET
184 callx{0,4,8,12} 0000 || {00,01,10,11} || 11 || OFFSET. */
185
91d8eb23 186 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
ca3bf3bd
DJ
187 {
188 if (((insn & 0xf) == 0x5) || ((insn & 0xcf) == 0xc0))
bdb4c075 189 winsize = (insn & 0x30) >> 2; /* 0, 4, 8, 12. */
ca3bf3bd
DJ
190 }
191 else
192 {
193 if (((insn >> 20) == 0x5) || (((insn >> 16) & 0xf3) == 0x03))
bdb4c075 194 winsize = (insn >> 16) & 0xc; /* 0, 4, 8, 12. */
ca3bf3bd
DJ
195 }
196 return winsize;
197}
198
199
200/* REGISTER INFORMATION */
201
202/* Returns the name of a register. */
ca3bf3bd 203static const char *
d93859e2 204xtensa_register_name (struct gdbarch *gdbarch, int regnum)
ca3bf3bd
DJ
205{
206 /* Return the name stored in the register map. */
d93859e2
UW
207 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)
208 + gdbarch_num_pseudo_regs (gdbarch))
209 return gdbarch_tdep (gdbarch)->regmap[regnum].name;
ca3bf3bd 210
ca3bf3bd
DJ
211 internal_error (__FILE__, __LINE__, _("invalid register %d"), regnum);
212 return 0;
213}
214
ca3bf3bd
DJ
215/* Return the type of a register. Create a new type, if necessary. */
216
217static struct ctype_cache
218{
219 struct ctype_cache *next;
220 int size;
221 struct type *virtual_type;
222} *type_entries = NULL;
223
224static struct type *
225xtensa_register_type (struct gdbarch *gdbarch, int regnum)
226{
227 /* Return signed integer for ARx and Ax registers. */
6b50c0b0
UW
228 if ((regnum >= gdbarch_tdep (gdbarch)->ar_base
229 && regnum < gdbarch_tdep (gdbarch)->ar_base
230 + gdbarch_tdep (gdbarch)->num_aregs)
231 || (regnum >= gdbarch_tdep (gdbarch)->a0_base
232 && regnum < gdbarch_tdep (gdbarch)->a0_base + 16))
0dfff4cb 233 return builtin_type (gdbarch)->builtin_int;
ca3bf3bd 234
6b50c0b0
UW
235 if (regnum == gdbarch_pc_regnum (gdbarch)
236 || regnum == gdbarch_tdep (gdbarch)->a0_base + 1)
fde6c819 237 return builtin_type (gdbarch)->builtin_data_ptr;
ca3bf3bd
DJ
238
239 /* Return the stored type for all other registers. */
6b50c0b0
UW
240 else if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)
241 + gdbarch_num_pseudo_regs (gdbarch))
ca3bf3bd 242 {
6b50c0b0 243 xtensa_register_t* reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
ca3bf3bd 244
bdb4c075 245 /* Set ctype for this register (only the first time). */
ca3bf3bd
DJ
246
247 if (reg->ctype == 0)
248 {
249 struct ctype_cache *tp;
250 int size = reg->byte_size;
251
bdb4c075
MG
252 /* We always use the memory representation,
253 even if the register width is smaller. */
ca3bf3bd
DJ
254 switch (size)
255 {
256 case 1:
257 reg->ctype = builtin_type_uint8;
258 break;
259
260 case 2:
261 reg->ctype = builtin_type_uint16;
262 break;
263
264 case 4:
265 reg->ctype = builtin_type_uint32;
266 break;
267
268 case 8:
269 reg->ctype = builtin_type_uint64;
270 break;
271
272 case 16:
273 reg->ctype = builtin_type_uint128;
274 break;
275
276 default:
277 for (tp = type_entries; tp != NULL; tp = tp->next)
278 if (tp->size == size)
279 break;
280
281 if (tp == NULL)
282 {
283 char *name = xmalloc (16);
284 tp = xmalloc (sizeof (struct ctype_cache));
285 tp->next = type_entries;
286 type_entries = tp;
287 tp->size = size;
288
289 sprintf (name, "int%d", size * 8);
290 tp->virtual_type = init_type (TYPE_CODE_INT, size,
291 TYPE_FLAG_UNSIGNED, name,
292 NULL);
293 }
294
295 reg->ctype = tp->virtual_type;
296 }
297 }
298 return reg->ctype;
299 }
300
ca3bf3bd
DJ
301 internal_error (__FILE__, __LINE__, _("invalid register number %d"), regnum);
302 return 0;
303}
304
305
bdb4c075 306/* Return the 'local' register number for stubs, dwarf2, etc.
ca3bf3bd
DJ
307 The debugging information enumerates registers starting from 0 for A0
308 to n for An. So, we only have to add the base number for A0. */
309
310static int
d3f73121 311xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
ca3bf3bd
DJ
312{
313 int i;
314
315 if (regnum >= 0 && regnum < 16)
d3f73121 316 return gdbarch_tdep (gdbarch)->a0_base + regnum;
ca3bf3bd 317
f57d151a 318 for (i = 0;
d3f73121 319 i < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
f57d151a 320 i++)
d3f73121 321 if (regnum == gdbarch_tdep (gdbarch)->regmap[i].target_number)
ca3bf3bd
DJ
322 return i;
323
ca3bf3bd
DJ
324 internal_error (__FILE__, __LINE__,
325 _("invalid dwarf/stabs register number %d"), regnum);
326 return 0;
327}
328
329
bdb4c075
MG
330/* Write the bits of a masked register to the various registers.
331 Only the masked areas of these registers are modified; the other
332 fields are untouched. The size of masked registers is always less
333 than or equal to 32 bits. */
ca3bf3bd
DJ
334
335static void
9c9acae0
UW
336xtensa_register_write_masked (struct regcache *regcache,
337 xtensa_register_t *reg, const gdb_byte *buffer)
ca3bf3bd
DJ
338{
339 unsigned int value[(MAX_REGISTER_SIZE + 3) / 4];
ca3bf3bd
DJ
340 const xtensa_mask_t *mask = reg->mask;
341
342 int shift = 0; /* Shift for next mask (mod 32). */
343 int start, size; /* Start bit and size of current mask. */
344
345 unsigned int *ptr = value;
346 unsigned int regval, m, mem = 0;
347
348 int bytesize = reg->byte_size;
349 int bitsize = bytesize * 8;
350 int i, r;
351
352 DEBUGTRACE ("xtensa_register_write_masked ()\n");
353
354 /* Copy the masked register to host byte-order. */
6b50c0b0 355 if (gdbarch_byte_order (get_regcache_arch (regcache)) == BFD_ENDIAN_BIG)
ca3bf3bd
DJ
356 for (i = 0; i < bytesize; i++)
357 {
358 mem >>= 8;
359 mem |= (buffer[bytesize - i - 1] << 24);
360 if ((i & 3) == 3)
361 *ptr++ = mem;
362 }
363 else
364 for (i = 0; i < bytesize; i++)
365 {
366 mem >>= 8;
367 mem |= (buffer[i] << 24);
368 if ((i & 3) == 3)
369 *ptr++ = mem;
370 }
371
372 /* We might have to shift the final value:
373 bytesize & 3 == 0 -> nothing to do, we use the full 32 bits,
374 bytesize & 3 == x -> shift (4-x) * 8. */
375
376 *ptr = mem >> (((0 - bytesize) & 3) * 8);
377 ptr = value;
378 mem = *ptr;
379
380 /* Write the bits to the masked areas of the other registers. */
381 for (i = 0; i < mask->count; i++)
382 {
383 start = mask->mask[i].bit_start;
384 size = mask->mask[i].bit_size;
385 regval = mem >> shift;
386
387 if ((shift += size) > bitsize)
388 error (_("size of all masks is larger than the register"));
389
390 if (shift >= 32)
391 {
392 mem = *(++ptr);
393 shift -= 32;
394 bitsize -= 32;
395
396 if (shift > 0)
397 regval |= mem << (size - shift);
398 }
399
400 /* Make sure we have a valid register. */
401 r = mask->mask[i].reg_num;
402 if (r >= 0 && size > 0)
403 {
404 /* Don't overwrite the unmasked areas. */
9c9acae0
UW
405 ULONGEST old_val;
406 regcache_cooked_read_unsigned (regcache, r, &old_val);
ca3bf3bd
DJ
407 m = 0xffffffff >> (32 - size) << start;
408 regval <<= start;
9c9acae0
UW
409 regval = (regval & m) | (old_val & ~m);
410 regcache_cooked_write_unsigned (regcache, r, regval);
ca3bf3bd
DJ
411 }
412 }
413}
414
415
bdb4c075
MG
416/* Read a tie state or mapped registers. Read the masked areas
417 of the registers and assemble them into a single value. */
ca3bf3bd
DJ
418
419static void
9c9acae0
UW
420xtensa_register_read_masked (struct regcache *regcache,
421 xtensa_register_t *reg, gdb_byte *buffer)
ca3bf3bd
DJ
422{
423 unsigned int value[(MAX_REGISTER_SIZE + 3) / 4];
ca3bf3bd
DJ
424 const xtensa_mask_t *mask = reg->mask;
425
426 int shift = 0;
427 int start, size;
428
429 unsigned int *ptr = value;
430 unsigned int regval, mem = 0;
431
432 int bytesize = reg->byte_size;
433 int bitsize = bytesize * 8;
434 int i;
435
436 DEBUGTRACE ("xtensa_register_read_masked (reg \"%s\", ...)\n",
437 reg->name == 0 ? "" : reg->name);
438
439 /* Assemble the register from the masked areas of other registers. */
440 for (i = 0; i < mask->count; i++)
441 {
442 int r = mask->mask[i].reg_num;
9c9acae0
UW
443 if (r >= 0)
444 {
445 ULONGEST val;
446 regcache_cooked_read_unsigned (regcache, r, &val);
447 regval = (unsigned int) val;
448 }
449 else
450 regval = 0;
451
ca3bf3bd
DJ
452 start = mask->mask[i].bit_start;
453 size = mask->mask[i].bit_size;
454
455 regval >>= start;
456
457 if (size < 32)
458 regval &= (0xffffffff >> (32 - size));
459
460 mem |= regval << shift;
461
462 if ((shift += size) > bitsize)
463 error (_("size of all masks is larger than the register"));
464
465 if (shift >= 32)
466 {
467 *ptr++ = mem;
468 bitsize -= 32;
469 shift -= 32;
470
471 if (shift == 0)
472 mem = 0;
473 else
474 mem = regval >> (size - shift);
475 }
476 }
477
478 if (shift > 0)
479 *ptr = mem;
480
481 /* Copy value to target byte order. */
482 ptr = value;
483 mem = *ptr;
484
6b50c0b0 485 if (gdbarch_byte_order (get_regcache_arch (regcache)) == BFD_ENDIAN_BIG)
ca3bf3bd
DJ
486 for (i = 0; i < bytesize; i++)
487 {
488 if ((i & 3) == 0)
489 mem = *ptr++;
490 buffer[bytesize - i - 1] = mem & 0xff;
491 mem >>= 8;
492 }
493 else
494 for (i = 0; i < bytesize; i++)
495 {
496 if ((i & 3) == 0)
497 mem = *ptr++;
498 buffer[i] = mem & 0xff;
499 mem >>= 8;
500 }
501}
502
503
504/* Read pseudo registers. */
505
506static void
507xtensa_pseudo_register_read (struct gdbarch *gdbarch,
508 struct regcache *regcache,
509 int regnum,
510 gdb_byte *buffer)
511{
512 DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
d93859e2 513 regnum, xtensa_register_name (gdbarch, regnum));
ca3bf3bd 514
6b50c0b0 515 if (regnum == gdbarch_num_regs (gdbarch)
94a0e877 516 + gdbarch_num_pseudo_regs (gdbarch) - 1)
6b50c0b0 517 regnum = gdbarch_tdep (gdbarch)->a0_base + 1;
ca3bf3bd 518
bdb4c075 519 /* Read aliases a0..a15, if this is a Windowed ABI. */
6b50c0b0 520 if (gdbarch_tdep (gdbarch)->isa_use_windowed_registers
94a0e877 521 && (regnum >= gdbarch_tdep (gdbarch)->a0_base)
6b50c0b0 522 && (regnum <= gdbarch_tdep (gdbarch)->a0_base + 15))
ca3bf3bd 523 {
ff7a4c00 524 gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
ca3bf3bd 525
6b50c0b0 526 regcache_raw_read (regcache, gdbarch_tdep (gdbarch)->wb_regnum, buf);
ee967b5f
MG
527 regnum = arreg_number (gdbarch, regnum,
528 extract_unsigned_integer (buf, 4));
ca3bf3bd
DJ
529 }
530
bdb4c075 531 /* We can always read non-pseudo registers. */
6b50c0b0 532 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
ca3bf3bd
DJ
533 regcache_raw_read (regcache, regnum, buffer);
534
94a0e877
MG
535
536 /* We have to find out how to deal with priveleged registers.
537 Let's treat them as pseudo-registers, but we cannot read/write them. */
538
539 else if (regnum < gdbarch_tdep (gdbarch)->a0_base)
540 {
541 buffer[0] = (gdb_byte)0;
542 buffer[1] = (gdb_byte)0;
543 buffer[2] = (gdb_byte)0;
544 buffer[3] = (gdb_byte)0;
545 }
ca3bf3bd 546 /* Pseudo registers. */
f57d151a 547 else if (regnum >= 0
6b50c0b0
UW
548 && regnum < gdbarch_num_regs (gdbarch)
549 + gdbarch_num_pseudo_regs (gdbarch))
ca3bf3bd 550 {
6b50c0b0 551 xtensa_register_t *reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
ca3bf3bd 552 xtensa_register_type_t type = reg->type;
6b50c0b0 553 int flags = gdbarch_tdep (gdbarch)->target_flags;
ca3bf3bd 554
bdb4c075 555 /* We cannot read Unknown or Unmapped registers. */
ca3bf3bd
DJ
556 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
557 {
558 if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
559 {
560 warning (_("cannot read register %s"),
d93859e2 561 xtensa_register_name (gdbarch, regnum));
ca3bf3bd
DJ
562 return;
563 }
564 }
565
566 /* Some targets cannot read TIE register files. */
567 else if (type == xtRegisterTypeTieRegfile)
568 {
569 /* Use 'fetch' to get register? */
570 if (flags & xtTargetFlagsUseFetchStore)
571 {
572 warning (_("cannot read register"));
573 return;
574 }
575
576 /* On some targets (esp. simulators), we can always read the reg. */
577 else if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
578 {
579 warning (_("cannot read register"));
580 return;
581 }
582 }
583
584 /* We can always read mapped registers. */
585 else if (type == xtRegisterTypeMapped || type == xtRegisterTypeTieState)
586 {
9c9acae0 587 xtensa_register_read_masked (regcache, reg, buffer);
ca3bf3bd
DJ
588 return;
589 }
590
591 /* Assume that we can read the register. */
592 regcache_raw_read (regcache, regnum, buffer);
593 }
ca3bf3bd
DJ
594 else
595 internal_error (__FILE__, __LINE__,
596 _("invalid register number %d"), regnum);
597}
598
599
600/* Write pseudo registers. */
601
602static void
603xtensa_pseudo_register_write (struct gdbarch *gdbarch,
604 struct regcache *regcache,
605 int regnum,
606 const gdb_byte *buffer)
607{
608 DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
d93859e2 609 regnum, xtensa_register_name (gdbarch, regnum));
ca3bf3bd 610
6b50c0b0 611 if (regnum == gdbarch_num_regs (gdbarch)
94a0e877 612 + gdbarch_num_pseudo_regs (gdbarch) -1)
6b50c0b0 613 regnum = gdbarch_tdep (gdbarch)->a0_base + 1;
ca3bf3bd 614
bdb4c075 615 /* Renumber register, if aliase a0..a15 on Windowed ABI. */
6b50c0b0 616 if (gdbarch_tdep (gdbarch)->isa_use_windowed_registers
94a0e877 617 && (regnum >= gdbarch_tdep (gdbarch)->a0_base)
6b50c0b0 618 && (regnum <= gdbarch_tdep (gdbarch)->a0_base + 15))
ca3bf3bd 619 {
ff7a4c00 620 gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
ca3bf3bd
DJ
621 unsigned int wb;
622
304fe255 623 regcache_raw_read (regcache,
6b50c0b0 624 gdbarch_tdep (gdbarch)->wb_regnum, buf);
ee967b5f
MG
625 regnum = arreg_number (gdbarch, regnum,
626 extract_unsigned_integer (buf, 4));
ca3bf3bd
DJ
627 }
628
629 /* We can always write 'core' registers.
630 Note: We might have converted Ax->ARy. */
6b50c0b0 631 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
ca3bf3bd
DJ
632 regcache_raw_write (regcache, regnum, buffer);
633
94a0e877
MG
634 /* We have to find out how to deal with priveleged registers.
635 Let's treat them as pseudo-registers, but we cannot read/write them. */
636
637 else if (regnum < gdbarch_tdep (gdbarch)->a0_base)
638 {
639 return;
640 }
ca3bf3bd 641 /* Pseudo registers. */
f57d151a 642 else if (regnum >= 0
6b50c0b0
UW
643 && regnum < gdbarch_num_regs (gdbarch)
644 + gdbarch_num_pseudo_regs (gdbarch))
ca3bf3bd 645 {
6b50c0b0 646 xtensa_register_t *reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
ca3bf3bd 647 xtensa_register_type_t type = reg->type;
6b50c0b0 648 int flags = gdbarch_tdep (gdbarch)->target_flags;
ca3bf3bd 649
bdb4c075
MG
650 /* On most targets, we cannot write registers
651 of type "Unknown" or "Unmapped". */
ca3bf3bd
DJ
652 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
653 {
654 if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
655 {
656 warning (_("cannot write register %s"),
d93859e2 657 xtensa_register_name (gdbarch, regnum));
ca3bf3bd
DJ
658 return;
659 }
660 }
661
662 /* Some targets cannot read TIE register files. */
663 else if (type == xtRegisterTypeTieRegfile)
664 {
665 /* Use 'store' to get register? */
666 if (flags & xtTargetFlagsUseFetchStore)
667 {
668 warning (_("cannot write register"));
669 return;
670 }
671
672 /* On some targets (esp. simulators), we can always write
673 the register. */
ca3bf3bd
DJ
674 else if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
675 {
676 warning (_("cannot write register"));
677 return;
678 }
679 }
680
681 /* We can always write mapped registers. */
682 else if (type == xtRegisterTypeMapped || type == xtRegisterTypeTieState)
683 {
9c9acae0 684 xtensa_register_write_masked (regcache, reg, buffer);
ca3bf3bd
DJ
685 return;
686 }
687
688 /* Assume that we can write the register. */
689 regcache_raw_write (regcache, regnum, buffer);
690 }
ca3bf3bd
DJ
691 else
692 internal_error (__FILE__, __LINE__,
693 _("invalid register number %d"), regnum);
694}
695
ca3bf3bd
DJ
696static struct reggroup *xtensa_ar_reggroup;
697static struct reggroup *xtensa_user_reggroup;
698static struct reggroup *xtensa_vectra_reggroup;
7b871568 699static struct reggroup *xtensa_cp[XTENSA_MAX_COPROCESSOR];
ca3bf3bd
DJ
700
701static void
702xtensa_init_reggroups (void)
703{
704 xtensa_ar_reggroup = reggroup_new ("ar", USER_REGGROUP);
705 xtensa_user_reggroup = reggroup_new ("user", USER_REGGROUP);
706 xtensa_vectra_reggroup = reggroup_new ("vectra", USER_REGGROUP);
ca3bf3bd 707
7b871568
MG
708 xtensa_cp[0] = reggroup_new ("cp0", USER_REGGROUP);
709 xtensa_cp[1] = reggroup_new ("cp1", USER_REGGROUP);
710 xtensa_cp[2] = reggroup_new ("cp2", USER_REGGROUP);
711 xtensa_cp[3] = reggroup_new ("cp3", USER_REGGROUP);
712 xtensa_cp[4] = reggroup_new ("cp4", USER_REGGROUP);
713 xtensa_cp[5] = reggroup_new ("cp5", USER_REGGROUP);
714 xtensa_cp[6] = reggroup_new ("cp6", USER_REGGROUP);
715 xtensa_cp[7] = reggroup_new ("cp7", USER_REGGROUP);
716}
ca3bf3bd
DJ
717
718static void
719xtensa_add_reggroups (struct gdbarch *gdbarch)
720{
7b871568
MG
721 int i;
722
723 /* Predefined groups. */
ca3bf3bd
DJ
724 reggroup_add (gdbarch, all_reggroup);
725 reggroup_add (gdbarch, save_reggroup);
726 reggroup_add (gdbarch, restore_reggroup);
727 reggroup_add (gdbarch, system_reggroup);
7b871568
MG
728 reggroup_add (gdbarch, vector_reggroup);
729 reggroup_add (gdbarch, general_reggroup);
730 reggroup_add (gdbarch, float_reggroup);
731
732 /* Xtensa-specific groups. */
733 reggroup_add (gdbarch, xtensa_ar_reggroup);
734 reggroup_add (gdbarch, xtensa_user_reggroup);
735 reggroup_add (gdbarch, xtensa_vectra_reggroup);
ca3bf3bd 736
7b871568
MG
737 for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
738 reggroup_add (gdbarch, xtensa_cp[i]);
ca3bf3bd
DJ
739}
740
7b871568
MG
741static int
742xtensa_coprocessor_register_group (struct reggroup *group)
743{
744 int i;
745
746 for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
747 if (group == xtensa_cp[i])
748 return i;
749
750 return -1;
751}
ca3bf3bd
DJ
752
753#define SAVE_REST_FLAGS (XTENSA_REGISTER_FLAGS_READABLE \
754 | XTENSA_REGISTER_FLAGS_WRITABLE \
755 | XTENSA_REGISTER_FLAGS_VOLATILE)
756
757#define SAVE_REST_VALID (XTENSA_REGISTER_FLAGS_READABLE \
758 | XTENSA_REGISTER_FLAGS_WRITABLE)
759
760static int
761xtensa_register_reggroup_p (struct gdbarch *gdbarch,
762 int regnum,
763 struct reggroup *group)
764{
6b50c0b0 765 xtensa_register_t* reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
ca3bf3bd
DJ
766 xtensa_register_type_t type = reg->type;
767 xtensa_register_group_t rg = reg->group;
7b871568 768 int cp_number;
ca3bf3bd
DJ
769
770 /* First, skip registers that are not visible to this target
771 (unknown and unmapped registers when not using ISS). */
772
773 if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
774 return 0;
775 if (group == all_reggroup)
776 return 1;
777 if (group == xtensa_ar_reggroup)
778 return rg & xtRegisterGroupAddrReg;
779 if (group == xtensa_user_reggroup)
780 return rg & xtRegisterGroupUser;
781 if (group == float_reggroup)
782 return rg & xtRegisterGroupFloat;
783 if (group == general_reggroup)
784 return rg & xtRegisterGroupGeneral;
785 if (group == float_reggroup)
786 return rg & xtRegisterGroupFloat;
787 if (group == system_reggroup)
788 return rg & xtRegisterGroupState;
789 if (group == vector_reggroup || group == xtensa_vectra_reggroup)
790 return rg & xtRegisterGroupVectra;
791 if (group == save_reggroup || group == restore_reggroup)
6b50c0b0 792 return (regnum < gdbarch_num_regs (gdbarch)
ca3bf3bd 793 && (reg->flags & SAVE_REST_FLAGS) == SAVE_REST_VALID);
7b871568
MG
794 if ((cp_number = xtensa_coprocessor_register_group (group)) >= 0)
795 return rg & (xtRegisterGroupCP0 << cp_number);
ca3bf3bd
DJ
796 else
797 return 1;
798}
799
800
ca3bf3bd
DJ
801/* Supply register REGNUM from the buffer specified by GREGS and LEN
802 in the general-purpose register set REGSET to register cache
bdb4c075 803 REGCACHE. If REGNUM is -1 do this for all registers in REGSET. */
ca3bf3bd
DJ
804
805static void
806xtensa_supply_gregset (const struct regset *regset,
807 struct regcache *rc,
808 int regnum,
809 const void *gregs,
810 size_t len)
811{
812 const xtensa_elf_gregset_t *regs = gregs;
6b50c0b0 813 struct gdbarch *gdbarch = get_regcache_arch (rc);
ca3bf3bd
DJ
814 int i;
815
816 DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...) \n", regnum);
817
6b50c0b0
UW
818 if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
819 regcache_raw_supply (rc, gdbarch_pc_regnum (gdbarch), (char *) &regs->pc);
820 if (regnum == gdbarch_ps_regnum (gdbarch) || regnum == -1)
821 regcache_raw_supply (rc, gdbarch_ps_regnum (gdbarch), (char *) &regs->ps);
822 if (regnum == gdbarch_tdep (gdbarch)->wb_regnum || regnum == -1)
823 regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->wb_regnum,
304fe255 824 (char *) &regs->windowbase);
6b50c0b0
UW
825 if (regnum == gdbarch_tdep (gdbarch)->ws_regnum || regnum == -1)
826 regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->ws_regnum,
304fe255 827 (char *) &regs->windowstart);
6b50c0b0
UW
828 if (regnum == gdbarch_tdep (gdbarch)->lbeg_regnum || regnum == -1)
829 regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->lbeg_regnum,
304fe255 830 (char *) &regs->lbeg);
6b50c0b0
UW
831 if (regnum == gdbarch_tdep (gdbarch)->lend_regnum || regnum == -1)
832 regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->lend_regnum,
304fe255 833 (char *) &regs->lend);
6b50c0b0
UW
834 if (regnum == gdbarch_tdep (gdbarch)->lcount_regnum || regnum == -1)
835 regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->lcount_regnum,
304fe255 836 (char *) &regs->lcount);
6b50c0b0
UW
837 if (regnum == gdbarch_tdep (gdbarch)->sar_regnum || regnum == -1)
838 regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->sar_regnum,
304fe255 839 (char *) &regs->sar);
6b50c0b0
UW
840 if (regnum >=gdbarch_tdep (gdbarch)->ar_base
841 && regnum < gdbarch_tdep (gdbarch)->ar_base
842 + gdbarch_tdep (gdbarch)->num_aregs)
304fe255
UW
843 regcache_raw_supply (rc, regnum,
844 (char *) &regs->ar[regnum - gdbarch_tdep
6b50c0b0 845 (gdbarch)->ar_base]);
ca3bf3bd
DJ
846 else if (regnum == -1)
847 {
6b50c0b0
UW
848 for (i = 0; i < gdbarch_tdep (gdbarch)->num_aregs; ++i)
849 regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->ar_base + i,
304fe255 850 (char *) &regs->ar[i]);
ca3bf3bd
DJ
851 }
852}
853
854
855/* Xtensa register set. */
856
857static struct regset
858xtensa_gregset =
859{
860 NULL,
861 xtensa_supply_gregset
862};
863
864
bdb4c075
MG
865/* Return the appropriate register set for the core
866 section identified by SECT_NAME and SECT_SIZE. */
ca3bf3bd
DJ
867
868static const struct regset *
869xtensa_regset_from_core_section (struct gdbarch *core_arch,
870 const char *sect_name,
871 size_t sect_size)
872{
873 DEBUGTRACE ("xtensa_regset_from_core_section "
874 "(..., sect_name==\"%s\", sect_size==%x) \n",
ec20a626 875 sect_name, (unsigned int) sect_size);
ca3bf3bd
DJ
876
877 if (strcmp (sect_name, ".reg") == 0
878 && sect_size >= sizeof(xtensa_elf_gregset_t))
879 return &xtensa_gregset;
880
881 return NULL;
882}
883
884
bdb4c075 885/* Handling frames. */
ca3bf3bd 886
bdb4c075
MG
887/* Number of registers to save in case of Windowed ABI. */
888#define XTENSA_NUM_SAVED_AREGS 12
ca3bf3bd 889
bdb4c075
MG
890/* Frame cache part for Windowed ABI. */
891typedef struct xtensa_windowed_frame_cache
ca3bf3bd 892{
ee967b5f
MG
893 int wb; /* WINDOWBASE of the previous frame. */
894 int callsize; /* Call size of this frame. */
895 int ws; /* WINDOWSTART of the previous frame. It keeps track of
896 life windows only. If there is no bit set for the
897 window, that means it had been already spilled
898 because of window overflow. */
899
900 /* Spilled A-registers from the previous frame.
901 AREGS[i] == -1, if corresponding AR is alive. */
ca3bf3bd 902 CORE_ADDR aregs[XTENSA_NUM_SAVED_AREGS];
bdb4c075
MG
903} xtensa_windowed_frame_cache_t;
904
905/* Call0 ABI Definitions. */
906
907#define C0_MAXOPDS 3 /* Maximum number of operands for prologue analysis. */
908#define C0_NREGS 16 /* Number of A-registers to track. */
909#define C0_CLESV 12 /* Callee-saved registers are here and up. */
910#define C0_SP 1 /* Register used as SP. */
911#define C0_FP 15 /* Register used as FP. */
912#define C0_RA 0 /* Register used as return address. */
913#define C0_ARGS 2 /* Register used as first arg/retval. */
914#define C0_NARGS 6 /* Number of A-regs for args/retvals. */
915
916/* Each element of xtensa_call0_frame_cache.c0_rt[] describes for each
917 A-register where the current content of the reg came from (in terms
918 of an original reg and a constant). Negative values of c0_rt[n].fp_reg
919 mean that the orignal content of the register was saved to the stack.
920 c0_rt[n].fr.ofs is NOT the offset from the frame base because we don't
921 know where SP will end up until the entire prologue has been analyzed. */
922
923#define C0_CONST -1 /* fr_reg value if register contains a constant. */
924#define C0_INEXP -2 /* fr_reg value if inexpressible as reg + offset. */
925#define C0_NOSTK -1 /* to_stk value if register has not been stored. */
926
927extern xtensa_isa xtensa_default_isa;
928
929typedef struct xtensa_c0reg
930{
931 int fr_reg; /* original register from which register content
932 is derived, or C0_CONST, or C0_INEXP. */
933 int fr_ofs; /* constant offset from reg, or immediate value. */
934 int to_stk; /* offset from original SP to register (4-byte aligned),
935 or C0_NOSTK if register has not been saved. */
936} xtensa_c0reg_t;
937
938
939/* Frame cache part for Call0 ABI. */
940typedef struct xtensa_call0_frame_cache
941{
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 xtensa_c0reg_t c0_rt[C0_NREGS]; /* Register tracking information. */
947} xtensa_call0_frame_cache_t;
948
949typedef struct xtensa_frame_cache
950{
ee967b5f 951 CORE_ADDR base; /* Stack pointer of this frame. */
bdb4c075 952 CORE_ADDR pc; /* PC at the entry point to the function. */
ee967b5f 953 CORE_ADDR ra; /* The raw return address (without CALLINC). */
9f61f19b 954 CORE_ADDR ps; /* The PS register of this frame. */
ee967b5f 955 CORE_ADDR prev_sp; /* Stack Pointer of the previous frame. */
bdb4c075
MG
956 int call0; /* It's a call0 framework (else windowed). */
957 union
958 {
959 xtensa_windowed_frame_cache_t wd; /* call0 == false. */
960 xtensa_call0_frame_cache_t c0; /* call0 == true. */
961 };
ca3bf3bd
DJ
962} xtensa_frame_cache_t;
963
964
965static struct xtensa_frame_cache *
bdb4c075 966xtensa_alloc_frame_cache (int windowed)
ca3bf3bd
DJ
967{
968 xtensa_frame_cache_t *cache;
969 int i;
970
971 DEBUGTRACE ("xtensa_alloc_frame_cache ()\n");
972
973 cache = FRAME_OBSTACK_ZALLOC (xtensa_frame_cache_t);
974
975 cache->base = 0;
976 cache->pc = 0;
977 cache->ra = 0;
ca3bf3bd 978 cache->ps = 0;
ca3bf3bd 979 cache->prev_sp = 0;
bdb4c075
MG
980 cache->call0 = !windowed;
981 if (cache->call0)
982 {
983 cache->c0.c0_frmsz = -1;
984 cache->c0.c0_hasfp = 0;
985 cache->c0.fp_regnum = -1;
986 cache->c0.c0_fp = -1;
ca3bf3bd 987
bdb4c075
MG
988 for (i = 0; i < C0_NREGS; i++)
989 {
990 cache->c0.c0_rt[i].fr_reg = i;
991 cache->c0.c0_rt[i].fr_ofs = 0;
992 cache->c0.c0_rt[i].to_stk = C0_NOSTK;
993 }
994 }
995 else
996 {
997 cache->wd.wb = 0;
ee967b5f 998 cache->wd.ws = 0;
bdb4c075 999 cache->wd.callsize = -1;
ca3bf3bd 1000
bdb4c075
MG
1001 for (i = 0; i < XTENSA_NUM_SAVED_AREGS; i++)
1002 cache->wd.aregs[i] = -1;
1003 }
ca3bf3bd
DJ
1004 return cache;
1005}
1006
1007
1008static CORE_ADDR
1009xtensa_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
1010{
1011 return address & ~15;
1012}
1013
1014
1015static CORE_ADDR
1016xtensa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1017{
ff7a4c00 1018 gdb_byte buf[8];
0dfff4cb 1019 CORE_ADDR pc;
ca3bf3bd
DJ
1020
1021 DEBUGTRACE ("xtensa_unwind_pc (next_frame = %p)\n", next_frame);
1022
6b50c0b0 1023 frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
0dfff4cb 1024 pc = extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
ca3bf3bd 1025
0dfff4cb 1026 DEBUGINFO ("[xtensa_unwind_pc] pc = 0x%08x\n", (unsigned int) pc);
ca3bf3bd 1027
0dfff4cb 1028 return pc;
ca3bf3bd
DJ
1029}
1030
1031
1032static struct frame_id
5142f611 1033xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
ca3bf3bd
DJ
1034{
1035 CORE_ADDR pc, fp;
ca3bf3bd 1036
5142f611 1037 /* THIS-FRAME is a dummy frame. Return a frame ID of that frame. */
ca3bf3bd 1038
5142f611
MG
1039 pc = get_frame_pc (this_frame);
1040 fp = get_frame_register_unsigned
1041 (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
ca3bf3bd
DJ
1042
1043 /* Make dummy frame ID unique by adding a constant. */
bdb4c075 1044 return frame_id_build (fp + SP_ALIGNMENT, pc);
ca3bf3bd
DJ
1045}
1046
ee967b5f
MG
1047/* Returns the best guess about which register is a frame pointer
1048 for the function containing CURRENT_PC. */
1049
1050#define XTENSA_ISA_BSZ 32 /* Instruction buffer size. */
1051
1052static unsigned int
1053xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
1054{
1055#define RETURN_FP goto done
1056
1057 unsigned int fp_regnum = gdbarch_tdep (gdbarch)->a0_base + 1;
1058 CORE_ADDR start_addr;
1059 xtensa_isa isa;
1060 xtensa_insnbuf ins, slot;
1061 char ibuf[XTENSA_ISA_BSZ];
1062 CORE_ADDR ia, bt, ba;
1063 xtensa_format ifmt;
1064 int ilen, islots, is;
1065 xtensa_opcode opc;
1066 const char *opcname;
1067
1068 find_pc_partial_function (current_pc, NULL, &start_addr, NULL);
1069 if (start_addr == 0)
1070 return fp_regnum;
1071
1072 if (!xtensa_default_isa)
1073 xtensa_default_isa = xtensa_isa_init (0, 0);
1074 isa = xtensa_default_isa;
1075 gdb_assert (XTENSA_ISA_BSZ >= xtensa_isa_maxlength (isa));
1076 ins = xtensa_insnbuf_alloc (isa);
1077 slot = xtensa_insnbuf_alloc (isa);
1078 ba = 0;
1079
1080 for (ia = start_addr, bt = ia; ia < current_pc ; ia += ilen)
1081 {
1082 if (ia + xtensa_isa_maxlength (isa) > bt)
1083 {
1084 ba = ia;
1085 bt = (ba + XTENSA_ISA_BSZ) < current_pc
1086 ? ba + XTENSA_ISA_BSZ : current_pc;
1087 read_memory (ba, ibuf, bt - ba);
1088 }
1089
1090 xtensa_insnbuf_from_chars (isa, ins, &ibuf[ia-ba], 0);
1091 ifmt = xtensa_format_decode (isa, ins);
1092 if (ifmt == XTENSA_UNDEFINED)
1093 RETURN_FP;
1094 ilen = xtensa_format_length (isa, ifmt);
1095 if (ilen == XTENSA_UNDEFINED)
1096 RETURN_FP;
1097 islots = xtensa_format_num_slots (isa, ifmt);
1098 if (islots == XTENSA_UNDEFINED)
1099 RETURN_FP;
1100
1101 for (is = 0; is < islots; ++is)
1102 {
1103 if (xtensa_format_get_slot (isa, ifmt, is, ins, slot))
1104 RETURN_FP;
1105
1106 opc = xtensa_opcode_decode (isa, ifmt, is, slot);
1107 if (opc == XTENSA_UNDEFINED)
1108 RETURN_FP;
1109
1110 opcname = xtensa_opcode_name (isa, opc);
1111
1112 if (strcasecmp (opcname, "mov.n") == 0
1113 || strcasecmp (opcname, "or") == 0)
1114 {
1115 unsigned int register_operand;
1116
1117 /* Possible candidate for setting frame pointer
1118 from A1. This is what we are looking for. */
1119
1120 if (xtensa_operand_get_field (isa, opc, 1, ifmt,
1121 is, slot, &register_operand) != 0)
1122 RETURN_FP;
1123 if (xtensa_operand_decode (isa, opc, 1, &register_operand) != 0)
1124 RETURN_FP;
1125 if (register_operand == 1) /* Mov{.n} FP A1. */
1126 {
1127 if (xtensa_operand_get_field (isa, opc, 0, ifmt, is, slot,
1128 &register_operand) != 0)
1129 RETURN_FP;
1130 if (xtensa_operand_decode (isa, opc, 0,
1131 &register_operand) != 0)
1132 RETURN_FP;
1133
1134 fp_regnum = gdbarch_tdep (gdbarch)->a0_base + register_operand;
1135 RETURN_FP;
1136 }
1137 }
1138
1139 if (
1140 /* We have problems decoding the memory. */
1141 opcname == NULL
1142 || strcasecmp (opcname, "ill") == 0
1143 || strcasecmp (opcname, "ill.n") == 0
1144 /* Hit planted breakpoint. */
1145 || strcasecmp (opcname, "break") == 0
1146 || strcasecmp (opcname, "break.n") == 0
1147 /* Flow control instructions finish prologue. */
1148 || xtensa_opcode_is_branch (isa, opc) > 0
1149 || xtensa_opcode_is_jump (isa, opc) > 0
1150 || xtensa_opcode_is_loop (isa, opc) > 0
1151 || xtensa_opcode_is_call (isa, opc) > 0
1152 || strcasecmp (opcname, "simcall") == 0
1153 || strcasecmp (opcname, "syscall") == 0)
1154 /* Can not continue analysis. */
1155 RETURN_FP;
1156 }
1157 }
1158done:
1159 xtensa_insnbuf_free(isa, slot);
1160 xtensa_insnbuf_free(isa, ins);
1161 return fp_regnum;
1162}
1163
bdb4c075
MG
1164/* The key values to identify the frame using "cache" are
1165
ee967b5f 1166 cache->base = SP (or best guess about FP) of this frame;
bdb4c075
MG
1167 cache->pc = entry-PC (entry point of the frame function);
1168 cache->prev_sp = SP of the previous frame.
1169*/
1170
1171static void
5142f611 1172call0_frame_cache (struct frame_info *this_frame,
bdb4c075 1173 xtensa_frame_cache_t *cache,
9f61f19b 1174 CORE_ADDR pc, CORE_ADDR litbase);
ca3bf3bd
DJ
1175
1176static struct xtensa_frame_cache *
5142f611 1177xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
ca3bf3bd
DJ
1178{
1179 xtensa_frame_cache_t *cache;
ca3bf3bd 1180 CORE_ADDR ra, wb, ws, pc, sp, ps;
5142f611 1181 struct gdbarch *gdbarch = get_frame_arch (this_frame);
ee967b5f 1182 unsigned int fp_regnum;
ca3bf3bd 1183 char op1;
bdb4c075 1184 int windowed;
ca3bf3bd 1185
ca3bf3bd
DJ
1186 if (*this_cache)
1187 return *this_cache;
1188
9f61f19b
MG
1189 ps = get_frame_register_unsigned (this_frame, gdbarch_ps_regnum (gdbarch));
1190 windowed = windowing_enabled (ps);
bdb4c075 1191
ca3bf3bd 1192 /* Get pristine xtensa-frame. */
bdb4c075 1193 cache = xtensa_alloc_frame_cache (windowed);
ca3bf3bd
DJ
1194 *this_cache = cache;
1195
9f61f19b 1196 pc = get_frame_register_unsigned (this_frame, gdbarch_pc_regnum (gdbarch));
ca3bf3bd 1197
bdb4c075 1198 if (windowed)
ca3bf3bd 1199 {
bdb4c075 1200 /* Get WINDOWBASE, WINDOWSTART, and PS registers. */
5142f611
MG
1201 wb = get_frame_register_unsigned (this_frame,
1202 gdbarch_tdep (gdbarch)->wb_regnum);
1203 ws = get_frame_register_unsigned (this_frame,
1204 gdbarch_tdep (gdbarch)->ws_regnum);
ca3bf3bd 1205
bdb4c075 1206 op1 = read_memory_integer (pc, 1);
91d8eb23 1207 if (XTENSA_IS_ENTRY (gdbarch, op1))
ca3bf3bd 1208 {
bdb4c075 1209 int callinc = CALLINC (ps);
5142f611
MG
1210 ra = get_frame_register_unsigned
1211 (this_frame, gdbarch_tdep (gdbarch)->a0_base + callinc * 4);
bdb4c075
MG
1212
1213 /* ENTRY hasn't been executed yet, therefore callsize is still 0. */
1214 cache->wd.callsize = 0;
1215 cache->wd.wb = wb;
1216 cache->wd.ws = ws;
5142f611
MG
1217 cache->prev_sp = get_frame_register_unsigned
1218 (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
ee967b5f
MG
1219
1220 /* This only can be the outermost frame since we are
1221 just about to execute ENTRY. SP hasn't been set yet.
1222 We can assume any frame size, because it does not
1223 matter, and, let's fake frame base in cache. */
1224 cache->base = cache->prev_sp + 16;
1225
1226 cache->pc = pc;
1227 cache->ra = (cache->pc & 0xc0000000) | (ra & 0x3fffffff);
1228 cache->ps = (ps & ~PS_CALLINC_MASK)
1229 | ((WINSIZE(ra)/4) << PS_CALLINC_SHIFT);
1230
1231 return cache;
bdb4c075
MG
1232 }
1233 else
1234 {
ee967b5f 1235 fp_regnum = xtensa_scan_prologue (gdbarch, pc);
5142f611
MG
1236 ra = get_frame_register_unsigned (this_frame,
1237 gdbarch_tdep (gdbarch)->a0_base);
bdb4c075 1238 cache->wd.callsize = WINSIZE (ra);
304fe255 1239 cache->wd.wb = (wb - cache->wd.callsize / 4)
6b50c0b0 1240 & (gdbarch_tdep (gdbarch)->num_aregs / 4 - 1);
bdb4c075 1241 cache->wd.ws = ws & ~(1 << wb);
ca3bf3bd 1242
5142f611 1243 cache->pc = get_frame_func (this_frame);
ee967b5f
MG
1244 cache->ra = (cache->pc & 0xc0000000) | (ra & 0x3fffffff);
1245 cache->ps = (ps & ~PS_CALLINC_MASK)
1246 | ((WINSIZE(ra)/4) << PS_CALLINC_SHIFT);
1247 }
bdb4c075
MG
1248
1249 if (cache->wd.ws == 0)
ca3bf3bd 1250 {
bdb4c075 1251 int i;
ca3bf3bd 1252
bdb4c075 1253 /* Set A0...A3. */
5142f611
MG
1254 sp = get_frame_register_unsigned
1255 (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1) - 16;
bdb4c075
MG
1256
1257 for (i = 0; i < 4; i++, sp += 4)
1258 {
1259 cache->wd.aregs[i] = sp;
1260 }
ca3bf3bd 1261
bdb4c075 1262 if (cache->wd.callsize > 4)
ca3bf3bd 1263 {
bdb4c075 1264 /* Set A4...A7/A11. */
ee967b5f
MG
1265 /* Get the SP of the frame previous to the previous one.
1266 To achieve this, we have to dereference SP twice. */
bdb4c075 1267 sp = (CORE_ADDR) read_memory_integer (sp - 12, 4);
94a0e877 1268 sp = (CORE_ADDR) read_memory_integer (sp - 12, 4);
bdb4c075
MG
1269 sp -= cache->wd.callsize * 4;
1270
ee967b5f 1271 for ( i = 4; i < cache->wd.callsize; i++, sp += 4)
bdb4c075
MG
1272 {
1273 cache->wd.aregs[i] = sp;
1274 }
ca3bf3bd
DJ
1275 }
1276 }
ca3bf3bd 1277
bdb4c075
MG
1278 if ((cache->prev_sp == 0) && ( ra != 0 ))
1279 /* If RA is equal to 0 this frame is an outermost frame. Leave
1280 cache->prev_sp unchanged marking the boundary of the frame stack. */
ca3bf3bd 1281 {
ee967b5f 1282 if ((cache->wd.ws & (1 << cache->wd.wb)) == 0)
bdb4c075
MG
1283 {
1284 /* Register window overflow already happened.
1285 We can read caller's SP from the proper spill loction. */
5142f611
MG
1286 sp = get_frame_register_unsigned
1287 (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
ee967b5f 1288 cache->prev_sp = read_memory_integer (sp - 12, 4);
bdb4c075
MG
1289 }
1290 else
1291 {
1292 /* Read caller's frame SP directly from the previous window. */
ee967b5f 1293 int regnum = arreg_number
91d8eb23 1294 (gdbarch, gdbarch_tdep (gdbarch)->a0_base + 1,
304fe255 1295 cache->wd.wb);
ca3bf3bd 1296
9f61f19b 1297 cache->prev_sp = get_frame_register_unsigned (this_frame, regnum);
bdb4c075 1298 }
ca3bf3bd
DJ
1299 }
1300 }
bdb4c075
MG
1301 else /* Call0 framework. */
1302 {
9f61f19b
MG
1303 unsigned int litbase_regnum = gdbarch_tdep (gdbarch)->litbase_regnum;
1304 CORE_ADDR litbase = (litbase_regnum == -1)
1305 ? 0 : get_frame_register_unsigned (this_frame, litbase_regnum);
1306
1307 call0_frame_cache (this_frame, cache, pc, litbase);
ee967b5f 1308 fp_regnum = cache->c0.fp_regnum;
bdb4c075 1309 }
ca3bf3bd 1310
5142f611 1311 cache->base = get_frame_register_unsigned (this_frame, fp_regnum);
ca3bf3bd 1312
ca3bf3bd
DJ
1313 return cache;
1314}
1315
ca3bf3bd 1316static void
5142f611 1317xtensa_frame_this_id (struct frame_info *this_frame,
ca3bf3bd
DJ
1318 void **this_cache,
1319 struct frame_id *this_id)
1320{
1321 struct xtensa_frame_cache *cache =
5142f611 1322 xtensa_frame_cache (this_frame, this_cache);
ca3bf3bd
DJ
1323
1324 if (cache->prev_sp == 0)
1325 return;
1326
5142f611 1327 (*this_id) = frame_id_build (cache->prev_sp, cache->pc);
bdb4c075 1328}
ca3bf3bd 1329
5142f611
MG
1330static struct value *
1331xtensa_frame_prev_register (struct frame_info *this_frame,
ca3bf3bd 1332 void **this_cache,
5142f611 1333 int regnum)
ca3bf3bd 1334{
5142f611
MG
1335 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1336 struct xtensa_frame_cache *cache;
1337 ULONGEST saved_reg = 0;
ca3bf3bd
DJ
1338 int done = 1;
1339
5142f611
MG
1340 if (*this_cache == NULL)
1341 *this_cache = xtensa_frame_cache (this_frame, this_cache);
1342 cache = *this_cache;
ca3bf3bd 1343
6b50c0b0 1344 if (regnum ==gdbarch_pc_regnum (gdbarch))
bdb4c075 1345 saved_reg = cache->ra;
6b50c0b0 1346 else if (regnum == gdbarch_tdep (gdbarch)->a0_base + 1)
bdb4c075
MG
1347 saved_reg = cache->prev_sp;
1348 else if (!cache->call0)
ca3bf3bd 1349 {
6b50c0b0 1350 if (regnum == gdbarch_tdep (gdbarch)->ws_regnum)
ee967b5f 1351 saved_reg = cache->wd.ws;
6b50c0b0 1352 else if (regnum == gdbarch_tdep (gdbarch)->wb_regnum)
bdb4c075 1353 saved_reg = cache->wd.wb;
6b50c0b0 1354 else if (regnum == gdbarch_ps_regnum (gdbarch))
bdb4c075 1355 saved_reg = cache->ps;
ca3bf3bd 1356 else
bdb4c075 1357 done = 0;
ca3bf3bd 1358 }
ca3bf3bd
DJ
1359 else
1360 done = 0;
1361
1362 if (done)
5142f611 1363 return frame_unwind_got_constant (this_frame, regnum, saved_reg);
ca3bf3bd 1364
bdb4c075 1365 if (!cache->call0) /* Windowed ABI. */
ca3bf3bd 1366 {
ee967b5f
MG
1367 /* Convert A-register numbers to AR-register numbers,
1368 if we deal with A-register. */
94a0e877 1369 if (regnum >= gdbarch_tdep (gdbarch)->a0_base
6b50c0b0 1370 && regnum <= gdbarch_tdep (gdbarch)->a0_base + 15)
ee967b5f 1371 regnum = arreg_number (gdbarch, regnum, cache->wd.wb);
ca3bf3bd 1372
ee967b5f 1373 /* Check, if we deal with AR-register saved on stack. */
6b50c0b0
UW
1374 if (regnum >= gdbarch_tdep (gdbarch)->ar_base
1375 && regnum <= (gdbarch_tdep (gdbarch)->ar_base
1376 + gdbarch_tdep (gdbarch)->num_aregs))
bdb4c075 1377 {
ee967b5f 1378 int areg = areg_number (gdbarch, regnum, cache->wd.wb);
ca3bf3bd 1379
bdb4c075
MG
1380 if (areg >= 0
1381 && areg < XTENSA_NUM_SAVED_AREGS
1382 && cache->wd.aregs[areg] != -1)
5142f611
MG
1383 return frame_unwind_got_memory (this_frame, regnum,
1384 cache->wd.aregs[areg]);
ca3bf3bd
DJ
1385 }
1386 }
bdb4c075
MG
1387 else /* Call0 ABI. */
1388 {
6b50c0b0
UW
1389 int reg = (regnum >= gdbarch_tdep (gdbarch)->ar_base
1390 && regnum <= (gdbarch_tdep (gdbarch)->ar_base
304fe255 1391 + C0_NREGS))
6b50c0b0 1392 ? regnum - gdbarch_tdep (gdbarch)->ar_base : regnum;
ca3bf3bd 1393
bdb4c075
MG
1394 if (reg < C0_NREGS)
1395 {
1396 CORE_ADDR spe;
1397 int stkofs;
1398
1399 /* If register was saved in the prologue, retrieve it. */
1400 stkofs = cache->c0.c0_rt[reg].to_stk;
1401 if (stkofs != C0_NOSTK)
1402 {
1403 /* Determine SP on entry based on FP. */
1404 spe = cache->c0.c0_fp
1405 - cache->c0.c0_rt[cache->c0.fp_regnum].fr_ofs;
5142f611
MG
1406
1407 return frame_unwind_got_memory (this_frame, regnum, spe + stkofs);
bdb4c075
MG
1408 }
1409 }
1410 }
1411
1412 /* All other registers have been either saved to
1413 the stack or are still alive in the processor. */
ca3bf3bd 1414
5142f611 1415 return frame_unwind_got_register (this_frame, regnum, regnum);
ca3bf3bd
DJ
1416}
1417
1418
1419static const struct frame_unwind
5142f611 1420xtensa_unwind =
ca3bf3bd
DJ
1421{
1422 NORMAL_FRAME,
1423 xtensa_frame_this_id,
5142f611
MG
1424 xtensa_frame_prev_register,
1425 NULL,
1426 default_frame_sniffer
ca3bf3bd
DJ
1427};
1428
ca3bf3bd 1429static CORE_ADDR
5142f611 1430xtensa_frame_base_address (struct frame_info *this_frame, void **this_cache)
ca3bf3bd
DJ
1431{
1432 struct xtensa_frame_cache *cache =
5142f611 1433 xtensa_frame_cache (this_frame, this_cache);
ca3bf3bd
DJ
1434
1435 return cache->base;
1436}
1437
1438static const struct frame_base
1439xtensa_frame_base =
1440{
5142f611 1441 &xtensa_unwind,
ca3bf3bd
DJ
1442 xtensa_frame_base_address,
1443 xtensa_frame_base_address,
1444 xtensa_frame_base_address
1445};
1446
1447
1448static void
1449xtensa_extract_return_value (struct type *type,
1450 struct regcache *regcache,
1451 void *dst)
1452{
6b50c0b0 1453 struct gdbarch *gdbarch = get_regcache_arch (regcache);
ca3bf3bd
DJ
1454 bfd_byte *valbuf = dst;
1455 int len = TYPE_LENGTH (type);
1456 ULONGEST pc, wb;
1457 int callsize, areg;
1458 int offset = 0;
1459
1460 DEBUGTRACE ("xtensa_extract_return_value (...)\n");
1461
1462 gdb_assert(len > 0);
1463
6b50c0b0 1464 if (gdbarch_tdep (gdbarch)->call_abi != CallAbiCall0Only)
bdb4c075
MG
1465 {
1466 /* First, we have to find the caller window in the register file. */
6b50c0b0 1467 regcache_raw_read_unsigned (regcache, gdbarch_pc_regnum (gdbarch), &pc);
91d8eb23 1468 callsize = extract_call_winsize (gdbarch, pc);
ca3bf3bd 1469
bdb4c075
MG
1470 /* On Xtensa, we can return up to 4 words (or 2 for call12). */
1471 if (len > (callsize > 8 ? 8 : 16))
1472 internal_error (__FILE__, __LINE__,
1473 _("cannot extract return value of %d bytes long"), len);
ca3bf3bd 1474
bdb4c075
MG
1475 /* Get the register offset of the return
1476 register (A2) in the caller window. */
304fe255 1477 regcache_raw_read_unsigned
6b50c0b0 1478 (regcache, gdbarch_tdep (gdbarch)->wb_regnum, &wb);
ee967b5f 1479 areg = arreg_number (gdbarch,
91d8eb23 1480 gdbarch_tdep (gdbarch)->a0_base + 2 + callsize, wb);
bdb4c075
MG
1481 }
1482 else
1483 {
1484 /* No windowing hardware - Call0 ABI. */
94a0e877 1485 areg = gdbarch_tdep (gdbarch)->a0_base + C0_ARGS;
bdb4c075 1486 }
ca3bf3bd
DJ
1487
1488 DEBUGINFO ("[xtensa_extract_return_value] areg %d len %d\n", areg, len);
1489
6b50c0b0 1490 if (len < 4 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
ca3bf3bd
DJ
1491 offset = 4 - len;
1492
1493 for (; len > 0; len -= 4, areg++, valbuf += 4)
1494 {
1495 if (len < 4)
1496 regcache_raw_read_part (regcache, areg, offset, len, valbuf);
1497 else
1498 regcache_raw_read (regcache, areg, valbuf);
1499 }
1500}
1501
1502
1503static void
1504xtensa_store_return_value (struct type *type,
1505 struct regcache *regcache,
1506 const void *dst)
1507{
6b50c0b0 1508 struct gdbarch *gdbarch = get_regcache_arch (regcache);
ca3bf3bd
DJ
1509 const bfd_byte *valbuf = dst;
1510 unsigned int areg;
1511 ULONGEST pc, wb;
1512 int callsize;
1513 int len = TYPE_LENGTH (type);
1514 int offset = 0;
1515
1516 DEBUGTRACE ("xtensa_store_return_value (...)\n");
1517
6b50c0b0 1518 if (gdbarch_tdep (gdbarch)->call_abi != CallAbiCall0Only)
bdb4c075 1519 {
6b50c0b0
UW
1520 regcache_raw_read_unsigned
1521 (regcache, gdbarch_tdep (gdbarch)->wb_regnum, &wb);
1522 regcache_raw_read_unsigned (regcache, gdbarch_pc_regnum (gdbarch), &pc);
91d8eb23 1523 callsize = extract_call_winsize (gdbarch, pc);
ca3bf3bd 1524
bdb4c075
MG
1525 if (len > (callsize > 8 ? 8 : 16))
1526 internal_error (__FILE__, __LINE__,
1527 _("unimplemented for this length: %d"),
1528 TYPE_LENGTH (type));
ee967b5f
MG
1529 areg = arreg_number (gdbarch,
1530 gdbarch_tdep (gdbarch)->a0_base + 2 + callsize, wb);
ca3bf3bd 1531
bdb4c075 1532 DEBUGTRACE ("[xtensa_store_return_value] callsize %d wb %d\n",
ca3bf3bd 1533 callsize, (int) wb);
bdb4c075
MG
1534 }
1535 else
1536 {
94a0e877 1537 areg = gdbarch_tdep (gdbarch)->a0_base + C0_ARGS;
bdb4c075 1538 }
ca3bf3bd 1539
6b50c0b0 1540 if (len < 4 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
ca3bf3bd
DJ
1541 offset = 4 - len;
1542
ca3bf3bd
DJ
1543 for (; len > 0; len -= 4, areg++, valbuf += 4)
1544 {
1545 if (len < 4)
1546 regcache_raw_write_part (regcache, areg, offset, len, valbuf);
1547 else
1548 regcache_raw_write (regcache, areg, valbuf);
1549 }
1550}
1551
1552
bdb4c075 1553static enum return_value_convention
ca3bf3bd 1554xtensa_return_value (struct gdbarch *gdbarch,
c055b101 1555 struct type *func_type,
ca3bf3bd
DJ
1556 struct type *valtype,
1557 struct regcache *regcache,
1558 gdb_byte *readbuf,
1559 const gdb_byte *writebuf)
1560{
bdb4c075 1561 /* Structures up to 16 bytes are returned in registers. */
ca3bf3bd
DJ
1562
1563 int struct_return = ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
1564 || TYPE_CODE (valtype) == TYPE_CODE_UNION
1565 || TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
1566 && TYPE_LENGTH (valtype) > 16);
1567
1568 if (struct_return)
1569 return RETURN_VALUE_STRUCT_CONVENTION;
1570
1571 DEBUGTRACE ("xtensa_return_value(...)\n");
1572
1573 if (writebuf != NULL)
1574 {
1575 xtensa_store_return_value (valtype, regcache, writebuf);
1576 }
1577
1578 if (readbuf != NULL)
1579 {
1580 gdb_assert (!struct_return);
1581 xtensa_extract_return_value (valtype, regcache, readbuf);
1582 }
1583 return RETURN_VALUE_REGISTER_CONVENTION;
1584}
1585
1586
1587/* DUMMY FRAME */
1588
1589static CORE_ADDR
1590xtensa_push_dummy_call (struct gdbarch *gdbarch,
1591 struct value *function,
1592 struct regcache *regcache,
1593 CORE_ADDR bp_addr,
1594 int nargs,
1595 struct value **args,
1596 CORE_ADDR sp,
1597 int struct_return,
1598 CORE_ADDR struct_addr)
1599{
1600 int i;
1601 int size, onstack_size;
ff7a4c00 1602 gdb_byte *buf = (gdb_byte *) alloca (16);
ca3bf3bd
DJ
1603 CORE_ADDR ra, ps;
1604 struct argument_info
1605 {
1606 const bfd_byte *contents;
1607 int length;
1608 int onstack; /* onstack == 0 => in reg */
1609 int align; /* alignment */
1610 union
1611 {
1612 int offset; /* stack offset if on stack */
1613 int regno; /* regno if in register */
1614 } u;
1615 };
1616
1617 struct argument_info *arg_info =
1618 (struct argument_info *) alloca (nargs * sizeof (struct argument_info));
1619
1620 CORE_ADDR osp = sp;
1621
1622 DEBUGTRACE ("xtensa_push_dummy_call (...)\n");
1623
1624 if (xtensa_debug_level > 3)
1625 {
1626 int i;
1627 DEBUGINFO ("[xtensa_push_dummy_call] nargs = %d\n", nargs);
1628 DEBUGINFO ("[xtensa_push_dummy_call] sp=0x%x, struct_return=%d, "
1629 "struct_addr=0x%x\n",
1630 (int) sp, (int) struct_return, (int) struct_addr);
1631
1632 for (i = 0; i < nargs; i++)
1633 {
1634 struct value *arg = args[i];
1635 struct type *arg_type = check_typedef (value_type (arg));
ec20a626
UW
1636 fprintf_unfiltered (gdb_stdlog, "%2d: 0x%lx %3d ",
1637 i, (unsigned long) arg, TYPE_LENGTH (arg_type));
ca3bf3bd
DJ
1638 switch (TYPE_CODE (arg_type))
1639 {
1640 case TYPE_CODE_INT:
1641 fprintf_unfiltered (gdb_stdlog, "int");
1642 break;
1643 case TYPE_CODE_STRUCT:
1644 fprintf_unfiltered (gdb_stdlog, "struct");
1645 break;
1646 default:
1647 fprintf_unfiltered (gdb_stdlog, "%3d", TYPE_CODE (arg_type));
1648 break;
1649 }
ec20a626
UW
1650 fprintf_unfiltered (gdb_stdlog, " 0x%lx\n",
1651 (unsigned long) value_contents (arg));
ca3bf3bd
DJ
1652 }
1653 }
1654
1655 /* First loop: collect information.
1656 Cast into type_long. (This shouldn't happen often for C because
1657 GDB already does this earlier.) It's possible that GDB could
1658 do it all the time but it's harmless to leave this code here. */
1659
1660 size = 0;
1661 onstack_size = 0;
1662 i = 0;
1663
1664 if (struct_return)
1665 size = REGISTER_SIZE;
1666
1667 for (i = 0; i < nargs; i++)
1668 {
1669 struct argument_info *info = &arg_info[i];
1670 struct value *arg = args[i];
1671 struct type *arg_type = check_typedef (value_type (arg));
1672
1673 switch (TYPE_CODE (arg_type))
1674 {
1675 case TYPE_CODE_INT:
1676 case TYPE_CODE_BOOL:
1677 case TYPE_CODE_CHAR:
1678 case TYPE_CODE_RANGE:
1679 case TYPE_CODE_ENUM:
1680
1681 /* Cast argument to long if necessary as the mask does it too. */
0dfff4cb
UW
1682 if (TYPE_LENGTH (arg_type)
1683 < TYPE_LENGTH (builtin_type (gdbarch)->builtin_long))
ca3bf3bd 1684 {
0dfff4cb 1685 arg_type = builtin_type (gdbarch)->builtin_long;
ca3bf3bd
DJ
1686 arg = value_cast (arg_type, arg);
1687 }
bdb4c075
MG
1688 /* Aligment is equal to the type length for the basic types. */
1689 info->align = TYPE_LENGTH (arg_type);
ca3bf3bd
DJ
1690 break;
1691
1692 case TYPE_CODE_FLT:
1693
1694 /* Align doubles correctly. */
0dfff4cb
UW
1695 if (TYPE_LENGTH (arg_type)
1696 == TYPE_LENGTH (builtin_type (gdbarch)->builtin_double))
1697 info->align = TYPE_LENGTH (builtin_type (gdbarch)->builtin_double);
ca3bf3bd 1698 else
0dfff4cb 1699 info->align = TYPE_LENGTH (builtin_type (gdbarch)->builtin_long);
ca3bf3bd
DJ
1700 break;
1701
1702 case TYPE_CODE_STRUCT:
1703 default:
0dfff4cb 1704 info->align = TYPE_LENGTH (builtin_type (gdbarch)->builtin_long);
ca3bf3bd
DJ
1705 break;
1706 }
1707 info->length = TYPE_LENGTH (arg_type);
1708 info->contents = value_contents (arg);
1709
1710 /* Align size and onstack_size. */
1711 size = (size + info->align - 1) & ~(info->align - 1);
1712 onstack_size = (onstack_size + info->align - 1) & ~(info->align - 1);
1713
91d8eb23 1714 if (size + info->length > REGISTER_SIZE * ARG_NOF (gdbarch))
ca3bf3bd
DJ
1715 {
1716 info->onstack = 1;
1717 info->u.offset = onstack_size;
1718 onstack_size += info->length;
1719 }
1720 else
1721 {
1722 info->onstack = 0;
91d8eb23 1723 info->u.regno = ARG_1ST (gdbarch) + size / REGISTER_SIZE;
ca3bf3bd
DJ
1724 }
1725 size += info->length;
1726 }
1727
1728 /* Adjust the stack pointer and align it. */
1729 sp = align_down (sp - onstack_size, SP_ALIGNMENT);
1730
bdb4c075 1731 /* Simulate MOVSP, if Windowed ABI. */
6b50c0b0 1732 if ((gdbarch_tdep (gdbarch)->call_abi != CallAbiCall0Only)
304fe255 1733 && (sp != osp))
ca3bf3bd
DJ
1734 {
1735 read_memory (osp - 16, buf, 16);
1736 write_memory (sp - 16, buf, 16);
1737 }
1738
1739 /* Second Loop: Load arguments. */
1740
1741 if (struct_return)
1742 {
1743 store_unsigned_integer (buf, REGISTER_SIZE, struct_addr);
91d8eb23 1744 regcache_cooked_write (regcache, ARG_1ST (gdbarch), buf);
ca3bf3bd
DJ
1745 }
1746
1747 for (i = 0; i < nargs; i++)
1748 {
1749 struct argument_info *info = &arg_info[i];
1750
1751 if (info->onstack)
1752 {
1753 int n = info->length;
1754 CORE_ADDR offset = sp + info->u.offset;
1755
1756 /* Odd-sized structs are aligned to the lower side of a memory
1757 word in big-endian mode and require a shift. This only
1758 applies for structures smaller than one word. */
1759
4c6b5505 1760 if (n < REGISTER_SIZE
6b50c0b0 1761 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
ca3bf3bd
DJ
1762 offset += (REGISTER_SIZE - n);
1763
1764 write_memory (offset, info->contents, info->length);
1765
1766 }
1767 else
1768 {
1769 int n = info->length;
1770 const bfd_byte *cp = info->contents;
1771 int r = info->u.regno;
1772
1773 /* Odd-sized structs are aligned to the lower side of registers in
1774 big-endian mode and require a shift. The odd-sized leftover will
1775 be at the end. Note that this is only true for structures smaller
1776 than REGISTER_SIZE; for larger odd-sized structures the excess
1777 will be left-aligned in the register on both endiannesses. */
1778
4c6b5505 1779 if (n < REGISTER_SIZE
6b50c0b0 1780 && gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
ca3bf3bd
DJ
1781 {
1782 ULONGEST v = extract_unsigned_integer (cp, REGISTER_SIZE);
1783 v = v >> ((REGISTER_SIZE - n) * TARGET_CHAR_BIT);
1784
1785 store_unsigned_integer (buf, REGISTER_SIZE, v);
1786 regcache_cooked_write (regcache, r, buf);
1787
1788 cp += REGISTER_SIZE;
1789 n -= REGISTER_SIZE;
1790 r++;
1791 }
1792 else
1793 while (n > 0)
1794 {
ca3bf3bd
DJ
1795 regcache_cooked_write (regcache, r, cp);
1796
ca3bf3bd
DJ
1797 cp += REGISTER_SIZE;
1798 n -= REGISTER_SIZE;
1799 r++;
1800 }
1801 }
1802 }
1803
ca3bf3bd 1804 /* Set the return address of dummy frame to the dummy address.
bdb4c075 1805 The return address for the current function (in A0) is
ca3bf3bd
DJ
1806 saved in the dummy frame, so we can savely overwrite A0 here. */
1807
6b50c0b0 1808 if (gdbarch_tdep (gdbarch)->call_abi != CallAbiCall0Only)
bdb4c075
MG
1809 {
1810 ra = (bp_addr & 0x3fffffff) | 0x40000000;
6b50c0b0 1811 regcache_raw_read (regcache, gdbarch_ps_regnum (gdbarch), buf);
bdb4c075 1812 ps = extract_unsigned_integer (buf, 4) & ~0x00030000;
304fe255 1813 regcache_cooked_write_unsigned
6b50c0b0 1814 (regcache, gdbarch_tdep (gdbarch)->a0_base + 4, ra);
bdb4c075 1815 regcache_cooked_write_unsigned (regcache,
6b50c0b0 1816 gdbarch_ps_regnum (gdbarch),
bdb4c075 1817 ps | 0x00010000);
94a0e877
MG
1818
1819 /* All the registers have been saved. After executing
1820 dummy call, they all will be restored. So it's safe
1821 to modify WINDOWSTART register to make it look like there
1822 is only one register window corresponding to WINDOWEBASE. */
1823
1824 regcache_raw_read (regcache, gdbarch_tdep (gdbarch)->wb_regnum, buf);
1825 regcache_cooked_write_unsigned (regcache,
1826 gdbarch_tdep (gdbarch)->ws_regnum,
1827 1 << extract_unsigned_integer (buf, 4));
bdb4c075
MG
1828 }
1829 else
1830 {
1831 /* Simulate CALL0: write RA into A0 register. */
304fe255 1832 regcache_cooked_write_unsigned
94a0e877 1833 (regcache, gdbarch_tdep (gdbarch)->a0_base, bp_addr);
bdb4c075 1834 }
ca3bf3bd
DJ
1835
1836 /* Set new stack pointer and return it. */
304fe255 1837 regcache_cooked_write_unsigned (regcache,
6b50c0b0 1838 gdbarch_tdep (gdbarch)->a0_base + 1, sp);
ca3bf3bd
DJ
1839 /* Make dummy frame ID unique by adding a constant. */
1840 return sp + SP_ALIGNMENT;
1841}
1842
1843
1844/* Return a breakpoint for the current location of PC. We always use
1845 the density version if we have density instructions (regardless of the
1846 current instruction at PC), and use regular instructions otherwise. */
1847
1848#define BIG_BREAKPOINT { 0x00, 0x04, 0x00 }
1849#define LITTLE_BREAKPOINT { 0x00, 0x40, 0x00 }
1850#define DENSITY_BIG_BREAKPOINT { 0xd2, 0x0f }
1851#define DENSITY_LITTLE_BREAKPOINT { 0x2d, 0xf0 }
1852
bdb4c075 1853static const unsigned char *
67d57894
MD
1854xtensa_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
1855 int *lenptr)
ca3bf3bd 1856{
ff7a4c00
MG
1857 static unsigned char big_breakpoint[] = BIG_BREAKPOINT;
1858 static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT;
1859 static unsigned char density_big_breakpoint[] = DENSITY_BIG_BREAKPOINT;
1860 static unsigned char density_little_breakpoint[] = DENSITY_LITTLE_BREAKPOINT;
ca3bf3bd
DJ
1861
1862 DEBUGTRACE ("xtensa_breakpoint_from_pc (pc = 0x%08x)\n", (int) *pcptr);
1863
67d57894 1864 if (gdbarch_tdep (gdbarch)->isa_use_density_instructions)
ca3bf3bd 1865 {
67d57894 1866 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
ca3bf3bd
DJ
1867 {
1868 *lenptr = sizeof (density_big_breakpoint);
1869 return density_big_breakpoint;
1870 }
1871 else
1872 {
1873 *lenptr = sizeof (density_little_breakpoint);
1874 return density_little_breakpoint;
1875 }
1876 }
1877 else
1878 {
67d57894 1879 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
ca3bf3bd
DJ
1880 {
1881 *lenptr = sizeof (big_breakpoint);
1882 return big_breakpoint;
1883 }
1884 else
1885 {
1886 *lenptr = sizeof (little_breakpoint);
1887 return little_breakpoint;
1888 }
1889 }
1890}
1891
bdb4c075
MG
1892/* Call0 ABI support routines. */
1893
1894/* Call0 opcode class. Opcodes are preclassified according to what they
1895 mean for Call0 prologue analysis, and their number of significant operands.
1896 The purpose of this is to simplify prologue analysis by separating
1897 instruction decoding (libisa) from the semantics of prologue analysis. */
1898
1899typedef enum {
1900 c0opc_illegal, /* Unknown to libisa (invalid) or 'ill' opcode. */
1901 c0opc_uninteresting, /* Not interesting for Call0 prologue analysis. */
1902 c0opc_flow, /* Flow control insn. */
1903 c0opc_entry, /* ENTRY indicates non-Call0 prologue. */
1904 c0opc_break, /* Debugger software breakpoints. */
1905 c0opc_add, /* Adding two registers. */
1906 c0opc_addi, /* Adding a register and an immediate. */
1907 c0opc_sub, /* Subtracting a register from a register. */
1908 c0opc_mov, /* Moving a register to a register. */
1909 c0opc_movi, /* Moving an immediate to a register. */
1910 c0opc_l32r, /* Loading a literal. */
1911 c0opc_s32i, /* Storing word at fixed offset from a base register. */
1912 c0opc_NrOf /* Number of opcode classifications. */
1913} xtensa_insn_kind;
1914
1915
1916/* Classify an opcode based on what it means for Call0 prologue analysis. */
1917
1918static xtensa_insn_kind
1919call0_classify_opcode (xtensa_isa isa, xtensa_opcode opc)
1920{
1921 const char *opcname;
1922 xtensa_insn_kind opclass = c0opc_uninteresting;
1923
1924 DEBUGTRACE ("call0_classify_opcode (..., opc = %d)\n", opc);
1925
1926 /* Get opcode name and handle special classifications. */
1927
1928 opcname = xtensa_opcode_name (isa, opc);
1929
1930 if (opcname == NULL
1931 || strcasecmp (opcname, "ill") == 0
1932 || strcasecmp (opcname, "ill.n") == 0)
1933 opclass = c0opc_illegal;
1934 else if (strcasecmp (opcname, "break") == 0
1935 || strcasecmp (opcname, "break.n") == 0)
1936 opclass = c0opc_break;
1937 else if (strcasecmp (opcname, "entry") == 0)
1938 opclass = c0opc_entry;
1939 else if (xtensa_opcode_is_branch (isa, opc) > 0
1940 || xtensa_opcode_is_jump (isa, opc) > 0
1941 || xtensa_opcode_is_loop (isa, opc) > 0
1942 || xtensa_opcode_is_call (isa, opc) > 0
1943 || strcasecmp (opcname, "simcall") == 0
1944 || strcasecmp (opcname, "syscall") == 0)
1945 opclass = c0opc_flow;
1946
1947 /* Also, classify specific opcodes that need to be tracked. */
1948 else if (strcasecmp (opcname, "add") == 0
1949 || strcasecmp (opcname, "add.n") == 0)
1950 opclass = c0opc_add;
1951 else if (strcasecmp (opcname, "addi") == 0
1952 || strcasecmp (opcname, "addi.n") == 0
1953 || strcasecmp (opcname, "addmi") == 0)
1954 opclass = c0opc_addi;
1955 else if (strcasecmp (opcname, "sub") == 0)
1956 opclass = c0opc_sub;
1957 else if (strcasecmp (opcname, "mov.n") == 0
1958 || strcasecmp (opcname, "or") == 0) /* Could be 'mov' asm macro. */
1959 opclass = c0opc_mov;
1960 else if (strcasecmp (opcname, "movi") == 0
1961 || strcasecmp (opcname, "movi.n") == 0)
1962 opclass = c0opc_movi;
1963 else if (strcasecmp (opcname, "l32r") == 0)
1964 opclass = c0opc_l32r;
1965 else if (strcasecmp (opcname, "s32i") == 0
1966 || strcasecmp (opcname, "s32i.n") == 0)
1967 opclass = c0opc_s32i;
1968
1969 return opclass;
1970}
1971
1972/* Tracks register movement/mutation for a given operation, which may
1973 be within a bundle. Updates the destination register tracking info
1974 accordingly. The pc is needed only for pc-relative load instructions
1975 (eg. l32r). The SP register number is needed to identify stores to
1976 the stack frame. */
1977
1978static void
1979call0_track_op (xtensa_c0reg_t dst[], xtensa_c0reg_t src[],
1980 xtensa_insn_kind opclass, int nods, unsigned odv[],
9f61f19b 1981 CORE_ADDR pc, CORE_ADDR litbase, int spreg)
bdb4c075 1982{
9f61f19b 1983 unsigned litaddr, litval;
bdb4c075
MG
1984
1985 switch (opclass)
1986 {
1987 case c0opc_addi:
1988 /* 3 operands: dst, src, imm. */
1989 gdb_assert (nods == 3);
1990 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
1991 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs + odv[2];
1992 break;
1993 case c0opc_add:
1994 /* 3 operands: dst, src1, src2. */
1995 gdb_assert (nods == 3);
1996 if (src[odv[1]].fr_reg == C0_CONST)
1997 {
1998 dst[odv[0]].fr_reg = src[odv[2]].fr_reg;
1999 dst[odv[0]].fr_ofs = src[odv[2]].fr_ofs + src[odv[1]].fr_ofs;
2000 }
2001 else if (src[odv[2]].fr_reg == C0_CONST)
2002 {
2003 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
2004 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs + src[odv[2]].fr_ofs;
2005 }
2006 else dst[odv[0]].fr_reg = C0_INEXP;
2007 break;
2008 case c0opc_sub:
2009 /* 3 operands: dst, src1, src2. */
2010 gdb_assert (nods == 3);
2011 if (src[odv[2]].fr_reg == C0_CONST)
2012 {
2013 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
2014 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs - src[odv[2]].fr_ofs;
2015 }
2016 else dst[odv[0]].fr_reg = C0_INEXP;
2017 break;
2018 case c0opc_mov:
2019 /* 2 operands: dst, src [, src]. */
2020 gdb_assert (nods == 2);
2021 dst[odv[0]].fr_reg = src[odv[1]].fr_reg;
2022 dst[odv[0]].fr_ofs = src[odv[1]].fr_ofs;
2023 break;
2024 case c0opc_movi:
2025 /* 2 operands: dst, imm. */
2026 gdb_assert (nods == 2);
2027 dst[odv[0]].fr_reg = C0_CONST;
2028 dst[odv[0]].fr_ofs = odv[1];
2029 break;
2030 case c0opc_l32r:
2031 /* 2 operands: dst, literal offset. */
2032 gdb_assert (nods == 2);
bdb4c075
MG
2033 litaddr = litbase & 1
2034 ? (litbase & ~1) + (signed)odv[1]
2035 : (pc + 3 + (signed)odv[1]) & ~3;
2036 litval = read_memory_integer(litaddr, 4);
2037 dst[odv[0]].fr_reg = C0_CONST;
2038 dst[odv[0]].fr_ofs = litval;
2039 break;
2040 case c0opc_s32i:
2041 /* 3 operands: value, base, offset. */
2042 gdb_assert (nods == 3 && spreg >= 0 && spreg < C0_NREGS);
2043 if (src[odv[1]].fr_reg == spreg /* Store to stack frame. */
2044 && (src[odv[1]].fr_ofs & 3) == 0 /* Alignment preserved. */
2045 && src[odv[0]].fr_reg >= 0 /* Value is from a register. */
2046 && src[odv[0]].fr_ofs == 0 /* Value hasn't been modified. */
2047 && src[src[odv[0]].fr_reg].to_stk == C0_NOSTK) /* First time. */
2048 {
2049 /* ISA encoding guarantees alignment. But, check it anyway. */
2050 gdb_assert ((odv[2] & 3) == 0);
2051 dst[src[odv[0]].fr_reg].to_stk = src[odv[1]].fr_ofs + odv[2];
2052 }
2053 break;
2054 default:
2055 gdb_assert (0);
2056 }
2057}
2058
2059/* Analyze prologue of the function at start address to determine if it uses
2060 the Call0 ABI, and if so track register moves and linear modifications
2061 in the prologue up to the PC or just beyond the prologue, whichever is first.
2062 An 'entry' instruction indicates non-Call0 ABI and the end of the prologue.
2063 The prologue may overlap non-prologue instructions but is guaranteed to end
2064 by the first flow-control instruction (jump, branch, call or return).
2065 Since an optimized function may move information around and change the
2066 stack frame arbitrarily during the prologue, the information is guaranteed
2067 valid only at the point in the function indicated by the PC.
2068 May be used to skip the prologue or identify the ABI, w/o tracking.
2069
2070 Returns: Address of first instruction after prologue, or PC (whichever
2071 is first), or 0, if decoding failed (in libisa).
2072 Input args:
2073 start Start address of function/prologue.
2074 pc Program counter to stop at. Use 0 to continue to end of prologue.
2075 If 0, avoids infinite run-on in corrupt code memory by bounding
2076 the scan to the end of the function if that can be determined.
2077 nregs Number of general registers to track (size of rt[] array).
2078 InOut args:
2079 rt[] Array[nregs] of xtensa_c0reg structures for register tracking info.
2080 If NULL, registers are not tracked.
2081 Output args:
2082 call0 If != NULL, *call0 is set non-zero if Call0 ABI used, else 0
2083 (more accurately, non-zero until 'entry' insn is encountered).
2084
2085 Note that these may produce useful results even if decoding fails
2086 because they begin with default assumptions that analysis may change. */
2087
2088static CORE_ADDR
9f61f19b 2089call0_analyze_prologue (CORE_ADDR start, CORE_ADDR pc, CORE_ADDR litbase,
bdb4c075
MG
2090 int nregs, xtensa_c0reg_t rt[], int *call0)
2091{
2092 CORE_ADDR ia; /* Current insn address in prologue. */
2093 CORE_ADDR ba = 0; /* Current address at base of insn buffer. */
2094 CORE_ADDR bt; /* Current address at top+1 of insn buffer. */
2095 #define BSZ 32 /* Instruction buffer size. */
2096 char ibuf[BSZ]; /* Instruction buffer for decoding prologue. */
2097 xtensa_isa isa; /* libisa ISA handle. */
2098 xtensa_insnbuf ins, slot; /* libisa handle to decoded insn, slot. */
2099 xtensa_format ifmt; /* libisa instruction format. */
2100 int ilen, islots, is; /* Instruction length, nbr slots, current slot. */
2101 xtensa_opcode opc; /* Opcode in current slot. */
2102 xtensa_insn_kind opclass; /* Opcode class for Call0 prologue analysis. */
2103 int nods; /* Opcode number of operands. */
2104 unsigned odv[C0_MAXOPDS]; /* Operand values in order provided by libisa. */
2105 xtensa_c0reg_t *rtmp; /* Register tracking info snapshot. */
2106 int j; /* General loop counter. */
2107 int fail = 0; /* Set non-zero and exit, if decoding fails. */
2108 CORE_ADDR body_pc; /* The PC for the first non-prologue insn. */
2109 CORE_ADDR end_pc; /* The PC for the lust function insn. */
2110
2111 struct symtab_and_line prologue_sal;
2112
2113 DEBUGTRACE ("call0_analyze_prologue (start = 0x%08x, pc = 0x%08x, ...)\n",
2114 (int)start, (int)pc);
2115
2116 /* Try to limit the scan to the end of the function if a non-zero pc
2117 arg was not supplied to avoid probing beyond the end of valid memory.
2118 If memory is full of garbage that classifies as c0opc_uninteresting.
2119 If this fails (eg. if no symbols) pc ends up 0 as it was.
2120 Intialize the Call0 frame and register tracking info.
2121 Assume it's Call0 until an 'entry' instruction is encountered.
2122 Assume we may be in the prologue until we hit a flow control instr. */
2123
2124 rtmp = NULL;
2125 body_pc = INT_MAX;
2126 end_pc = 0;
2127
2128 /* Find out, if we have an information about the prologue from DWARF. */
2129 prologue_sal = find_pc_line (start, 0);
2130 if (prologue_sal.line != 0) /* Found debug info. */
2131 body_pc = prologue_sal.end;
2132
2133 /* If we are going to analyze the prologue in general without knowing about
2134 the current PC, make the best assumtion for the end of the prologue. */
2135 if (pc == 0)
2136 {
2137 find_pc_partial_function (start, 0, NULL, &end_pc);
2138 body_pc = min (end_pc, body_pc);
2139 }
2140 else
2141 body_pc = min (pc, body_pc);
2142
2143 if (call0 != NULL)
2144 *call0 = 1;
2145
2146 if (rt != NULL)
2147 {
2148 rtmp = (xtensa_c0reg_t*) alloca(nregs * sizeof(xtensa_c0reg_t));
2149 /* rt is already initialized in xtensa_alloc_frame_cache(). */
2150 }
2151 else nregs = 0;
2152
94a0e877
MG
2153 if (!xtensa_default_isa)
2154 xtensa_default_isa = xtensa_isa_init (0, 0);
bdb4c075
MG
2155 isa = xtensa_default_isa;
2156 gdb_assert (BSZ >= xtensa_isa_maxlength (isa));
2157 ins = xtensa_insnbuf_alloc (isa);
2158 slot = xtensa_insnbuf_alloc (isa);
2159
2160 for (ia = start, bt = ia; ia < body_pc ; ia += ilen)
2161 {
2162 /* (Re)fill instruction buffer from memory if necessary, but do not
2163 read memory beyond PC to be sure we stay within text section
2164 (this protection only works if a non-zero pc is supplied). */
2165
2166 if (ia + xtensa_isa_maxlength (isa) > bt)
2167 {
2168 ba = ia;
2169 bt = (ba + BSZ) < body_pc ? ba + BSZ : body_pc;
2170 read_memory (ba, ibuf, bt - ba);
2171 }
2172
2173 /* Decode format information. */
2174
2175 xtensa_insnbuf_from_chars (isa, ins, &ibuf[ia-ba], 0);
2176 ifmt = xtensa_format_decode (isa, ins);
2177 if (ifmt == XTENSA_UNDEFINED)
2178 {
2179 fail = 1;
2180 goto done;
2181 }
2182 ilen = xtensa_format_length (isa, ifmt);
2183 if (ilen == XTENSA_UNDEFINED)
2184 {
2185 fail = 1;
2186 goto done;
2187 }
2188 islots = xtensa_format_num_slots (isa, ifmt);
2189 if (islots == XTENSA_UNDEFINED)
2190 {
2191 fail = 1;
2192 goto done;
2193 }
2194
2195 /* Analyze a bundle or a single instruction, using a snapshot of
2196 the register tracking info as input for the entire bundle so that
2197 register changes do not take effect within this bundle. */
ca3bf3bd 2198
bdb4c075
MG
2199 for (j = 0; j < nregs; ++j)
2200 rtmp[j] = rt[j];
2201
2202 for (is = 0; is < islots; ++is)
2203 {
2204 /* Decode a slot and classify the opcode. */
2205
2206 fail = xtensa_format_get_slot (isa, ifmt, is, ins, slot);
2207 if (fail)
2208 goto done;
2209
2210 opc = xtensa_opcode_decode (isa, ifmt, is, slot);
2211 DEBUGVERB ("[call0_analyze_prologue] instr addr = 0x%08x, opc = %d\n",
2212 (unsigned)ia, opc);
2213 if (opc == XTENSA_UNDEFINED)
2214 opclass = c0opc_illegal;
2215 else
2216 opclass = call0_classify_opcode (isa, opc);
2217
2218 /* Decide whether to track this opcode, ignore it, or bail out. */
2219
2220 switch (opclass)
2221 {
2222 case c0opc_illegal:
2223 case c0opc_break:
2224 fail = 1;
2225 goto done;
2226
2227 case c0opc_uninteresting:
2228 continue;
2229
2230 case c0opc_flow:
2231 goto done;
2232
2233 case c0opc_entry:
2234 if (call0 != NULL)
2235 *call0 = 0;
2236 ia += ilen; /* Skip over 'entry' insn. */
2237 goto done;
2238
2239 default:
2240 if (call0 != NULL)
2241 *call0 = 1;
2242 }
2243
2244 /* Only expected opcodes should get this far. */
2245 if (rt == NULL)
2246 continue;
2247
2248 /* Extract and decode the operands. */
2249 nods = xtensa_opcode_num_operands (isa, opc);
2250 if (nods == XTENSA_UNDEFINED)
2251 {
2252 fail = 1;
2253 goto done;
2254 }
2255
2256 for (j = 0; j < nods && j < C0_MAXOPDS; ++j)
2257 {
2258 fail = xtensa_operand_get_field (isa, opc, j, ifmt,
2259 is, slot, &odv[j]);
2260 if (fail)
2261 goto done;
2262
2263 fail = xtensa_operand_decode (isa, opc, j, &odv[j]);
2264 if (fail)
2265 goto done;
2266 }
2267
2268 /* Check operands to verify use of 'mov' assembler macro. */
2269 if (opclass == c0opc_mov && nods == 3)
2270 {
2271 if (odv[2] == odv[1])
2272 nods = 2;
2273 else
2274 {
2275 opclass = c0opc_uninteresting;
2276 continue;
2277 }
2278 }
2279
2280 /* Track register movement and modification for this operation. */
9f61f19b 2281 call0_track_op (rt, rtmp, opclass, nods, odv, ia, litbase, 1);
bdb4c075
MG
2282 }
2283 }
2284done:
2285 DEBUGVERB ("[call0_analyze_prologue] stopped at instr addr 0x%08x, %s\n",
2286 (unsigned)ia, fail ? "failed" : "succeeded");
2287 xtensa_insnbuf_free(isa, slot);
2288 xtensa_insnbuf_free(isa, ins);
2289 return fail ? 0 : ia;
2290}
2291
5142f611 2292/* Initialize frame cache for the current frame in CALL0 ABI. */
bdb4c075
MG
2293
2294static void
5142f611 2295call0_frame_cache (struct frame_info *this_frame,
9f61f19b 2296 xtensa_frame_cache_t *cache, CORE_ADDR pc, CORE_ADDR litbase)
bdb4c075 2297{
5142f611 2298 struct gdbarch *gdbarch = get_frame_arch (this_frame);
bdb4c075
MG
2299 CORE_ADDR start_pc; /* The beginning of the function. */
2300 CORE_ADDR body_pc=UINT_MAX; /* PC, where prologue analysis stopped. */
2301 CORE_ADDR sp, fp, ra;
2302 int fp_regnum, c0_hasfp, c0_frmsz, prev_sp, to_stk;
2303
2304 /* Find the beginning of the prologue of the function containing the PC
2305 and analyze it up to the PC or the end of the prologue. */
2306
2307 if (find_pc_partial_function (pc, NULL, &start_pc, NULL))
2308 {
9f61f19b 2309 body_pc = call0_analyze_prologue (start_pc, pc, litbase, C0_NREGS,
bdb4c075
MG
2310 &cache->c0.c0_rt[0],
2311 &cache->call0);
2312 }
2313
5142f611
MG
2314 sp = get_frame_register_unsigned
2315 (this_frame, gdbarch_tdep (gdbarch)->a0_base + 1);
bdb4c075
MG
2316 fp = sp; /* Assume FP == SP until proven otherwise. */
2317
2318 /* Get the frame information and FP (if used) at the current PC.
2319 If PC is in the prologue, the prologue analysis is more reliable
2320 than DWARF info. We don't not know for sure if PC is in the prologue,
2321 but we know no calls have yet taken place, so we can almost
2322 certainly rely on the prologue analysis. */
2323
2324 if (body_pc <= pc)
2325 {
2326 /* Prologue analysis was successful up to the PC.
2327 It includes the cases when PC == START_PC. */
2328 c0_hasfp = cache->c0.c0_rt[C0_FP].fr_reg == C0_SP;
2329 /* c0_hasfp == true means there is a frame pointer because
2330 we analyzed the prologue and found that cache->c0.c0_rt[C0_FP]
2331 was derived from SP. Otherwise, it would be C0_FP. */
2332 fp_regnum = c0_hasfp ? C0_FP : C0_SP;
2333 c0_frmsz = - cache->c0.c0_rt[fp_regnum].fr_ofs;
6b50c0b0 2334 fp_regnum += gdbarch_tdep (gdbarch)->a0_base;
bdb4c075
MG
2335 }
2336 else /* No data from the prologue analysis. */
2337 {
2338 c0_hasfp = 0;
6b50c0b0 2339 fp_regnum = gdbarch_tdep (gdbarch)->a0_base + C0_SP;
bdb4c075
MG
2340 c0_frmsz = 0;
2341 start_pc = pc;
2342 }
2343
2344 prev_sp = fp + c0_frmsz;
2345
2346 /* Frame size from debug info or prologue tracking does not account for
2347 alloca() and other dynamic allocations. Adjust frame size by FP - SP. */
2348 if (c0_hasfp)
2349 {
5142f611 2350 fp = get_frame_register_unsigned (this_frame, fp_regnum);
bdb4c075
MG
2351
2352 /* Recalculate previous SP. */
2353 prev_sp = fp + c0_frmsz;
2354 /* Update the stack frame size. */
2355 c0_frmsz += fp - sp;
2356 }
2357
2358 /* Get the return address (RA) from the stack if saved,
2359 or try to get it from a register. */
2360
2361 to_stk = cache->c0.c0_rt[C0_RA].to_stk;
2362 if (to_stk != C0_NOSTK)
2363 ra = (CORE_ADDR)
2364 read_memory_integer (sp + c0_frmsz + cache->c0.c0_rt[C0_RA].to_stk, 4);
2365
2366 else if (cache->c0.c0_rt[C0_RA].fr_reg == C0_CONST
2367 && cache->c0.c0_rt[C0_RA].fr_ofs == 0)
2368 {
2369 /* Special case for terminating backtrace at a function that wants to
2370 be seen as the outermost. Such a function will clear it's RA (A0)
2371 register to 0 in the prologue instead of saving its original value. */
2372 ra = 0;
2373 }
2374 else
2375 {
2376 /* RA was copied to another register or (before any function call) may
2377 still be in the original RA register. This is not always reliable:
2378 even in a leaf function, register tracking stops after prologue, and
2379 even in prologue, non-prologue instructions (not tracked) may overwrite
2380 RA or any register it was copied to. If likely in prologue or before
2381 any call, use retracking info and hope for the best (compiler should
2382 have saved RA in stack if not in a leaf function). If not in prologue,
2383 too bad. */
2384
2385 int i;
2386 for (i = 0;
2387 (i < C0_NREGS) &&
2388 (i == C0_RA || cache->c0.c0_rt[i].fr_reg != C0_RA);
2389 ++i);
2390 if (i >= C0_NREGS && cache->c0.c0_rt[C0_RA].fr_reg == C0_RA)
2391 i = C0_RA;
5142f611 2392 if (i < C0_NREGS)
bdb4c075 2393 {
5142f611
MG
2394 ra = get_frame_register_unsigned
2395 (this_frame,
2396 gdbarch_tdep (gdbarch)->a0_base + cache->c0.c0_rt[i].fr_reg);
bdb4c075
MG
2397 }
2398 else ra = 0;
2399 }
2400
2401 cache->pc = start_pc;
2402 cache->ra = ra;
2403 /* RA == 0 marks the outermost frame. Do not go past it. */
2404 cache->prev_sp = (ra != 0) ? prev_sp : 0;
2405 cache->c0.fp_regnum = fp_regnum;
2406 cache->c0.c0_frmsz = c0_frmsz;
2407 cache->c0.c0_hasfp = c0_hasfp;
2408 cache->c0.c0_fp = fp;
2409}
2410
2411
2412/* Skip function prologue.
2413
2414 Return the pc of the first instruction after prologue. GDB calls this to
2415 find the address of the first line of the function or (if there is no line
2416 number information) to skip the prologue for planting breakpoints on
2417 function entries. Use debug info (if present) or prologue analysis to skip
2418 the prologue to achieve reliable debugging behavior. For windowed ABI,
2419 only the 'entry' instruction is skipped. It is not strictly necessary to
2420 skip the prologue (Call0) or 'entry' (Windowed) because xt-gdb knows how to
2421 backtrace at any point in the prologue, however certain potential hazards
2422 are avoided and a more "normal" debugging experience is ensured by
2423 skipping the prologue (can be disabled by defining DONT_SKIP_PROLOG).
2424 For example, if we don't skip the prologue:
2425 - Some args may not yet have been saved to the stack where the debug
2426 info expects to find them (true anyway when only 'entry' is skipped);
2427 - Software breakpoints ('break' instrs) may not have been unplanted
2428 when the prologue analysis is done on initializing the frame cache,
2429 and breaks in the prologue will throw off the analysis.
ca3bf3bd
DJ
2430
2431 If we have debug info ( line-number info, in particular ) we simply skip
2432 the code associated with the first function line effectively skipping
bdb4c075 2433 the prologue code. It works even in cases like
ca3bf3bd
DJ
2434
2435 int main()
2436 { int local_var = 1;
2437 ....
2438 }
2439
2440 because, for this source code, both Xtensa compilers will generate two
2441 separate entries ( with the same line number ) in dwarf line-number
2442 section to make sure there is a boundary between the prologue code and
2443 the rest of the function.
2444
bdb4c075
MG
2445 If there is no debug info, we need to analyze the code. */
2446
2447/* #define DONT_SKIP_PROLOGUE */
ca3bf3bd
DJ
2448
2449CORE_ADDR
6093d2eb 2450xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
ca3bf3bd 2451{
bdb4c075
MG
2452 struct symtab_and_line prologue_sal;
2453 CORE_ADDR body_pc;
2454
ca3bf3bd
DJ
2455 DEBUGTRACE ("xtensa_skip_prologue (start_pc = 0x%08x)\n", (int) start_pc);
2456
bdb4c075
MG
2457#if DONT_SKIP_PROLOGUE
2458 return start_pc;
2459#endif
2460
2461 /* Try to find first body line from debug info. */
2462
2463 prologue_sal = find_pc_line (start_pc, 0);
2464 if (prologue_sal.line != 0) /* Found debug info. */
ca3bf3bd 2465 {
bdb4c075
MG
2466 /* In Call0, it is possible to have a function with only one instruction
2467 ('ret') resulting from a 1-line optimized function that does nothing.
2468 In that case, prologue_sal.end may actually point to the start of the
2469 next function in the text section, causing a breakpoint to be set at
2470 the wrong place. Check if the end address is in a different function,
2471 and if so return the start PC. We know we have symbol info. */
ca3bf3bd 2472
bdb4c075
MG
2473 CORE_ADDR end_func;
2474
2475 find_pc_partial_function (prologue_sal.end, NULL, &end_func, NULL);
2476 if (end_func != start_pc)
ca3bf3bd
DJ
2477 return start_pc;
2478
bdb4c075 2479 return prologue_sal.end;
ca3bf3bd 2480 }
ca3bf3bd 2481
bdb4c075 2482 /* No debug line info. Analyze prologue for Call0 or simply skip ENTRY. */
9f61f19b 2483 body_pc = call0_analyze_prologue(start_pc, 0, 0, 0, NULL, NULL);
bdb4c075
MG
2484 return body_pc != 0 ? body_pc : start_pc;
2485}
ca3bf3bd
DJ
2486
2487/* Verify the current configuration. */
ca3bf3bd
DJ
2488static void
2489xtensa_verify_config (struct gdbarch *gdbarch)
2490{
2491 struct ui_file *log;
2492 struct cleanup *cleanups;
2493 struct gdbarch_tdep *tdep;
2494 long dummy;
2495 char *buf;
2496
2497 tdep = gdbarch_tdep (gdbarch);
2498 log = mem_fileopen ();
2499 cleanups = make_cleanup_ui_file_delete (log);
2500
2501 /* Verify that we got a reasonable number of AREGS. */
2502 if ((tdep->num_aregs & -tdep->num_aregs) != tdep->num_aregs)
bdb4c075
MG
2503 fprintf_unfiltered (log, _("\
2504\n\tnum_aregs: Number of AR registers (%d) is not a power of two!"),
2505 tdep->num_aregs);
ca3bf3bd
DJ
2506
2507 /* Verify that certain registers exist. */
bdb4c075 2508
ca3bf3bd 2509 if (tdep->pc_regnum == -1)
bdb4c075
MG
2510 fprintf_unfiltered (log, _("\n\tpc_regnum: No PC register"));
2511 if (tdep->isa_use_exceptions && tdep->ps_regnum == -1)
2512 fprintf_unfiltered (log, _("\n\tps_regnum: No PS register"));
2513
2514 if (tdep->isa_use_windowed_registers)
2515 {
2516 if (tdep->wb_regnum == -1)
2517 fprintf_unfiltered (log, _("\n\twb_regnum: No WB register"));
2518 if (tdep->ws_regnum == -1)
2519 fprintf_unfiltered (log, _("\n\tws_regnum: No WS register"));
2520 if (tdep->ar_base == -1)
2521 fprintf_unfiltered (log, _("\n\tar_base: No AR registers"));
2522 }
2523
ca3bf3bd 2524 if (tdep->a0_base == -1)
bdb4c075 2525 fprintf_unfiltered (log, _("\n\ta0_base: No Ax registers"));
ca3bf3bd
DJ
2526
2527 buf = ui_file_xstrdup (log, &dummy);
2528 make_cleanup (xfree, buf);
2529 if (strlen (buf) > 0)
2530 internal_error (__FILE__, __LINE__,
2531 _("the following are invalid: %s"), buf);
2532 do_cleanups (cleanups);
2533}
2534
94a0e877
MG
2535
2536/* Derive specific register numbers from the array of registers. */
2537
2538void
2539xtensa_derive_tdep (struct gdbarch_tdep *tdep)
2540{
2541 xtensa_register_t* rmap;
2542 int n, max_size = 4;
2543
2544 tdep->num_regs = 0;
2545 tdep->num_nopriv_regs = 0;
2546
2547/* Special registers 0..255 (core). */
2548#define XTENSA_DBREGN_SREG(n) (0x0200+(n))
2549
2550 for (rmap = tdep->regmap, n = 0; rmap->target_number != -1; n++, rmap++)
2551 {
2552 if (rmap->target_number == 0x0020)
2553 tdep->pc_regnum = n;
2554 else if (rmap->target_number == 0x0100)
2555 tdep->ar_base = n;
2556 else if (rmap->target_number == 0x0000)
2557 tdep->a0_base = n;
2558 else if (rmap->target_number == XTENSA_DBREGN_SREG(72))
2559 tdep->wb_regnum = n;
2560 else if (rmap->target_number == XTENSA_DBREGN_SREG(73))
2561 tdep->ws_regnum = n;
2562 else if (rmap->target_number == XTENSA_DBREGN_SREG(233))
2563 tdep->debugcause_regnum = n;
2564 else if (rmap->target_number == XTENSA_DBREGN_SREG(232))
2565 tdep->exccause_regnum = n;
2566 else if (rmap->target_number == XTENSA_DBREGN_SREG(238))
2567 tdep->excvaddr_regnum = n;
2568 else if (rmap->target_number == XTENSA_DBREGN_SREG(0))
2569 tdep->lbeg_regnum = n;
2570 else if (rmap->target_number == XTENSA_DBREGN_SREG(1))
2571 tdep->lend_regnum = n;
2572 else if (rmap->target_number == XTENSA_DBREGN_SREG(2))
2573 tdep->lcount_regnum = n;
2574 else if (rmap->target_number == XTENSA_DBREGN_SREG(3))
2575 tdep->sar_regnum = n;
2576 else if (rmap->target_number == XTENSA_DBREGN_SREG(5))
2577 tdep->litbase_regnum = n;
2578 else if (rmap->target_number == XTENSA_DBREGN_SREG(230))
2579 tdep->ps_regnum = n;
2580#if 0
2581 else if (rmap->target_number == XTENSA_DBREGN_SREG(226))
2582 tdep->interrupt_regnum = n;
2583 else if (rmap->target_number == XTENSA_DBREGN_SREG(227))
2584 tdep->interrupt2_regnum = n;
2585 else if (rmap->target_number == XTENSA_DBREGN_SREG(224))
2586 tdep->cpenable_regnum = n;
2587#endif
2588
2589 if (rmap->byte_size > max_size)
2590 max_size = rmap->byte_size;
2591 if (rmap->mask != 0 && tdep->num_regs == 0)
2592 tdep->num_regs = n;
2593 /* Find out out how to deal with priveleged registers.
2594
2595 if ((rmap->flags & XTENSA_REGISTER_FLAGS_PRIVILEGED) != 0
2596 && tdep->num_nopriv_regs == 0)
2597 tdep->num_nopriv_regs = n;
2598 */
2599 if ((rmap->flags & XTENSA_REGISTER_FLAGS_PRIVILEGED) != 0
2600 && tdep->num_regs == 0)
2601 tdep->num_regs = n;
2602 }
2603
2604 /* Number of pseudo registers. */
2605 tdep->num_pseudo_regs = n - tdep->num_regs;
2606
2607 /* Empirically determined maximum sizes. */
2608 tdep->max_register_raw_size = max_size;
2609 tdep->max_register_virtual_size = max_size;
2610}
2611
ca3bf3bd
DJ
2612/* Module "constructor" function. */
2613
94a0e877
MG
2614extern struct gdbarch_tdep xtensa_tdep;
2615
ca3bf3bd
DJ
2616static struct gdbarch *
2617xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2618{
2619 struct gdbarch_tdep *tdep;
2620 struct gdbarch *gdbarch;
2621 struct xtensa_abi_handler *abi_handler;
2622
2623 DEBUGTRACE ("gdbarch_init()\n");
2624
2625 /* We have to set the byte order before we call gdbarch_alloc. */
94a0e877 2626 info.byte_order = XCHAL_HAVE_BE ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
ca3bf3bd 2627
94a0e877 2628 tdep = &xtensa_tdep;
ca3bf3bd 2629 gdbarch = gdbarch_alloc (&info, tdep);
94a0e877 2630 xtensa_derive_tdep (tdep);
ca3bf3bd
DJ
2631
2632 /* Verify our configuration. */
2633 xtensa_verify_config (gdbarch);
2634
bdb4c075 2635 /* Pseudo-Register read/write. */
ca3bf3bd
DJ
2636 set_gdbarch_pseudo_register_read (gdbarch, xtensa_pseudo_register_read);
2637 set_gdbarch_pseudo_register_write (gdbarch, xtensa_pseudo_register_write);
2638
2639 /* Set target information. */
2640 set_gdbarch_num_regs (gdbarch, tdep->num_regs);
2641 set_gdbarch_num_pseudo_regs (gdbarch, tdep->num_pseudo_regs);
2642 set_gdbarch_sp_regnum (gdbarch, tdep->a0_base + 1);
2643 set_gdbarch_pc_regnum (gdbarch, tdep->pc_regnum);
2644 set_gdbarch_ps_regnum (gdbarch, tdep->ps_regnum);
2645
ba2b1c56 2646 /* Renumber registers for known formats (stabs and dwarf2). */
ca3bf3bd 2647 set_gdbarch_stab_reg_to_regnum (gdbarch, xtensa_reg_to_regnum);
ca3bf3bd
DJ
2648 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, xtensa_reg_to_regnum);
2649
2650 /* We provide our own function to get register information. */
2651 set_gdbarch_register_name (gdbarch, xtensa_register_name);
2652 set_gdbarch_register_type (gdbarch, xtensa_register_type);
2653
2654 /* To call functions from GDB using dummy frame */
2655 set_gdbarch_push_dummy_call (gdbarch, xtensa_push_dummy_call);
2656
2657 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
2658
2659 set_gdbarch_return_value (gdbarch, xtensa_return_value);
2660
2661 /* Advance PC across any prologue instructions to reach "real" code. */
2662 set_gdbarch_skip_prologue (gdbarch, xtensa_skip_prologue);
2663
2664 /* Stack grows downward. */
2665 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2666
2667 /* Set breakpoints. */
2668 set_gdbarch_breakpoint_from_pc (gdbarch, xtensa_breakpoint_from_pc);
2669
2670 /* After breakpoint instruction or illegal instruction, pc still
2671 points at break instruction, so don't decrement. */
2672 set_gdbarch_decr_pc_after_break (gdbarch, 0);
2673
2674 /* We don't skip args. */
2675 set_gdbarch_frame_args_skip (gdbarch, 0);
2676
2677 set_gdbarch_unwind_pc (gdbarch, xtensa_unwind_pc);
2678
2679 set_gdbarch_frame_align (gdbarch, xtensa_frame_align);
2680
5142f611 2681 set_gdbarch_dummy_id (gdbarch, xtensa_dummy_id);
ca3bf3bd
DJ
2682
2683 /* Frame handling. */
2684 frame_base_set_default (gdbarch, &xtensa_frame_base);
5142f611
MG
2685 frame_unwind_append_unwinder (gdbarch, &xtensa_unwind);
2686 dwarf2_append_unwinders (gdbarch);
ca3bf3bd
DJ
2687
2688 set_gdbarch_print_insn (gdbarch, print_insn_xtensa);
2689
2690 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
2691
2692 xtensa_add_reggroups (gdbarch);
2693 set_gdbarch_register_reggroup_p (gdbarch, xtensa_register_reggroup_p);
2694
2695 set_gdbarch_regset_from_core_section (gdbarch,
2696 xtensa_regset_from_core_section);
2697
ee967b5f
MG
2698 set_solib_svr4_fetch_link_map_offsets
2699 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
2700
ca3bf3bd
DJ
2701 return gdbarch;
2702}
2703
ca3bf3bd 2704static void
6b50c0b0 2705xtensa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
ca3bf3bd
DJ
2706{
2707 error (_("xtensa_dump_tdep(): not implemented"));
2708}
2709
ca3bf3bd
DJ
2710void
2711_initialize_xtensa_tdep (void)
2712{
2713 struct cmd_list_element *c;
2714
2715 gdbarch_register (bfd_arch_xtensa, xtensa_gdbarch_init, xtensa_dump_tdep);
2716 xtensa_init_reggroups ();
2717
2718 add_setshow_zinteger_cmd ("xtensa",
2719 class_maintenance,
2720 &xtensa_debug_level, _("\
2721Set Xtensa debugging."), _("\
2722Show Xtensa debugging."), _("\
2723When non-zero, Xtensa-specific debugging is enabled. \
2724Can be 1, 2, 3, or 4 indicating the level of debugging."),
2725 NULL,
2726 NULL,
2727 &setdebuglist, &showdebuglist);
2728}
This page took 0.357038 seconds and 4 git commands to generate.