| 1 | /* Parameters for targeting on a Gould NP1, for GDB, the GNU debugger. |
| 2 | Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GDB. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 19 | |
| 20 | #define GOULD_NPL |
| 21 | |
| 22 | #define TARGET_BYTE_ORDER BIG_ENDIAN |
| 23 | |
| 24 | /* N_ENTRY appears in libraries on Gould machines. |
| 25 | Don't know what 0xa4 is; it's mentioned in stab.h |
| 26 | but only in the sdb symbol list. */ |
| 27 | #define IGNORE_SYMBOL(type) (type == N_ENTRY || type == 0xa4) |
| 28 | |
| 29 | /* We don't want the extra gnu symbols on the machine; |
| 30 | they will interfere with the shared segment symbols. */ |
| 31 | #define NO_GNU_STABS |
| 32 | |
| 33 | /* Macro for text-offset and data info (in NPL a.out format). */ |
| 34 | #define TEXTINFO \ |
| 35 | text_offset = N_TXTOFF (exec_coffhdr, exec_aouthdr); \ |
| 36 | exec_data_offset = N_TXTOFF (exec_coffhdr, exec_aouthdr)\ |
| 37 | + exec_aouthdr.a_text |
| 38 | |
| 39 | /* Macro for number of symbol table entries */ |
| 40 | #define NUMBER_OF_SYMBOLS \ |
| 41 | (coffhdr.f_nsyms) |
| 42 | |
| 43 | /* Macro for file-offset of symbol table (in NPL a.out format). */ |
| 44 | #define SYMBOL_TABLE_OFFSET \ |
| 45 | N_SYMOFF (coffhdr) |
| 46 | |
| 47 | /* Macro for file-offset of string table (in NPL a.out format). */ |
| 48 | #define STRING_TABLE_OFFSET \ |
| 49 | (N_STROFF (coffhdr)) |
| 50 | |
| 51 | /* Macro to store the length of the string table data in INTO. */ |
| 52 | #define READ_STRING_TABLE_SIZE(INTO) \ |
| 53 | { INTO = hdr.a_stsize; } |
| 54 | |
| 55 | /* Macro to declare variables to hold the file's header data. */ |
| 56 | #define DECLARE_FILE_HEADERS struct exec hdr; \ |
| 57 | FILHDR coffhdr |
| 58 | |
| 59 | /* Macro to read the header data from descriptor DESC and validate it. |
| 60 | NAME is the file name, for error messages. */ |
| 61 | #define READ_FILE_HEADERS(DESC, NAME) \ |
| 62 | { val = myread (DESC, &coffhdr, sizeof coffhdr); \ |
| 63 | if (val < 0) \ |
| 64 | perror_with_name (NAME); \ |
| 65 | val = myread (DESC, &hdr, sizeof hdr); \ |
| 66 | if (val < 0) \ |
| 67 | perror_with_name (NAME); \ |
| 68 | if (coffhdr.f_magic != GNP1MAGIC) \ |
| 69 | error ("File \"%s\" not in coff executable format.", NAME); \ |
| 70 | if (N_BADMAG (hdr)) \ |
| 71 | error ("File \"%s\" not in executable format.", NAME); } |
| 72 | |
| 73 | /* Define COFF and other symbolic names needed on NP1 */ |
| 74 | #define NS32GMAGIC GNP1MAGIC |
| 75 | #define NS32SMAGIC GPNMAGIC |
| 76 | |
| 77 | /* Define this if the C compiler puts an underscore at the front |
| 78 | of external names before giving them to the linker. */ |
| 79 | #define NAMES_HAVE_UNDERSCORE |
| 80 | |
| 81 | /* Debugger information will be in DBX format. */ |
| 82 | #define READ_DBX_FORMAT |
| 83 | |
| 84 | /* Address of blocks in N_LBRAC and N_RBRAC symbols are absolute addresses, |
| 85 | not relative to start of source address. */ |
| 86 | #define BLOCK_ADDRESS_ABSOLUTE |
| 87 | |
| 88 | /* Offset from address of function to start of its code. |
| 89 | Zero on most machines. */ |
| 90 | #define FUNCTION_START_OFFSET 8 |
| 91 | |
| 92 | /* Advance PC across any function entry prologue instructions |
| 93 | to reach some "real" code. One NPL we can have one two startup |
| 94 | sequences depending on the size of the local stack: |
| 95 | |
| 96 | Either: |
| 97 | "suabr b2, #" |
| 98 | of |
| 99 | "lil r4, #", "suabr b2, #(r4)" |
| 100 | |
| 101 | "lwbr b6, #", "stw r1, 8(b2)" |
| 102 | Optional "stwbr b3, c(b2)" |
| 103 | Optional "trr r2,r7" (Gould first argument register passing) |
| 104 | or |
| 105 | Optional "stw r2,8(b3)" (Gould first argument register passing) |
| 106 | */ |
| 107 | #define SKIP_PROLOGUE(pc) { \ |
| 108 | register int op = read_memory_integer ((pc), 4); \ |
| 109 | if ((op & 0xffff0000) == 0xFA0B0000) { \ |
| 110 | pc += 4; \ |
| 111 | op = read_memory_integer ((pc), 4); \ |
| 112 | if ((op & 0xffff0000) == 0x59400000) { \ |
| 113 | pc += 4; \ |
| 114 | op = read_memory_integer ((pc), 4); \ |
| 115 | if ((op & 0xffff0000) == 0x5F000000) { \ |
| 116 | pc += 4; \ |
| 117 | op = read_memory_integer ((pc), 4); \ |
| 118 | if (op == 0xD4820008) { \ |
| 119 | pc += 4; \ |
| 120 | op = read_memory_integer ((pc), 4); \ |
| 121 | if (op == 0x5582000C) { \ |
| 122 | pc += 4; \ |
| 123 | op = read_memory_integer ((pc), 2); \ |
| 124 | if (op == 0x2fa0) { \ |
| 125 | pc += 2; \ |
| 126 | } else { \ |
| 127 | op = read_memory_integer ((pc), 4); \ |
| 128 | if (op == 0xd5030008) { \ |
| 129 | pc += 4; \ |
| 130 | } \ |
| 131 | } \ |
| 132 | } else { \ |
| 133 | op = read_memory_integer ((pc), 2); \ |
| 134 | if (op == 0x2fa0) { \ |
| 135 | pc += 2; \ |
| 136 | } \ |
| 137 | } \ |
| 138 | } \ |
| 139 | } \ |
| 140 | } \ |
| 141 | } \ |
| 142 | if ((op & 0xffff0000) == 0x59000000) { \ |
| 143 | pc += 4; \ |
| 144 | op = read_memory_integer ((pc), 4); \ |
| 145 | if ((op & 0xffff0000) == 0x5F000000) { \ |
| 146 | pc += 4; \ |
| 147 | op = read_memory_integer ((pc), 4); \ |
| 148 | if (op == 0xD4820008) { \ |
| 149 | pc += 4; \ |
| 150 | op = read_memory_integer ((pc), 4); \ |
| 151 | if (op == 0x5582000C) { \ |
| 152 | pc += 4; \ |
| 153 | op = read_memory_integer ((pc), 2); \ |
| 154 | if (op == 0x2fa0) { \ |
| 155 | pc += 2; \ |
| 156 | } else { \ |
| 157 | op = read_memory_integer ((pc), 4); \ |
| 158 | if (op == 0xd5030008) { \ |
| 159 | pc += 4; \ |
| 160 | } \ |
| 161 | } \ |
| 162 | } else { \ |
| 163 | op = read_memory_integer ((pc), 2); \ |
| 164 | if (op == 0x2fa0) { \ |
| 165 | pc += 2; \ |
| 166 | } \ |
| 167 | } \ |
| 168 | } \ |
| 169 | } \ |
| 170 | } \ |
| 171 | } |
| 172 | |
| 173 | /* Immediately after a function call, return the saved pc. |
| 174 | Can't go through the frames for this because on some machines |
| 175 | the new frame is not set up until the new function executes |
| 176 | some instructions. True on NPL! Return address is in R1. |
| 177 | The true return address is REALLY 4 past that location! */ |
| 178 | #define SAVED_PC_AFTER_CALL(frame) \ |
| 179 | (read_register(R1_REGNUM) + 4) |
| 180 | |
| 181 | /* Address of end of stack space. */ |
| 182 | #define STACK_END_ADDR 0x7fffc000 |
| 183 | |
| 184 | /* Stack grows downward. */ |
| 185 | #define INNER_THAN < |
| 186 | |
| 187 | /* Sequence of bytes for breakpoint instruction. |
| 188 | This is padded out to the size of a machine word. When it was just |
| 189 | {0x28, 0x09} it gave problems if hit breakpoint on returning from a |
| 190 | function call. */ |
| 191 | #define BREAKPOINT {0x28, 0x09, 0x0, 0x0} |
| 192 | |
| 193 | /* Amount PC must be decremented by after a breakpoint. |
| 194 | This is often the number of bytes in BREAKPOINT |
| 195 | but not always. */ |
| 196 | #define DECR_PC_AFTER_BREAK 2 |
| 197 | |
| 198 | /* Nonzero if instruction at PC is a return instruction. "bu 4(r1)" */ |
| 199 | #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 4) == 0x40100004) |
| 200 | |
| 201 | /* Return 1 if P points to an invalid floating point value. */ |
| 202 | #define INVALID_FLOAT(p, len) ((*(short *)p & 0xff80) == 0x8000) |
| 203 | |
| 204 | /* Say how long (ordinary) registers are. */ |
| 205 | #define REGISTER_TYPE long |
| 206 | |
| 207 | /* Size of bytes of vector register (NP1 only), 32 elements * sizeof(int) */ |
| 208 | #define VR_SIZE 128 |
| 209 | |
| 210 | /* Number of machine registers */ |
| 211 | #define NUM_REGS 27 |
| 212 | #define NUM_GEN_REGS 16 |
| 213 | #define NUM_CPU_REGS 4 |
| 214 | #define NUM_VECTOR_REGS 7 |
| 215 | |
| 216 | /* Initializer for an array of names of registers. |
| 217 | There should be NUM_REGS strings in this initializer. */ |
| 218 | #define REGISTER_NAMES { \ |
| 219 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \ |
| 220 | "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", \ |
| 221 | "sp", "ps", "pc", "ve", \ |
| 222 | "v1", "v2", "v3", "v4", "v5", "v6", "v7", \ |
| 223 | } |
| 224 | |
| 225 | /* Register numbers of various important registers. |
| 226 | Note that some of these values are "real" register numbers, |
| 227 | and correspond to the general registers of the machine, |
| 228 | and some are "phony" register numbers which are too large |
| 229 | to be actual register numbers as far as the user is concerned |
| 230 | but do serve to get the desired values when passed to read_register. */ |
| 231 | #define R1_REGNUM 1 /* Gr1 => return address of caller */ |
| 232 | #define R2_REGNUM 2 /* Gr2 => return value from function */ |
| 233 | #define R4_REGNUM 4 /* Gr4 => register save area */ |
| 234 | #define R5_REGNUM 5 /* Gr5 => register save area */ |
| 235 | #define R6_REGNUM 6 /* Gr6 => register save area */ |
| 236 | #define R7_REGNUM 7 /* Gr7 => register save area */ |
| 237 | #define B1_REGNUM 9 /* Br1 => start of this code routine */ |
| 238 | #define SP_REGNUM 10 /* Br2 == (sp) */ |
| 239 | #define AP_REGNUM 11 /* Br3 == (ap) */ |
| 240 | #define FP_REGNUM 16 /* A copy of Br2 saved in trap */ |
| 241 | #define PS_REGNUM 17 /* Contains processor status */ |
| 242 | #define PC_REGNUM 18 /* Contains program counter */ |
| 243 | #define VE_REGNUM 19 /* Vector end (user setup) register */ |
| 244 | #define V1_REGNUM 20 /* First vector register */ |
| 245 | #define V7_REGNUM 26 /* First vector register */ |
| 246 | |
| 247 | /* Total amount of space needed to store our copies of the machine's |
| 248 | register state, the array `registers'. */ |
| 249 | #define REGISTER_BYTES \ |
| 250 | (NUM_GEN_REGS*4 + NUM_VECTOR_REGS*VR_SIZE + NUM_CPU_REGS*4) |
| 251 | |
| 252 | /* Index within `registers' of the first byte of the space for |
| 253 | register N. */ |
| 254 | #define REGISTER_BYTE(N) \ |
| 255 | (((N) < V1_REGNUM) ? ((N) * 4) : (((N) - V1_REGNUM) * VR_SIZE) + 80) |
| 256 | |
| 257 | /* Number of bytes of storage in the actual machine representation |
| 258 | for register N. On the NP1, all normal regs are 4 bytes, but |
| 259 | the vector registers are VR_SIZE*4 bytes long. */ |
| 260 | #define REGISTER_RAW_SIZE(N) \ |
| 261 | (((N) < V1_REGNUM) ? 4 : VR_SIZE) |
| 262 | |
| 263 | /* Number of bytes of storage in the program's representation |
| 264 | for register N. On the NP1, all regs are 4 bytes. */ |
| 265 | #define REGISTER_VIRTUAL_SIZE(N) \ |
| 266 | (((N) < V1_REGNUM) ? 4 : VR_SIZE) |
| 267 | |
| 268 | /* Largest value REGISTER_RAW_SIZE can have. */ |
| 269 | #define MAX_REGISTER_RAW_SIZE VR_SIZE |
| 270 | |
| 271 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ |
| 272 | #define MAX_REGISTER_VIRTUAL_SIZE VR_SIZE |
| 273 | |
| 274 | /* Nonzero if register N requires conversion |
| 275 | from raw format to virtual format. */ |
| 276 | #define REGISTER_CONVERTIBLE(N) (0) |
| 277 | |
| 278 | /* Convert data from raw format for register REGNUM |
| 279 | to virtual format for register REGNUM. */ |
| 280 | #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \ |
| 281 | bcopy ((FROM), (TO), REGISTER_RAW_SIZE(REGNUM)); |
| 282 | |
| 283 | /* Convert data from virtual format for register REGNUM |
| 284 | to raw format for register REGNUM. */ |
| 285 | #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \ |
| 286 | bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM)); |
| 287 | |
| 288 | /* Return the GDB type object for the "standard" data type |
| 289 | of data in register N. */ |
| 290 | #define REGISTER_VIRTUAL_TYPE(N) \ |
| 291 | ((N) > VE_REGNUM ? builtin_type_np1_vector : builtin_type_int) |
| 292 | extern struct type *builtin_type_np1_vector; |
| 293 | |
| 294 | /* Store the address of the place in which to copy the structure the |
| 295 | subroutine will return. This is called from call_function. |
| 296 | |
| 297 | On this machine this is a no-op, because gcc isn't used on it |
| 298 | yet. So this calling convention is not used. */ |
| 299 | |
| 300 | #define STORE_STRUCT_RETURN(ADDR, SP) push_word(SP + 8, ADDR) |
| 301 | |
| 302 | /* Extract from an arrary REGBUF containing the (raw) register state |
| 303 | a function return value of type TYPE, and copy that, in virtual format, |
| 304 | into VALBUF. */ |
| 305 | |
| 306 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ |
| 307 | bcopy (((int *)(REGBUF)) + 2, VALBUF, TYPE_LENGTH (TYPE)) |
| 308 | |
| 309 | /* Write into appropriate registers a function return value |
| 310 | of type TYPE, given in virtual format. */ |
| 311 | |
| 312 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ |
| 313 | write_register_bytes (REGISTER_BYTE (R2_REGNUM), VALBUF, \ |
| 314 | TYPE_LENGTH (TYPE)) |
| 315 | |
| 316 | /* Extract from an array REGBUF containing the (raw) register state |
| 317 | the address in which a function should return its structure value, |
| 318 | as a CORE_ADDR (or an expression that can be used as one). */ |
| 319 | |
| 320 | #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*((int *)(REGBUF) + 2)) |
| 321 | |
| 322 | /* Both gcc and cc return small structs in registers (i.e. in GDB |
| 323 | terminology, small structs don't use the struct return convention). */ |
| 324 | #define USE_STRUCT_CONVENTION(gcc_p, type) (TYPE_LENGTH(type) > 8) |
| 325 | \f |
| 326 | /* Describe the pointer in each stack frame to the previous stack frame |
| 327 | (its caller). */ |
| 328 | |
| 329 | /* FRAME_CHAIN takes a frame's nominal address |
| 330 | and produces the frame's chain-pointer. |
| 331 | |
| 332 | FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address |
| 333 | and produces the nominal address of the caller frame. |
| 334 | |
| 335 | However, if FRAME_CHAIN_VALID returns zero, |
| 336 | it means the given frame is the outermost one and has no caller. |
| 337 | In that case, FRAME_CHAIN_COMBINE is not used. */ |
| 338 | |
| 339 | /* In the case of the NPL, the frame's norminal address is Br2 and the |
| 340 | previous routines frame is up the stack X bytes, where X is the |
| 341 | value stored in the code function header xA(Br1). */ |
| 342 | #define FRAME_CHAIN(thisframe) (findframe(thisframe)) |
| 343 | |
| 344 | #define FRAME_CHAIN_VALID(chain, thisframe) \ |
| 345 | (chain != 0 && chain != (thisframe)->frame) |
| 346 | |
| 347 | #define FRAME_CHAIN_COMBINE(chain, thisframe) \ |
| 348 | (chain) |
| 349 | |
| 350 | /* Define other aspects of the stack frame on NPL. */ |
| 351 | #define FRAME_SAVED_PC(FRAME) \ |
| 352 | (read_memory_integer ((FRAME)->frame + 8, 4)) |
| 353 | |
| 354 | #define FRAME_ARGS_ADDRESS(fi) \ |
| 355 | ((fi)->next_frame ? \ |
| 356 | read_memory_integer ((fi)->frame + 12, 4) : \ |
| 357 | read_register (AP_REGNUM)) |
| 358 | |
| 359 | #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) |
| 360 | |
| 361 | /* Set VAL to the number of args passed to frame described by FI. |
| 362 | Can set VAL to -1, meaning no way to tell. */ |
| 363 | |
| 364 | /* We can check the stab info to see how |
| 365 | many arg we have. No info in stack will tell us */ |
| 366 | #define FRAME_NUM_ARGS(val,fi) (val = findarg(fi)) |
| 367 | |
| 368 | /* Return number of bytes at start of arglist that are not really args. */ |
| 369 | #define FRAME_ARGS_SKIP 8 |
| 370 | |
| 371 | /* Put here the code to store, into a struct frame_saved_regs, |
| 372 | the addresses of the saved registers of frame described by FRAME_INFO. |
| 373 | This includes special registers such as pc and fp saved in special |
| 374 | ways in the stack frame. sp is even more special: |
| 375 | the address we return for it IS the sp for the next frame. */ |
| 376 | |
| 377 | #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ |
| 378 | { \ |
| 379 | bzero (&frame_saved_regs, sizeof frame_saved_regs); \ |
| 380 | (frame_saved_regs).regs[SP_REGNUM] = framechain (frame_info); \ |
| 381 | (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 8; \ |
| 382 | (frame_saved_regs).regs[R4_REGNUM] = (frame_info)->frame + 0x30; \ |
| 383 | (frame_saved_regs).regs[R5_REGNUM] = (frame_info)->frame + 0x34; \ |
| 384 | (frame_saved_regs).regs[R6_REGNUM] = (frame_info)->frame + 0x38; \ |
| 385 | (frame_saved_regs).regs[R7_REGNUM] = (frame_info)->frame + 0x3C; \ |
| 386 | } |
| 387 | \f |
| 388 | /* Things needed for making the inferior call functions. */ |
| 389 | |
| 390 | #define CALL_DUMMY_LOCATION BEFORE_TEXT_END |
| 391 | #define NEED_TEXT_START_END |
| 392 | |
| 393 | /* Push an empty stack frame, to record the current PC, etc. */ |
| 394 | |
| 395 | #define PUSH_DUMMY_FRAME \ |
| 396 | { register CORE_ADDR sp = read_register (SP_REGNUM); \ |
| 397 | register int regnum; \ |
| 398 | for (regnum = 0; regnum < FP_REGNUM; regnum++) \ |
| 399 | sp = push_word (sp, read_register (regnum)); \ |
| 400 | sp = push_word (sp, read_register (PS_REGNUM)); \ |
| 401 | sp = push_word (sp, read_register (PC_REGNUM)); \ |
| 402 | write_register (SP_REGNUM, sp);} |
| 403 | |
| 404 | /* Discard from the stack the innermost frame, |
| 405 | restoring all saved registers. */ |
| 406 | |
| 407 | #define POP_FRAME \ |
| 408 | { CORE_ADDR sp = read_register(SP_REGNUM); \ |
| 409 | REGISTER_TYPE reg; \ |
| 410 | int regnum; \ |
| 411 | for(regnum = 0;regnum < FP_REGNUM;regnum++){ \ |
| 412 | sp-=sizeof(REGISTER_TYPE); \ |
| 413 | read_memory(sp,®,sizeof(REGISTER_TYPE)); \ |
| 414 | write_register(regnum,reg);} \ |
| 415 | sp-=sizeof(REGISTER_TYPE); \ |
| 416 | read_memory(sp,®,sizeof(REGISTER_TYPE)); \ |
| 417 | write_register(PS_REGNUM,reg); \ |
| 418 | sp-=sizeof(REGISTER_TYPE); \ |
| 419 | read_memory(sp,®,sizeof(REGISTER_TYPE)); \ |
| 420 | write_register(PC_REGNUM,reg);} |
| 421 | |
| 422 | /* MJD - Size of dummy frame pushed onto stack by PUSH_DUMMY_FRAME */ |
| 423 | |
| 424 | #define DUMMY_FRAME_SIZE (0x48) |
| 425 | |
| 426 | /* MJD - The sequence of words in the instructions is |
| 427 | halt |
| 428 | halt |
| 429 | halt |
| 430 | halt |
| 431 | subr b2,stack size,0 grab stack space for dummy call |
| 432 | labr b3,x0(b2),0 set AP_REGNUM to point at arguments |
| 433 | lw r2,x8(b3),0 load r2 with first argument |
| 434 | lwbr b1,arguments size(b2),0 load address of function to be called |
| 435 | brlnk r1,x8(b1),0 call function |
| 436 | halt |
| 437 | halt |
| 438 | labr b2,stack size(b2),0 give back stack |
| 439 | break break |
| 440 | */ |
| 441 | |
| 442 | #define CALL_DUMMY {0x00000000, \ |
| 443 | 0x00000000, \ |
| 444 | 0x59000000, \ |
| 445 | 0x598a0000, \ |
| 446 | 0xb5030008, \ |
| 447 | 0x5c820000, \ |
| 448 | 0x44810008, \ |
| 449 | 0x00000000, \ |
| 450 | 0x590a0000, \ |
| 451 | 0x28090000 } |
| 452 | |
| 453 | #define CALL_DUMMY_LENGTH 40 |
| 454 | |
| 455 | #define CALL_DUMMY_START_OFFSET 8 |
| 456 | |
| 457 | #define CALL_DUMMY_STACK_ADJUST 8 |
| 458 | |
| 459 | /* MJD - Fixup CALL_DUMMY for the specific function call. |
| 460 | OK heres the problems |
| 461 | 1) On a trap there are two copies of the stack pointer, one in SP_REGNUM |
| 462 | which is read/write and one in FP_REGNUM which is only read. It seems |
| 463 | that when restarting the GOULD NP1 uses FP_REGNUM's value. |
| 464 | 2) Loading function address into b1 looks a bit difficult if bigger than |
| 465 | 0x0000fffc, infact from what I can tell the compiler sets up table of |
| 466 | function address in base3 through which function calls are referenced. |
| 467 | |
| 468 | OK my solutions |
| 469 | Calculate the size of the dummy stack frame and do adjustments of |
| 470 | SP_REGNUM in the dummy call. |
| 471 | Push function address onto the stack and load it in the dummy call |
| 472 | */ |
| 473 | |
| 474 | #define FIX_CALL_DUMMY(dummyname, sp, fun, nargs, args, type, gcc_p) \ |
| 475 | { int i;\ |
| 476 | int arg_len = 0, total_len;\ |
| 477 | old_sp = push_word(old_sp,fun);\ |
| 478 | for(i = nargs - 1;i >= 0;i--)\ |
| 479 | arg_len += TYPE_LENGTH (VALUE_TYPE (value_arg_coerce (args[i])));\ |
| 480 | if(struct_return)\ |
| 481 | arg_len += TYPE_LENGTH(value_type);\ |
| 482 | total_len = DUMMY_FRAME_SIZE+CALL_DUMMY_STACK_ADJUST+4+arg_len;\ |
| 483 | dummyname[0] += total_len;\ |
| 484 | dummyname[2] += total_len;\ |
| 485 | dummyname[5] += arg_len+CALL_DUMMY_STACK_ADJUST;\ |
| 486 | dummyname[8] += total_len;} |
| 487 | |
| 488 | /* MJD - So the stack should end up looking like this |
| 489 | |
| 490 | | Normal stack frame | |
| 491 | | from normal program | |
| 492 | | flow | |
| 493 | +---------------------+ <- Final sp - 0x08 - argument size |
| 494 | | | - 0x4 - dummy_frame_size |
| 495 | | Pushed dummy frame | |
| 496 | | b0-b7, r0-r7 | |
| 497 | | pc and ps | |
| 498 | | | |
| 499 | +---------------------+ |
| 500 | | Function address | |
| 501 | +---------------------+ <- Final sp - 0x8 - arguments size |
| 502 | | | |
| 503 | | | |
| 504 | | | |
| 505 | | Arguments to | |
| 506 | | Function | |
| 507 | | | |
| 508 | | | |
| 509 | | | |
| 510 | +---------------------+ <- Final sp - 0x8 |
| 511 | | Dummy_stack_adjust | |
| 512 | +---------------------+ <- Final sp |
| 513 | | | |
| 514 | | where call will | |
| 515 | | build frame | |
| 516 | */ |