1 /* Parameters for execution on a Hewlett-Packard PA-RISC machine.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 Contributed by the Center for Software Science at the
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Target system byte order. */
25 #define TARGET_BYTE_ORDER BIG_ENDIAN
27 /* Get at various relevent fields of an instruction word. */
31 #define MASK_14 0x3fff
32 #define MASK_21 0x1fffff
34 /* This macro gets bit fields using HP's numbering (MSB = 0) */
36 #define GET_FIELD(X, FROM, TO) \
37 ((X) >> 31 - (TO) & (1 << ((TO) - (FROM) + 1)) - 1)
39 /* Watch out for NaNs */
45 #define ARGS_GROW_DOWN
47 /* Define this if the C compiler puts an underscore at the front
48 of external names before giving them to the linker. */
50 /* #define NAMES_HAVE_UNDERSCORE */
52 /* Offset from address of function to start of its code.
53 Zero on most machines. */
55 #define FUNCTION_START_OFFSET 0
57 /* Advance PC across any function entry prologue instructions
58 to reach some "real" code. */
60 /* skip (stw rp, -20(0,sp)); copy 4,1; copy sp, 4; stwm 1,framesize(sp)
61 for gcc, or (stw rp, -20(0,sp); stwm 1, framesize(sp) for hcc */
63 #define SKIP_PROLOGUE(pc) \
64 { if (read_memory_integer ((pc), 4) == 0x6BC23FD9) \
65 { if (read_memory_integer ((pc) + 4, 4) == 0x8040241) \
67 else if ((read_memory_integer (pc + 4, 4) & ~MASK_14) == 0x68810000) \
69 else if (read_memory_integer ((pc), 4) == 0x8040241) \
71 else if ((read_memory_integer (pc, 4) & ~MASK_14) == 0x68810000) \
74 /* Immediately after a function call, return the saved pc.
75 Can't go through the frames for this because on some machines
76 the new frame is not set up until the new function executes
79 #define SAVED_PC_AFTER_CALL(frame) (read_register (RP_REGNUM) & ~3)
81 /* Address of end of stack space. Who knows. */
83 #define STACK_END_ADDR 0x80000000
85 /* Stack grows upward */
90 /* Sequence of bytes for breakpoint instruction. */
92 /*#define BREAKPOINT {0x00, 0x00, 0x00, 0x00}*/
93 #ifdef KERNELDEBUG /* XXX */
94 #define BREAKPOINT {0x00, 0x00, 0xa0, 0x00}
96 #define BREAKPOINT {0x00, 0x01, 0x00, 0x04}
99 /* Amount PC must be decremented by after a breakpoint.
100 This is often the number of bytes in BREAKPOINT
103 Not on the PA-RISC */
105 #define DECR_PC_AFTER_BREAK 0
107 /* return instruction is bv r0(rp) */
109 #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 4) == 0xE840C000)
111 /* Return 1 if P points to an invalid floating point value. */
113 #define INVALID_FLOAT(p, len) 0 /* Just a first guess; not checked */
115 /* Largest integer type */
118 /* Name of the builtin type for the LONGEST type above. */
119 #define BUILTIN_TYPE_LONGEST builtin_type_long
121 /* Say how long (ordinary) registers are. */
123 #define REGISTER_TYPE long
125 /* Number of machine registers */
129 /* Initializer for an array of names of registers.
130 There should be NUM_REGS strings in this initializer. */
132 #define REGISTER_NAMES \
133 {"flags", "r1", "rp", "r3", "r4", "r5", "r6", "r7", "r8", "r9", \
134 "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", \
135 "r20", "r21", "r22", "arg3", "arg2", "arg1", "arg0", "dp", "ret0", "ret1", \
136 "sp", "r31", "sar", "pcoqh", "pcsqh", "pcoqt", "pcsqt", \
137 "eiem", "iir", "isr", "ior", "ipsw", "goto", "sr4", "sr0", "sr1", "sr2", \
138 "sr3", "sr5", "sr6", "sr7", "cr0", "cr8", "cr9", "ccr", "cr12", "cr13", \
139 "cr24", "cr25", "cr26", "mpsfu_high", "mpsfu_low", "mpsfu_ovflo", "pad", \
140 "fpsr", "fpe1", "fpe2", "fpe3", "fpe4", "fpe5", "fpe6", "fpe7", \
141 "fp4", "fp5", "fp6", "fp7", "fp8", \
142 "fp9", "fp10", "fp11", "fp12", "fp13", "fp14", "fp15", \
143 "fp16", "fp17", "fp18", "fp19", "fp20", "fp21", "fp22", "fp23", \
144 "fp24", "fp25", "fp26", "fp27", "fp28", "fp29", "fp30", "fp31"}
146 /* Register numbers of various important registers.
147 Note that some of these values are "real" register numbers,
148 and correspond to the general registers of the machine,
149 and some are "phony" register numbers which are too large
150 to be actual register numbers as far as the user is concerned
151 but do serve to get the desired values when passed to read_register. */
153 #define RP_REGNUM 2 /* return pointer */
154 #define FP_REGNUM 4 /* Contains address of executing stack */
156 #define SP_REGNUM 30 /* Contains address of top of stack */
157 #define SAR_REGNUM 32 /* shift amount register */
158 #define IPSW_REGNUM 41 /* processor status word. ? */
159 #define PCOQ_HEAD_REGNUM 33 /* instruction offset queue head */
160 #define PCSQ_HEAD_REGNUM 34 /* instruction space queue head */
161 #define PCOQ_TAIL_REGNUM 35 /* instruction offset queue tail */
162 #define PCSQ_TAIL_REGNUM 36 /* instruction space queue tail */
163 #define FP0_REGNUM 64 /* floating point reg. 0 */
164 #define FP4_REGNUM 72
166 /* compatibility with the rest of gdb. */
167 #define PC_REGNUM PCOQ_HEAD_REGNUM
168 #define NPC_REGNUM PCOQ_TAIL_REGNUM
170 /* Define DO_REGISTERS_INFO() to do machine-specific formatting
171 of register dumps. */
173 #define DO_REGISTERS_INFO(_regnum, fp) pa_do_registers_info (_regnum, fp)
175 /* PA specific macro to see if the current instruction is nullified. */
176 #define INSTRUCTION_NULLIFIED ((int)read_register (IPSW_REGNUM) & 0x00200000)
178 /* Total amount of space needed to store our copies of the machine's
179 register state, the array `registers'. */
180 #define REGISTER_BYTES (32 * 4 + 11 * 4 + 8 * 4 + 12 * 4 + 4 + 32 * 8)
182 /* Index within `registers' of the first byte of the space for
185 #define REGISTER_BYTE(N) \
186 ((N) >= FP4_REGNUM ? ((N) - FP4_REGNUM) * 8 + 288 : (N) * 4)
188 /* Number of bytes of storage in the actual machine representation
189 for register N. On the PA-RISC, all regs are 4 bytes
190 except the floating point regs which are 8 bytes. */
192 #define REGISTER_RAW_SIZE(N) ((N) < FP4_REGNUM ? 4 : 8)
194 /* Number of bytes of storage in the program's representation
197 #define REGISTER_VIRTUAL_SIZE(N) REGISTER_RAW_SIZE(N)
199 /* Largest value REGISTER_RAW_SIZE can have. */
201 #define MAX_REGISTER_RAW_SIZE 8
203 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
205 #define MAX_REGISTER_VIRTUAL_SIZE 8
207 /* Nonzero if register N requires conversion
208 from raw format to virtual format. */
210 #define REGISTER_CONVERTIBLE(N) 0
212 /* Convert data from raw format for register REGNUM
213 to virtual format for register REGNUM. */
215 #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
216 { bcopy ((FROM), (TO), (REGNUM) < FP4_REGNUM ? 4 : 8); }
218 /* Convert data from virtual format for register REGNUM
219 to raw format for register REGNUM. */
221 #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
222 { bcopy ((FROM), (TO), (REGNUM) < FP4_REGNUM ? 4 : 8); }
224 /* Return the GDB type object for the "standard" data type
225 of data in register N. */
227 #define REGISTER_VIRTUAL_TYPE(N) \
228 ((N) < FP4_REGNUM ? builtin_type_int : builtin_type_double)
230 /* Store the address of the place in which to copy the structure the
231 subroutine will return. This is called from call_function. */
233 #define STORE_STRUCT_RETURN(ADDR, SP) {write_register (28, (ADDR)); }
235 /* Extract from an array REGBUF containing the (raw) register state
236 a function return value of type TYPE, and copy that, in virtual format,
239 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
240 bcopy ((REGBUF) + REGISTER_BYTE(TYPE_LENGTH(TYPE) > 4 ? \
241 FP4_REGNUM :28), VALBUF, TYPE_LENGTH (TYPE))
243 /* Write into appropriate registers a function return value
244 of type TYPE, given in virtual format. */
246 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
247 write_register_bytes (TYPE_LENGTH(TYPE) > 4 ? FP4_REGNUM :28, \
248 VALBUF, TYPE_LENGTH (TYPE))
250 /* Extract from an array REGBUF containing the (raw) register state
251 the address in which a function should return its structure value,
252 as a CORE_ADDR (or an expression that can be used as one). */
254 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)((REGBUF) + 28))
256 /* This is a piece of magic that is given a register number REGNO
257 and as BLOCKEND the address in the system of the end of the user structure
258 and stores in ADDR the address in the kernel or core dump
262 /* Describe the pointer in each stack frame to the previous stack frame
265 /* FRAME_CHAIN takes a frame's nominal address
266 and produces the frame's chain-pointer.
268 FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
269 and produces the nominal address of the caller frame.
271 However, if FRAME_CHAIN_VALID returns zero,
272 it means the given frame is the outermost one and has no caller.
273 In that case, FRAME_CHAIN_COMBINE is not used. */
275 /* In the case of the PA-RISC, the frame's nominal address
276 is the address of a 4-byte word containing the calling frame's
277 address (previous FP). */
279 #define FRAME_CHAIN(thisframe) \
280 (inside_entry_file ((thisframe)->pc) ? \
281 read_memory_integer ((thisframe)->frame, 4) :\
284 #define FRAME_CHAIN_VALID(chain, thisframe) \
285 frame_chain_valid (chain, thisframe)
287 #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
289 /* Define other aspects of the stack frame. */
291 /* A macro that tells us whether the function invocation represented
292 by FI does not have a frame on the stack associated with it. If it
293 does not, FRAMELESS is set to 1, else 0. */
294 #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
295 (FRAMELESS) = frameless_look_for_prologue(FI)
297 #define FRAME_SAVED_PC(FRAME) frame_saved_pc (FRAME)
299 #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
301 #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
302 /* Set VAL to the number of args passed to frame described by FI.
303 Can set VAL to -1, meaning no way to tell. */
305 /* We can't tell how many args there are
306 now that the C compiler delays popping them. */
307 #define FRAME_NUM_ARGS(val,fi) (val = -1)
309 /* Return number of bytes at start of arglist that are not really args. */
311 #define FRAME_ARGS_SKIP 0
313 /* Put here the code to store, into a struct frame_saved_regs,
314 the addresses of the saved registers of frame described by FRAME_INFO.
315 This includes special registers such as pc and fp saved in special
316 ways in the stack frame. sp is even more special:
317 the address we return for it IS the sp for the next frame. */
319 /* Deal with dummy functions later. */
321 #define STW_P(INSN) (((INSN) & 0xfc000000) == 0x68000000)
322 #define ADDIL_P(INSN) (((INSN) & 0xfc000000) == 0x28000000)
323 #define LDO_P(INSN) (((INSN) & 0xfc00c000) == 0x34000000)
326 #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
327 { register int regnum; \
328 register CORE_ADDR next_addr; \
329 register CORE_ADDR pc; \
330 unsigned this_insn; \
333 bzero (&frame_saved_regs, sizeof frame_saved_regs); \
334 if ((frame_info)->pc <= ((frame_info)->frame - CALL_DUMMY_LENGTH - \
335 FP_REGNUM * 4 - 16 * 8) \
336 && (frame_info)->pc > (frame_info)->frame) \
337 find_dummy_frame_regs ((frame_info), &(frame_saved_regs)); \
339 { pc = get_pc_function_start ((frame_info)->pc); \
340 if (read_memory_integer (pc, 4) == 0x6BC23FD9) \
341 { (frame_saved_regs).regs[RP_REGNUM] = (frame_info)->frame - 20;\
344 if (read_memory_integer (pc, 4) != 0x8040241) goto lose; \
345 pc += 8; /* skip "copy 4,1; copy 30, 4" */ \
346 /* skip either "stw 1,0(4);addil L'fsize,30;ldo R'fsize(1),30" \
347 or "stwm 1,fsize(30)" */ \
348 if ((read_memory_integer (pc, 4) & ~MASK_14) == 0x68810000) \
353 { this_insn = read_memory_integer(pc, 4); \
354 if (STW_P (this_insn)) /* stw */ \
355 { regnum = GET_FIELD (this_insn, 11, 15); \
356 if (!regnum) goto lose; \
357 (frame_saved_regs).regs[regnum] = (frame_info)->frame + \
358 extract_14 (this_insn); \
361 else if (ADDIL_P (this_insn)) /* addil */ \
363 next_insn = read_memory_integer(pc + 4, 4); \
364 if (STW_P (next_insn)) /* stw */ \
365 { regnum = GET_FIELD (this_insn, 6, 10); \
366 if (!regnum) goto lose; \
367 (frame_saved_regs).regs[regnum] = (frame_info)->frame +\
368 (extract_21 (this_insn) << 11) + extract_14 (next_insn);\
379 this_insn = read_memory_integer (pc, 4); \
380 if (LDO_P (this_insn)) \
381 { next_addr = (frame_info)->frame + extract_14 (this_insn); \
384 else if (ADDIL_P (this_insn)) \
385 { next_addr = (frame_info)->frame + (extract_21 (this_insn) << 11)\
386 + extract_14 (read_memory_integer (pc + 4, 4)); \
390 { this_insn = read_memory_integer (pc, 4); \
391 if ((this_insn & 0xfc001fe0) == 0x2c001220) /* fstds,ma */ \
392 { regnum = GET_FIELD (this_insn, 27, 31); \
393 (frame_saved_regs).regs[regnum + FP0_REGNUM] = next_addr; \
400 (frame_saved_regs).regs[FP_REGNUM] = (frame_info)->frame; \
401 (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame -4; \
404 /* Things needed for making the inferior call functions. */
406 /* Push an empty stack frame, to record the current PC, etc. */
408 #define PUSH_DUMMY_FRAME \
409 { register CORE_ADDR sp = read_register (SP_REGNUM); \
410 register int regnum; \
412 double freg_buffer; \
413 /* Space for "arguments"; the RP goes in here. */ \
415 int_buffer = read_register (RP_REGNUM) | 0x3; \
416 write_memory (sp - 20, &int_buffer, 4); \
417 int_buffer = read_register (FP_REGNUM); \
418 write_memory (sp, &int_buffer, 4); \
419 write_register (FP_REGNUM, sp); \
421 for (regnum = 1; regnum < 31; regnum++) \
422 if (regnum != RP_REGNUM && regnum != FP_REGNUM) \
423 sp = push_word (sp, read_register (regnum)); \
424 for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++) \
425 { read_register_bytes (REGISTER_BYTE (regnum), &freg_buffer, 8); \
426 sp = push_bytes (sp, &freg_buffer, 8);} \
427 sp = push_word (sp, read_register (IPSW_REGNUM)); \
428 sp = push_word (sp, read_register (SAR_REGNUM)); \
429 sp = push_word (sp, read_register (PCOQ_TAIL_REGNUM)); \
430 sp = push_word (sp, read_register (PCSQ_TAIL_REGNUM)); \
431 write_register (SP_REGNUM, sp);}
433 /* Discard from the stack the innermost frame,
434 restoring all saved registers. */
436 { register FRAME frame = get_current_frame (); \
437 register CORE_ADDR fp; \
438 register int regnum; \
439 struct frame_saved_regs fsr; \
440 struct frame_info *fi; \
441 double freg_buffer; \
442 fi = get_frame_info (frame); \
444 get_frame_saved_regs (fi, &fsr); \
445 for (regnum = 31; regnum > 0; regnum--) \
446 if (fsr.regs[regnum]) \
447 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
448 for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM ; regnum--) \
449 if (fsr.regs[regnum]) \
450 { read_memory (fsr.regs[regnum], &freg_buffer, 8); \
451 write_register_bytes (REGISTER_BYTE (regnum), &freg_buffer, 8); }\
452 if (fsr.regs[IPSW_REGNUM]) \
453 write_register (IPSW_REGNUM, \
454 read_memory_integer (fsr.regs[IPSW_REGNUM], 4)); \
455 if (fsr.regs[SAR_REGNUM]) \
456 write_register (SAR_REGNUM, \
457 read_memory_integer (fsr.regs[SAR_REGNUM], 4)); \
458 if (fsr.regs[PCOQ_TAIL_REGNUM]) \
459 write_register (PCOQ_TAIL_REGNUM, \
460 read_memory_integer (fsr.regs[PCOQ_TAIL_REGNUM], 4));\
461 if (fsr.regs[PCSQ_TAIL_REGNUM]) \
462 write_register (PCSQ_TAIL_REGNUM, \
463 read_memory_integer (fsr.regs[PCSQ_TAIL_REGNUM], 4));\
464 write_register (FP_REGNUM, read_memory_integer (fp, 4)); \
465 write_register (SP_REGNUM, fp + 8); \
466 flush_cached_frames (); \
467 set_current_frame (create_new_frame (read_register (FP_REGNUM),\
470 /* This sequence of words is the instructions
472 ; Call stack frame has already been built by gdb. Since we could be calling
473 ; a varargs function, and we do not have the benefit of a stub to put things in
474 ; the right place, we load the first 4 word of arguments into both the general
485 fldds -12(0, r1), fr7
486 ldil 0, r22 ; target will be placed here.
489 ldil 0, r1 ; _sr4export will be placed here.
492 combt,=,n r3, r4, text_space ; If target is in data space, do a
493 ble 0(sr5, r22) ; "normal" procedure call
496 text_space ; Otherwise, go through _sr4export,
497 ble (sr4, r1) ; which will return back here.
501 The dummy decides if the target is in text space or data space. If
502 it's in data space, there's no problem because the target can
503 return back to the dummy. However, if the target is in text space,
504 the dummy calls the secret, undocumented routine _sr4export, which
505 calls a function in text space and can return to any space. Instead
506 of including fake instructions to represent saved registers, we
507 know that the frame is associated with the call dummy and treat it
510 #define CALL_DUMMY { 0x4bda3fb9, 0x4bd93fb1, 0x4bd83fa9, 0x4bd73fa1, \
511 0x37c13fb9, 0x24201004, 0x2c391005, 0x24311006, \
512 0x2c291007, 0x22c00000, 0x36d60000, 0x02c010a3, \
513 0x20200000, 0x34210000, 0x002010a4, 0x80832012, \
514 0xe6c06000, 0x081f0242, 0x00010004, 0xe4202000, \
515 0x6bdf3fd1, 0x00010004}
517 #define CALL_DUMMY_LENGTH 88
518 #define CALL_DUMMY_START_OFFSET 0
519 /* Insert the specified number of args and function address
520 into a call sequence of the above form stored at DUMMYNAME. */
521 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \
522 { static CORE_ADDR sr4export_address = 0; \
524 if (!sr4export_address) \
526 struct minimal_symbol *msymbol; \
527 msymbol = lookup_minimal_symbol ("_sr4export", (struct objfile *) NULL);\
528 if (msymbol = NULL) \
529 error ("Can't find an address for _sr4export trampoline"); \
531 sr4export_address = msymbol -> address; \
533 dummyname[9] = deposit_21 (fun >> 11, dummyname[9]); \
534 dummyname[10] = deposit_14 (fun & MASK_11, dummyname[10]); \
535 dummyname[12] = deposit_21 (sr4export_address >> 11, dummyname[12]); \
536 dummyname[13] = deposit_14 (sr4export_address & MASK_11, dummyname[13]);\
539 /* Write the PC to a random value.
540 On PA-RISC, we need to be sure that the PC space queue is correct. */
542 #define WRITE_PC(addr) \
543 { int space_reg, space = ((addr) >> 30); \
546 space_reg = 43; /* Space reg sr4 */ \
547 else if (space == 1) \
548 space_reg = 48; /* Space reg sr5*/ \
550 error ("pc = %x is in illegal space.", addr); \
551 space_val = read_register (space_reg); \
552 write_register (PCOQ_HEAD_REGNUM, addr); \
553 write_register (PCSQ_HEAD_REGNUM, space_val); \
554 write_register (PCOQ_TAIL_REGNUM, addr); \
555 write_register (PCSQ_TAIL_REGNUM, space_val);}