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