| 1 | /* Target-machine dependent code for the AMD 29000 |
| 2 | Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc. |
| 3 | Contributed by Cygnus Support. Written by Jim Kingdon. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "gdbcore.h" |
| 23 | #include "frame.h" |
| 24 | #include "value.h" |
| 25 | #include "symtab.h" |
| 26 | #include "inferior.h" |
| 27 | #include "gdbcmd.h" |
| 28 | |
| 29 | /* If all these bits in an instruction word are zero, it is a "tag word" |
| 30 | which precedes a function entry point and gives stack traceback info. |
| 31 | This used to be defined as 0xff000000, but that treated 0x00000deb as |
| 32 | a tag word, while it is really used as a breakpoint. */ |
| 33 | #define TAGWORD_ZERO_MASK 0xff00f800 |
| 34 | |
| 35 | extern CORE_ADDR text_start; /* FIXME, kludge... */ |
| 36 | |
| 37 | /* The user-settable top of the register stack in virtual memory. We |
| 38 | won't attempt to access any stored registers above this address, if set |
| 39 | nonzero. */ |
| 40 | |
| 41 | static CORE_ADDR rstack_high_address = UINT_MAX; |
| 42 | |
| 43 | /* Structure to hold cached info about function prologues. */ |
| 44 | struct prologue_info |
| 45 | { |
| 46 | CORE_ADDR pc; /* First addr after fn prologue */ |
| 47 | unsigned rsize, msize; /* register stack frame size, mem stack ditto */ |
| 48 | unsigned mfp_used : 1; /* memory frame pointer used */ |
| 49 | unsigned rsize_valid : 1; /* Validity bits for the above */ |
| 50 | unsigned msize_valid : 1; |
| 51 | unsigned mfp_valid : 1; |
| 52 | }; |
| 53 | |
| 54 | /* Examine the prologue of a function which starts at PC. Return |
| 55 | the first addess past the prologue. If MSIZE is non-NULL, then |
| 56 | set *MSIZE to the memory stack frame size. If RSIZE is non-NULL, |
| 57 | then set *RSIZE to the register stack frame size (not including |
| 58 | incoming arguments and the return address & frame pointer stored |
| 59 | with them). If no prologue is found, *RSIZE is set to zero. |
| 60 | If no prologue is found, or a prologue which doesn't involve |
| 61 | allocating a memory stack frame, then set *MSIZE to zero. |
| 62 | |
| 63 | Note that both msize and rsize are in bytes. This is not consistent |
| 64 | with the _User's Manual_ with respect to rsize, but it is much more |
| 65 | convenient. |
| 66 | |
| 67 | If MFP_USED is non-NULL, *MFP_USED is set to nonzero if a memory |
| 68 | frame pointer is being used. */ |
| 69 | CORE_ADDR |
| 70 | examine_prologue (pc, rsize, msize, mfp_used) |
| 71 | CORE_ADDR pc; |
| 72 | unsigned *msize; |
| 73 | unsigned *rsize; |
| 74 | int *mfp_used; |
| 75 | { |
| 76 | long insn; |
| 77 | CORE_ADDR p = pc; |
| 78 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc); |
| 79 | struct prologue_info *mi = 0; |
| 80 | |
| 81 | if (msymbol != NULL) |
| 82 | mi = (struct prologue_info *) msymbol -> info; |
| 83 | |
| 84 | if (mi != 0) |
| 85 | { |
| 86 | int valid = 1; |
| 87 | if (rsize != NULL) |
| 88 | { |
| 89 | *rsize = mi->rsize; |
| 90 | valid &= mi->rsize_valid; |
| 91 | } |
| 92 | if (msize != NULL) |
| 93 | { |
| 94 | *msize = mi->msize; |
| 95 | valid &= mi->msize_valid; |
| 96 | } |
| 97 | if (mfp_used != NULL) |
| 98 | { |
| 99 | *mfp_used = mi->mfp_used; |
| 100 | valid &= mi->mfp_valid; |
| 101 | } |
| 102 | if (valid) |
| 103 | return mi->pc; |
| 104 | } |
| 105 | |
| 106 | if (rsize != NULL) |
| 107 | *rsize = 0; |
| 108 | if (msize != NULL) |
| 109 | *msize = 0; |
| 110 | if (mfp_used != NULL) |
| 111 | *mfp_used = 0; |
| 112 | |
| 113 | /* Prologue must start with subtracting a constant from gr1. |
| 114 | Normally this is sub gr1,gr1,<rsize * 4>. */ |
| 115 | insn = read_memory_integer (p, 4); |
| 116 | if ((insn & 0xffffff00) != 0x25010100) |
| 117 | { |
| 118 | /* If the frame is large, instead of a single instruction it |
| 119 | might be a pair of instructions: |
| 120 | const <reg>, <rsize * 4> |
| 121 | sub gr1,gr1,<reg> |
| 122 | */ |
| 123 | int reg; |
| 124 | /* Possible value for rsize. */ |
| 125 | unsigned int rsize0; |
| 126 | |
| 127 | if ((insn & 0xff000000) != 0x03000000) |
| 128 | { |
| 129 | p = pc; |
| 130 | goto done; |
| 131 | } |
| 132 | reg = (insn >> 8) & 0xff; |
| 133 | rsize0 = (((insn >> 8) & 0xff00) | (insn & 0xff)); |
| 134 | p += 4; |
| 135 | insn = read_memory_integer (p, 4); |
| 136 | if ((insn & 0xffffff00) != 0x24010100 |
| 137 | || (insn & 0xff) != reg) |
| 138 | { |
| 139 | p = pc; |
| 140 | goto done; |
| 141 | } |
| 142 | if (rsize != NULL) |
| 143 | *rsize = rsize0; |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | if (rsize != NULL) |
| 148 | *rsize = (insn & 0xff); |
| 149 | } |
| 150 | p += 4; |
| 151 | |
| 152 | /* Next instruction must be asgeu V_SPILL,gr1,rab. |
| 153 | * We don't check the vector number to allow for kernel debugging. The |
| 154 | * kernel will use a different trap number. |
| 155 | */ |
| 156 | insn = read_memory_integer (p, 4); |
| 157 | if ((insn & 0xff00ffff) != (0x5e000100|RAB_HW_REGNUM)) |
| 158 | { |
| 159 | p = pc; |
| 160 | goto done; |
| 161 | } |
| 162 | p += 4; |
| 163 | |
| 164 | /* Next instruction usually sets the frame pointer (lr1) by adding |
| 165 | <size * 4> from gr1. However, this can (and high C does) be |
| 166 | deferred until anytime before the first function call. So it is |
| 167 | OK if we don't see anything which sets lr1. |
| 168 | To allow for alternate register sets (gcc -mkernel-registers) the msp |
| 169 | register number is a compile time constant. */ |
| 170 | |
| 171 | /* Normally this is just add lr1,gr1,<size * 4>. */ |
| 172 | insn = read_memory_integer (p, 4); |
| 173 | if ((insn & 0xffffff00) == 0x15810100) |
| 174 | p += 4; |
| 175 | else |
| 176 | { |
| 177 | /* However, for large frames it can be |
| 178 | const <reg>, <size *4> |
| 179 | add lr1,gr1,<reg> |
| 180 | */ |
| 181 | int reg; |
| 182 | CORE_ADDR q; |
| 183 | |
| 184 | if ((insn & 0xff000000) == 0x03000000) |
| 185 | { |
| 186 | reg = (insn >> 8) & 0xff; |
| 187 | q = p + 4; |
| 188 | insn = read_memory_integer (q, 4); |
| 189 | if ((insn & 0xffffff00) == 0x14810100 |
| 190 | && (insn & 0xff) == reg) |
| 191 | p = q; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /* Next comes "add lr{<rsize-1>},msp,0", but only if a memory |
| 196 | frame pointer is in use. We just check for add lr<anything>,msp,0; |
| 197 | we don't check this rsize against the first instruction, and |
| 198 | we don't check that the trace-back tag indicates a memory frame pointer |
| 199 | is in use. |
| 200 | To allow for alternate register sets (gcc -mkernel-registers) the msp |
| 201 | register number is a compile time constant. |
| 202 | |
| 203 | The recommended instruction is actually "sll lr<whatever>,msp,0". |
| 204 | We check for that, too. Originally Jim Kingdon's code seemed |
| 205 | to be looking for a "sub" instruction here, but the mask was set |
| 206 | up to lose all the time. */ |
| 207 | insn = read_memory_integer (p, 4); |
| 208 | if (((insn & 0xff80ffff) == (0x15800000|(MSP_HW_REGNUM<<8))) /* add */ |
| 209 | || ((insn & 0xff80ffff) == (0x81800000|(MSP_HW_REGNUM<<8)))) /* sll */ |
| 210 | { |
| 211 | p += 4; |
| 212 | if (mfp_used != NULL) |
| 213 | *mfp_used = 1; |
| 214 | } |
| 215 | |
| 216 | /* Next comes a subtraction from msp to allocate a memory frame, |
| 217 | but only if a memory frame is |
| 218 | being used. We don't check msize against the trace-back tag. |
| 219 | |
| 220 | To allow for alternate register sets (gcc -mkernel-registers) the msp |
| 221 | register number is a compile time constant. |
| 222 | |
| 223 | Normally this is just |
| 224 | sub msp,msp,<msize> |
| 225 | */ |
| 226 | insn = read_memory_integer (p, 4); |
| 227 | if ((insn & 0xffffff00) == |
| 228 | (0x25000000|(MSP_HW_REGNUM<<16)|(MSP_HW_REGNUM<<8))) |
| 229 | { |
| 230 | p += 4; |
| 231 | if (msize != NULL) |
| 232 | *msize = insn & 0xff; |
| 233 | } |
| 234 | else |
| 235 | { |
| 236 | /* For large frames, instead of a single instruction it might |
| 237 | be |
| 238 | |
| 239 | const <reg>, <msize> |
| 240 | consth <reg>, <msize> ; optional |
| 241 | sub msp,msp,<reg> |
| 242 | */ |
| 243 | int reg; |
| 244 | unsigned msize0; |
| 245 | CORE_ADDR q = p; |
| 246 | |
| 247 | if ((insn & 0xff000000) == 0x03000000) |
| 248 | { |
| 249 | reg = (insn >> 8) & 0xff; |
| 250 | msize0 = ((insn >> 8) & 0xff00) | (insn & 0xff); |
| 251 | q += 4; |
| 252 | insn = read_memory_integer (q, 4); |
| 253 | /* Check for consth. */ |
| 254 | if ((insn & 0xff000000) == 0x02000000 |
| 255 | && (insn & 0x0000ff00) == reg) |
| 256 | { |
| 257 | msize0 |= (insn << 8) & 0xff000000; |
| 258 | msize0 |= (insn << 16) & 0x00ff0000; |
| 259 | q += 4; |
| 260 | insn = read_memory_integer (q, 4); |
| 261 | } |
| 262 | /* Check for sub msp,msp,<reg>. */ |
| 263 | if ((insn & 0xffffff00) == |
| 264 | (0x24000000|(MSP_HW_REGNUM<<16)|(MSP_HW_REGNUM<<8)) |
| 265 | && (insn & 0xff) == reg) |
| 266 | { |
| 267 | p = q + 4; |
| 268 | if (msize != NULL) |
| 269 | *msize = msize0; |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | done: |
| 275 | if (msymbol != NULL) |
| 276 | { |
| 277 | if (mi == 0) |
| 278 | { |
| 279 | /* Add a new cache entry. */ |
| 280 | mi = (struct prologue_info *)xmalloc (sizeof (struct prologue_info)); |
| 281 | msymbol -> info = (char *)mi; |
| 282 | mi->rsize_valid = 0; |
| 283 | mi->msize_valid = 0; |
| 284 | mi->mfp_valid = 0; |
| 285 | } |
| 286 | /* else, cache entry exists, but info is incomplete. */ |
| 287 | mi->pc = p; |
| 288 | if (rsize != NULL) |
| 289 | { |
| 290 | mi->rsize = *rsize; |
| 291 | mi->rsize_valid = 1; |
| 292 | } |
| 293 | if (msize != NULL) |
| 294 | { |
| 295 | mi->msize = *msize; |
| 296 | mi->msize_valid = 1; |
| 297 | } |
| 298 | if (mfp_used != NULL) |
| 299 | { |
| 300 | mi->mfp_used = *mfp_used; |
| 301 | mi->mfp_valid = 1; |
| 302 | } |
| 303 | } |
| 304 | return p; |
| 305 | } |
| 306 | |
| 307 | /* Advance PC across any function entry prologue instructions |
| 308 | to reach some "real" code. */ |
| 309 | |
| 310 | CORE_ADDR |
| 311 | skip_prologue (pc) |
| 312 | CORE_ADDR pc; |
| 313 | { |
| 314 | return examine_prologue (pc, (unsigned *)NULL, (unsigned *)NULL, |
| 315 | (int *)NULL); |
| 316 | } |
| 317 | /* |
| 318 | * Examine the one or two word tag at the beginning of a function. |
| 319 | * The tag word is expect to be at 'p', if it is not there, we fail |
| 320 | * by returning 0. The documentation for the tag word was taken from |
| 321 | * page 7-15 of the 29050 User's Manual. We are assuming that the |
| 322 | * m bit is in bit 22 of the tag word, which seems to be the agreed upon |
| 323 | * convention today (1/15/92). |
| 324 | * msize is return in bytes. |
| 325 | */ |
| 326 | static int /* 0/1 - failure/success of finding the tag word */ |
| 327 | examine_tag(p, is_trans, argcount, msize, mfp_used) |
| 328 | CORE_ADDR p; |
| 329 | int *is_trans; |
| 330 | int *argcount; |
| 331 | unsigned *msize; |
| 332 | int *mfp_used; |
| 333 | { |
| 334 | unsigned int tag1, tag2; |
| 335 | |
| 336 | tag1 = read_memory_integer (p, 4); |
| 337 | if ((tag1 & TAGWORD_ZERO_MASK) != 0) /* Not a tag word */ |
| 338 | return 0; |
| 339 | if (tag1 & (1<<23)) /* A two word tag */ |
| 340 | { |
| 341 | tag2 = read_memory_integer (p+4, 4); |
| 342 | if (msize) |
| 343 | *msize = tag2; |
| 344 | } |
| 345 | else /* A one word tag */ |
| 346 | { |
| 347 | if (msize) |
| 348 | *msize = tag1 & 0x7ff; |
| 349 | } |
| 350 | if (is_trans) |
| 351 | *is_trans = ((tag1 & (1<<21)) ? 1 : 0); |
| 352 | if (argcount) |
| 353 | *argcount = (tag1 >> 16) & 0x1f; |
| 354 | if (mfp_used) |
| 355 | *mfp_used = ((tag1 & (1<<22)) ? 1 : 0); |
| 356 | return(1); |
| 357 | } |
| 358 | |
| 359 | /* Initialize the frame. In addition to setting "extra" frame info, |
| 360 | we also set ->frame because we use it in a nonstandard way, and ->pc |
| 361 | because we need to know it to get the other stuff. See the diagram |
| 362 | of stacks and the frame cache in tm-a29k.h for more detail. */ |
| 363 | static void |
| 364 | init_frame_info (innermost_frame, fci) |
| 365 | int innermost_frame; |
| 366 | struct frame_info *fci; |
| 367 | { |
| 368 | CORE_ADDR p; |
| 369 | long insn; |
| 370 | unsigned rsize; |
| 371 | unsigned msize; |
| 372 | int mfp_used, trans; |
| 373 | struct symbol *func; |
| 374 | |
| 375 | p = fci->pc; |
| 376 | |
| 377 | if (innermost_frame) |
| 378 | fci->frame = read_register (GR1_REGNUM); |
| 379 | else |
| 380 | fci->frame = fci->next->frame + fci->next->rsize; |
| 381 | |
| 382 | #if CALL_DUMMY_LOCATION == ON_STACK |
| 383 | This wont work; |
| 384 | #else |
| 385 | if (PC_IN_CALL_DUMMY (p, 0, 0)) |
| 386 | #endif |
| 387 | { |
| 388 | fci->rsize = DUMMY_FRAME_RSIZE; |
| 389 | /* This doesn't matter since we never try to get locals or args |
| 390 | from a dummy frame. */ |
| 391 | fci->msize = 0; |
| 392 | /* Dummy frames always use a memory frame pointer. */ |
| 393 | fci->saved_msp = |
| 394 | read_register_stack_integer (fci->frame + DUMMY_FRAME_RSIZE - 4, 4); |
| 395 | fci->flags |= (TRANSPARENT|MFP_USED); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | func = find_pc_function (p); |
| 400 | if (func != NULL) |
| 401 | p = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); |
| 402 | else |
| 403 | { |
| 404 | /* Search backward to find the trace-back tag. However, |
| 405 | do not trace back beyond the start of the text segment |
| 406 | (just as a sanity check to avoid going into never-never land). */ |
| 407 | while (p >= text_start |
| 408 | && ((insn = read_memory_integer (p, 4)) & TAGWORD_ZERO_MASK) != 0) |
| 409 | p -= 4; |
| 410 | |
| 411 | if (p < text_start) |
| 412 | { |
| 413 | /* Couldn't find the trace-back tag. |
| 414 | Something strange is going on. */ |
| 415 | fci->saved_msp = 0; |
| 416 | fci->rsize = 0; |
| 417 | fci->msize = 0; |
| 418 | fci->flags = TRANSPARENT; |
| 419 | return; |
| 420 | } |
| 421 | else |
| 422 | /* Advance to the first word of the function, i.e. the word |
| 423 | after the trace-back tag. */ |
| 424 | p += 4; |
| 425 | } |
| 426 | /* We've found the start of the function. |
| 427 | * Try looking for a tag word that indicates whether there is a |
| 428 | * memory frame pointer and what the memory stack allocation is. |
| 429 | * If one doesn't exist, try using a more exhaustive search of |
| 430 | * the prologue. For now we don't care about the argcount or |
| 431 | * whether or not the routine is transparent. |
| 432 | */ |
| 433 | if (examine_tag(p-4,&trans,NULL,&msize,&mfp_used)) /* Found a good tag */ |
| 434 | examine_prologue (p, &rsize, 0, 0); |
| 435 | else /* No tag try prologue */ |
| 436 | examine_prologue (p, &rsize, &msize, &mfp_used); |
| 437 | |
| 438 | fci->rsize = rsize; |
| 439 | fci->msize = msize; |
| 440 | fci->flags = 0; |
| 441 | if (mfp_used) |
| 442 | fci->flags |= MFP_USED; |
| 443 | if (trans) |
| 444 | fci->flags |= TRANSPARENT; |
| 445 | if (innermost_frame) |
| 446 | { |
| 447 | fci->saved_msp = read_register (MSP_REGNUM) + msize; |
| 448 | } |
| 449 | else |
| 450 | { |
| 451 | if (mfp_used) |
| 452 | fci->saved_msp = |
| 453 | read_register_stack_integer (fci->frame + rsize - 4, 4); |
| 454 | else |
| 455 | fci->saved_msp = fci->next->saved_msp + msize; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | void |
| 460 | init_extra_frame_info (fci) |
| 461 | struct frame_info *fci; |
| 462 | { |
| 463 | if (fci->next == 0) |
| 464 | /* Assume innermost frame. May produce strange results for "info frame" |
| 465 | but there isn't any way to tell the difference. */ |
| 466 | init_frame_info (1, fci); |
| 467 | else { |
| 468 | /* We're in get_prev_frame_info. |
| 469 | Take care of everything in init_frame_pc. */ |
| 470 | ; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | void |
| 475 | init_frame_pc (fromleaf, fci) |
| 476 | int fromleaf; |
| 477 | struct frame_info *fci; |
| 478 | { |
| 479 | fci->pc = (fromleaf ? SAVED_PC_AFTER_CALL (fci->next) : |
| 480 | fci->next ? FRAME_SAVED_PC (fci->next) : read_pc ()); |
| 481 | init_frame_info (fromleaf, fci); |
| 482 | } |
| 483 | \f |
| 484 | /* Local variables (i.e. LOC_LOCAL) are on the memory stack, with their |
| 485 | offsets being relative to the memory stack pointer (high C) or |
| 486 | saved_msp (gcc). */ |
| 487 | |
| 488 | CORE_ADDR |
| 489 | frame_locals_address (fi) |
| 490 | struct frame_info *fi; |
| 491 | { |
| 492 | if (fi->flags & MFP_USED) |
| 493 | return fi->saved_msp; |
| 494 | else |
| 495 | return fi->saved_msp - fi->msize; |
| 496 | } |
| 497 | \f |
| 498 | /* Routines for reading the register stack. The caller gets to treat |
| 499 | the register stack as a uniform stack in memory, from address $gr1 |
| 500 | straight through $rfb and beyond. */ |
| 501 | |
| 502 | /* Analogous to read_memory except the length is understood to be 4. |
| 503 | Also, myaddr can be NULL (meaning don't bother to read), and |
| 504 | if actual_mem_addr is non-NULL, store there the address that it |
| 505 | was fetched from (or if from a register the offset within |
| 506 | registers). Set *LVAL to lval_memory or lval_register, depending |
| 507 | on where it came from. The contents written into MYADDR are in |
| 508 | target format. */ |
| 509 | void |
| 510 | read_register_stack (memaddr, myaddr, actual_mem_addr, lval) |
| 511 | CORE_ADDR memaddr; |
| 512 | char *myaddr; |
| 513 | CORE_ADDR *actual_mem_addr; |
| 514 | enum lval_type *lval; |
| 515 | { |
| 516 | long rfb = read_register (RFB_REGNUM); |
| 517 | long rsp = read_register (RSP_REGNUM); |
| 518 | |
| 519 | /* If we don't do this 'info register' stops in the middle. */ |
| 520 | if (memaddr >= rstack_high_address) |
| 521 | { |
| 522 | /* a bogus value */ |
| 523 | static char val[] = {~0, ~0, ~0, ~0}; |
| 524 | /* It's in a local register, but off the end of the stack. */ |
| 525 | int regnum = (memaddr - rsp) / 4 + LR0_REGNUM; |
| 526 | if (myaddr != NULL) |
| 527 | { |
| 528 | /* Provide bogusness */ |
| 529 | memcpy (myaddr, val, 4); |
| 530 | } |
| 531 | supply_register(regnum, val); /* More bogusness */ |
| 532 | if (lval != NULL) |
| 533 | *lval = lval_register; |
| 534 | if (actual_mem_addr != NULL) |
| 535 | *actual_mem_addr = REGISTER_BYTE (regnum); |
| 536 | } |
| 537 | /* If it's in the part of the register stack that's in real registers, |
| 538 | get the value from the registers. If it's anywhere else in memory |
| 539 | (e.g. in another thread's saved stack), skip this part and get |
| 540 | it from real live memory. */ |
| 541 | else if (memaddr < rfb && memaddr >= rsp) |
| 542 | { |
| 543 | /* It's in a register. */ |
| 544 | int regnum = (memaddr - rsp) / 4 + LR0_REGNUM; |
| 545 | if (regnum > LR0_REGNUM + 127) |
| 546 | error ("Attempt to read register stack out of range."); |
| 547 | if (myaddr != NULL) |
| 548 | read_register_gen (regnum, myaddr); |
| 549 | if (lval != NULL) |
| 550 | *lval = lval_register; |
| 551 | if (actual_mem_addr != NULL) |
| 552 | *actual_mem_addr = REGISTER_BYTE (regnum); |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | /* It's in the memory portion of the register stack. */ |
| 557 | if (myaddr != NULL) |
| 558 | read_memory (memaddr, myaddr, 4); |
| 559 | if (lval != NULL) |
| 560 | *lval = lval_memory; |
| 561 | if (actual_mem_addr != NULL) |
| 562 | *actual_mem_addr = memaddr; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | /* Analogous to read_memory_integer |
| 567 | except the length is understood to be 4. */ |
| 568 | long |
| 569 | read_register_stack_integer (memaddr, len) |
| 570 | CORE_ADDR memaddr; |
| 571 | int len; |
| 572 | { |
| 573 | char buf[4]; |
| 574 | read_register_stack (memaddr, buf, NULL, NULL); |
| 575 | return extract_signed_integer (buf, 4); |
| 576 | } |
| 577 | |
| 578 | /* Copy 4 bytes from GDB memory at MYADDR into inferior memory |
| 579 | at MEMADDR and put the actual address written into in |
| 580 | *ACTUAL_MEM_ADDR. */ |
| 581 | static void |
| 582 | write_register_stack (memaddr, myaddr, actual_mem_addr) |
| 583 | CORE_ADDR memaddr; |
| 584 | char *myaddr; |
| 585 | CORE_ADDR *actual_mem_addr; |
| 586 | { |
| 587 | long rfb = read_register (RFB_REGNUM); |
| 588 | long rsp = read_register (RSP_REGNUM); |
| 589 | /* If we don't do this 'info register' stops in the middle. */ |
| 590 | if (memaddr >= rstack_high_address) |
| 591 | { |
| 592 | /* It's in a register, but off the end of the stack. */ |
| 593 | if (actual_mem_addr != NULL) |
| 594 | *actual_mem_addr = 0; |
| 595 | } |
| 596 | else if (memaddr < rfb) |
| 597 | { |
| 598 | /* It's in a register. */ |
| 599 | int regnum = (memaddr - rsp) / 4 + LR0_REGNUM; |
| 600 | if (regnum < LR0_REGNUM || regnum > LR0_REGNUM + 127) |
| 601 | error ("Attempt to read register stack out of range."); |
| 602 | if (myaddr != NULL) |
| 603 | write_register (regnum, *(long *)myaddr); |
| 604 | if (actual_mem_addr != NULL) |
| 605 | *actual_mem_addr = 0; |
| 606 | } |
| 607 | else |
| 608 | { |
| 609 | /* It's in the memory portion of the register stack. */ |
| 610 | if (myaddr != NULL) |
| 611 | write_memory (memaddr, myaddr, 4); |
| 612 | if (actual_mem_addr != NULL) |
| 613 | *actual_mem_addr = memaddr; |
| 614 | } |
| 615 | } |
| 616 | \f |
| 617 | /* Find register number REGNUM relative to FRAME and put its |
| 618 | (raw) contents in *RAW_BUFFER. Set *OPTIMIZED if the variable |
| 619 | was optimized out (and thus can't be fetched). If the variable |
| 620 | was fetched from memory, set *ADDRP to where it was fetched from, |
| 621 | otherwise it was fetched from a register. |
| 622 | |
| 623 | The argument RAW_BUFFER must point to aligned memory. */ |
| 624 | void |
| 625 | get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lvalp) |
| 626 | char *raw_buffer; |
| 627 | int *optimized; |
| 628 | CORE_ADDR *addrp; |
| 629 | FRAME frame; |
| 630 | int regnum; |
| 631 | enum lval_type *lvalp; |
| 632 | { |
| 633 | struct frame_info *fi; |
| 634 | CORE_ADDR addr; |
| 635 | enum lval_type lval; |
| 636 | |
| 637 | if (frame == 0) |
| 638 | return; |
| 639 | |
| 640 | fi = get_frame_info (frame); |
| 641 | |
| 642 | /* Once something has a register number, it doesn't get optimized out. */ |
| 643 | if (optimized != NULL) |
| 644 | *optimized = 0; |
| 645 | if (regnum == RSP_REGNUM) |
| 646 | { |
| 647 | if (raw_buffer != NULL) |
| 648 | { |
| 649 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), fi->frame); |
| 650 | } |
| 651 | if (lvalp != NULL) |
| 652 | *lvalp = not_lval; |
| 653 | return; |
| 654 | } |
| 655 | else if (regnum == PC_REGNUM) |
| 656 | { |
| 657 | if (raw_buffer != NULL) |
| 658 | { |
| 659 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), fi->pc); |
| 660 | } |
| 661 | |
| 662 | /* Not sure we have to do this. */ |
| 663 | if (lvalp != NULL) |
| 664 | *lvalp = not_lval; |
| 665 | |
| 666 | return; |
| 667 | } |
| 668 | else if (regnum == MSP_REGNUM) |
| 669 | { |
| 670 | if (raw_buffer != NULL) |
| 671 | { |
| 672 | if (fi->next != NULL) |
| 673 | { |
| 674 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), |
| 675 | fi->next->saved_msp); |
| 676 | } |
| 677 | else |
| 678 | read_register_gen (MSP_REGNUM, raw_buffer); |
| 679 | } |
| 680 | /* The value may have been computed, not fetched. */ |
| 681 | if (lvalp != NULL) |
| 682 | *lvalp = not_lval; |
| 683 | return; |
| 684 | } |
| 685 | else if (regnum < LR0_REGNUM || regnum >= LR0_REGNUM + 128) |
| 686 | { |
| 687 | /* These registers are not saved over procedure calls, |
| 688 | so just print out the current values. */ |
| 689 | if (raw_buffer != NULL) |
| 690 | read_register_gen (regnum, raw_buffer); |
| 691 | if (lvalp != NULL) |
| 692 | *lvalp = lval_register; |
| 693 | if (addrp != NULL) |
| 694 | *addrp = REGISTER_BYTE (regnum); |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | addr = fi->frame + (regnum - LR0_REGNUM) * 4; |
| 699 | if (raw_buffer != NULL) |
| 700 | read_register_stack (addr, raw_buffer, &addr, &lval); |
| 701 | if (lvalp != NULL) |
| 702 | *lvalp = lval; |
| 703 | if (addrp != NULL) |
| 704 | *addrp = addr; |
| 705 | } |
| 706 | \f |
| 707 | |
| 708 | /* Discard from the stack the innermost frame, |
| 709 | restoring all saved registers. */ |
| 710 | |
| 711 | void |
| 712 | pop_frame () |
| 713 | { |
| 714 | FRAME frame = get_current_frame (); |
| 715 | struct frame_info *fi = get_frame_info (frame); |
| 716 | CORE_ADDR rfb = read_register (RFB_REGNUM); |
| 717 | CORE_ADDR gr1 = fi->frame + fi->rsize; |
| 718 | CORE_ADDR lr1; |
| 719 | int i; |
| 720 | |
| 721 | /* If popping a dummy frame, need to restore registers. */ |
| 722 | if (PC_IN_CALL_DUMMY (read_register (PC_REGNUM), |
| 723 | read_register (SP_REGNUM), |
| 724 | FRAME_FP (fi))) |
| 725 | { |
| 726 | int lrnum = LR0_REGNUM + DUMMY_ARG/4; |
| 727 | for (i = 0; i < DUMMY_SAVE_SR128; ++i) |
| 728 | write_register (SR_REGNUM (i + 128),read_register (lrnum++)); |
| 729 | for (i = 0; i < DUMMY_SAVE_SR160; ++i) |
| 730 | write_register (SR_REGNUM(i+160), read_register (lrnum++)); |
| 731 | for (i = 0; i < DUMMY_SAVE_GREGS; ++i) |
| 732 | write_register (RETURN_REGNUM + i, read_register (lrnum++)); |
| 733 | /* Restore the PCs. */ |
| 734 | write_register(PC_REGNUM, read_register (lrnum++)); |
| 735 | write_register(NPC_REGNUM, read_register (lrnum)); |
| 736 | } |
| 737 | |
| 738 | /* Restore the memory stack pointer. */ |
| 739 | write_register (MSP_REGNUM, fi->saved_msp); |
| 740 | /* Restore the register stack pointer. */ |
| 741 | write_register (GR1_REGNUM, gr1); |
| 742 | /* Check whether we need to fill registers. */ |
| 743 | lr1 = read_register (LR0_REGNUM + 1); |
| 744 | if (lr1 > rfb) |
| 745 | { |
| 746 | /* Fill. */ |
| 747 | int num_bytes = lr1 - rfb; |
| 748 | int i; |
| 749 | long word; |
| 750 | write_register (RAB_REGNUM, read_register (RAB_REGNUM) + num_bytes); |
| 751 | write_register (RFB_REGNUM, lr1); |
| 752 | for (i = 0; i < num_bytes; i += 4) |
| 753 | { |
| 754 | /* Note: word is in host byte order. */ |
| 755 | word = read_memory_integer (rfb + i, 4); |
| 756 | write_register (LR0_REGNUM + ((rfb - gr1) % 0x80) + i / 4, word); |
| 757 | } |
| 758 | } |
| 759 | flush_cached_frames (); |
| 760 | set_current_frame (create_new_frame (0, read_pc())); |
| 761 | } |
| 762 | |
| 763 | /* Push an empty stack frame, to record the current PC, etc. */ |
| 764 | |
| 765 | void |
| 766 | push_dummy_frame () |
| 767 | { |
| 768 | long w; |
| 769 | CORE_ADDR rab, gr1; |
| 770 | CORE_ADDR msp = read_register (MSP_REGNUM); |
| 771 | int lrnum, i, saved_lr0; |
| 772 | |
| 773 | |
| 774 | /* Allocate the new frame. */ |
| 775 | gr1 = read_register (GR1_REGNUM) - DUMMY_FRAME_RSIZE; |
| 776 | write_register (GR1_REGNUM, gr1); |
| 777 | |
| 778 | rab = read_register (RAB_REGNUM); |
| 779 | if (gr1 < rab) |
| 780 | { |
| 781 | /* We need to spill registers. */ |
| 782 | int num_bytes = rab - gr1; |
| 783 | CORE_ADDR rfb = read_register (RFB_REGNUM); |
| 784 | int i; |
| 785 | long word; |
| 786 | |
| 787 | write_register (RFB_REGNUM, rfb - num_bytes); |
| 788 | write_register (RAB_REGNUM, gr1); |
| 789 | for (i = 0; i < num_bytes; i += 4) |
| 790 | { |
| 791 | /* Note: word is in target byte order. */ |
| 792 | read_register_gen (LR0_REGNUM + i / 4, (char *) &word); |
| 793 | write_memory (rfb - num_bytes + i, (char *) &word, 4); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | /* There are no arguments in to the dummy frame, so we don't need |
| 798 | more than rsize plus the return address and lr1. */ |
| 799 | write_register (LR0_REGNUM + 1, gr1 + DUMMY_FRAME_RSIZE + 2 * 4); |
| 800 | |
| 801 | /* Set the memory frame pointer. */ |
| 802 | write_register (LR0_REGNUM + DUMMY_FRAME_RSIZE / 4 - 1, msp); |
| 803 | |
| 804 | /* Allocate arg_slop. */ |
| 805 | write_register (MSP_REGNUM, msp - 16 * 4); |
| 806 | |
| 807 | /* Save registers. */ |
| 808 | lrnum = LR0_REGNUM + DUMMY_ARG/4; |
| 809 | for (i = 0; i < DUMMY_SAVE_SR128; ++i) |
| 810 | write_register (lrnum++, read_register (SR_REGNUM (i + 128))); |
| 811 | for (i = 0; i < DUMMY_SAVE_SR160; ++i) |
| 812 | write_register (lrnum++, read_register (SR_REGNUM (i + 160))); |
| 813 | for (i = 0; i < DUMMY_SAVE_GREGS; ++i) |
| 814 | write_register (lrnum++, read_register (RETURN_REGNUM + i)); |
| 815 | /* Save the PCs. */ |
| 816 | write_register (lrnum++, read_register (PC_REGNUM)); |
| 817 | write_register (lrnum, read_register (NPC_REGNUM)); |
| 818 | } |
| 819 | |
| 820 | enum a29k_processor_types processor_type = a29k_unknown; |
| 821 | |
| 822 | void |
| 823 | a29k_get_processor_type () |
| 824 | { |
| 825 | unsigned int cfg_reg = (unsigned int) read_register (CFG_REGNUM); |
| 826 | |
| 827 | /* Most of these don't have freeze mode. */ |
| 828 | processor_type = a29k_no_freeze_mode; |
| 829 | |
| 830 | switch ((cfg_reg >> 28) & 0xf) |
| 831 | { |
| 832 | case 0: |
| 833 | fprintf_filtered (stderr, "Remote debugging an Am29000"); |
| 834 | break; |
| 835 | case 1: |
| 836 | fprintf_filtered (stderr, "Remote debugging an Am29005"); |
| 837 | break; |
| 838 | case 2: |
| 839 | fprintf_filtered (stderr, "Remote debugging an Am29050"); |
| 840 | processor_type = a29k_freeze_mode; |
| 841 | break; |
| 842 | case 3: |
| 843 | fprintf_filtered (stderr, "Remote debugging an Am29035"); |
| 844 | break; |
| 845 | case 4: |
| 846 | fprintf_filtered (stderr, "Remote debugging an Am29030"); |
| 847 | break; |
| 848 | case 5: |
| 849 | fprintf_filtered (stderr, "Remote debugging an Am2920*"); |
| 850 | break; |
| 851 | case 6: |
| 852 | fprintf_filtered (stderr, "Remote debugging an Am2924*"); |
| 853 | break; |
| 854 | case 7: |
| 855 | fprintf_filtered (stderr, "Remote debugging an Am29040"); |
| 856 | break; |
| 857 | default: |
| 858 | fprintf_filtered (stderr, "Remote debugging an unknown Am29k\n"); |
| 859 | /* Don't bother to print the revision. */ |
| 860 | return; |
| 861 | } |
| 862 | fprintf_filtered (stderr, " revision %c\n", 'A' + ((cfg_reg >> 24) & 0x0f)); |
| 863 | } |
| 864 | |
| 865 | void |
| 866 | _initialize_29k() |
| 867 | { |
| 868 | extern CORE_ADDR text_end; |
| 869 | |
| 870 | /* FIXME, there should be a way to make a CORE_ADDR variable settable. */ |
| 871 | add_show_from_set |
| 872 | (add_set_cmd ("rstack_high_address", class_support, var_uinteger, |
| 873 | (char *)&rstack_high_address, |
| 874 | "Set top address in memory of the register stack.\n\ |
| 875 | Attempts to access registers saved above this address will be ignored\n\ |
| 876 | or will produce the value -1.", &setlist), |
| 877 | &showlist); |
| 878 | |
| 879 | /* FIXME, there should be a way to make a CORE_ADDR variable settable. */ |
| 880 | add_show_from_set |
| 881 | (add_set_cmd ("call_scratch_address", class_support, var_uinteger, |
| 882 | (char *)&text_end, |
| 883 | "Set address in memory where small amounts of RAM can be used\n\ |
| 884 | when making function calls into the inferior.", &setlist), |
| 885 | &showlist); |
| 886 | } |