| 1 | /* Parameters for target machine of AMD 29000, for GDB, the GNU debugger. |
| 2 | Copyright 1990, 1991 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 | /* Parameters for an EB29K (a board which plugs into a PC and is |
| 22 | accessed through EBMON software running on the PC, which we |
| 23 | use as we'd use a remote stub (see remote-eb.c). |
| 24 | |
| 25 | If gdb is ported to other 29k machines/systems, the |
| 26 | machine/system-specific parts should be removed from this file (a |
| 27 | la tm-68k.h). */ |
| 28 | |
| 29 | /* Byte order is configurable, but this machine runs big-endian. */ |
| 30 | #define TARGET_BYTE_ORDER BIG_ENDIAN |
| 31 | |
| 32 | /* Floating point uses IEEE representations. */ |
| 33 | #define IEEE_FLOAT |
| 34 | |
| 35 | /* Recognize our magic number. */ |
| 36 | #define BADMAG(x) ((x).f_magic != 0572) |
| 37 | |
| 38 | /* Define this if the C compiler puts an underscore at the front |
| 39 | of external names before giving them to the linker. */ |
| 40 | |
| 41 | #define NAMES_HAVE_UNDERSCORE |
| 42 | |
| 43 | /* Offset from address of function to start of its code. |
| 44 | Zero on most machines. */ |
| 45 | |
| 46 | #define FUNCTION_START_OFFSET 0 |
| 47 | |
| 48 | /* Advance PC across any function entry prologue instructions |
| 49 | to reach some "real" code. */ |
| 50 | |
| 51 | #define SKIP_PROLOGUE(pc) \ |
| 52 | { pc = skip_prologue (pc); } |
| 53 | CORE_ADDR skip_prologue (); |
| 54 | |
| 55 | /* Immediately after a function call, return the saved pc. |
| 56 | Can't go through the frames for this because on some machines |
| 57 | the new frame is not set up until the new function executes |
| 58 | some instructions. */ |
| 59 | |
| 60 | #define SAVED_PC_AFTER_CALL(frame) (read_register (LR0_REGNUM)) |
| 61 | |
| 62 | /* I'm not sure about the exact value of this, but based on looking |
| 63 | at the stack pointer when we get to main this seems to be right. |
| 64 | |
| 65 | This is the register stack; We call it "CONTROL" in GDB for consistency |
| 66 | with Pyramid. */ |
| 67 | #define CONTROL_END_ADDR 0x80200000 |
| 68 | |
| 69 | /* Memory stack. This is for the default register stack size, which is |
| 70 | only 0x800 bytes. Perhaps we should let the user specify stack sizes |
| 71 | (and tell EBMON with the "ZS" command). */ |
| 72 | #define STACK_END_ADDR 0x801ff800 |
| 73 | |
| 74 | /* Stack grows downward. */ |
| 75 | |
| 76 | #define INNER_THAN < |
| 77 | |
| 78 | /* Stack must be aligned on 32-bit word boundaries. */ |
| 79 | #define STACK_ALIGN(ADDR) (((ADDR) + 3) & ~3) |
| 80 | |
| 81 | /* Sequence of bytes for breakpoint instruction. */ |
| 82 | /* ASNEQ 0x50, gr1, gr1 |
| 83 | The trap number 0x50 is chosen arbitrarily. |
| 84 | We let the command line (or previously included files) override this |
| 85 | setting. */ |
| 86 | #ifndef BREAKPOINT |
| 87 | #if TARGET_BYTE_ORDER == BIG_ENDIAN |
| 88 | #define BREAKPOINT {0x72, 0x50, 0x01, 0x01} |
| 89 | #else /* Target is little-endian. */ |
| 90 | #define BREAKPOINT {0x01, 0x01, 0x50, 0x72} |
| 91 | #endif /* Target is little-endian. */ |
| 92 | #endif /* BREAKPOINT */ |
| 93 | |
| 94 | /* Amount PC must be decremented by after a breakpoint. |
| 95 | This is often the number of bytes in BREAKPOINT |
| 96 | but not always. */ |
| 97 | |
| 98 | #define DECR_PC_AFTER_BREAK 0 |
| 99 | |
| 100 | /* Nonzero if instruction at PC is a return instruction. |
| 101 | On the 29k, this is a "jmpi l0" instruction. */ |
| 102 | |
| 103 | #define ABOUT_TO_RETURN(pc) \ |
| 104 | ((read_memory_integer (pc, 4) & 0xff0000ff) == 0xc0000080) |
| 105 | |
| 106 | /* Return 1 if P points to an invalid floating point value. */ |
| 107 | |
| 108 | #define INVALID_FLOAT(p, len) 0 /* Just a first guess; not checked */ |
| 109 | |
| 110 | /* Say how long (ordinary) registers are. */ |
| 111 | |
| 112 | #define REGISTER_TYPE long |
| 113 | |
| 114 | /* Allow the register declarations here to be overridden for remote |
| 115 | kernel debugging. */ |
| 116 | #if !defined (REGISTER_NAMES) |
| 117 | |
| 118 | /* Number of machine registers */ |
| 119 | |
| 120 | #define NUM_REGS 205 |
| 121 | |
| 122 | /* Initializer for an array of names of registers. |
| 123 | There should be NUM_REGS strings in this initializer. |
| 124 | |
| 125 | FIXME, add floating point registers and support here. |
| 126 | |
| 127 | Also note that this list does not attempt to deal with kernel |
| 128 | debugging (in which the first 32 registers are gr64-gr95). */ |
| 129 | |
| 130 | #define REGISTER_NAMES \ |
| 131 | {"gr96", "gr97", "gr98", "gr99", "gr100", "gr101", "gr102", "gr103", "gr104", \ |
| 132 | "gr105", "gr106", "gr107", "gr108", "gr109", "gr110", "gr111", "gr112", \ |
| 133 | "gr113", "gr114", "gr115", "gr116", "gr117", "gr118", "gr119", "gr120", \ |
| 134 | "gr121", "gr122", "gr123", "gr124", "gr125", "gr126", "gr127", \ |
| 135 | "lr0", "lr1", "lr2", "lr3", "lr4", "lr5", "lr6", "lr7", "lr8", "lr9", \ |
| 136 | "lr10", "lr11", "lr12", "lr13", "lr14", "lr15", "lr16", "lr17", "lr18", \ |
| 137 | "lr19", "lr20", "lr21", "lr22", "lr23", "lr24", "lr25", "lr26", "lr27", \ |
| 138 | "lr28", "lr29", "lr30", "lr31", "lr32", "lr33", "lr34", "lr35", "lr36", \ |
| 139 | "lr37", "lr38", "lr39", "lr40", "lr41", "lr42", "lr43", "lr44", "lr45", \ |
| 140 | "lr46", "lr47", "lr48", "lr49", "lr50", "lr51", "lr52", "lr53", "lr54", \ |
| 141 | "lr55", "lr56", "lr57", "lr58", "lr59", "lr60", "lr61", "lr62", "lr63", \ |
| 142 | "lr64", "lr65", "lr66", "lr67", "lr68", "lr69", "lr70", "lr71", "lr72", \ |
| 143 | "lr73", "lr74", "lr75", "lr76", "lr77", "lr78", "lr79", "lr80", "lr81", \ |
| 144 | "lr82", "lr83", "lr84", "lr85", "lr86", "lr87", "lr88", "lr89", "lr90", \ |
| 145 | "lr91", "lr92", "lr93", "lr94", "lr95", "lr96", "lr97", "lr98", "lr99", \ |
| 146 | "lr100", "lr101", "lr102", "lr103", "lr104", "lr105", "lr106", "lr107", \ |
| 147 | "lr108", "lr109", "lr110", "lr111", "lr112", "lr113", "lr114", "lr115", \ |
| 148 | "lr116", "lr117", "lr118", "lr119", "lr120", "lr121", "lr122", "lr123", \ |
| 149 | "lr124", "lr125", "lr126", "lr127", \ |
| 150 | "AI0", "AI1", "AI2", "AI3", "AI4", "AI5", "AI6", "AI7", "AI8", "AI9", \ |
| 151 | "AI10", "AI11", "AI12", "AI13", "AI14", "AI15", "FP", \ |
| 152 | "bp", "fc", "cr", "q", \ |
| 153 | "vab", "ops", "cps", "cfg", "cha", "chd", "chc", "rbp", "tmc", "tmr", \ |
| 154 | "pc0", "pc1", "pc2", "mmu", "lru", "fpe", "inte", "fps", "exo", "gr1", \ |
| 155 | "alu", "ipc", "ipa", "ipb" } |
| 156 | |
| 157 | /* |
| 158 | * Converts an sdb register number to an internal gdb register number. |
| 159 | * Currently under epi, gr96->0...gr127->31...lr0->32...lr127->159, or... |
| 160 | * gr64->0...gr95->31, lr0->32...lr127->159. |
| 161 | */ |
| 162 | #define SDB_REG_TO_REGNUM(value) \ |
| 163 | (((value) >= 96 && (value) <= 127) ? ((value) - 96) : \ |
| 164 | ((value) >= 128 && (value) <= 255) ? ((value) - 128 + LR0_REGNUM) : \ |
| 165 | (value)) |
| 166 | |
| 167 | /* |
| 168 | * Provide the processor register numbers of some registers that are |
| 169 | * expected/written in instructions that might change under different |
| 170 | * register sets. Namely, gcc can compile (-mkernel-registers) so that |
| 171 | * it uses gr64-gr95 in stead of gr96-gr127. |
| 172 | */ |
| 173 | #define MSP_HW_REGNUM 125 /* gr125 */ |
| 174 | #define RAB_HW_REGNUM 126 /* gr126 */ |
| 175 | |
| 176 | /* Convert Processor Special register #x to REGISTER_NAMES register # */ |
| 177 | #define SR_REGNUM(x) \ |
| 178 | ((x) < 15 ? VAB_REGNUM + (x) \ |
| 179 | : (x) >= 128 && (x) < 131 ? IPC_REGNUM + (x) - 128 \ |
| 180 | : (x) == 131 ? Q_REGNUM \ |
| 181 | : (x) == 132 ? ALU_REGNUM \ |
| 182 | : (x) >= 133 && (x) < 136 ? BP_REGNUM + (x) - 133 \ |
| 183 | : (x) >= 160 && (x) < 163 ? FPE_REGNUM + (x) - 160 \ |
| 184 | : (x) == 164 ? EXO_REGNUM \ |
| 185 | : (error ("Internal error in SR_REGNUM"), 0)) |
| 186 | #define GR96_REGNUM 0 |
| 187 | /* Define the return register separately, so it can be overridden for |
| 188 | kernel procedure calling conventions. */ |
| 189 | #define RETURN_REGNUM GR96_REGNUM |
| 190 | #define GR1_REGNUM 200 |
| 191 | /* This needs to be the memory stack pointer, not the register stack pointer, |
| 192 | to make call_function work right. */ |
| 193 | #define SP_REGNUM MSP_REGNUM |
| 194 | #define FP_REGNUM 33 /* lr1 */ |
| 195 | /* Large Return Pointer (gr123). */ |
| 196 | #define LRP_REGNUM (123 - 96 + GR96_REGNUM) |
| 197 | /* Static link pointer (gr124). */ |
| 198 | #define SLP_REGNUM (124 - 96 + GR96_REGNUM) |
| 199 | /* Memory Stack Pointer (gr125). */ |
| 200 | #define MSP_REGNUM (125 - 96 + GR96_REGNUM) |
| 201 | /* Register allocate bound (gr126). */ |
| 202 | #define RAB_REGNUM (126 - 96 + GR96_REGNUM) |
| 203 | /* Register Free Bound (gr127). */ |
| 204 | #define RFB_REGNUM (127 - 96 + GR96_REGNUM) |
| 205 | /* Register Stack Pointer. */ |
| 206 | #define RSP_REGNUM GR1_REGNUM |
| 207 | #define LR0_REGNUM 32 |
| 208 | #define BP_REGNUM 177 |
| 209 | #define FC_REGNUM 178 |
| 210 | #define CR_REGNUM 179 |
| 211 | #define Q_REGNUM 180 |
| 212 | #define VAB_REGNUM 181 |
| 213 | #define OPS_REGNUM (VAB_REGNUM + 1) |
| 214 | #define CPS_REGNUM (VAB_REGNUM + 2) |
| 215 | #define CFG_REGNUM (VAB_REGNUM + 3) |
| 216 | #define CHA_REGNUM (VAB_REGNUM + 4) |
| 217 | #define CHD_REGNUM (VAB_REGNUM + 5) |
| 218 | #define CHC_REGNUM (VAB_REGNUM + 6) |
| 219 | #define RBP_REGNUM (VAB_REGNUM + 7) |
| 220 | #define TMC_REGNUM (VAB_REGNUM + 8) |
| 221 | #define TMR_REGNUM (VAB_REGNUM + 9) |
| 222 | #define NPC_REGNUM (VAB_REGNUM + 10) /* pc0 */ |
| 223 | #define PC_REGNUM (VAB_REGNUM + 11) /* pc1 */ |
| 224 | #define PC2_REGNUM (VAB_REGNUM + 12) |
| 225 | #define MMU_REGNUM (VAB_REGNUM + 13) |
| 226 | #define LRU_REGNUM (VAB_REGNUM + 14) |
| 227 | #define FPE_REGNUM (VAB_REGNUM + 15) |
| 228 | #define INTE_REGNUM (VAB_REGNUM + 16) |
| 229 | #define FPS_REGNUM (VAB_REGNUM + 17) |
| 230 | #define EXO_REGNUM (VAB_REGNUM + 18) |
| 231 | /* gr1 is defined above as 200 = VAB_REGNUM + 19 */ |
| 232 | #define ALU_REGNUM (VAB_REGNUM + 20) |
| 233 | #define PS_REGNUM ALU_REGNUM |
| 234 | #define IPC_REGNUM (VAB_REGNUM + 21) |
| 235 | #define IPA_REGNUM (VAB_REGNUM + 22) |
| 236 | #define IPB_REGNUM (VAB_REGNUM + 23) |
| 237 | |
| 238 | #endif /* !defined(REGISTER_NAMES) */ |
| 239 | |
| 240 | /* Total amount of space needed to store our copies of the machine's |
| 241 | register state, the array `registers'. */ |
| 242 | #define REGISTER_BYTES (NUM_REGS * 4) |
| 243 | |
| 244 | /* Index within `registers' of the first byte of the space for |
| 245 | register N. */ |
| 246 | #define REGISTER_BYTE(N) ((N)*4) |
| 247 | |
| 248 | /* Number of bytes of storage in the actual machine representation |
| 249 | for register N. */ |
| 250 | |
| 251 | /* All regs are 4 bytes. */ |
| 252 | |
| 253 | #define REGISTER_RAW_SIZE(N) (4) |
| 254 | |
| 255 | /* Number of bytes of storage in the program's representation |
| 256 | for register N. */ |
| 257 | |
| 258 | /* All regs are 4 bytes. */ |
| 259 | |
| 260 | #define REGISTER_VIRTUAL_SIZE(N) (4) |
| 261 | |
| 262 | /* Largest value REGISTER_RAW_SIZE can have. */ |
| 263 | |
| 264 | #define MAX_REGISTER_RAW_SIZE (4) |
| 265 | |
| 266 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ |
| 267 | |
| 268 | #define MAX_REGISTER_VIRTUAL_SIZE (4) |
| 269 | |
| 270 | /* Nonzero if register N requires conversion |
| 271 | from raw format to virtual format. */ |
| 272 | |
| 273 | #define REGISTER_CONVERTIBLE(N) (0) |
| 274 | |
| 275 | /* Convert data from raw format for register REGNUM |
| 276 | to virtual format for register REGNUM. */ |
| 277 | |
| 278 | #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \ |
| 279 | { bcopy ((FROM), (TO), 4); } |
| 280 | |
| 281 | /* Convert data from virtual format for register REGNUM |
| 282 | to raw format for register REGNUM. */ |
| 283 | |
| 284 | #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \ |
| 285 | { bcopy ((FROM), (TO), 4); } |
| 286 | |
| 287 | /* Return the GDB type object for the "standard" data type |
| 288 | of data in register N. */ |
| 289 | |
| 290 | #define REGISTER_VIRTUAL_TYPE(N) \ |
| 291 | (((N) == PC_REGNUM || (N) == LRP_REGNUM || (N) == SLP_REGNUM \ |
| 292 | || (N) == MSP_REGNUM || (N) == RAB_REGNUM || (N) == RFB_REGNUM \ |
| 293 | || (N) == GR1_REGNUM || (N) == FP_REGNUM || (N) == LR0_REGNUM \ |
| 294 | || (N) == NPC_REGNUM || (N) == PC2_REGNUM) \ |
| 295 | ? lookup_pointer_type (builtin_type_void) : builtin_type_int) |
| 296 | \f |
| 297 | /* Store the address of the place in which to copy the structure the |
| 298 | subroutine will return. This is called from call_function. */ |
| 299 | /* On the 29k the LRP points to the part of the structure beyond the first |
| 300 | 16 words. */ |
| 301 | #define STORE_STRUCT_RETURN(ADDR, SP) \ |
| 302 | write_register (LRP_REGNUM, (ADDR) + 16 * 4); |
| 303 | |
| 304 | /* Should call_function allocate stack space for a struct return? */ |
| 305 | /* On the 29k objects over 16 words require the caller to allocate space. */ |
| 306 | #define USE_STRUCT_CONVENTION(gcc_p, type) (TYPE_LENGTH (type) > 16 * 4) |
| 307 | |
| 308 | /* Extract from an array REGBUF containing the (raw) register state |
| 309 | a function return value of type TYPE, and copy that, in virtual format, |
| 310 | into VALBUF. */ |
| 311 | |
| 312 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ |
| 313 | { \ |
| 314 | int reg_length = TYPE_LENGTH (TYPE); \ |
| 315 | if (reg_length > 16 * 4) \ |
| 316 | { \ |
| 317 | reg_length = 16 * 4; \ |
| 318 | read_memory (*((int *)(REGBUF) + LRP_REGNUM), (VALBUF) + 16 * 4, \ |
| 319 | TYPE_LENGTH (TYPE) - 16 * 4); \ |
| 320 | } \ |
| 321 | bcopy (((int *)(REGBUF))+RETURN_REGNUM, (VALBUF), reg_length); \ |
| 322 | } |
| 323 | |
| 324 | /* Write into appropriate registers a function return value |
| 325 | of type TYPE, given in virtual format. */ |
| 326 | |
| 327 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ |
| 328 | { \ |
| 329 | int reg_length = TYPE_LENGTH (TYPE); \ |
| 330 | if (reg_length > 16 * 4) \ |
| 331 | { \ |
| 332 | reg_length = 16 * 4; \ |
| 333 | write_memory (read_register (LRP_REGNUM), \ |
| 334 | (char *)(VALBUF) + 16 * 4, \ |
| 335 | TYPE_LENGTH (TYPE) - 16 * 4); \ |
| 336 | } \ |
| 337 | write_register_bytes (REGISTER_BYTE (RETURN_REGNUM), (char *)(VALBUF), \ |
| 338 | TYPE_LENGTH (TYPE)); \ |
| 339 | } |
| 340 | \f |
| 341 | /* The am29k user's guide documents well what the stacks look like. |
| 342 | But what isn't so clear there is how this interracts with the |
| 343 | symbols, or with GDB. |
| 344 | In the following saved_msp, saved memory stack pointer (which functions |
| 345 | as a memory frame pointer), means either |
| 346 | a register containing the memory frame pointer or, in the case of |
| 347 | functions with fixed size memory frames (i.e. those who don't use |
| 348 | alloca()), the result of the calculation msp + msize. |
| 349 | |
| 350 | LOC_ARG, LOC_LOCAL - For GCC, these are relative to saved_msp. |
| 351 | For high C, these are relative to msp (making alloca impossible). |
| 352 | LOC_REGISTER, LOC_REGPARM - The register number is the number at the |
| 353 | time the function is running (after the prologue), or in the case |
| 354 | of LOC_REGPARM, may be a register number in the range 160-175. |
| 355 | |
| 356 | The compilers do things like store an argument into memory, and then put out |
| 357 | a LOC_ARG for it, or put it into global registers and put out a |
| 358 | LOC_REGPARM. Thus is it important to execute the first line of |
| 359 | code (i.e. the line of the open brace, i.e. the prologue) of a function |
| 360 | before trying to print arguments or anything. |
| 361 | |
| 362 | The following diagram attempts to depict what is going on in memory |
| 363 | (see also the _am29k user's guide_) and also how that interacts with |
| 364 | GDB frames. We arbitrarily pick fci->frame to point the same place |
| 365 | as the register stack pointer; since we set it ourself in |
| 366 | INIT_EXTRA_FRAME_INFO, and access it only through the FRAME_* |
| 367 | macros, it doesn't really matter exactly how we |
| 368 | do it. However, note that FRAME_FP is used in two ways in GDB: |
| 369 | (1) as a "magic cookie" which uniquely identifies frames (even over |
| 370 | calls to the inferior), (2) (in PC_IN_CALL_DUMMY [ON_STACK]) |
| 371 | as the value of SP_REGNUM before the dummy frame was pushed. These |
| 372 | two meanings would be incompatible for the 29k if we defined |
| 373 | CALL_DUMMY_LOCATION == ON_STACK (but we don't, so don't worry about it). |
| 374 | Also note that "lr1" below, while called a frame pointer |
| 375 | in the user's guide, has only one function: To determine whether |
| 376 | registers need to be filled in the function epilogue. |
| 377 | |
| 378 | Consider the code: |
| 379 | < call bar> |
| 380 | loc1: . . . |
| 381 | bar: sub gr1,gr1,rsize_b |
| 382 | . . . |
| 383 | add mfp,msp,0 |
| 384 | sub msp,msp,msize_b |
| 385 | . . . |
| 386 | < call foo > |
| 387 | loc2: . . . |
| 388 | foo: sub gr1,gr1,rsize_f |
| 389 | . . . |
| 390 | add mfp,msp,0 |
| 391 | sub msp,msp,msize_f |
| 392 | . . . |
| 393 | loc3: < suppose the inferior stops here > |
| 394 | |
| 395 | memory stack register stack |
| 396 | | | |____________| |
| 397 | | | |____loc1____| |
| 398 | +------->|___________| | | ^ |
| 399 | | | ^ | | locals_b | | |
| 400 | | | | | |____________| | |
| 401 | | | | | | | | rsize_b |
| 402 | | | | msize_b | | args_to_f | | |
| 403 | | | | | |____________| | |
| 404 | | | | | |____lr1_____| V |
| 405 | | | V | |____loc2____|<----------------+ |
| 406 | | +--->|___________|<---------mfp | ^ | |
| 407 | | | | ^ | | locals_f | | | |
| 408 | | | | | msize_f | |____________| | | |
| 409 | | | | | | | | | rsize_f | |
| 410 | | | | V | | args | | | |
| 411 | | | |___________|<msp |____________| | | |
| 412 | | | |_____lr1____| V | |
| 413 | | | |___garbage__| <- gr1 <----+ | |
| 414 | | | | | |
| 415 | | | | | |
| 416 | | | pc=loc3 | | |
| 417 | | | | | |
| 418 | | | | | |
| 419 | | | frame cache | | |
| 420 | | | |_________________| | | |
| 421 | | | |rsize=rsize_b | | | |
| 422 | | | |msize=msize_b | | | |
| 423 | +---|--------saved_msp | | | |
| 424 | | |frame------------------------------------|---+ |
| 425 | | |pc=loc2 | | |
| 426 | | |_________________| | |
| 427 | | |rsize=rsize_f | | |
| 428 | | |msize=msize_f | | |
| 429 | +--------saved_msp | | |
| 430 | |frame------------------------------------+ |
| 431 | |pc=loc3 | |
| 432 | |_________________| |
| 433 | |
| 434 | So, is that sufficiently confusing? Welcome to the 29000. |
| 435 | Notes: |
| 436 | * The frame for foo uses a memory frame pointer but the frame for |
| 437 | bar does not. In the latter case the saved_msp is |
| 438 | computed by adding msize to the saved_msp of the |
| 439 | next frame. |
| 440 | * msize is in the frame cache only for high C's sake. */ |
| 441 | |
| 442 | void read_register_stack (); |
| 443 | long read_register_stack_integer (); |
| 444 | \f |
| 445 | #define EXTRA_FRAME_INFO \ |
| 446 | CORE_ADDR saved_msp; \ |
| 447 | unsigned int rsize; \ |
| 448 | unsigned int msize; \ |
| 449 | unsigned char flags; |
| 450 | |
| 451 | /* Bits for flags in EXTRA_FRAME_INFO */ |
| 452 | #define TRANSPARENT 0x1 /* This is a transparent frame */ |
| 453 | #define MFP_USED 0x2 /* A memory frame pointer is used */ |
| 454 | |
| 455 | /* Because INIT_FRAME_PC gets passed fromleaf, that's where we init |
| 456 | not only ->pc and ->frame, but all the extra stuff, when called from |
| 457 | get_prev_frame_info, that is. */ |
| 458 | #define INIT_EXTRA_FRAME_INFO(fromleaf, fci) init_extra_frame_info(fci) |
| 459 | void init_extra_frame_info (); |
| 460 | |
| 461 | #define INIT_FRAME_PC(fromleaf, fci) init_frame_pc(fromleaf, fci) |
| 462 | void init_frame_pc (); |
| 463 | |
| 464 | \f |
| 465 | /* FRAME_CHAIN takes a FRAME |
| 466 | and produces the frame's chain-pointer. |
| 467 | |
| 468 | However, if FRAME_CHAIN_VALID returns zero, |
| 469 | it means the given frame is the outermost one and has no caller. */ |
| 470 | |
| 471 | /* On the 29k, the nominal address of a frame is the address on the |
| 472 | register stack of the return address (the one next to the incoming |
| 473 | arguments, not down at the bottom so nominal address == stack pointer). |
| 474 | |
| 475 | GDB expects "nominal address" to equal contents of FP_REGNUM, |
| 476 | at least when it comes time to create the innermost frame. |
| 477 | However, that doesn't work for us, so when creating the innermost |
| 478 | frame we set ->frame ourselves in INIT_EXTRA_FRAME_INFO. */ |
| 479 | |
| 480 | /* These are mostly dummies for the 29k because INIT_FRAME_PC |
| 481 | sets prev->frame instead. */ |
| 482 | #define FRAME_CHAIN(thisframe) ((thisframe)->frame + (thisframe)->rsize) |
| 483 | |
| 484 | /* Determine if the frame has a 'previous' and back-traceable frame. */ |
| 485 | #define FRAME_IS_UNCHAINED(frame) ((frame)->flags & TRANSPARENT) |
| 486 | |
| 487 | /* Find the previous frame of a transparent routine. |
| 488 | * For now lets not try and trace through a transparent routine (we might |
| 489 | * have to assume that all transparent routines are traps). |
| 490 | */ |
| 491 | #define FIND_PREV_UNCHAINED_FRAME(frame) 0 |
| 492 | |
| 493 | /* Define other aspects of the stack frame. */ |
| 494 | |
| 495 | /* A macro that tells us whether the function invocation represented |
| 496 | by FI does not have a frame on the stack associated with it. If it |
| 497 | does not, FRAMELESS is set to 1, else 0. */ |
| 498 | #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \ |
| 499 | (FRAMELESS) = frameless_look_for_prologue(FI) |
| 500 | |
| 501 | /* Saved pc (i.e. return address). */ |
| 502 | #define FRAME_SAVED_PC(fraim) \ |
| 503 | (read_register_stack_integer ((fraim)->frame + (fraim)->rsize, 4)) |
| 504 | |
| 505 | /* Local variables (i.e. LOC_LOCAL) are on the memory stack, with their |
| 506 | offsets being relative to the memory stack pointer (high C) or |
| 507 | saved_msp (gcc). */ |
| 508 | |
| 509 | #define FRAME_LOCALS_ADDRESS(fi) frame_locals_address (fi) |
| 510 | extern CORE_ADDR frame_locals_address (); |
| 511 | |
| 512 | /* Return number of args passed to a frame. |
| 513 | Can return -1, meaning no way to tell. */ |
| 514 | /* While we could go the effort of finding the tags word and getting |
| 515 | the argcount field from it, |
| 516 | (1) It only counts arguments in registers, i.e. the first 16 words |
| 517 | of arguments |
| 518 | (2) It gives the number of arguments the function was declared with |
| 519 | not how many it was called with (or some variation, like all 16 |
| 520 | words for varadic functions). This makes argcount pretty much |
| 521 | redundant with -g info, even for varadic functions. |
| 522 | So don't bother. */ |
| 523 | #define FRAME_NUM_ARGS(numargs, fi) ((numargs) = -1) |
| 524 | |
| 525 | #define FRAME_ARGS_ADDRESS(fi) FRAME_LOCALS_ADDRESS (fi) |
| 526 | |
| 527 | /* Return number of bytes at start of arglist that are not really args. */ |
| 528 | |
| 529 | #define FRAME_ARGS_SKIP 0 |
| 530 | |
| 531 | /* Provide our own get_saved_register. HAVE_REGISTER_WINDOWS is insufficient |
| 532 | because registers get renumbered on the 29k without getting saved. */ |
| 533 | |
| 534 | #define GET_SAVED_REGISTER |
| 535 | \f |
| 536 | /* Call function stuff. */ |
| 537 | |
| 538 | /* The dummy frame looks like this (see also the general frame picture |
| 539 | above): |
| 540 | |
| 541 | register stack |
| 542 | |
| 543 | | | frame for function |
| 544 | | locals_sproc | executing at time |
| 545 | |________________| of call_function. |
| 546 | | | We must not disturb |
| 547 | | args_out_sproc | it. |
| 548 | memory stack |________________| |
| 549 | |____lr1_sproc___|<-+ |
| 550 | | | |__retaddr_sproc_| | <-- gr1 (at start) |
| 551 | |____________|<-msp 0 <-----------mfp_dummy_____| | |
| 552 | | | (at start) | save regs | | |
| 553 | | arg_slop | | pc0,pc1 | | |
| 554 | | (16 words) | | gr96-gr124 | | |
| 555 | |____________|<-msp 1--after | sr160-sr162 | | |
| 556 | | | PUSH_DUMMY_FRAME| sr128-sr135 | | |
| 557 | | struct ret | |________________| | |
| 558 | | 17+ | | | | |
| 559 | |____________|<- lrp | args_out_dummy | | |
| 560 | | struct ret | | (16 words) | | |
| 561 | | 16 | |________________| | |
| 562 | | (16 words) | |____lr1_dummy___|--+ |
| 563 | |____________|<- msp 2--after |_retaddr_dummy__|<- gr1 after |
| 564 | | | struct ret | | PUSH_DUMMY_FRAME |
| 565 | | margs17+ | area allocated | locals_inf | |
| 566 | | | |________________| called |
| 567 | |____________|<- msp 4--when | | function's |
| 568 | | | inf called | args_out_inf | frame (set up |
| 569 | | margs16 | |________________| by called |
| 570 | | (16 words) | |_____lr1_inf____| function). |
| 571 | |____________|<- msp 3--after | . | |
| 572 | | | args pushed | . | |
| 573 | | | | . | |
| 574 | | | |
| 575 | |
| 576 | arg_slop: This area is so that when the call dummy adds 16 words to |
| 577 | the msp, it won't end up larger than mfp_dummy (it is needed in the |
| 578 | case where margs and struct_ret do not add up to at least 16 words). |
| 579 | struct ret: This area is allocated by GDB if the return value is more |
| 580 | than 16 words. struct ret_16 is not used on the 29k. |
| 581 | margs: Pushed by GDB. The call dummy copies the first 16 words to |
| 582 | args_out_dummy. |
| 583 | retaddr_sproc: Contains the PC at the time we call the function. |
| 584 | set by PUSH_DUMMY_FRAME and read by POP_FRAME. |
| 585 | retaddr_dummy: This points to a breakpoint instruction in the dummy. */ |
| 586 | \f |
| 587 | /* Rsize for dummy frame, in bytes. */ |
| 588 | |
| 589 | /* Bytes for outgoing args, lr1, and retaddr. */ |
| 590 | #define DUMMY_ARG (2 * 4 + 16 * 4) |
| 591 | |
| 592 | /* Number of special registers (sr128-) to save. */ |
| 593 | #define DUMMY_SAVE_SR128 8 |
| 594 | /* Number of special registers (sr160-) to save. */ |
| 595 | #define DUMMY_SAVE_SR160 3 |
| 596 | /* Number of general (gr96- or gr64-) registers to save. */ |
| 597 | #define DUMMY_SAVE_GREGS 29 |
| 598 | |
| 599 | #define DUMMY_FRAME_RSIZE \ |
| 600 | (4 /* mfp_dummy */ \ |
| 601 | + 2 * 4 /* pc0, pc1 */ \ |
| 602 | + DUMMY_SAVE_GREGS * 4 \ |
| 603 | + DUMMY_SAVE_SR160 * 4 \ |
| 604 | + DUMMY_SAVE_SR128 * 4 \ |
| 605 | + DUMMY_ARG \ |
| 606 | ) |
| 607 | |
| 608 | /* Push an empty stack frame, to record the current PC, etc. */ |
| 609 | |
| 610 | #define PUSH_DUMMY_FRAME push_dummy_frame() |
| 611 | extern void push_dummy_frame (); |
| 612 | |
| 613 | /* Discard from the stack the innermost frame, |
| 614 | restoring all saved registers. */ |
| 615 | |
| 616 | #define POP_FRAME pop_frame() |
| 617 | extern void pop_frame (); |
| 618 | |
| 619 | /* This sequence of words is the instructions |
| 620 | mtsrim cr, 15 |
| 621 | loadm 0, 0, lr2, msp ; load first 16 words of arguments into registers |
| 622 | add msp, msp, 16 * 4 ; point to the remaining arguments |
| 623 | CONST_INSN: |
| 624 | const lr0,inf ; (replaced by half of target addr) |
| 625 | consth lr0,inf ; (replaced by other half of target addr) |
| 626 | calli lr0, lr0 |
| 627 | aseq 0x40,gr1,gr1 ; nop |
| 628 | BREAKPT_INSN: |
| 629 | asneq 0x50,gr1,gr1 ; breakpoint (replaced by local breakpoint insn) |
| 630 | */ |
| 631 | |
| 632 | #if TARGET_BYTE_ORDER == HOST_BYTE_ORDER |
| 633 | #define BS(const) const |
| 634 | #else |
| 635 | #define BS(const) (((const) & 0xff) << 24) | \ |
| 636 | (((const) & 0xff00) << 8) | \ |
| 637 | (((const) & 0xff0000) >> 8) | \ |
| 638 | (((const) & 0xff000000) >> 24) |
| 639 | #endif |
| 640 | |
| 641 | /* Position of the "const" and blkt instructions within CALL_DUMMY in bytes. */ |
| 642 | #define CONST_INSN (3 * 4) |
| 643 | #define BREAKPT_INSN (7 * 4) |
| 644 | #define CALL_DUMMY { \ |
| 645 | BS(0x0400870f),\ |
| 646 | BS(0x36008200|(MSP_HW_REGNUM)), \ |
| 647 | BS(0x15000040|(MSP_HW_REGNUM<<8)|(MSP_HW_REGNUM<<16)), \ |
| 648 | BS(0x03ff80ff), \ |
| 649 | BS(0x02ff80ff), \ |
| 650 | BS(0xc8008080), \ |
| 651 | BS(0x70400101), \ |
| 652 | BS(0x72500101)} |
| 653 | #define CALL_DUMMY_LENGTH (8 * 4) |
| 654 | |
| 655 | #define CALL_DUMMY_START_OFFSET 0 /* Start execution at beginning of dummy */ |
| 656 | |
| 657 | /* Helper macro for FIX_CALL_DUMMY. WORDP is a long * which points to a |
| 658 | word in target byte order; bits 0-7 and 16-23 of *WORDP are replaced with |
| 659 | bits 0-7 and 8-15 of DATA (which is in host byte order). */ |
| 660 | |
| 661 | #if TARGET_BYTE_ORDER == BIG_ENDIAN |
| 662 | #define STUFF_I16(WORDP, DATA) \ |
| 663 | { \ |
| 664 | *((char *)(WORDP) + 3) = ((DATA) & 0xff);\ |
| 665 | *((char *)(WORDP) + 1) = (((DATA) >> 8) & 0xff);\ |
| 666 | } |
| 667 | #else /* Target is little endian. */ |
| 668 | #define STUFF_I16(WORDP, DATA) \ |
| 669 | { |
| 670 | *(char *)(WORDP) = ((DATA) & 0xff); |
| 671 | *((char *)(WORDP) + 2) = (((DATA) >> 8) & 0xff); |
| 672 | } |
| 673 | #endif /* Target is little endian. */ |
| 674 | |
| 675 | /* Insert the specified number of args and function address |
| 676 | into a call sequence of the above form stored at DUMMYNAME. */ |
| 677 | |
| 678 | /* Currently this stuffs in the address of the function that we are calling. |
| 679 | Since different 29k systems use different breakpoint instructions, it |
| 680 | also stuffs BREAKPOINT in the right place (to avoid having to |
| 681 | duplicate CALL_DUMMY in each tm-*.h file). */ |
| 682 | |
| 683 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ |
| 684 | {\ |
| 685 | STUFF_I16((char *)dummyname + CONST_INSN, fun); \ |
| 686 | STUFF_I16((char *)dummyname + CONST_INSN + 4, fun >> 16); \ |
| 687 | /* FIXME memcpy ((char *)(dummyname) + BREAKPT_INSN, break_insn, 4); */ \ |
| 688 | } |
| 689 | |
| 690 | /* 29k architecture has separate data & instruction memories -- wired to |
| 691 | different pins on the chip -- and can't execute the data memory. |
| 692 | Also, there should be space after text_end; |
| 693 | we won't get a SIGSEGV or scribble on data space. */ |
| 694 | |
| 695 | #define CALL_DUMMY_LOCATION AFTER_TEXT_END |
| 696 | |
| 697 | /* Because of this, we need (as a kludge) to know the addresses of the |
| 698 | text section. */ |
| 699 | |
| 700 | #define NEED_TEXT_START_END |
| 701 | |
| 702 | /* How to translate register numbers in the .stab's into gdb's internal register |
| 703 | numbers. We don't translate them, but we warn if an invalid register |
| 704 | number is seen. Note that FIXME, we use the value "sym" as an implicit |
| 705 | argument in printing the error message. It happens to be available where |
| 706 | this macro is used. (This macro definition appeared in a late revision |
| 707 | of gdb-3.91.6 and is not well tested. Also, it should be a "complaint".) */ |
| 708 | |
| 709 | #define STAB_REG_TO_REGNUM(num) \ |
| 710 | (((num) > LR0_REGNUM + 127) \ |
| 711 | ? fprintf(stderr, \ |
| 712 | "Invalid register number %d in symbol table entry for %s\n", \ |
| 713 | (num), SYMBOL_NAME (sym)), (num) \ |
| 714 | : (num)) |