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 /* If an argument is declared "register", Sun cc will keep it in a register,
28 never saving it onto the stack. So we better not believe the "p" symbol
31 #define USE_REGISTER_NOT_ARG
33 /* When passing a structure to a function, Sun cc passes the address
34 not the structure itself. It (under SunOS4) creates two symbols,
35 which we need to combine to a LOC_REGPARM. Gcc version two (as of
36 1.92) behaves like sun cc. REG_STRUCT_HAS_ADDR is smart enough to
37 distinguish between Sun cc, gcc version 1 and gcc version 2. */
39 #define REG_STRUCT_HAS_ADDR(gcc_p,type) (gcc_p != 1)
41 /* Sun /bin/cc gets this right as of SunOS 4.1.x. We need to define
42 BELIEVE_PCC_PROMOTION to get this right now that the code which
43 detects gcc2_compiled. is broken. This loses for SunOS 4.0.x and
46 #define BELIEVE_PCC_PROMOTION 1
48 /* For acc, there's no need to correct LBRAC entries by guessing how
49 they should work. In fact, this is harmful because the LBRAC
50 entries now all appear at the end of the function, not intermixed
51 with the SLINE entries. n_opt_found detects acc for Solaris binaries;
52 function_stab_type detects acc for SunOS4 binaries.
54 For binary from SunOS4 /bin/cc, need to correct LBRAC's.
56 For gcc, like acc, don't correct. */
58 #define SUN_FIXED_LBRAC_BUG \
60 || function_stab_type == N_STSYM \
61 || function_stab_type == N_GSYM \
62 || processing_gcc_compilation)
64 /* Do variables in the debug stabs occur after the N_LBRAC or before it?
65 acc: after, gcc: before, SunOS4 /bin/cc: before. */
67 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) \
70 || function_stab_type == N_STSYM \
71 || function_stab_type == N_GSYM))
73 /* Offset from address of function to start of its code.
74 Zero on most machines. */
76 #define FUNCTION_START_OFFSET 0
78 /* Advance PC across any function entry prologue instructions
79 to reach some "real" code. SKIP_PROLOGUE_FRAMELESS_P advances
80 the PC past some of the prologue, but stops as soon as it
81 knows that the function has a frame. Its result is equal
82 to its input PC if the function is frameless, unequal otherwise. */
84 #define SKIP_PROLOGUE(pc) \
85 { pc = skip_prologue (pc, 0); }
86 #define SKIP_PROLOGUE_FRAMELESS_P(pc) \
87 { pc = skip_prologue (pc, 1); }
88 extern CORE_ADDR
skip_prologue ();
90 /* Immediately after a function call, return the saved pc.
91 Can't go through the frames for this because on some machines
92 the new frame is not set up until the new function executes
95 /* On the Sun 4 under SunOS, the compile will leave a fake insn which
96 encodes the structure size being returned. If we detect such
97 a fake insn, step past it. */
99 #define PC_ADJUST(pc) sparc_pc_adjust(pc)
100 extern CORE_ADDR
sparc_pc_adjust();
102 #define SAVED_PC_AFTER_CALL(frame) PC_ADJUST (read_register (RP_REGNUM))
104 /* Stack grows downward. */
108 /* Stack has strict alignment. */
110 #define STACK_ALIGN(ADDR) (((ADDR)+7)&-8)
112 /* Sequence of bytes for breakpoint instruction. */
114 #define BREAKPOINT {0x91, 0xd0, 0x20, 0x01}
116 /* Amount PC must be decremented by after a breakpoint.
117 This is often the number of bytes in BREAKPOINT
120 #define DECR_PC_AFTER_BREAK 0
122 /* Nonzero if instruction at PC is a return instruction. */
123 /* For SPARC, this is either a "jmpl %o7+8,%g0" or "jmpl %i7+8,%g0".
125 Note: this does not work for functions returning structures under SunOS. */
126 #define ABOUT_TO_RETURN(pc) \
127 ((read_memory_integer (pc, 4)|0x00040000) == 0x81c7e008)
129 /* Say how long (ordinary) registers are. This is a piece of bogosity
130 used in push_word and a few other places; REGISTER_RAW_SIZE is the
131 real way to know how big a register is. */
133 #define REGISTER_SIZE 4
135 /* Number of machine registers */
139 /* Initializer for an array of names of registers.
140 There should be NUM_REGS strings in this initializer. */
142 #define REGISTER_NAMES \
143 { "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", \
144 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7", \
145 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", \
146 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7", \
148 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
149 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
150 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
151 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
153 "y", "psr", "wim", "tbr", "pc", "npc", "fpsr", "cpsr" }
155 /* Register numbers of various important registers.
156 Note that some of these values are "real" register numbers,
157 and correspond to the general registers of the machine,
158 and some are "phony" register numbers which are too large
159 to be actual register numbers as far as the user is concerned
160 but do serve to get the desired values when passed to read_register. */
162 #define G0_REGNUM 0 /* %g0 */
163 #define G1_REGNUM 1 /* %g1 */
164 #define O0_REGNUM 8 /* %o0 */
165 #define SP_REGNUM 14 /* Contains address of top of stack, \
166 which is also the bottom of the frame. */
167 #define RP_REGNUM 15 /* Contains return address value, *before* \
168 any windows get switched. */
169 #define O7_REGNUM 15 /* Last local reg not saved on stack frame */
170 #define L0_REGNUM 16 /* First local reg that's saved on stack frame
171 rather than in machine registers */
172 #define I0_REGNUM 24 /* %i0 */
173 #define FP_REGNUM 30 /* Contains address of executing stack frame */
174 #define I7_REGNUM 31 /* Last local reg saved on stack frame */
175 #define FP0_REGNUM 32 /* Floating point register 0 */
176 #define Y_REGNUM 64 /* Temp register for multiplication, etc. */
177 #define PS_REGNUM 65 /* Contains processor status */
178 #define WIM_REGNUM 66 /* Window Invalid Mask (not really supported) */
179 #define TBR_REGNUM 67 /* Trap Base Register (not really supported) */
180 #define PC_REGNUM 68 /* Contains program counter */
181 #define NPC_REGNUM 69 /* Contains next PC */
182 #define FPS_REGNUM 70 /* Floating point status register */
183 #define CPS_REGNUM 71 /* Coprocessor status register */
185 /* Total amount of space needed to store our copies of the machine's
186 register state, the array `registers'. On the sparc, `registers'
187 contains the ins and locals, even though they are saved on the
188 stack rather than with the other registers, and this causes hair
189 and confusion in places like pop_frame. It probably would be
190 better to remove the ins and locals from `registers', make sure
191 that get_saved_register can get them from the stack (even in the
192 innermost frame), and make this the way to access them. For the
193 frame pointer we would do that via TARGET_READ_FP. */
195 #define REGISTER_BYTES (32*4+32*4+8*4)
197 /* Index within `registers' of the first byte of the space for
200 #define REGISTER_BYTE(N) ((N)*4)
202 /* The SPARC processor has register windows. */
204 #define HAVE_REGISTER_WINDOWS
206 /* Is this register part of the register window system? A yes answer
207 implies that 1) The name of this register will not be the same in
208 other frames, and 2) This register is automatically "saved" (out
209 registers shifting into ins counts) upon subroutine calls and thus
210 there is no need to search more than one stack frame for it. */
212 #define REGISTER_IN_WINDOW_P(regnum) \
213 ((regnum) >= 8 && (regnum) < 32)
215 /* Number of bytes of storage in the actual machine representation
218 /* On the SPARC, all regs are 4 bytes. */
220 #define REGISTER_RAW_SIZE(N) (4)
222 /* Number of bytes of storage in the program's representation
225 /* On the SPARC, all regs are 4 bytes. */
227 #define REGISTER_VIRTUAL_SIZE(N) (4)
229 /* Largest value REGISTER_RAW_SIZE can have. */
231 #define MAX_REGISTER_RAW_SIZE 8
233 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
235 #define MAX_REGISTER_VIRTUAL_SIZE 8
237 /* Return the GDB type object for the "standard" data type
238 of data in register N. */
240 #define REGISTER_VIRTUAL_TYPE(N) \
241 ((N) < 32 ? builtin_type_int : (N) < 64 ? builtin_type_float : \
244 /* Writing to %g0 is a noop (not an error or exception or anything like
247 #define CANNOT_STORE_REGISTER(regno) ((regno) == G0_REGNUM)
249 /* Store the address of the place in which to copy the structure the
250 subroutine will return. This is called from call_function. */
252 #define STORE_STRUCT_RETURN(ADDR, SP) \
253 { target_write_memory ((SP)+(16*4), (char *)&(ADDR), 4); }
255 /* Extract from an array REGBUF containing the (raw) register state
256 a function return value of type TYPE, and copy that, in virtual format,
259 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
261 if (TYPE_CODE (TYPE) == TYPE_CODE_FLT) \
263 memcpy ((VALBUF), ((int *)(REGBUF))+FP0_REGNUM, TYPE_LENGTH(TYPE));\
267 (char *)(REGBUF) + 4 * 8 + \
268 (TYPE_LENGTH(TYPE) >= 4 ? 0 : 4 - TYPE_LENGTH(TYPE)), \
269 TYPE_LENGTH(TYPE)); \
272 /* Write into appropriate registers a function return value
273 of type TYPE, given in virtual format. */
274 /* On sparc, values are returned in register %o0. */
275 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
277 if (TYPE_CODE (TYPE) == TYPE_CODE_FLT) \
278 /* Floating-point values are returned in the register pair */ \
279 /* formed by %f0 and %f1 (doubles are, anyway). */ \
280 write_register_bytes (REGISTER_BYTE (FP0_REGNUM), (VALBUF), \
281 TYPE_LENGTH (TYPE)); \
283 /* Other values are returned in register %o0. */ \
284 write_register_bytes (REGISTER_BYTE (O0_REGNUM), (VALBUF), \
285 TYPE_LENGTH (TYPE)); \
288 /* Extract from an array REGBUF containing the (raw) register state
289 the address in which a function should return its structure value,
290 as a CORE_ADDR (or an expression that can be used as one). */
292 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) \
293 (sparc_extract_struct_value_address (REGBUF))
296 sparc_extract_struct_value_address
PARAMS ((char [REGISTER_BYTES
]));
299 /* Describe the pointer in each stack frame to the previous stack frame
302 /* FRAME_CHAIN takes a frame's nominal address
303 and produces the frame's chain-pointer. */
305 /* In the case of the Sun 4, the frame-chain's nominal address
306 is held in the frame pointer register.
308 On the Sun4, the frame (in %fp) is %sp for the previous frame.
309 From the previous frame's %sp, we can find the previous frame's
310 %fp: it is in the save area just above the previous frame's %sp.
312 If we are setting up an arbitrary frame, we'll need to know where
313 it ends. Hence the following. This part of the frame cache
314 structure should be checked before it is assumed that this frame's
315 bottom is in the stack pointer.
317 If there isn't a frame below this one, the bottom of this frame is
318 in the stack pointer.
320 If there is a frame below this one, and the frame pointers are
321 identical, it's a leaf frame and the bottoms are the same also.
323 Otherwise the bottom of this frame is the top of the next frame.
325 The bottom field is misnamed, since it might imply that memory from
326 bottom to frame contains this frame. That need not be true if
327 stack frames are allocated in different segments (e.g. some on a
328 stack, some on a heap in the data segment). */
330 #define EXTRA_FRAME_INFO FRAME_ADDR bottom;
331 #define INIT_EXTRA_FRAME_INFO(fromleaf, fci) \
334 ((fci)->frame == (fci)->next->frame ? \
335 (fci)->next->bottom : (fci)->next->frame) : \
336 read_register (SP_REGNUM));
338 #define FRAME_CHAIN(thisframe) (sparc_frame_chain (thisframe))
339 CORE_ADDR
sparc_frame_chain ();
341 /* Define other aspects of the stack frame. */
343 /* A macro that tells us whether the function invocation represented
344 by FI does not have a frame on the stack associated with it. If it
345 does not, FRAMELESS is set to 1, else 0. */
346 #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
347 (FRAMELESS) = frameless_look_for_prologue(FI)
349 /* The location of I0 w.r.t SP. This is actually dependent on how the system's
350 window overflow/underflow routines are written. Most vendors save the L regs
351 followed by the I regs (at the higher address). Some vendors get it wrong.
354 #define FRAME_SAVED_L0 0
355 #define FRAME_SAVED_I0 (8 * REGISTER_RAW_SIZE (L0_REGNUM))
357 /* Where is the PC for a specific frame */
359 #define FRAME_SAVED_PC(FRAME) sparc_frame_saved_pc (FRAME)
360 CORE_ADDR
sparc_frame_saved_pc ();
362 /* If the argument is on the stack, it will be here. */
363 #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
365 #define FRAME_STRUCT_ARGS_ADDRESS(fi) ((fi)->frame)
367 #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
369 /* Set VAL to the number of args passed to frame described by FI.
370 Can set VAL to -1, meaning no way to tell. */
372 /* We can't tell how many args there are
373 now that the C compiler delays popping them. */
374 #define FRAME_NUM_ARGS(val,fi) (val = -1)
376 /* Return number of bytes at start of arglist that are not really args. */
378 #define FRAME_ARGS_SKIP 68
380 /* Put here the code to store, into a struct frame_saved_regs,
381 the addresses of the saved registers of frame described by FRAME_INFO.
382 The actual code is in sparc-tdep.c so we can debug it sanely. */
384 #define FRAME_FIND_SAVED_REGS(fi, frame_saved_regs) \
385 sparc_frame_find_saved_regs ((fi), &(frame_saved_regs))
386 extern void sparc_frame_find_saved_regs ();
388 /* Things needed for making the inferior call functions. */
390 * First of all, let me give my opinion of what the DUMMY_FRAME
391 * actually looks like.
395 * + - - - - - - - - - - - - - - - - +<-- fp (level 0)
400 * | Frame of innermost program |
407 * |---------------------------------|<-- sp (level 0), fp (c)
411 * | ------ |<-- fp - 0x80
412 * FRAME | g0-7 |<-- fp - 0xa0
413 * | i0-7 |<-- fp - 0xc0
414 * | other |<-- fp - 0xe0
417 * |---------------------------------|<-- sp' = fp - 0x140
420 * sp' + 0x94 -->| CALL_DUMMY (x code) |
423 * |---------------------------------|<-- sp'' = fp - 0x200
424 * | align sp to 8 byte boundary |
425 * | ==> args to fn <== |
427 * i & l's + agg | CALL_DUMMY_STACK_ADJUST = 0x0x44|
428 * |---------------------------------|<-- final sp (variable)
430 * | Where function called will |
435 * I understand everything in this picture except what the space
436 * between fp - 0xe0 and fp - 0x140 is used for. Oh, and I don't
437 * understand why there's a large chunk of CALL_DUMMY that never gets
438 * executed (its function is superceeded by PUSH_DUMMY_FRAME; they
439 * are designed to do the same thing).
441 * PUSH_DUMMY_FRAME saves the registers above sp' and pushes the
442 * register file stack down one.
444 * call_function then writes CALL_DUMMY, pushes the args onto the
445 * stack, and adjusts the stack pointer.
447 * run_stack_dummy then starts execution (in the middle of
448 * CALL_DUMMY, as directed by call_function).
451 /* Push an empty stack frame, to record the current PC, etc. */
453 #define PUSH_DUMMY_FRAME sparc_push_dummy_frame ()
454 #define POP_FRAME sparc_pop_frame ()
456 void sparc_push_dummy_frame (), sparc_pop_frame ();
457 /* This sequence of words is the instructions
484 nop ! stcsr [%fp-0xc4]
485 nop ! stfsr [%fp-0xc8]
486 nop ! wr %npc,[%fp-0xcc]
487 nop ! wr %pc,[%fp-0xd0]
497 /..* The arguments are pushed at this point by GDB;
498 no code is needed in the dummy for this.
499 The CALL_DUMMY_START_OFFSET gives the position of
500 the following ld instruction. *../
513 note that this is 192 bytes, which is a multiple of 8 (not only 4) bytes.
514 note that the `call' insn is a relative, not an absolute call.
515 note that the `nop' at the end is needed to keep the trap from
516 clobbering things (if NPC pointed to garbage instead).
518 We actually start executing at the `sethi', since the pushing of the
519 registers (as arguments) is done by PUSH_DUMMY_FRAME. If this were
520 real code, the arguments for the function called by the CALL would be
521 pushed between the list of ST insns and the CALL, and we could allow
522 it to execute through. But the arguments have to be pushed by GDB
523 after the PUSH_DUMMY_FRAME is done, and we cannot allow these ST
524 insns to be performed again, lest the registers saved be taken for
527 #define CALL_DUMMY { 0x9de3bee0, 0xfd3fbff8, 0xf93fbff0, 0xf53fbfe8, \
528 0xf13fbfe0, 0xed3fbfd8, 0xe93fbfd0, 0xe53fbfc8, \
529 0xe13fbfc0, 0xdd3fbfb8, 0xd93fbfb0, 0xd53fbfa8, \
530 0xd13fbfa0, 0xcd3fbf98, 0xc93fbf90, 0xc53fbf88, \
531 0xc13fbf80, 0xcc3fbf78, 0xc83fbf70, 0xc43fbf68, \
532 0xc03fbf60, 0xfc3fbf58, 0xf83fbf50, 0xf43fbf48, \
533 0xf03fbf40, 0x01000000, 0x01000000, 0x01000000, \
534 0x01000000, 0x91580000, 0xd027bf50, 0x93500000, \
535 0xd027bf4c, 0x91480000, 0xd027bf48, 0x91400000, \
536 0xd027bf44, 0xda03a058, 0xd803a054, 0xd603a050, \
537 0xd403a04c, 0xd203a048, 0x40000000, 0xd003a044, \
538 0x01000000, 0x91d02001, 0x01000000, 0x01000000}
540 #define CALL_DUMMY_LENGTH 192
542 #define CALL_DUMMY_START_OFFSET 148
544 #define CALL_DUMMY_BREAKPOINT_OFFSET (CALL_DUMMY_START_OFFSET + (8 * 4))
546 #define CALL_DUMMY_STACK_ADJUST 68
548 /* Insert the specified number of args and function address
549 into a call sequence of the above form stored at DUMMYNAME.
551 For structs and unions, if the function was compiled with Sun cc,
552 it expects 'unimp' after the call. But gcc doesn't use that
553 (twisted) convention. So leave a nop there for gcc (FIX_CALL_DUMMY
554 can assume it is operating on a pristine CALL_DUMMY, not one that
555 has already been customized for a different function). */
557 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \
559 *(int *)((char *) dummyname+168) = (0x40000000|((fun-(pc+168))>>2)); \
561 && (TYPE_CODE (type) == TYPE_CODE_STRUCT \
562 || TYPE_CODE (type) == TYPE_CODE_UNION)) \
563 *(int *)((char *) dummyname+176) = (TYPE_LENGTH (type) & 0x1fff); \
567 /* Sparc has no reliable single step ptrace call */
569 #define NO_SINGLE_STEP 1
570 extern void single_step ();
572 /* We need more arguments in a frame specification for the
573 "frame" or "info frame" command. */
575 #define SETUP_ARBITRARY_FRAME(argc, argv) setup_arbitrary_frame (argc, argv)
576 /* FIXME: Depends on equivalence between FRAME and "struct frame_info *",
577 and equivalence between CORE_ADDR and FRAME_ADDR. */
578 extern struct frame_info
*setup_arbitrary_frame
PARAMS ((int, CORE_ADDR
*));
580 /* To print every pair of float registers as a double, we use this hook. */
582 #define PRINT_REGISTER_HOOK(regno) \
583 if (((regno) >= FP0_REGNUM) \
584 && ((regno) < FP0_REGNUM + 32) \
585 && (0 == ((regno) & 1))) { \
586 char doublereg[8]; /* two float regs */ \
587 if (!read_relative_register_raw_bytes ((regno) , doublereg ) \
588 && !read_relative_register_raw_bytes ((regno)+1, doublereg+4)) { \
590 print_floating (doublereg, builtin_type_double, stdout); \
594 /* Optimization for storing registers to the inferior. The hook
596 actually executes any deferred stores. It is called any time
597 we are going to proceed the child, or read its registers.
598 The hook CLEAR_DEFERRED_STORES is called when we want to throw
599 away the inferior process, e.g. when it dies or we kill it.
600 FIXME, this does not handle remote debugging cleanly. */
602 extern int deferred_stores
;
603 #define DO_DEFERRED_STORES \
604 if (deferred_stores) \
605 target_store_registers (-2);
606 #define CLEAR_DEFERRED_STORES \