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