1 /* Target machine sub-parameters for SPARC, for GDB, the GNU debugger.
2 This is included by other tm-*.h files to define SPARC cpu-related info.
3 Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@mcc.com)
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #define TARGET_BYTE_ORDER BIG_ENDIAN
24 /* Floating point is IEEE compatible. */
27 /* When passing a structure to a function, Sun cc passes the address
28 in a register, not the structure itself. It (under SunOS4) creates
29 two symbols, so we get a LOC_ARG saying the address is on the stack
30 (a lie, and a serious one since we don't know which register to
31 use), and a LOC_REGISTER saying that the struct is in a register
32 (sort of a lie, but fixable with REG_STRUCT_HAS_ADDR). Gcc version
33 two (as of 1.92) behaves like sun cc. REG_STRUCT_HAS_ADDR is smart
34 enough to distinguish between Sun cc, gcc version 1 and gcc version 2.
36 This still doesn't work if the argument is not one passed in a
37 register (i.e. it's the 7th or later argument). */
38 #define REG_STRUCT_HAS_ADDR(gcc_p) (gcc_p != 1)
39 #define STRUCT_ARG_SYM_GARBAGE(gcc_p) (gcc_p != 1)
41 /* If Pcc says that a parameter is a short, it's a short. This is
42 because the parameter does get passed in in a register as an int,
43 but pcc puts it onto the stack frame as a short (not nailing
44 whatever else might be there. I'm not sure that I consider this
47 No, don't do this. The problem here is that pcc says that the
48 argument is in the upper half of the word reserved on the stack,
49 but puts it in the lower half. */
50 /* #define BELIEVE_PCC_PROMOTION 1 */
51 /* OK, I've added code to dbxread.c to deal with this case. */
52 #define BELIEVE_PCC_PROMOTION_TYPE
54 /* Offset from address of function to start of its code.
55 Zero on most machines. */
57 #define FUNCTION_START_OFFSET 0
59 /* Advance PC across any function entry prologue instructions
60 to reach some "real" code. SKIP_PROLOGUE_FRAMELESS_P advances
61 the PC past some of the prologue, but stops as soon as it
62 knows that the function has a frame. Its result is equal
63 to its input PC if the function is frameless, unequal otherwise. */
65 #define SKIP_PROLOGUE(pc) \
66 { pc = skip_prologue (pc, 0); }
67 #define SKIP_PROLOGUE_FRAMELESS_P(pc) \
68 { pc = skip_prologue (pc, 1); }
69 extern CORE_ADDR
skip_prologue ();
71 /* Immediately after a function call, return the saved pc.
72 Can't go through the frames for this because on some machines
73 the new frame is not set up until the new function executes
76 /* On the Sun 4 under SunOS, the compile will leave a fake insn which
77 encodes the structure size being returned. If we detect such
78 a fake insn, step past it. */
80 #define PC_ADJUST(pc) sparc_pc_adjust(pc)
81 extern CORE_ADDR
sparc_pc_adjust();
83 #define SAVED_PC_AFTER_CALL(frame) PC_ADJUST (read_register (RP_REGNUM))
85 /* Stack grows downward. */
89 /* Stack has strict alignment. */
91 #define STACK_ALIGN(ADDR) (((ADDR)+7)&-8)
93 /* Sequence of bytes for breakpoint instruction. */
95 #define BREAKPOINT {0x91, 0xd0, 0x20, 0x01}
97 /* Amount PC must be decremented by after a breakpoint.
98 This is often the number of bytes in BREAKPOINT
101 #define DECR_PC_AFTER_BREAK 0
103 /* Nonzero if instruction at PC is a return instruction. */
104 /* For SPARC, this is either a "jmpl %o7+8,%g0" or "jmpl %i7+8,%g0".
106 Note: this does not work for functions returning structures under SunOS. */
107 #define ABOUT_TO_RETURN(pc) \
108 ((read_memory_integer (pc, 4)|0x00040000) == 0x81c7e008)
110 /* Return 1 if P points to an invalid floating point value. */
112 #define INVALID_FLOAT(p, len) 0 /* Just a first guess; not checked */
114 /* Say how long (ordinary) registers are. */
116 #define REGISTER_TYPE long
118 /* Number of machine registers */
122 /* Initializer for an array of names of registers.
123 There should be NUM_REGS strings in this initializer. */
125 #define REGISTER_NAMES \
126 { "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", \
127 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7", \
128 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", \
129 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7", \
131 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
132 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
133 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
134 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
136 "y", "psr", "wim", "tbr", "pc", "npc", "fpsr", "cpsr" }
138 /* Register numbers of various important registers.
139 Note that some of these values are "real" register numbers,
140 and correspond to the general registers of the machine,
141 and some are "phony" register numbers which are too large
142 to be actual register numbers as far as the user is concerned
143 but do serve to get the desired values when passed to read_register. */
145 #define G0_REGNUM 0 /* %g0 */
146 #define G1_REGNUM 1 /* %g1 */
147 #define O0_REGNUM 8 /* %o0 */
148 #define SP_REGNUM 14 /* Contains address of top of stack, \
149 which is also the bottom of the frame. */
150 #define RP_REGNUM 15 /* Contains return address value, *before* \
151 any windows get switched. */
152 #define O7_REGNUM 15 /* Last local reg not saved on stack frame */
153 #define L0_REGNUM 16 /* First local reg that's saved on stack frame
154 rather than in machine registers */
155 #define I0_REGNUM 24 /* %i0 */
156 #define FP_REGNUM 30 /* Contains address of executing stack frame */
157 #define I7_REGNUM 31 /* Last local reg saved on stack frame */
158 #define FP0_REGNUM 32 /* Floating point register 0 */
159 #define Y_REGNUM 64 /* Temp register for multiplication, etc. */
160 #define PS_REGNUM 65 /* Contains processor status */
161 #define WIM_REGNUM 66 /* Window Invalid Mask (not really supported) */
162 #define TBR_REGNUM 67 /* Trap Base Register (not really supported) */
163 #define PC_REGNUM 68 /* Contains program counter */
164 #define NPC_REGNUM 69 /* Contains next PC */
165 #define FPS_REGNUM 70 /* Floating point status register */
166 #define CPS_REGNUM 71 /* Coprocessor status register */
168 /* Total amount of space needed to store our copies of the machine's
169 register state, the array `registers'. */
170 #define REGISTER_BYTES (32*4+32*4+8*4)
172 /* Index within `registers' of the first byte of the space for
175 #define REGISTER_BYTE(N) ((N)*4)
177 /* The SPARC processor has register windows. */
179 #define HAVE_REGISTER_WINDOWS
181 /* Is this register part of the register window system? A yes answer
182 implies that 1) The name of this register will not be the same in
183 other frames, and 2) This register is automatically "saved" (out
184 registers shifting into ins counts) upon subroutine calls and thus
185 there is no need to search more than one stack frame for it. */
187 #define REGISTER_IN_WINDOW_P(regnum) \
188 ((regnum) >= 8 && (regnum) < 32)
192 /* Number of bytes of storage in the actual machine representation
195 /* On the SPARC, all regs are 4 bytes. */
197 #define REGISTER_RAW_SIZE(N) (4)
199 /* Number of bytes of storage in the program's representation
202 /* On the SPARC, all regs are 4 bytes. */
204 #define REGISTER_VIRTUAL_SIZE(N) (4)
206 /* Largest value REGISTER_RAW_SIZE can have. */
208 #define MAX_REGISTER_RAW_SIZE 8
210 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
212 #define MAX_REGISTER_VIRTUAL_SIZE 8
214 /* Nonzero if register N requires conversion
215 from raw format to virtual format. */
217 #define REGISTER_CONVERTIBLE(N) (0)
219 /* Convert data from raw format for register REGNUM
220 to virtual format for register REGNUM. */
222 #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
223 { memcpy ((TO), (FROM), 4); }
225 /* Convert data from virtual format for register REGNUM
226 to raw format for register REGNUM. */
228 #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
229 { memcpy ((TO), (FROM), 4); }
231 /* Return the GDB type object for the "standard" data type
232 of data in register N. */
234 #define REGISTER_VIRTUAL_TYPE(N) \
235 ((N) < 32 ? builtin_type_int : (N) < 64 ? builtin_type_float : \
238 /* Writing to %g0 is a noop (not an error or exception or anything like
241 #define CANNOT_STORE_REGISTER(regno) ((regno) == G0_REGNUM)
243 /* Store the address of the place in which to copy the structure the
244 subroutine will return. This is called from call_function. */
246 #define STORE_STRUCT_RETURN(ADDR, SP) \
247 { target_write_memory ((SP)+(16*4), (char *)&(ADDR), 4); }
249 /* Extract from an array REGBUF containing the (raw) register state
250 a function return value of type TYPE, and copy that, in virtual format,
253 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
255 if (TYPE_CODE (TYPE) == TYPE_CODE_FLT) \
257 memcpy ((VALBUF), ((int *)(REGBUF))+FP0_REGNUM, TYPE_LENGTH(TYPE));\
261 (char *)(REGBUF) + 4 * 8 + \
262 (TYPE_LENGTH(TYPE) >= 4 ? 0 : 4 - TYPE_LENGTH(TYPE)), \
263 TYPE_LENGTH(TYPE)); \
266 /* Write into appropriate registers a function return value
267 of type TYPE, given in virtual format. */
268 /* On sparc, values are returned in register %o0. */
269 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
271 if (TYPE_CODE (TYPE) == TYPE_CODE_FLT) \
272 /* Floating-point values are returned in the register pair */ \
273 /* formed by %f0 and %f1 (doubles are, anyway). */ \
274 write_register_bytes (REGISTER_BYTE (FP0_REGNUM), (VALBUF), \
275 TYPE_LENGTH (TYPE)); \
277 /* Other values are returned in register %o0. */ \
278 write_register_bytes (REGISTER_BYTE (O0_REGNUM), (VALBUF), \
279 TYPE_LENGTH (TYPE)); \
282 /* Extract from an array REGBUF containing the (raw) register state
283 the address in which a function should return its structure value,
284 as a CORE_ADDR (or an expression that can be used as one). */
286 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) \
287 (sparc_extract_struct_value_address (REGBUF))
290 sparc_extract_struct_value_address
PARAMS ((char [REGISTER_BYTES
]));
293 /* Describe the pointer in each stack frame to the previous stack frame
296 /* FRAME_CHAIN takes a frame's nominal address
297 and produces the frame's chain-pointer. */
299 /* In the case of the Sun 4, the frame-chain's nominal address
300 is held in the frame pointer register.
302 On the Sun4, the frame (in %fp) is %sp for the previous frame.
303 From the previous frame's %sp, we can find the previous frame's
304 %fp: it is in the save area just above the previous frame's %sp.
306 If we are setting up an arbitrary frame, we'll need to know where
307 it ends. Hence the following. This part of the frame cache
308 structure should be checked before it is assumed that this frame's
309 bottom is in the stack pointer.
311 If there isn't a frame below this one, the bottom of this frame is
312 in the stack pointer.
314 If there is a frame below this one, and the frame pointers are
315 identical, it's a leaf frame and the bottoms are the same also.
317 Otherwise the bottom of this frame is the top of the next frame. */
319 #define EXTRA_FRAME_INFO FRAME_ADDR bottom;
320 #define INIT_EXTRA_FRAME_INFO(fromleaf, fci) \
323 ((fci)->frame == (fci)->next_frame ? \
324 (fci)->next->bottom : (fci)->next->frame) : \
325 read_register (SP_REGNUM));
327 #define FRAME_CHAIN(thisframe) (sparc_frame_chain (thisframe))
328 CORE_ADDR
sparc_frame_chain ();
330 /* Define other aspects of the stack frame. */
332 /* A macro that tells us whether the function invocation represented
333 by FI does not have a frame on the stack associated with it. If it
334 does not, FRAMELESS is set to 1, else 0. */
335 #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
336 (FRAMELESS) = frameless_look_for_prologue(FI)
338 /* Where is the PC for a specific frame */
340 #define FRAME_SAVED_PC(FRAME) frame_saved_pc (FRAME)
341 CORE_ADDR
frame_saved_pc ();
343 /* If the argument is on the stack, it will be here. */
344 #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
346 #define FRAME_STRUCT_ARGS_ADDRESS(fi) ((fi)->frame)
348 #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
350 /* Set VAL to the number of args passed to frame described by FI.
351 Can set VAL to -1, meaning no way to tell. */
353 /* We can't tell how many args there are
354 now that the C compiler delays popping them. */
355 #define FRAME_NUM_ARGS(val,fi) (val = -1)
357 /* Return number of bytes at start of arglist that are not really args. */
359 #define FRAME_ARGS_SKIP 68
361 /* Put here the code to store, into a struct frame_saved_regs,
362 the addresses of the saved registers of frame described by FRAME_INFO.
363 The actual code is in sparc-tdep.c so we can debug it sanely. */
365 #define FRAME_FIND_SAVED_REGS(fi, frame_saved_regs) \
366 sparc_frame_find_saved_regs ((fi), &(frame_saved_regs))
367 extern void sparc_frame_find_saved_regs ();
369 /* Things needed for making the inferior call functions. */
371 * First of all, let me give my opinion of what the DUMMY_FRAME
372 * actually looks like.
376 * + - - - - - - - - - - - - - - - - +<-- fp (level 0)
381 * | Frame of innermost program |
388 * |---------------------------------|<-- sp (level 0), fp (c)
392 * | ------ |<-- fp - 0x80
393 * FRAME | g0-7 |<-- fp - 0xa0
394 * | i0-7 |<-- fp - 0xc0
395 * | other |<-- fp - 0xe0
398 * |---------------------------------|<-- sp' = fp - 0x140
401 * sp' + 0x94 -->| CALL_DUMMY (x code) |
404 * |---------------------------------|<-- sp'' = fp - 0x200
405 * | align sp to 8 byte boundary |
406 * | ==> args to fn <== |
408 * i & l's + agg | CALL_DUMMY_STACK_ADJUST = 0x0x44|
409 * |---------------------------------|<-- final sp (variable)
411 * | Where function called will |
416 * I understand everything in this picture except what the space
417 * between fp - 0xe0 and fp - 0x140 is used for. Oh, and I don't
418 * understand why there's a large chunk of CALL_DUMMY that never gets
419 * executed (its function is superceeded by PUSH_DUMMY_FRAME; they
420 * are designed to do the same thing).
422 * PUSH_DUMMY_FRAME saves the registers above sp' and pushes the
423 * register file stack down one.
425 * call_function then writes CALL_DUMMY, pushes the args onto the
426 * stack, and adjusts the stack pointer.
428 * run_stack_dummy then starts execution (in the middle of
429 * CALL_DUMMY, as directed by call_function).
432 /* Push an empty stack frame, to record the current PC, etc. */
434 #define PUSH_DUMMY_FRAME sparc_push_dummy_frame ()
435 #define POP_FRAME sparc_pop_frame ()
437 void sparc_push_dummy_frame (), sparc_pop_frame ();
438 /* This sequence of words is the instructions
465 nop ! stcsr [%fp-0xc4]
466 nop ! stfsr [%fp-0xc8]
467 nop ! wr %npc,[%fp-0xcc]
468 nop ! wr %pc,[%fp-0xd0]
478 /..* The arguments are pushed at this point by GDB;
479 no code is needed in the dummy for this.
480 The CALL_DUMMY_START_OFFSET gives the position of
481 the following ld instruction. *../
494 note that this is 192 bytes, which is a multiple of 8 (not only 4) bytes.
495 note that the `call' insn is a relative, not an absolute call.
496 note that the `nop' at the end is needed to keep the trap from
497 clobbering things (if NPC pointed to garbage instead).
499 We actually start executing at the `sethi', since the pushing of the
500 registers (as arguments) is done by PUSH_DUMMY_FRAME. If this were
501 real code, the arguments for the function called by the CALL would be
502 pushed between the list of ST insns and the CALL, and we could allow
503 it to execute through. But the arguments have to be pushed by GDB
504 after the PUSH_DUMMY_FRAME is done, and we cannot allow these ST
505 insns to be performed again, lest the registers saved be taken for
508 #define CALL_DUMMY { 0x9de3bee0, 0xfd3fbff8, 0xf93fbff0, 0xf53fbfe8, \
509 0xf13fbfe0, 0xed3fbfd8, 0xe93fbfd0, 0xe53fbfc8, \
510 0xe13fbfc0, 0xdd3fbfb8, 0xd93fbfb0, 0xd53fbfa8, \
511 0xd13fbfa0, 0xcd3fbf98, 0xc93fbf90, 0xc53fbf88, \
512 0xc13fbf80, 0xcc3fbf78, 0xc83fbf70, 0xc43fbf68, \
513 0xc03fbf60, 0xfc3fbf58, 0xf83fbf50, 0xf43fbf48, \
514 0xf03fbf40, 0x01000000, 0x01000000, 0x01000000, \
515 0x01000000, 0x91580000, 0xd027bf50, 0x93500000, \
516 0xd027bf4c, 0x91480000, 0xd027bf48, 0x91400000, \
517 0xd027bf44, 0xda03a058, 0xd803a054, 0xd603a050, \
518 0xd403a04c, 0xd203a048, 0x40000000, 0xd003a044, \
519 0x01000000, 0x91d02001, 0x01000000, 0x01000000}
521 #define CALL_DUMMY_LENGTH 192
523 #define CALL_DUMMY_START_OFFSET 148
525 #define CALL_DUMMY_STACK_ADJUST 68
527 /* Insert the specified number of args and function address
528 into a call sequence of the above form stored at DUMMYNAME.
530 For structs and unions, if the function was compiled with Sun cc,
531 it expects 'unimp' after the call. But gcc doesn't use that
532 (twisted) convention. So leave a nop there for gcc (FIX_CALL_DUMMY
533 can assume it is operating on a pristine CALL_DUMMY, not one that
534 has already been customized for a different function). */
536 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \
538 *(int *)((char *) dummyname+168) = (0x40000000|((fun-(pc+168))>>2)); \
540 && (TYPE_CODE (type) == TYPE_CODE_STRUCT \
541 || TYPE_CODE (type) == TYPE_CODE_UNION)) \
542 *(int *)((char *) dummyname+176) = (TYPE_LENGTH (type) & 0x1fff); \
546 /* Sparc has no reliable single step ptrace call */
548 #define NO_SINGLE_STEP 1
549 extern void single_step ();
551 /* We need more arguments in a frame specification for the
552 "frame" or "info frame" command. */
554 #define SETUP_ARBITRARY_FRAME(argc, argv) setup_arbitrary_frame (argc, argv)
555 extern struct frame_info
*setup_arbitrary_frame ();
557 /* To print every pair of float registers as a double, we use this hook. */
559 #define PRINT_REGISTER_HOOK(regno) \
560 if (((regno) >= FP0_REGNUM) \
561 && ((regno) < FP0_REGNUM + 32) \
562 && (0 == (regno & 1))) { \
563 char doublereg[8]; /* two float regs */ \
564 if (!read_relative_register_raw_bytes (i , doublereg ) \
565 && !read_relative_register_raw_bytes (i+1, doublereg+4)) { \
567 print_floating (doublereg, builtin_type_double, stdout); \
571 /* Optimization for storing registers to the inferior. The hook
573 actually executes any deferred stores. It is called any time
574 we are going to proceed the child, or read its registers.
575 The hook CLEAR_DEFERRED_STORES is called when we want to throw
576 away the inferior process, e.g. when it dies or we kill it.
577 FIXME, this does not handle remote debugging cleanly. */
579 extern int deferred_stores
;
580 #define DO_DEFERRED_STORES \
581 if (deferred_stores) \
582 target_store_registers (-2);
583 #define CLEAR_DEFERRED_STORES \