BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / gdb / config / m-sparc.h
CommitLineData
af359dea
C
1/*-
2 * This code is derived from software copyrighted by the Free Software
3 * Foundation.
4 *
5 * Modified 1991 by Donn Seeley at UUNET Technologies, Inc.
6 * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory.
7 *
8 * @(#)m-sparc.h 6.4 (Berkeley) 5/8/91
9 */
10
11/* Parameters for execution on a Sun 4, for GDB, the GNU debugger.
12 Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
13 Contributed by Michael Tiemann (tiemann@mcc.com)
14This file is part of GDB.
15
16GDB is free software; you can redistribute it and/or modify
17it under the terms of the GNU General Public License as published by
18the Free Software Foundation; either version 1, or (at your option)
19any later version.
20
21GDB is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with GDB; see the file COPYING. If not, write to
28the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
29
30#ifndef sun4
31#define sun4
32#endif
33
34/* Define the bit, byte, and word ordering of the machine. */
35#define BITS_BIG_ENDIAN
36#define BYTES_BIG_ENDIAN
37#define WORDS_BIG_ENDIAN
38
39/* Floating point is IEEE compatible. */
40#define IEEE_FLOAT
41
42/* Get rid of any system-imposed stack limit if possible. */
43
44#define SET_STACK_LIMIT_HUGE
45
46/* Define this if the C compiler puts an underscore at the front
47 of external names before giving them to the linker. */
48
49#define NAMES_HAVE_UNDERSCORE
50
51/* Debugger information will be in DBX format. */
52
53#define READ_DBX_FORMAT
54
55/* When passing a structure to a function, Sun cc passes the address
56 in a register, not the structure itself. It (under SunOS4) creates
57 two symbols, so we get a LOC_ARG saying the address is on the stack
58 (a lie, and a serious one since we don't know which register to
59 use), and a LOC_REGISTER saying that the struct is in a register
60 (sort of a lie, but fixable with REG_STRUCT_HAS_ADDR).
61
62 This still doesn't work if the argument is not one passed in a
63 register (i.e. it's the 7th or later argument). */
64#define REG_STRUCT_HAS_ADDR(gcc_p) (!gcc_p)
65#define STRUCT_ARG_SYM_GARBAGE(gcc_p) (!gcc_p)
66
67/* If Pcc says that a parameter is a short, it's a short. This is
68 because the parameter does get passed in in a register as an int,
69 but pcc puts it onto the stack frame as a short (not nailing
70 whatever else might be there. I'm not sure that I consider this
71 swift. Sigh.)
72
73 No, don't do this. The problem here is that pcc says that the
74 argument is in the upper half of the word reserved on the stack,
75 but puts it in the lower half. */
76/* #define BELIEVE_PCC_PROMOTION 1 */
77/* OK, I've added code to dbxread.c to deal with this case. */
78#define BELIEVE_PCC_PROMOTION_TYPE
79
80/* Offset from address of function to start of its code.
81 Zero on most machines. */
82
83#define FUNCTION_START_OFFSET 0
84
85/* Advance PC across any function entry prologue instructions
86 to reach some "real" code. */
87
88#define SKIP_PROLOGUE(pc) \
89 { pc = skip_prologue (pc); }
90
91/* Immediately after a function call, return the saved pc.
92 Can't go through the frames for this because on some machines
93 the new frame is not set up until the new function executes
94 some instructions. */
95
96/* On the Sun 4 under SunOS, the compile will leave a fake insn which
97 encodes the structure size being returned. If we detect such
98 a fake insn, step past it. */
99
100#define PC_ADJUST(pc) ((read_memory_integer (pc + 8, 4) & 0xfffffe00) == 0 ? \
101 pc+12 : pc+8)
102
103#define SAVED_PC_AFTER_CALL(frame) PC_ADJUST (read_register (RP_REGNUM))
104
105/* Address of end of stack space. */
106#include <sys/types.h>
107#include <machine/vmparam.h>
108#define STACK_END_ADDR USRSTACK
109
110#define INNER_THAN <
111
112/* Stack has strict alignment. */
113
114#define STACK_ALIGN(ADDR) (((ADDR)+7)&-8)
115
116/* Sequence of bytes for breakpoint instruction. */
117
118#define BREAKPOINT {0x91, 0xd0, 0x20, 0x01}
119
120/* Amount PC must be decremented by after a breakpoint.
121 This is often the number of bytes in BREAKPOINT
122 but not always. */
123
124#define DECR_PC_AFTER_BREAK 0
125
126/* Nonzero if instruction at PC is a return instruction. */
127/* For SPARC, this is either a "jmpl %o7+8,%g0" or "jmpl %i7+8,%g0".
128
129 Note: this does not work for functions returning structures under SunOS. */
130#define ABOUT_TO_RETURN(pc) \
131 ((read_memory_integer (pc, 4)|0x00040000) == 0x81c7e008)
132
133/* Return 1 if P points to an invalid floating point value. */
134
135#define INVALID_FLOAT(p, len) 0 /* Just a first guess; not checked */
136
137/* Largest integer type */
138#define LONGEST long
139
140/* Name of the builtin type for the LONGEST type above. */
141#define BUILTIN_TYPE_LONGEST builtin_type_long
142
143/* Say how long (ordinary) registers are. */
144
145#define REGISTER_TYPE long
146
147/* Number of machine registers */
148
149#define NUM_REGS 72
150
151/* Initializer for an array of names of registers.
152 There should be NUM_REGS strings in this initializer. */
153
154#define REGISTER_NAMES \
155{ "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", \
156 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7", \
157 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", \
158 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7", \
159 \
160 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
161 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
162 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
163 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
164 \
165 "y", "psr", "wim", "tbr", "pc", "npc", "fpsr", "cpsr" };
166
167/* Register numbers of various important registers.
168 Note that some of these values are "real" register numbers,
169 and correspond to the general registers of the machine,
170 and some are "phony" register numbers which are too large
171 to be actual register numbers as far as the user is concerned
172 but do serve to get the desired values when passed to read_register. */
173
174#define FP_REGNUM 30 /* Contains address of executing stack frame */
175#define RP_REGNUM 15 /* Contains return address value, *before* \
176 any windows get switched. */
177#define SP_REGNUM 14 /* Contains address of top of stack, \
178 which is also the bottom of the frame. */
179#define Y_REGNUM 64 /* Temp register for multiplication, etc. */
180#define PS_REGNUM 65 /* Contains processor status */
181#define PC_REGNUM 68 /* Contains program counter */
182#define NPC_REGNUM 69 /* Contains next PC */
183#define FP0_REGNUM 32 /* Floating point register 0 */
184#define FPS_REGNUM 70 /* Floating point status register */
185#define CPS_REGNUM 71 /* Coprocessor status register */
186
187/* Total amount of space needed to store our copies of the machine's
188 register state, the array `registers'. */
189#define REGISTER_BYTES (32*4+32*4+8*4)
190
191/* Index within `registers' of the first byte of the space for
192 register N. */
193/* ?? */
194#define REGISTER_BYTE(N) ((N)*4)
195
196/* The SPARC processor has register windows. */
197
198#define HAVE_REGISTER_WINDOWS
199
200/* Is this register part of the register window system? A yes answer
201 implies that 1) The name of this register will not be the same in
202 other frames, and 2) This register is automatically "saved" (out
203 registers shifting into ins counts) upon subroutine calls and thus
204 there is no need to search more than one stack frame for it. */
205
206#define REGISTER_IN_WINDOW_P(regnum) \
207 ((regnum) >= 8 && (regnum) < 32)
208
209/* Number of bytes of storage in the actual machine representation
210 for register N. */
211
212/* On the SPARC, all regs are 4 bytes. */
213
214#define REGISTER_RAW_SIZE(N) (4)
215
216/* Number of bytes of storage in the program's representation
217 for register N. */
218
219/* On the SPARC, all regs are 4 bytes. */
220
221#define REGISTER_VIRTUAL_SIZE(N) (4)
222
223/* Largest value REGISTER_RAW_SIZE can have. */
224
225#define MAX_REGISTER_RAW_SIZE 8
226
227/* Largest value REGISTER_VIRTUAL_SIZE can have. */
228
229#define MAX_REGISTER_VIRTUAL_SIZE 8
230
231/* Nonzero if register N requires conversion
232 from raw format to virtual format. */
233
234#define REGISTER_CONVERTIBLE(N) (0)
235
236/* Convert data from raw format for register REGNUM
237 to virtual format for register REGNUM. */
238
239#define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
240{ bcopy ((FROM), (TO), 4); }
241
242/* Convert data from virtual format for register REGNUM
243 to raw format for register REGNUM. */
244
245#define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
246{ bcopy ((FROM), (TO), 4); }
247
248/* Return the GDB type object for the "standard" data type
249 of data in register N. */
250
251#define REGISTER_VIRTUAL_TYPE(N) \
252 ((N) < 32 ? builtin_type_int : (N) < 64 ? builtin_type_float : \
253 builtin_type_int)
254
255/* Store the address of the place in which to copy the structure the
256 subroutine will return. This is called from call_function. */
257
258#define STORE_STRUCT_RETURN(ADDR, SP) \
259 { write_memory ((SP)+(16*4), &(ADDR), 4); }
260
261/* Extract from an array REGBUF containing the (raw) register state
262 a function return value of type TYPE, and copy that, in virtual format,
263 into VALBUF. */
264
265#define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
266 { \
267 if (TYPE_CODE (TYPE) == TYPE_CODE_FLT) \
268 { \
269 bcopy (((int *)(REGBUF))+FP0_REGNUM, \
270 (VALBUF), TYPE_LENGTH(TYPE)); \
271 } \
272 else \
273 bcopy ((char *)((int *)(REGBUF) + 8) + \
274 (TYPE_LENGTH (TYPE) < 4 ? 4 - TYPE_LENGTH (TYPE) : 0), \
275 VALBUF, TYPE_LENGTH (TYPE)); \
276 }
277
278/* Write into appropriate registers a function return value
279 of type TYPE, given in virtual format. */
280/* On sparc, values are returned in register %o0. */
281#define STORE_RETURN_VALUE(TYPE,VALBUF) \
282 { \
283 if (TYPE_CODE (TYPE) = TYPE_CODE_FLT) \
284 /* Floating-point values are returned in the register pair */ \
285 /* formed by %f0 and %f1 (doubles are, anyway). */ \
286 write_register_bytes (REGISTER_BYTE (FP0_REGNUM), (VALBUF), \
287 TYPE_LENGTH (TYPE)); \
288 else \
289 /* Other values are returned in register %o0. */ \
290 write_register_bytes (REGISTER_BYTE (8), VALBUF, TYPE_LENGTH (TYPE)); \
291 }
292
293/* Extract from an array REGBUF containing the (raw) register state
294 the address in which a function should return its structure value,
295 as a CORE_ADDR (or an expression that can be used as one). */
296
297#define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) \
298 (read_memory_integer (((int *)(REGBUF))[SP_REGNUM]+(16*4), 4))
299
300/* Enable use of alternate code to read and write registers. */
301
302#define NEW_SUN_PTRACE
303
304/* Enable use of alternate code for Sun's format of core dump file. */
305
306#define NEW_SUN_CORE
307
308/* Do implement the attach and detach commands. */
309
310#define ATTACH_DETACH
311
312\f
313/* Describe the pointer in each stack frame to the previous stack frame
314 (its caller). */
315#include <machine/reg.h>
316
317#define GET_RWINDOW_REG(FRAME, REG) \
318 (read_memory_integer (&((struct rwindow *)FRAME)->REG, 4))
319
320/* FRAME_CHAIN takes a frame's nominal address
321 and produces the frame's chain-pointer.
322
323 FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
324 and produces the nominal address of the caller frame.
325
326 However, if FRAME_CHAIN_VALID returns zero,
327 it means the given frame is the outermost one and has no caller.
328 In that case, FRAME_CHAIN_COMBINE is not used. */
329
330/* In the case of the Sun 4, the frame-chain's nominal address
331 is held in the frame pointer register.
332
333 On the Sun4, the frame (in %fp) is %sp for the previous frame.
334 From the previous frame's %sp, we can find the previous frame's
335 %fp: it is in the save area just above the previous frame's %sp.
336
337 If we are setting up an arbitrary frame, we'll need to know where
338 it ends. Hence the following. This part of the frame cache
339 structure should be checked before it is assumed that this frame's
340 bottom is in the stack pointer.
341
342 If there isn't a frame below this one, the bottom of this frame is
343 in the stack pointer.
344
345 If there is a frame below this one, and the frame pointers are
346 identical, it's a leaf frame and the bottoms are the same also.
347
348 Otherwise the bottom of this frame is the top of the next frame. */
349
350#define EXTRA_FRAME_INFO FRAME_ADDR bottom;
351#define INIT_EXTRA_FRAME_INFO(fci) \
352 (fci)->bottom = \
353 ((fci)->next ? \
354 ((fci)->frame == (fci)->next_frame ? \
355 (fci)->next->bottom : (fci)->next->frame) : \
356 read_register (SP_REGNUM));
357
358
359#ifdef KERNELDEBUG
360extern int kernel_debugging;
361#define FRAME_CHAIN_VALID(chain, thisframe) \
362 (chain != 0 && \
363 kernel_debugging ? inside_kernstack(chain) : \
364 outside_startup_file(FRAME_SAVED_PC(thisframe)))
365#else
366#define FRAME_CHAIN_VALID(chain, thisframe) \
367 (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe))))
368#endif
369
370#define FRAME_CHAIN(thisframe) \
371 GET_RWINDOW_REG ((thisframe)->frame, rw_in[6])
372
373#define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
374
375/* Define other aspects of the stack frame. */
376
377/* A macro that tells us whether the function invocation represented
378 by FI does not have a frame on the stack associated with it. If it
379 does not, FRAMELESS is set to 1, else 0. */
380#define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
381 FRAMELESS_LOOK_FOR_PROLOGUE(FI, FRAMELESS)
382
383/* Where is the PC for a specific frame */
384
385#define FRAME_SAVED_PC(FRAME) frame_saved_pc (FRAME)
386
387/* If the argument is on the stack, it will be here. */
388#define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
389
390#define FRAME_STRUCT_ARGS_ADDRESS(fi) ((fi)->frame)
391
392#define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
393
394/* Set VAL to the number of args passed to frame described by FI.
395 Can set VAL to -1, meaning no way to tell. */
396
397/* We can't tell how many args there are
398 now that the C compiler delays popping them. */
399extern int default_function_nargs;
400#define FRAME_NUM_ARGS(val,fi) (val = default_function_nargs)
401
402/* Return number of bytes at start of arglist that are not really args. */
403
404#define FRAME_ARGS_SKIP 68
405
406/* Put here the code to store, into a struct frame_saved_regs,
407 the addresses of the saved registers of frame described by FRAME_INFO.
408 This includes special registers such as pc and fp saved in special
409 ways in the stack frame. sp is even more special:
410 the address we return for it IS the sp for the next frame.
411
412 Note that on register window machines, we are currently making the
413 assumption that window registers are being saved somewhere in the
414 frame in which they are being used. If they are stored in an
415 inferior frame, find_saved_register will break.
416
417 On the Sun 4, the only time all registers are saved is when
418 a dummy frame is involved. Otherwise, the only saved registers
419 are the LOCAL and IN registers which are saved as a result
420 of the "save/restore" opcodes. This condition is determined
421 by address rather than by value. */
422
423#define FRAME_FIND_SAVED_REGS(fi, frame_saved_regs) \
424 frame_find_saved_regs(fi, &(frame_saved_regs))
425
426/* Discard from the stack the innermost frame,
427 restoring all saved registers.
428 Note that the values stored in fsr by get_frame_saved_regs are *in
429 the context of the inferior frame*. What this means is that the i
430 regs of fsr must be restored into the o regs of the frame popped
431 into. We don't care about the output regs of the inferior frame.
432
433 This is true for dummy frames. Is it true for normal frames? It
434 really does appear so. */
435
436#define POP_FRAME \
437{ register FRAME frame = get_current_frame (); \
438 register CORE_ADDR fp; \
439 register CORE_ADDR pc; \
440 register int regnum; \
441 struct frame_saved_regs fsr; \
442 struct frame_info *fi; \
443 char raw_buffer[REGISTER_BYTES]; \
444 void do_restore_insn (); \
445 fi = get_frame_info (frame); \
446 fp = fi->frame; \
447 get_frame_saved_regs (fi, &fsr); \
448 pc = read_memory_integer (fsr.regs[PC_REGNUM], 4); \
449 do_restore_insn (PC_ADJUST (pc)); \
450 if (fsr.regs[FP0_REGNUM]) \
451 { \
452 read_memory (fsr.regs[FP0_REGNUM], raw_buffer, 32 * 4); \
453 write_register_bytes (REGISTER_BYTE (FP0_REGNUM), raw_buffer, 32 * 4); \
454 } \
455 if (fsr.regs[1]) \
456 { \
457 read_memory (fsr.regs[1], raw_buffer, 7 * 4); \
458 write_register_bytes (REGISTER_BYTE (1), raw_buffer, 7 * 4); \
459 } \
460 if (fsr.regs[24]) \
461 { \
462 read_memory (fsr.regs[24], raw_buffer, 8 * 4); \
463 write_register_bytes (REGISTER_BYTE (8), raw_buffer, 8 * 4); \
464 } \
465 if (fsr.regs[PS_REGNUM]) \
466 write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4)); \
467 if (fsr.regs[Y_REGNUM]) \
468 write_register (Y_REGNUM, read_memory_integer (fsr.regs[Y_REGNUM], 4)); \
469 if (fsr.regs[NPC_REGNUM]) \
470 write_register (NPC_REGNUM, read_memory_integer (fsr.regs[NPC_REGNUM], 4)); \
471 flush_cached_frames (); \
472 set_current_frame ( create_new_frame (read_register (FP_REGNUM), \
473 read_pc ())); }
474
475#define NEW_CALL_FUNCTION
476
477\f
478/* Sparc has no reliable single step ptrace call */
479
480#define NO_SINGLE_STEP 1
481
482/* It does have a wait structure, and it might help things out . . . */
483
484#define HAVE_WAIT_STRUCT
485
486/* Handle a feature in the sun4 compiler ("call .stret4" at the end of
487 functions returning structures). */
488
489#define SUN4_COMPILER_FEATURE
490
491/* We need two arguments (in general) to the "info frame" command.
492 Note that the definition of this macro implies that there exists a
493 function "setup_arbitrary_frame" in mach-dep.c */
494
495#define FRAME_SPECIFICATION_DYADIC
496
497/* KDB stuff flushed for now. */
498
499#define NAMELESS_ARG(fi, n) GET_RWINDOW_REG((fi)->bottom, rw_in[n])
500