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