gdb-3.5
[deliverable/binutils-gdb.git] / gdb / m-sun3.h
1 /* Parameters for execution on a Sun, 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 GDB 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 1, or (at your option)
9 any later version.
10
11 GDB 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 GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #ifndef sun3
21 #define sun3
22 #endif
23
24 /* Define the bit, byte, and word ordering of the machine. */
25 #define BITS_BIG_ENDIAN
26 #define BYTES_BIG_ENDIAN
27 #define WORDS_BIG_ENDIAN
28
29 /* Get rid of any system-imposed stack limit if possible. */
30
31 #define SET_STACK_LIMIT_HUGE
32
33 /* Define this if the C compiler puts an underscore at the front
34 of external names before giving them to the linker. */
35
36 #define NAMES_HAVE_UNDERSCORE
37
38 /* Debugger information will be in DBX format. */
39
40 #define READ_DBX_FORMAT
41
42 /* Offset from address of function to start of its code.
43 Zero on most machines. */
44
45 #define FUNCTION_START_OFFSET 0
46
47 /* Advance PC across any function entry prologue instructions
48 to reach some "real" code. */
49
50 #define SKIP_PROLOGUE(pc) \
51 { register int op = read_memory_integer (pc, 2); \
52 if (op == 0047126) \
53 pc += 4; /* Skip link #word */ \
54 else if (op == 0044016) \
55 pc += 6; /* Skip link #long */ \
56 }
57
58 /* Immediately after a function call, return the saved pc.
59 Can't go through the frames for this because on some machines
60 the new frame is not set up until the new function executes
61 some instructions. */
62
63 #define SAVED_PC_AFTER_CALL(frame) \
64 read_memory_integer (read_register (SP_REGNUM), 4)
65
66 /* Address of end of stack space. */
67
68 #define STACK_END_ADDR 0xf000000
69
70 /* Stack grows downward. */
71
72 #define INNER_THAN <
73
74 /* Sequence of bytes for breakpoint instruction. */
75
76 #define BREAKPOINT {0x4e, 0x4f}
77
78 /* Amount PC must be decremented by after a breakpoint.
79 This is often the number of bytes in BREAKPOINT
80 but not always. */
81
82 #define DECR_PC_AFTER_BREAK 2
83
84 /* Nonzero if instruction at PC is a return instruction. */
85 /* Allow any of the return instructions, including a trapv and a return
86 from interupt. */
87
88 #define ABOUT_TO_RETURN(pc) ((read_memory_integer (pc, 2) & ~0x3) == 0x4e74)
89
90 /* Return 1 if P points to an invalid floating point value. */
91
92 #define INVALID_FLOAT(p, len) 0 /* Just a first guess; not checked */
93
94 /* Largest integer type */
95 #define LONGEST long
96
97 /* Name of the builtin type for the LONGEST type above. */
98 #define BUILTIN_TYPE_LONGEST builtin_type_long
99
100 /* Say how long (ordinary) registers are. */
101
102 #define REGISTER_TYPE long
103
104 /* Number of machine registers */
105
106 #define NUM_REGS 31
107
108 /* Initializer for an array of names of registers.
109 There should be NUM_REGS strings in this initializer. */
110
111 #define REGISTER_NAMES \
112 {"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", \
113 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", \
114 "ps", "pc", \
115 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7", \
116 "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags" }
117
118 /* Register numbers of various important registers.
119 Note that some of these values are "real" register numbers,
120 and correspond to the general registers of the machine,
121 and some are "phony" register numbers which are too large
122 to be actual register numbers as far as the user is concerned
123 but do serve to get the desired values when passed to read_register. */
124
125 #define FP_REGNUM 14 /* Contains address of executing stack frame */
126 #define SP_REGNUM 15 /* Contains address of top of stack */
127 #define PS_REGNUM 16 /* Contains processor status */
128 #define PC_REGNUM 17 /* Contains program counter */
129 #define FP0_REGNUM 18 /* Floating point register 0 */
130 #define FPC_REGNUM 26 /* 68881 control register */
131
132 /* Total amount of space needed to store our copies of the machine's
133 register state, the array `registers'. */
134 #define REGISTER_BYTES (16*4+8*12+8+20)
135
136 /* Index within `registers' of the first byte of the space for
137 register N. */
138
139 #define REGISTER_BYTE(N) \
140 ((N) >= FPC_REGNUM ? (((N) - FPC_REGNUM) * 4) + 168 \
141 : (N) >= FP0_REGNUM ? (((N) - FP0_REGNUM) * 12) + 72 \
142 : (N) * 4)
143
144 /* Number of bytes of storage in the actual machine representation
145 for register N. On the 68000, all regs are 4 bytes
146 except the floating point regs which are 12 bytes. */
147 /* Note that the unsigned cast here forces the result of the
148 subtractiion to very high positive values if N < FP0_REGNUM */
149
150 #define REGISTER_RAW_SIZE(N) (((unsigned)(N) - FP0_REGNUM) < 8 ? 12 : 4)
151
152 /* Number of bytes of storage in the program's representation
153 for register N. On the 68000, all regs are 4 bytes
154 except the floating point regs which are 8-byte doubles. */
155
156 #define REGISTER_VIRTUAL_SIZE(N) (((unsigned)(N) - FP0_REGNUM) < 8 ? 8 : 4)
157
158 /* Largest value REGISTER_RAW_SIZE can have. */
159
160 #define MAX_REGISTER_RAW_SIZE 12
161
162 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
163
164 #define MAX_REGISTER_VIRTUAL_SIZE 8
165
166 /* Nonzero if register N requires conversion
167 from raw format to virtual format. */
168
169 #define REGISTER_CONVERTIBLE(N) (((unsigned)(N) - FP0_REGNUM) < 8)
170
171 /* Convert data from raw format for register REGNUM
172 to virtual format for register REGNUM. */
173
174 #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
175 { if ((REGNUM) >= FP0_REGNUM && (REGNUM) < FPC_REGNUM) \
176 convert_from_68881 ((FROM), (TO)); \
177 else \
178 bcopy ((FROM), (TO), 4); }
179
180 /* Convert data from virtual format for register REGNUM
181 to raw format for register REGNUM. */
182
183 #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
184 { if ((REGNUM) >= FP0_REGNUM && (REGNUM) < FPC_REGNUM) \
185 convert_to_68881 ((FROM), (TO)); \
186 else \
187 bcopy ((FROM), (TO), 4); }
188
189 /* Return the GDB type object for the "standard" data type
190 of data in register N. */
191
192 #define REGISTER_VIRTUAL_TYPE(N) \
193 (((unsigned)(N) - FP0_REGNUM) < 8 ? builtin_type_double : builtin_type_int)
194
195 /* Store the address of the place in which to copy the structure the
196 subroutine will return. This is called from call_function. */
197
198 #define STORE_STRUCT_RETURN(ADDR, SP) \
199 { write_register (9, (ADDR)); }
200
201 /* Extract from an array REGBUF containing the (raw) register state
202 a function return value of type TYPE, and copy that, in virtual format,
203 into VALBUF. */
204
205 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
206 bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
207
208 /* Write into appropriate registers a function return value
209 of type TYPE, given in virtual format. */
210
211 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
212 write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
213
214 /* Extract from an array REGBUF containing the (raw) register state
215 the address in which a function should return its structure value,
216 as a CORE_ADDR (or an expression that can be used as one). */
217
218 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
219
220 /* Enable use of alternate code to read and write registers. */
221
222 #define NEW_SUN_PTRACE
223
224 /* Enable use of alternate code for Sun's format of core dump file. */
225
226 #define NEW_SUN_CORE
227
228 /* Do implement the attach and detach commands. */
229
230 #define ATTACH_DETACH
231
232 \f
233 /* Describe the pointer in each stack frame to the previous stack frame
234 (its caller). */
235
236 /* FRAME_CHAIN takes a frame's nominal address
237 and produces the frame's chain-pointer.
238
239 FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
240 and produces the nominal address of the caller frame.
241
242 However, if FRAME_CHAIN_VALID returns zero,
243 it means the given frame is the outermost one and has no caller.
244 In that case, FRAME_CHAIN_COMBINE is not used. */
245
246 /* In the case of the Sun, the frame's nominal address
247 is the address of a 4-byte word containing the calling frame's address. */
248
249 #define FRAME_CHAIN(thisframe) \
250 (outside_startup_file ((thisframe)->pc) ? \
251 read_memory_integer ((thisframe)->frame, 4) :\
252 0)
253
254 #define FRAME_CHAIN_VALID(chain, thisframe) \
255 (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe))))
256
257 #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
258
259 /* Define other aspects of the stack frame. */
260
261 /* A macro that tells us whether the function invocation represented
262 by FI does not have a frame on the stack associated with it. If it
263 does not, FRAMELESS is set to 1, else 0. */
264 #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
265 FRAMELESS_LOOK_FOR_PROLOGUE(FI, FRAMELESS)
266
267 #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4))
268
269 #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
270
271 #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
272
273 /* Set VAL to the number of args passed to frame described by FI.
274 Can set VAL to -1, meaning no way to tell. */
275
276 /* We can't tell how many args there are
277 now that the C compiler delays popping them. */
278 #define FRAME_NUM_ARGS(val,fi) (val = -1)
279
280 #if 0
281 #define FRAME_NUM_ARGS(val, fi) \
282 { register CORE_ADDR pc = FRAME_SAVED_PC (fi); \
283 register int insn = 0177777 & read_memory_integer (pc, 2); \
284 val = 0; \
285 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */ \
286 val = read_memory_integer (pc + 2, 2); \
287 else if ((insn & 0170777) == 0050217 /* addql #N, sp */ \
288 || (insn & 0170777) == 0050117) /* addqw */ \
289 { val = (insn >> 9) & 7; if (val == 0) val = 8; } \
290 else if (insn == 0157774) /* addal #WW, sp */ \
291 val = read_memory_integer (pc + 2, 4); \
292 val >>= 2; }
293 #endif
294
295 /* Return number of bytes at start of arglist that are not really args. */
296
297 #define FRAME_ARGS_SKIP 8
298
299 /* Put here the code to store, into a struct frame_saved_regs,
300 the addresses of the saved registers of frame described by FRAME_INFO.
301 This includes special registers such as pc and fp saved in special
302 ways in the stack frame. sp is even more special:
303 the address we return for it IS the sp for the next frame. */
304
305 #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
306 { register int regnum; \
307 register int regmask; \
308 register CORE_ADDR next_addr; \
309 register CORE_ADDR pc; \
310 int nextinsn; \
311 bzero (&frame_saved_regs, sizeof frame_saved_regs); \
312 if ((frame_info)->pc >= (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM*4 - 8*12 - 4 \
313 && (frame_info)->pc <= (frame_info)->frame) \
314 { next_addr = (frame_info)->frame; \
315 pc = (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 8*12 - 4; }\
316 else \
317 { pc = get_pc_function_start ((frame_info)->pc); \
318 /* Verify we have a link a6 instruction next; \
319 if not we lose. If we win, find the address above the saved \
320 regs using the amount of storage from the link instruction. */\
321 if (044016 == read_memory_integer (pc, 2)) \
322 next_addr = (frame_info)->frame + read_memory_integer (pc += 2, 4), pc+=4; \
323 else if (047126 == read_memory_integer (pc, 2)) \
324 next_addr = (frame_info)->frame + read_memory_integer (pc += 2, 2), pc+=2; \
325 else goto lose; \
326 /* If have an addal #-n, sp next, adjust next_addr. */ \
327 if ((0177777 & read_memory_integer (pc, 2)) == 0157774) \
328 next_addr += read_memory_integer (pc += 2, 4), pc += 4; \
329 } \
330 /* next should be a moveml to (sp) or -(sp) or a movl r,-(sp) */ \
331 regmask = read_memory_integer (pc + 2, 2); \
332 /* But before that can come an fmovem. Check for it. */ \
333 nextinsn = 0xffff & read_memory_integer (pc, 2); \
334 if (0xf227 == nextinsn \
335 && (regmask & 0xff00) == 0xe000) \
336 { pc += 4; /* Regmask's low bit is for register fp7, the first pushed */ \
337 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--, regmask >>= 1) \
338 if (regmask & 1) \
339 (frame_saved_regs).regs[regnum] = (next_addr -= 12); \
340 regmask = read_memory_integer (pc + 2, 2); } \
341 if (0044327 == read_memory_integer (pc, 2)) \
342 { pc += 4; /* Regmask's low bit is for register 0, the first written */ \
343 for (regnum = 0; regnum < 16; regnum++, regmask >>= 1) \
344 if (regmask & 1) \
345 (frame_saved_regs).regs[regnum] = (next_addr += 4) - 4; } \
346 else if (0044347 == read_memory_integer (pc, 2)) \
347 { pc += 4; /* Regmask's low bit is for register 15, the first pushed */ \
348 for (regnum = 15; regnum >= 0; regnum--, regmask >>= 1) \
349 if (regmask & 1) \
350 (frame_saved_regs).regs[regnum] = (next_addr -= 4); } \
351 else if (0x2f00 == (0xfff0 & read_memory_integer (pc, 2))) \
352 { regnum = 0xf & read_memory_integer (pc, 2); pc += 2; \
353 (frame_saved_regs).regs[regnum] = (next_addr -= 4); } \
354 /* fmovemx to index of sp may follow. */ \
355 regmask = read_memory_integer (pc + 2, 2); \
356 nextinsn = 0xffff & read_memory_integer (pc, 2); \
357 if (0xf236 == nextinsn \
358 && (regmask & 0xff00) == 0xf000) \
359 { pc += 10; /* Regmask's low bit is for register fp0, the first written */ \
360 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--, regmask >>= 1) \
361 if (regmask & 1) \
362 (frame_saved_regs).regs[regnum] = (next_addr += 12) - 12; \
363 regmask = read_memory_integer (pc + 2, 2); } \
364 /* clrw -(sp); movw ccr,-(sp) may follow. */ \
365 if (0x426742e7 == read_memory_integer (pc, 4)) \
366 (frame_saved_regs).regs[PS_REGNUM] = (next_addr -= 4); \
367 lose: ; \
368 (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame + 8; \
369 (frame_saved_regs).regs[FP_REGNUM] = (frame_info)->frame; \
370 (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 4; \
371 }
372 \f
373 /* Things needed for making the inferior call functions. */
374
375 /* Push an empty stack frame, to record the current PC, etc. */
376
377 #define PUSH_DUMMY_FRAME \
378 { register CORE_ADDR sp = read_register (SP_REGNUM); \
379 register int regnum; \
380 char raw_buffer[12]; \
381 sp = push_word (sp, read_register (PC_REGNUM)); \
382 sp = push_word (sp, read_register (FP_REGNUM)); \
383 write_register (FP_REGNUM, sp); \
384 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--) \
385 { read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12); \
386 sp = push_bytes (sp, raw_buffer, 12); } \
387 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--) \
388 sp = push_word (sp, read_register (regnum)); \
389 sp = push_word (sp, read_register (PS_REGNUM)); \
390 write_register (SP_REGNUM, sp); }
391
392 /* Discard from the stack the innermost frame,
393 restoring all saved registers. */
394
395 #define POP_FRAME \
396 { register FRAME frame = get_current_frame (); \
397 register CORE_ADDR fp; \
398 register int regnum; \
399 struct frame_saved_regs fsr; \
400 struct frame_info *fi; \
401 char raw_buffer[12]; \
402 fi = get_frame_info (frame); \
403 fp = fi->frame; \
404 get_frame_saved_regs (fi, &fsr); \
405 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--) \
406 if (fsr.regs[regnum]) \
407 { read_memory (fsr.regs[regnum], raw_buffer, 12); \
408 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12); }\
409 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--) \
410 if (fsr.regs[regnum]) \
411 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
412 if (fsr.regs[PS_REGNUM]) \
413 write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4)); \
414 write_register (FP_REGNUM, read_memory_integer (fp, 4)); \
415 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \
416 write_register (SP_REGNUM, fp + 8); \
417 flush_cached_frames (); \
418 set_current_frame (create_new_frame (read_register (FP_REGNUM), \
419 read_pc ())); }
420
421 /* This sequence of words is the instructions
422 fmovem 0xff,-(sp)
423 moveml 0xfffc,-(sp)
424 clrw -(sp)
425 movew ccr,-(sp)
426 /..* The arguments are pushed at this point by GDB;
427 no code is needed in the dummy for this.
428 The CALL_DUMMY_START_OFFSET gives the position of
429 the following jsr instruction. *../
430 jsr @#32323232
431 addl #69696969,sp
432 trap #15
433 nop
434 Note this is 28 bytes.
435 We actually start executing at the jsr, since the pushing of the
436 registers is done by PUSH_DUMMY_FRAME. If this were real code,
437 the arguments for the function called by the jsr would be pushed
438 between the moveml and the jsr, and we could allow it to execute through.
439 But the arguments have to be pushed by GDB after the PUSH_DUMMY_FRAME is done,
440 and we cannot allow the moveml to push the registers again lest they be
441 taken for the arguments. */
442
443 #define CALL_DUMMY {0xf227e0ff, 0x48e7fffc, 0x426742e7, 0x4eb93232, 0x3232dffc, 0x69696969, 0x4e4f4e71}
444
445 #define CALL_DUMMY_LENGTH 28
446
447 #define CALL_DUMMY_START_OFFSET 12
448
449 /* Insert the specified number of args and function address
450 into a call sequence of the above form stored at DUMMYNAME. */
451
452 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, type) \
453 { *(int *)((char *) dummyname + 20) = nargs * 4; \
454 *(int *)((char *) dummyname + 14) = fun; }
455 \f
456 /* Interface definitions for kernel debugger KDB. */
457
458 /* Map machine fault codes into signal numbers.
459 First subtract 0, divide by 4, then index in a table.
460 Faults for which the entry in this table is 0
461 are not handled by KDB; the program's own trap handler
462 gets to handle then. */
463
464 #define FAULT_CODE_ORIGIN 0
465 #define FAULT_CODE_UNITS 4
466 #define FAULT_TABLE \
467 { 0, 0, 0, 0, SIGTRAP, 0, 0, 0, \
468 0, SIGTRAP, 0, 0, 0, 0, 0, SIGKILL, \
469 0, 0, 0, 0, 0, 0, 0, 0, \
470 SIGILL }
471
472 /* Start running with a stack stretching from BEG to END.
473 BEG and END should be symbols meaningful to the assembler.
474 This is used only for kdb. */
475
476 #define INIT_STACK(beg, end) \
477 { asm (".globl end"); \
478 asm ("movel #end, sp"); \
479 asm ("movel #0,a6"); }
480
481 /* Push the frame pointer register on the stack. */
482 #define PUSH_FRAME_PTR \
483 asm ("movel a6,sp@-");
484
485 /* Copy the top-of-stack to the frame pointer register. */
486 #define POP_FRAME_PTR \
487 asm ("movl sp@,a6");
488
489 /* After KDB is entered by a fault, push all registers
490 that GDB thinks about (all NUM_REGS of them),
491 so that they appear in order of ascending GDB register number.
492 The fault code will be on the stack beyond the last register. */
493
494 #define PUSH_REGISTERS \
495 { asm ("clrw -(sp)"); \
496 asm ("pea sp@(10)"); \
497 asm ("movem #0xfffe,sp@-"); }
498
499 /* Assuming the registers (including processor status) have been
500 pushed on the stack in order of ascending GDB register number,
501 restore them and return to the address in the saved PC register. */
502
503 #define POP_REGISTERS \
504 { asm ("subil #8,sp@(28)"); \
505 asm ("movem sp@,#0xffff"); \
506 asm ("rte"); }
This page took 0.049946 seconds and 4 git commands to generate.