gdb-2.8.1
[deliverable/binutils-gdb.git] / gdb / m-npl.h
CommitLineData
3bf57d21 1/* Parameters for execution on a Gould NP1, for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
3
4GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5WARRANTY. No author or distributor accepts responsibility to anyone
6for the consequences of using it or for whether it serves any
7particular purpose or works at all, unless he says so in writing.
8Refer to the GDB General Public License for full details.
9
10Everyone is granted permission to copy, modify and redistribute GDB,
11but only under the conditions described in the GDB General Public
12License. A copy of this license is supposed to have been given to you
13along with GDB so you can know your rights and responsibilities. It
14should be in a file named COPYING. Among other things, the copyright
15notice and this notice must be preserved on all copies.
16
17In other words, go ahead and share GDB, but don't try to stop
18anyone else from sharing it farther. Help stamp out software hoarding! */
19
20/* Read file headers properly in core.c */
21#define gould
22
23/* Macro for text-offset and data info (in NPL a.out format). */
24#define TEXTINFO \
25 text_offset = N_TXTOFF (exec_coffhdr, exec_aouthdr); \
26 exec_data_offset = N_TXTOFF (exec_coffhdr, exec_aouthdr)\
27 + exec_aouthdr.a_text
28
29/* Macro for number of symbol table entries */
30#define END_OF_TEXT_DEFAULT \
31 (0xffffff)
32
33/* Macro for number of symbol table entries */
34#define NUMBER_OF_SYMBOLS \
35 (coffhdr.f_nsyms)
36
37/* Macro for file-offset of symbol table (in NPL a.out format). */
38#define SYMBOL_TABLE_OFFSET \
39 N_SYMOFF (coffhdr)
40
41/* Macro for file-offset of string table (in NPL a.out format). */
42#define STRING_TABLE_OFFSET \
43 (N_STROFF (coffhdr) + sizeof(int))
44
45/* Macro to store the length of the string table data in INTO. */
46#define READ_STRING_TABLE_SIZE(INTO) \
47 { INTO = hdr.a_stsize; }
48
49/* Macro to declare variables to hold the file's header data. */
50#define DECLARE_FILE_HEADERS struct exec hdr; \
51 FILHDR coffhdr
52
53/* Macro to read the header data from descriptor DESC and validate it.
54 NAME is the file name, for error messages. */
55#define READ_FILE_HEADERS(DESC, NAME) \
56{ val = myread (DESC, &coffhdr, sizeof coffhdr); \
57 if (val < 0) \
58 perror_with_name (NAME); \
59 val = myread (DESC, &hdr, sizeof hdr); \
60 if (val < 0) \
61 perror_with_name (NAME); \
62 if (coffhdr.f_magic != GNP1MAGIC) \
63 error ("File \"%s\" not in coff executable format.", NAME); \
64 if (N_BADMAG (hdr)) \
65 error ("File \"%s\" not in executable format.", NAME); }
66
67/* Define COFF and other symbolic names needed on NP1 */
68#define NS32GMAGIC GNP1MAGIC
69#define NS32SMAGIC GPNMAGIC
70#define vprintf printf
71
72/* Get rid of any system-imposed stack limit if possible. */
73#define SET_STACK_LIMIT_HUGE
74
75/* Define this if the C compiler puts an underscore at the front
76 of external names before giving them to the linker. */
77#define NAMES_HAVE_UNDERSCORE
78
79/* Debugger information will be in DBX format. */
80#define READ_DBX_FORMAT
81
82/* Offset from address of function to start of its code.
83 Zero on most machines. */
84#define FUNCTION_START_OFFSET 8
85
86/* Advance PC across any function entry prologue instructions
87 to reach some "real" code. One NPL we can have one two startup
88 sequences depending on the size of the local stack:
89
90 Either:
91 "suabr b2, #"
92 of
93 "lil r4, #", "suabr b2, #(r4)"
94
95 "lwbr b6, #", "stw r1, 8(b2)"
96 Optional "stwbr b3, c(b2)"
97 Optional "trr r2,r7" (Gould first argument register passing)
98 or
99 Optional "stw r2,8(b3)" (Gould first argument register passing)
100 */
101#define SKIP_PROLOGUE(pc) { \
102 register int op = read_memory_integer ((pc), 4); \
103 if ((op & 0xffff0000) == 0xFA0B0000) { \
104 pc += 4; \
105 op = read_memory_integer ((pc), 4); \
106 if ((op & 0xffff0000) == 0x59400000) { \
107 pc += 4; \
108 op = read_memory_integer ((pc), 4); \
109 if ((op & 0xffff0000) == 0x5F000000) { \
110 pc += 4; \
111 op = read_memory_integer ((pc), 4); \
112 if (op == 0xD4820008) { \
113 pc += 4; \
114 op = read_memory_integer ((pc), 4); \
115 if (op == 0x5582000C) { \
116 pc += 4; \
117 op = read_memory_integer ((pc), 2); \
118 if (op == 0x2fa0) { \
119 pc += 2; \
120 } else { \
121 op = read_memory_integer ((pc), 4); \
122 if (op == 0xd5030008) { \
123 pc += 4; \
124 } \
125 } \
126 } else { \
127 op = read_memory_integer ((pc), 2); \
128 if (op == 0x2fa0) { \
129 pc += 2; \
130 } \
131 } \
132 } \
133 } \
134 } \
135 } \
136 if ((op & 0xffff0000) == 0x59000000) { \
137 pc += 4; \
138 op = read_memory_integer ((pc), 4); \
139 if ((op & 0xffff0000) == 0x5F000000) { \
140 pc += 4; \
141 op = read_memory_integer ((pc), 4); \
142 if (op == 0xD4820008) { \
143 pc += 4; \
144 op = read_memory_integer ((pc), 4); \
145 if (op == 0x5582000C) { \
146 pc += 4; \
147 op = read_memory_integer ((pc), 2); \
148 if (op == 0x2fa0) { \
149 pc += 2; \
150 } else { \
151 op = read_memory_integer ((pc), 4); \
152 if (op == 0xd5030008) { \
153 pc += 4; \
154 } \
155 } \
156 } else { \
157 op = read_memory_integer ((pc), 2); \
158 if (op == 0x2fa0) { \
159 pc += 2; \
160 } \
161 } \
162 } \
163 } \
164 } \
165}
166
167/* Immediately after a function call, return the saved pc.
168 Can't go through the frames for this because on some machines
169 the new frame is not set up until the new function executes
170 some instructions. True on NPL! Return address is in R1.
171 The true return address is REALLY 4 past that location! */
172#define SAVED_PC_AFTER_CALL(frame) \
173 (read_register(R1_REGNUM) + 4)
174
175/* Address of U in kernel space */
176#define KERNEL_U_ADDR 0x7fffc000
177
178/* Address of end of stack space. */
179#define STACK_END_ADDR 0x7fffc000
180
181/* Stack grows downward. */
182#define INNER_THAN <
183
184/* Sequence of bytes for breakpoint instruction. */
185#define BREAKPOINT {0x28, 0x09}
186
187/* Amount PC must be decremented by after a breakpoint.
188 This is often the number of bytes in BREAKPOINT
189 but not always. */
190#define DECR_PC_AFTER_BREAK 2
191
192/* Nonzero if instruction at PC is a return instruction. "bu 4(r1)" */
193#define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 4) == 0x40100004)
194
195/* Return 1 if P points to an invalid floating point value. */
196#define INVALID_FLOAT(p, len) ((*(short *)p & 0xff80) == 0x8000)
197
198/* Say how long (ordinary) registers are. */
199#define REGISTER_TYPE long
200
201/* Size of bytes of vector register (NP1 only), 32 elements * sizeof(int) */
202#define VR_SIZE 128
203
204/* Number of machine registers */
205#define NUM_REGS 27
206#define NUM_GEN_REGS 16
207#define NUM_CPU_REGS 4
208#define NUM_VECTOR_REGS 7
209
210/* Initializer for an array of names of registers.
211 There should be NUM_REGS strings in this initializer. */
212#define REGISTER_NAMES { \
213 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
214 "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", \
215 "sp", "ps", "pc", "ve", \
216 "v1", "v2", "v3", "v4", "v5", "v6", "v7", \
217}
218
219/* Register numbers of various important registers.
220 Note that some of these values are "real" register numbers,
221 and correspond to the general registers of the machine,
222 and some are "phony" register numbers which are too large
223 to be actual register numbers as far as the user is concerned
224 but do serve to get the desired values when passed to read_register. */
225#define R1_REGNUM 1 /* Gr1 => return address of caller */
226#define R4_REGNUM 4 /* Gr4 => register save area */
227#define R5_REGNUM 5 /* Gr5 => register save area */
228#define R6_REGNUM 6 /* Gr6 => register save area */
229#define R7_REGNUM 7 /* Gr7 => register save area */
230#define B1_REGNUM 9 /* Br1 => start of this code routine */
231#define FP_REGNUM 10 /* Br2 == (sp) */
232#define AP_REGNUM 11 /* Br3 == (ap) */
233#define SP_REGNUM 16 /* A copy of Br2 saved in trap */
234#define PS_REGNUM 17 /* Contains processor status */
235#define PC_REGNUM 18 /* Contains program counter */
236#define VE_REGNUM 19 /* Vector end (user setup) register */
237#define V1_REGNUM 20 /* First vector register */
238#define V7_REGNUM 27 /* First vector register */
239
240/* This is a piece of magic that is given a register number REGNO
241 and as BLOCKEND the address in the system of the end of the user structure
242 and stores in ADDR the address in the kernel or core dump
243 of that register. */
244#define REGISTER_U_ADDR(addr, blockend, regno) { \
245 addr = blockend + regno * 4; \
246 if (regno == VE_REGNUM) addr = blockend - 9 * 4; \
247 if (regno == PC_REGNUM) addr = blockend - 8 * 4; \
248 if (regno == PS_REGNUM) addr = blockend - 7 * 4; \
249 if (regno == SP_REGNUM) addr = blockend - 6 * 4; \
250 if (regno >= V1_REGNUM) \
251 addr = blockend + 16 * 4 + (regno - V1_REGNUM) * VR_SIZE; \
252}
253
254/* Total amount of space needed to store our copies of the machine's
255 register state, the array `registers'. */
256#define REGISTER_BYTES \
257 (NUM_GEN_REGS*4 + NUM_VECTOR_REGS*VR_SIZE + NUM_CPU_REGS*4)
258
259/* Index within `registers' of the first byte of the space for
260 register N. */
261#define REGISTER_BYTE(N) \
262 (((N) < V1_REGNUM) ? ((N) * 4) : (((N) - V1_REGNUM) * VR_SIZE) + 80)
263
264/* Number of bytes of storage in the actual machine representation
265 for register N. On the NP1, all normal regs are 4 bytes, but
266 the vector registers are VR_SIZE*4 bytes long. */
267#define REGISTER_RAW_SIZE(N) \
268 (((N) < V1_REGNUM) ? 4 : VR_SIZE)
269
270/* Number of bytes of storage in the program's representation
271 for register N. On the NP1, all regs are 4 bytes. */
272#define REGISTER_VIRTUAL_SIZE(N) \
273 (((N) < V1_REGNUM) ? 4 : VR_SIZE)
274
275/* Largest value REGISTER_RAW_SIZE can have. */
276#define MAX_REGISTER_RAW_SIZE VR_SIZE
277
278/* Largest value REGISTER_VIRTUAL_SIZE can have. */
279#define MAX_REGISTER_VIRTUAL_SIZE VR_SIZE
280
281/* Nonzero if register N requires conversion
282 from raw format to virtual format. */
283#define REGISTER_CONVERTIBLE(N) (0)
284
285/* Convert data from raw format for register REGNUM
286 to virtual format for register REGNUM. */
287#define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
288 bcopy ((FROM), (TO), REGISTER_RAW_SIZE(REGNUM));
289
290/* Convert data from virtual format for register REGNUM
291 to raw format for register REGNUM. */
292#define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
293 bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM));
294
295/* Return the GDB type object for the "standard" data type
296 of data in register N. */
297#define REGISTER_VIRTUAL_TYPE(N) (builtin_type_int)
298
299/* Extract from an arrary REGBUF containing the (raw) register state
300 a function return value of type TYPE, and copy that, in virtual format,
301 into VALBUF. */
302
303#define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
304 bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
305
306/* Write into appropriate registers a function return value
307 of type TYPE, given in virtual format. */
308
309#define STORE_RETURN_VALUE(TYPE,VALBUF) \
310 write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
311
312/* Extract from an array REGBUF containing the (raw) register state
313 the address in which a function should return its structure value,
314 as a CORE_ADDR (or an expression that can be used as one). */
315
316#define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
317
318\f
319/* Describe the pointer in each stack frame to the previous stack frame
320 (its caller). */
321
322/* FRAME_CHAIN takes a frame's nominal address
323 and produces the frame's chain-pointer.
324
325 FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
326 and produces the nominal address of the caller frame.
327
328 However, if FRAME_CHAIN_VALID returns zero,
329 it means the given frame is the outermost one and has no caller.
330 In that case, FRAME_CHAIN_COMBINE is not used. */
331
332/* In the case of the NPL, the frame's norminal address is Br2 and the
333 previous routines frame is up the stack X bytes, where X is the
334 value stored in the code function header xA(Br1). */
335#define FRAME_CHAIN(thisframe) (findframe(thisframe))
336
337#define FRAME_CHAIN_VALID(chain, thisframe) \
338 (chain != 0 && chain != thisframe)
339
340#define FRAME_CHAIN_COMBINE(chain, thisframe) \
341 (chain)
342
343/* Define other aspects of the stack frame on NPL. */
bb7592f0 344#define FRAME_SAVED_PC(frame,ignore) \
3bf57d21 345 (read_memory_integer (frame + 8, 4))
346
347#define FRAME_ARGS_ADDRESS(fi) \
348 ((fi).next_frame ? \
349 read_memory_integer ((fi).frame + 12, 4) : \
350 read_register (AP_REGNUM))
351
352#define FRAME_LOCALS_ADDRESS(fi) ((fi).frame + 80)
353
354/* Set VAL to the number of args passed to frame described by FI.
355 Can set VAL to -1, meaning no way to tell. */
356
357/* We can check the stab info to see how
358 many arg we have. No info in stack will tell us */
359#define FRAME_NUM_ARGS(val,fi) (val = findarg(fi))
360
361/* Return number of bytes at start of arglist that are not really args. */
362#define FRAME_ARGS_SKIP 8
363
364/* Put here the code to store, into a struct frame_saved_regs,
365 the addresses of the saved registers of frame described by FRAME_INFO.
366 This includes special registers such as pc and fp saved in special
367 ways in the stack frame. sp is even more special:
368 the address we return for it IS the sp for the next frame. */
369
370#define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
371{ \
372 bzero (&frame_saved_regs, sizeof frame_saved_regs); \
373 (frame_saved_regs).regs[PC_REGNUM] = (frame_info).frame + 8; \
374 (frame_saved_regs).regs[R4_REGNUM] = (frame_info).frame + 0x30; \
375 (frame_saved_regs).regs[R5_REGNUM] = (frame_info).frame + 0x34; \
376 (frame_saved_regs).regs[R6_REGNUM] = (frame_info).frame + 0x38; \
377 (frame_saved_regs).regs[R7_REGNUM] = (frame_info).frame + 0x3C; \
378}
379\f
380/* Things needed for making the inferior call functions. */
381
382/* Push an empty stack frame, to record the current PC, etc. */
383
384#define PUSH_DUMMY_FRAME \
385{ register CORE_ADDR sp = read_register (SP_REGNUM); \
386 register int regnum; \
387 sp = push_word (sp, read_register (PC_REGNUM)); \
388 sp = push_word (sp, read_register (FP_REGNUM)); \
389 write_register (FP_REGNUM, sp); \
390 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--) \
391 sp = push_word (sp, read_register (regnum)); \
392 sp = push_word (sp, read_register (PS_REGNUM)); \
393 write_register (SP_REGNUM, sp); }
394
395/* Discard from the stack the innermost frame,
396 restoring all saved registers. */
397
398#define POP_FRAME \
399{ register CORE_ADDR fp = read_register (FP_REGNUM); \
400 register int regnum; \
401 struct frame_saved_regs fsr; \
402 struct frame_info fi; \
403 fi = get_frame_info (fp); \
404 get_frame_saved_regs (&fi, &fsr); \
405 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--) \
406 if (fsr.regs[regnum]) \
407 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
408 if (fsr.regs[PS_REGNUM]) \
409 write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4)); \
410 write_register (FP_REGNUM, read_memory_integer (fp, 4)); \
411 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \
412 write_register (SP_REGNUM, fp + 8); \
413 set_current_frame (read_register (FP_REGNUM)); }
414
415/* This sequence of words is the instructions:
416 halt
417 halt
418 halt
419 halt
420 suabr b2, #<stacksize>
421 lwbr b6, #con
422 stw r1, 8(b2) - save caller address, do we care?
423 lw r2, 60(b2) - arg1
424 labr b3, 50(b2)
425 std r4, 30(b2) - save r4-r7
426 std r6, 38(b2)
427 lwbr b1, #<func> - load function call address
428 brlnk r1, 8(b1) - call function
429 halt
430 halt
431 ld r4, 30(b2) - restore r4-r7
432 ld r6, 38(b2)
433
434 Setup our stack frame, load argumemts, call and then restore registers.
435*/
436
437#define CALL_DUMMY {0xf227e0ff, 0x48e7fffc, 0x426742e7, 0x4eb93232, 0x3232dffc, 0x69696969, 0x4e4f4e71}
438
439#define CALL_DUMMY_LENGTH 28
440
441#define CALL_DUMMY_START_OFFSET 12
442
443/* Insert the specified number of args and function address
444 into a call sequence of the above form stored at DUMMYNAME. */
445
446#define FIX_CALL_DUMMY(dummyname, fun, nargs) \
447{ *(int *)((char *) dummyname + 20) = nargs * 4; \
448 *(int *)((char *) dummyname + 14) = fun; }
449\f
450/*
451 * No KDB support, Yet! */
452/* Interface definitions for kernel debugger KDB. */
453
454/* Map machine fault codes into signal numbers.
455 First subtract 0, divide by 4, then index in a table.
456 Faults for which the entry in this table is 0
457 are not handled by KDB; the program's own trap handler
458 gets to handle then. */
459
460#define FAULT_CODE_ORIGIN 0
461#define FAULT_CODE_UNITS 4
462#define FAULT_TABLE \
463{ 0, 0, 0, 0, SIGTRAP, 0, 0, 0, \
464 0, SIGTRAP, 0, 0, 0, 0, 0, SIGKILL, \
465 0, 0, 0, 0, 0, 0, 0, 0, \
466 SIGILL }
467
468/* Start running with a stack stretching from BEG to END.
469 BEG and END should be symbols meaningful to the assembler.
470 This is used only for kdb. */
471
472#define INIT_STACK(beg, end) \
473{ asm (".globl end"); \
474 asm ("movel $ end, sp"); \
475 asm ("clrl fp"); }
476
477/* Push the frame pointer register on the stack. */
478#define PUSH_FRAME_PTR \
479 asm ("movel fp, -(sp)");
480
481/* Copy the top-of-stack to the frame pointer register. */
482#define POP_FRAME_PTR \
483 asm ("movl (sp), fp");
484
485/* After KDB is entered by a fault, push all registers
486 that GDB thinks about (all NUM_REGS of them),
487 so that they appear in order of ascending GDB register number.
488 The fault code will be on the stack beyond the last register. */
489
490#define PUSH_REGISTERS \
491{ asm ("clrw -(sp)"); \
492 asm ("pea 10(sp)"); \
493 asm ("movem $ 0xfffe,-(sp)"); }
494
495/* Assuming the registers (including processor status) have been
496 pushed on the stack in order of ascending GDB register number,
497 restore them and return to the address in the saved PC register. */
498
499#define POP_REGISTERS \
500{ asm ("subil $8,28(sp)"); \
501 asm ("movem (sp),$ 0xffff"); \
502 asm ("rte"); }
This page took 0.042617 seconds and 4 git commands to generate.