]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/m-merlin.h
ef8d1ec363eab86650b8c299ed625672461167ef
[thirdparty/binutils-gdb.git] / gdb / m-merlin.h
1 /* Definitions to make GDB run on a merlin under utek 2.1
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 ns16000
21 #define ns16000
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 # include <machine/reg.h>
30
31 /* Define this if the C compiler puts an underscore at the front
32 of external names before giving them to the linker. */
33
34 #define NAMES_HAVE_UNDERSCORE
35
36 /* Debugger information will be in DBX format. */
37
38 #define READ_DBX_FORMAT
39
40 /* Offset from address of function to start of its code.
41 Zero on most machines. */
42
43 #define FUNCTION_START_OFFSET 0
44
45 /* Advance PC across any function entry prologue instructions
46 to reach some "real" code. */
47
48 #define SKIP_PROLOGUE(pc) \
49 { register int op = read_memory_integer (pc, 1); \
50 if (op == 0x82) \
51 { op = read_memory_integer (pc+2,1); \
52 if ((op & 0x80) == 0) pc += 3; \
53 else if ((op & 0xc0) == 0x80) pc += 4; \
54 else pc += 6; \
55 }}
56
57 /* Immediately after a function call, return the saved pc.
58 Can't always go through the frames for this because on some machines
59 the new frame is not set up until the new function executes
60 some instructions. */
61
62 #define SAVED_PC_AFTER_CALL(frame) \
63 read_memory_integer (read_register (SP_REGNUM), 4)
64
65 /* This is the amount to subtract from u.u_ar0
66 to get the offset in the core file of the register values. */
67
68 #define KERNEL_U_ADDR (0xfef000)
69
70 /* Address of end of stack space. */
71
72 #define STACK_END_ADDR (0x800000)
73
74 /* Stack grows downward. */
75
76 #define INNER_THAN <
77
78 /* Sequence of bytes for breakpoint instruction. */
79
80 #define BREAKPOINT {0xf2}
81
82 /* Amount PC must be decremented by after a breakpoint.
83 This is often the number of bytes in BREAKPOINT
84 but not always. */
85
86 #define DECR_PC_AFTER_BREAK 0
87
88 /* Nonzero if instruction at PC is a return instruction. */
89
90 #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 1) == 0x12)
91
92 /* Return 1 if P points to an invalid floating point value. */
93
94 #define INVALID_FLOAT(p, len) 0
95
96 /* Define this to say that the "svc" insn is followed by
97 codes in memory saying which kind of system call it is. */
98
99 #define NS32K_SVC_IMMED_OPERANDS
100
101 /* Largest integer type */
102 #define LONGEST long
103
104 /* Name of the builtin type for the LONGEST type above. */
105 #define BUILTIN_TYPE_LONGEST builtin_type_long
106
107 /* Say how long (ordinary) registers are. */
108
109 #define REGISTER_TYPE long
110
111 /* Number of machine registers */
112
113 #define NUM_REGS 25
114
115 #define NUM_GENERAL_REGS 8
116
117 /* Initializer for an array of names of registers.
118 There should be NUM_REGS strings in this initializer. */
119
120 #define REGISTER_NAMES {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
121 "pc", "sp", "fp", "ps", \
122 "fsr", \
123 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
124 "l0", "l1", "l2", "l3", "l4", \
125 }
126
127 /* Register numbers of various important registers.
128 Note that some of these values are "real" register numbers,
129 and correspond to the general registers of the machine,
130 and some are "phony" register numbers which are too large
131 to be actual register numbers as far as the user is concerned
132 but do serve to get the desired values when passed to read_register. */
133
134 #define AP_REGNUM FP_REGNUM
135 #define FP_REGNUM 10 /* Contains address of executing stack frame */
136 #define SP_REGNUM 9 /* Contains address of top of stack */
137 #define PC_REGNUM 8 /* Contains program counter */
138 #define PS_REGNUM 11 /* Contains processor status */
139 #define FPS_REGNUM 12 /* Floating point status register */
140 #define FP0_REGNUM 13 /* Floating point register 0 */
141 #define LP0_REGNUM 21 /* Double register 0 (same as FP0) */
142
143 #define REGISTER_U_ADDR(addr, blockend, regno) \
144 { \
145 switch (regno) { \
146 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: \
147 addr = blockend + (R0 - regno) * sizeof (int); break; \
148 case PC_REGNUM: \
149 addr = blockend + PC * sizeof (int); break; \
150 case SP_REGNUM: \
151 addr = blockend + SP * sizeof (int); break; \
152 case FP_REGNUM: \
153 addr = blockend + FP * sizeof (int); break; \
154 case PS_REGNUM: \
155 addr = blockend + 12 * sizeof (int); break; \
156 case FPS_REGNUM: \
157 addr = 108; break; \
158 case FP0_REGNUM + 0: case FP0_REGNUM + 1: \
159 case FP0_REGNUM + 2: case FP0_REGNUM + 3: \
160 case FP0_REGNUM + 4: case FP0_REGNUM + 5: \
161 case FP0_REGNUM + 6: case FP0_REGNUM + 7: \
162 addr = 76 + (regno - FP0_REGNUM) * sizeof (float); break; \
163 case LP0_REGNUM + 0: case LP0_REGNUM + 1: \
164 case LP0_REGNUM + 2: case LP0_REGNUM + 3: \
165 addr = 76 + (regno - LP0_REGNUM) * sizeof (double); break; \
166 default: \
167 printf ("bad argument to REGISTER_U_ADDR %d\n", regno); \
168 abort (); \
169 } \
170 }
171
172 /* Total amount of space needed to store our copies of the machine's
173 register state, the array `registers'. */
174 #define REGISTER_BYTES ((NUM_REGS - 4) * sizeof (int) + 4 * sizeof (double))
175
176 /* Index within `registers' of the first byte of the space for
177 register N. */
178
179 #define REGISTER_BYTE(N) ((N) >= LP0_REGNUM ? \
180 LP0_REGNUM * 4 + ((N) - LP0_REGNUM) * 8 : (N) * 4)
181
182 /* Number of bytes of storage in the actual machine representation
183 for register N. On the 32000, all regs are 4 bytes
184 except for the doubled floating registers. */
185
186 #define REGISTER_RAW_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4)
187
188 /* Number of bytes of storage in the program's representation
189 for register N. On the 32000, all regs are 4 bytes
190 except for the doubled floating registers. */
191
192 #define REGISTER_VIRTUAL_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4)
193
194 /* Largest value REGISTER_RAW_SIZE can have. */
195
196 #define MAX_REGISTER_RAW_SIZE 8
197
198 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
199
200 #define MAX_REGISTER_VIRTUAL_SIZE 8
201
202 /* Nonzero if register N requires conversion
203 from raw format to virtual format. */
204
205 #define REGISTER_CONVERTIBLE(N) 0
206
207 /* Convert data from raw format for register REGNUM
208 to virtual format for register REGNUM. */
209
210 #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
211 bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM));
212
213 /* Convert data from virtual format for register REGNUM
214 to raw format for register REGNUM. */
215
216 #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
217 bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM));
218
219 /* Return the GDB type object for the "standard" data type
220 of data in register N. */
221
222 #define REGISTER_VIRTUAL_TYPE(N) \
223 ((N) >= FP0_REGNUM ? \
224 ((N) >= LP0_REGNUM ? \
225 builtin_type_double \
226 : builtin_type_float) \
227 : builtin_type_int)
228
229 /* Store the address of the place in which to copy the structure the
230 subroutine will return. This is called from call_function.
231
232 On this machine this is a no-op, as gcc doesn't run on it yet.
233 This calling convention is not used. */
234
235 #define STORE_STRUCT_RETURN(ADDR, SP)
236
237 /* Extract from an array REGBUF containing the (raw) register state
238 a function return value of type TYPE, and copy that, in virtual format,
239 into VALBUF. */
240
241 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
242 bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
243
244 /* Write into appropriate registers a function return value
245 of type TYPE, given in virtual format. */
246
247 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
248 write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
249
250 /* Extract from an array REGBUF containing the (raw) register state
251 the address in which a function should return its structure value,
252 as a CORE_ADDR (or an expression that can be used as one). */
253
254 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
255 \f
256 /* Describe the pointer in each stack frame to the previous stack frame
257 (its caller). */
258
259 /* FRAME_CHAIN takes a frame's nominal address
260 and produces the frame's chain-pointer.
261
262 FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
263 and produces the nominal address of the caller frame.
264
265 However, if FRAME_CHAIN_VALID returns zero,
266 it means the given frame is the outermost one and has no caller.
267 In that case, FRAME_CHAIN_COMBINE is not used. */
268
269 /* In the case of the Merlin, the frame's nominal address is the FP value,
270 and at that address is saved previous FP value as a 4-byte word. */
271
272 #define FRAME_CHAIN(thisframe) \
273 (outside_startup_file ((thisframe)->pc) ? \
274 read_memory_integer ((thisframe)->frame, 4) :\
275 0)
276
277 #define FRAME_CHAIN_VALID(chain, thisframe) \
278 (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe))))
279
280 #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
281
282 /* Define other aspects of the stack frame. */
283
284 #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4))
285
286 /* compute base of arguments */
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(numargs, fi) \
295 { CORE_ADDR pc; \
296 int insn; \
297 int addr_mode; \
298 int width; \
299 \
300 pc = FRAME_SAVED_PC (fi); \
301 insn = read_memory_integer (pc,2); \
302 addr_mode = (insn >> 11) & 0x1f; \
303 insn = insn & 0x7ff; \
304 if ((insn & 0x7fc) == 0x57c \
305 && addr_mode == 0x14) /* immediate */ \
306 { if (insn == 0x57c) /* adjspb */ \
307 width = 1; \
308 else if (insn == 0x57d) /* adjspw */ \
309 width = 2; \
310 else if (insn == 0x57f) /* adjspd */ \
311 width = 4; \
312 numargs = read_memory_integer (pc+2,width); \
313 if (width > 1) \
314 flip_bytes (&numargs, width); \
315 numargs = - sign_extend (numargs, width*8) / 4; } \
316 else numargs = -1; \
317 }
318
319 /* Return number of bytes at start of arglist that are not really args. */
320
321 #define FRAME_ARGS_SKIP 8
322
323 /* Put here the code to store, into a struct frame_saved_regs,
324 the addresses of the saved registers of frame described by FRAME_INFO.
325 This includes special registers such as pc and fp saved in special
326 ways in the stack frame. sp is even more special:
327 the address we return for it IS the sp for the next frame. */
328
329 #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
330 { int regmask,regnum; \
331 int localcount; \
332 CORE_ADDR enter_addr; \
333 CORE_ADDR next_addr; \
334 \
335 enter_addr = get_pc_function_start ((frame_info)->pc); \
336 regmask = read_memory_integer (enter_addr+1, 1); \
337 localcount = ns32k_localcount (enter_addr); \
338 next_addr = (frame_info)->frame + localcount; \
339 for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) \
340 (frame_saved_regs).regs[regnum] \
341 = (regmask & 1) ? (next_addr -= 4) : 0; \
342 (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame + 4; \
343 (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 4; \
344 (frame_saved_regs).regs[FP_REGNUM] \
345 = read_memory_integer ((frame_info)->frame, 4); }
346
347 /* Compensate for lack of `vprintf' function. */
348 #ifndef HAVE_VPRINTF
349 #define vprintf(format, ap) _doprnt (format, ap, stdout)
350 #endif /* not HAVE_VPRINTF */
351 \f
352 /* Things needed for making the inferior call functions. */
353
354 /* Push an empty stack frame, to record the current PC, etc. */
355
356 #define PUSH_DUMMY_FRAME \
357 { register CORE_ADDR sp = read_register (SP_REGNUM); \
358 register int regnum; \
359 sp = push_word (sp, read_register (PC_REGNUM)); \
360 sp = push_word (sp, read_register (FP_REGNUM)); \
361 write_register (FP_REGNUM, sp); \
362 for (regnum = 0; regnum < 8; regnum++) \
363 sp = push_word (sp, read_register (regnum)); \
364 write_register (SP_REGNUM, sp); \
365 }
366
367 /* Discard from the stack the innermost frame, restoring all registers. */
368
369 #define POP_FRAME \
370 { register FRAME frame = get_current_frame (); \
371 register CORE_ADDR fp; \
372 register int regnum; \
373 struct frame_saved_regs fsr; \
374 struct frame_info *fi; \
375 fi = get_frame_info (frame); \
376 fp = fi->frame; \
377 get_frame_saved_regs (fi, &fsr); \
378 for (regnum = 0; regnum < 8; regnum++) \
379 if (fsr.regs[regnum]) \
380 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
381 write_register (FP_REGNUM, read_memory_integer (fp, 4)); \
382 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \
383 write_register (SP_REGNUM, fp + 8); \
384 flush_cached_frames (); \
385 set_current_frame (create_new_frame (read_register (FP_REGNUM),\
386 read_pc ())); \
387 }
388
389 /* This sequence of words is the instructions
390 enter 0xff,0 82 ff 00
391 jsr @0x00010203 7f ae c0 01 02 03
392 adjspd 0x69696969 7f a5 01 02 03 04
393 bpt f2
394 Note this is 16 bytes. */
395
396 #define CALL_DUMMY { 0x7f00ff82, 0x0201c0ae, 0x01a57f03, 0xf2040302 }
397
398 #define CALL_DUMMY_START_OFFSET 3
399 #define CALL_DUMMY_LENGTH 16
400 #define CALL_DUMMY_ADDR 5
401 #define CALL_DUMMY_NARGS 11
402
403 /* Insert the specified number of args and function address
404 into a call sequence of the above form stored at DUMMYNAME. */
405
406 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, type) \
407 { int flipped = fun | 0xc0000000; \
408 flip_bytes (&flipped, 4); \
409 *((int *) (((char *) dummyname)+CALL_DUMMY_ADDR)) = flipped; \
410 flipped = - nargs * 4; \
411 flip_bytes (&flipped, 4); \
412 *((int *) (((char *) dummyname)+CALL_DUMMY_NARGS)) = flipped; \
413 }
414 \f
415 #ifdef notdef
416 /* Interface definitions for kernel debugger KDB. */
417
418 /* Map machine fault codes into signal numbers.
419 First subtract 0, divide by 4, then index in a table.
420 Faults for which the entry in this table is 0
421 are not handled by KDB; the program's own trap handler
422 gets to handle then. */
423
424 #define FAULT_CODE_ORIGIN 0
425 #define FAULT_CODE_UNITS 4
426 #define FAULT_TABLE \
427 { 0, SIGKILL, SIGSEGV, 0, 0, 0, 0, 0, \
428 0, 0, SIGTRAP, SIGTRAP, 0, 0, 0, 0, \
429 0, 0, 0, 0, 0, 0, 0, 0}
430
431 /* Start running with a stack stretching from BEG to END.
432 BEG and END should be symbols meaningful to the assembler.
433 This is used only for kdb. */
434
435 #define INIT_STACK(beg, end) \
436 { asm (".globl end"); \
437 asm ("movl $ end, sp"); \
438 asm ("clrl fp"); }
439
440 /* Push the frame pointer register on the stack. */
441 #define PUSH_FRAME_PTR \
442 asm ("pushl fp");
443
444 /* Copy the top-of-stack to the frame pointer register. */
445 #define POP_FRAME_PTR \
446 asm ("movl (sp), fp");
447
448 /* After KDB is entered by a fault, push all registers
449 that GDB thinks about (all NUM_REGS of them),
450 so that they appear in order of ascending GDB register number.
451 The fault code will be on the stack beyond the last register. */
452
453 #define PUSH_REGISTERS \
454 { asm ("pushl 8(sp)"); \
455 asm ("pushl 8(sp)"); \
456 asm ("pushal 0x14(sp)"); \
457 asm ("pushr $037777"); }
458
459 /* Assuming the registers (including processor status) have been
460 pushed on the stack in order of ascending GDB register number,
461 restore them and return to the address in the saved PC register. */
462
463 #define POP_REGISTERS \
464 { asm ("popr $037777"); \
465 asm ("subl2 $8,(sp)"); \
466 asm ("movl (sp),sp"); \
467 asm ("rei"); }
468 #endif