Catch error on close so runtest won't bomb.
[deliverable/binutils-gdb.git] / gdb / tm-pyr.h
1 /* Definitions to make GDB run on a Pyramid under OSx 4.0 (4.2bsd).
2 Copyright 1988, 1989, 1991, 1993 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program 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 2 of the License, or
9 (at your option) any later version.
10
11 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #define TARGET_BYTE_ORDER BIG_ENDIAN
21
22 /* Traditional Unix virtual address spaces have thre regions: text,
23 data and stack. The text, initialised data, and uninitialised data
24 are represented in separate segments of the a.out file.
25 When a process dumps core, the data and stack regions are written
26 to a core file. This gives a debugger enough information to
27 reconstruct (and debug) the virtual address space at the time of
28 the coredump.
29 Pyramids have an distinct fourth region of the virtual address
30 space, in which the contents of the windowed registers are stacked
31 in fixed-size frames. Pyramid refer to this region as the control
32 stack. Each call (or trap) automatically allocates a new register
33 frame; each return deallocates the current frame and restores the
34 windowed registers to their values before the call.
35
36 When dumping core, the control stack is written to a core files as
37 a third segment. The core-handling functions need to know to deal
38 with it. */
39 /* Tell core.c there is an extra segment. */
40 #define REG_STACK_SEGMENT
41
42 /* Floating point is IEEE compatible on most Pyramid hardware
43 (Older processors do not have IEEE NaNs). */
44 #define IEEE_FLOAT
45
46 /* Offset from address of function to start of its code.
47 Zero on most machines. */
48
49 #define FUNCTION_START_OFFSET 0
50
51 /* Advance PC across any function entry prologue instructions
52 to reach some "real" code. */
53
54 /* FIXME -- do we want to skip insns to allocate the local frame?
55 If so, what do they look like?
56 This is becoming harder, since tege@sics.SE wants to change
57 gcc to not output a prologue when no frame is needed. */
58 #define SKIP_PROLOGUE(pc) do {} while (0)
59
60
61 /* Immediately after a function call, return the saved pc.
62 Can't always go through the frames for this because on some machines
63 the new frame is not set up until the new function executes
64 some instructions. */
65
66 #define SAVED_PC_AFTER_CALL(frame) FRAME_SAVED_PC(frame)
67
68 /* Address of end of stack space. */
69 /* This seems to be right for the 90x comp.vuw.ac.nz.
70 The correct value at any site may be a function of the configured
71 maximum control stack depth. If so, I don't know where the
72 control-stack depth is configured, so I can't #include it here. */
73 #define STACK_END_ADDR (0xc00cc000)
74
75 /* Register window stack (Control stack) stack definitions
76 - Address of beginning of control stack.
77 - size of control stack frame
78 (Note that since crts0 is usually the first function called,
79 main()'s control stack is one frame (0x80 bytes) beyond this value. */
80
81 #define CONTROL_STACK_ADDR (0xc00cd000)
82
83 /* Bytes in a register window -- 16 parameter regs, 16 local regs
84 for each call, is 32 regs * 4 bytes */
85
86 #define CONTROL_STACK_FRAME_SIZE (32*4)
87
88 /* FIXME. On a pyr, Data Stack grows downward; control stack goes upwards.
89 Which direction should we use for INNER_THAN, PC_INNER_THAN ?? */
90
91 #define INNER_THAN <
92 #define PC_INNER_THAN >
93
94 /* Stack has strict alignment. */
95
96 #define STACK_ALIGN(ADDR) (((ADDR)+3)&-4)
97
98 /* Sequence of bytes for breakpoint instruction. */
99
100 #define BREAKPOINT {0xf0, 00, 00, 00}
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
106 #define DECR_PC_AFTER_BREAK 0
107
108 /* Nonzero if instruction at PC is a return instruction.
109 On a pyr, this is either "ret" or "retd".
110 It would be friendly to check that any "retd" always had an
111 argument of 0, since anything else is invalid. */
112
113 #define ABOUT_TO_RETURN(pc) \
114 (((read_memory_integer (pc, 2) & 0x3ff0) == 0x3090) || \
115 ((read_memory_integer (pc, 2) & 0x0ff0) == 0x00a0))
116
117 /* Return 1 if P points to an invalid floating point value.
118 LEN is the length in bytes -- not relevant on the Vax. */
119 /* FIXME -- this is ok for a vax, bad for big-endian ieee format.
120 I would use the definition for a Sun; but it is no better! */
121
122 #define INVALID_FLOAT(p, len) ((*(short *) p & 0xff80) == 0x8000)
123
124 /* Say how long (ordinary) registers are. */
125
126 #define REGISTER_TYPE long
127
128 /* Number of machine registers */
129 /* pyramids have 64, plus one for the PSW; plus perhaps one more for the
130 kernel stack pointer (ksp) and control-stack pointer (CSP) */
131
132 #define NUM_REGS 67
133
134 /* Initializer for an array of names of registers.
135 There should be NUM_REGS strings in this initializer. */
136
137 #define REGISTER_NAMES \
138 {"gr0", "gr1", "gr2", "gr3", "gr4", "gr5", "gr6", "gr7", \
139 "gr8", "gr9", "gr10", "gr11", "logpsw", "cfp", "sp", "pc", \
140 "pr0", "pr1", "pr2", "pr3", "pr4", "pr5", "pr6", "pr7", \
141 "pr8", "pr9", "pr10", "pr11", "pr12", "pr13", "pr14", "pr15", \
142 "lr0", "lr1", "lr2", "lr3", "lr4", "lr5", "lr6", "lr7", \
143 "lr8", "lr9", "lr10", "lr11", "lr12", "lr13", "lr14", "lr15", \
144 "tr0", "tr1", "tr2", "tr3", "tr4", "tr5", "tr6", "tr7", \
145 "tr8", "tr9", "tr10", "tr11", "tr12", "tr13", "tr14", "tr15", \
146 "psw", "ksp", "csp"}
147
148 /* Register numbers of various important registers.
149 Note that some of these values are "real" register numbers,
150 and correspond to the general registers of the machine,
151 and some are "phony" register numbers which are too large
152 to be actual register numbers as far as the user is concerned
153 but do serve to get the desired values when passed to read_register. */
154
155 /* pseudo-registers: */
156 #define PS_REGNUM 64 /* Contains processor status */
157 #define PSW_REGNUM 64 /* Contains current psw, whatever it is.*/
158 #define CSP_REGNUM 65 /* address of this control stack frame*/
159 #define KSP_REGNUM 66 /* Contains process's Kernel Stack Pointer */
160
161 #define CFP_REGNUM 13 /* Current data-stack frame ptr */
162 #define TR0_REGNUM 48 /* After function call, contains
163 function result */
164
165 /* Registers interesting to the machine-independent part of gdb*/
166
167 #define FP_REGNUM CSP_REGNUM /* Contains address of executing (control)
168 stack frame */
169 #define SP_REGNUM 14 /* Contains address of top of stack -??*/
170 #define PC_REGNUM 15 /* Contains program counter */
171
172 /* Define DO_REGISTERS_INFO() to do machine-specific formatting
173 of register dumps. */
174
175 #define DO_REGISTERS_INFO(_regnum, fp) pyr_do_registers_info(_regnum, fp)
176
177 /* need this so we can find the global registers: they never get saved. */
178 extern unsigned int global_reg_offset;
179 extern unsigned int last_frame_offset;
180
181 /* Total amount of space needed to store our copies of the machine's
182 register state, the array `registers'. */
183 #define REGISTER_BYTES (NUM_REGS*4)
184
185 /* the Pyramid has register windows. */
186
187 #define HAVE_REGISTER_WINDOWS
188
189 /* Is this register part of the register window system? A yes answer
190 implies that 1) The name of this register will not be the same in
191 other frames, and 2) This register is automatically "saved" (out
192 registers shifting into ins counts) upon subroutine calls and thus
193 there is no need to search more than one stack frame for it. */
194
195 #define REGISTER_IN_WINDOW_P(regnum) \
196 ((regnum) >= 16 && (regnum) < 64)
197
198 /* Index within `registers' of the first byte of the space for
199 register N. */
200
201 #define REGISTER_BYTE(N) ((N) * 4)
202
203 /* Number of bytes of storage in the actual machine representation
204 for register N. On the Pyramid, all regs are 4 bytes. */
205
206 #define REGISTER_RAW_SIZE(N) 4
207
208 /* Number of bytes of storage in the program's representation
209 for register N. On the Pyramid, all regs are 4 bytes. */
210
211 #define REGISTER_VIRTUAL_SIZE(N) 4
212
213 /* Largest value REGISTER_RAW_SIZE can have. */
214
215 #define MAX_REGISTER_RAW_SIZE 4
216
217 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
218
219 #define MAX_REGISTER_VIRTUAL_SIZE 4
220
221 /* Nonzero if register N requires conversion
222 from raw format to virtual format. */
223
224 #define REGISTER_CONVERTIBLE(N) 0
225
226 /* Convert data from raw format for register REGNUM
227 to virtual format for register REGNUM. */
228
229 #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
230 bcopy ((FROM), (TO), 4);
231
232 /* Convert data from virtual format for register REGNUM
233 to raw format for register REGNUM. */
234
235 #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
236 bcopy ((FROM), (TO), 4);
237
238 /* Return the GDB type object for the "standard" data type
239 of data in register N. */
240
241 #define REGISTER_VIRTUAL_TYPE(N) builtin_type_int
242
243 /* FIXME: It seems impossible for both EXTRACT_RETURN_VALUE and
244 STORE_RETURN_VALUE to be correct. */
245
246 /* Store the address of the place in which to copy the structure the
247 subroutine will return. This is called from call_function. */
248
249 /****FIXME****/
250 #define STORE_STRUCT_RETURN(ADDR, SP) \
251 { write_register (TR0_REGNUM, (ADDR)); }
252
253 /* Extract from an array REGBUF containing the (raw) register state
254 a function return value of type TYPE, and copy that, in virtual format,
255 into VALBUF. */
256
257 /* Note that on a register-windowing machine (eg, Pyr, SPARC), this is
258 where the value is found after the function call -- ie, it should
259 correspond to GNU CC's FUNCTION_VALUE rather than FUNCTION_OUTGOING_VALUE.*/
260
261 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
262 bcopy (((int *)(REGBUF))+TR0_REGNUM, VALBUF, TYPE_LENGTH (TYPE))
263
264 /* Write into appropriate registers a function return value
265 of type TYPE, given in virtual format. */
266 /* on pyrs, values are returned in */
267
268 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
269 write_register_bytes (REGISTER_BYTE(TR0_REGNUM), VALBUF, TYPE_LENGTH (TYPE))
270
271 /* Extract from an array REGBUF containing the (raw) register state
272 the address in which a function should return its structure value,
273 as a CORE_ADDR (or an expression that can be used as one). */
274 /* FIXME */
275 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) \
276 ( ((int *)(REGBUF)) [TR0_REGNUM])
277
278 \f
279 /* Describe the pointer in each stack frame to the previous stack frame
280 (its caller). */
281
282 #define EXTRA_FRAME_INFO \
283 FRAME_ADDR bottom; \
284 CORE_ADDR frame_cfp; \
285 CORE_ADDR frame_window_addr;
286
287 #define INIT_EXTRA_FRAME_INFO(fromleaf, fci) \
288 do { \
289 (fci)->frame_window_addr = (fci)->frame; \
290 (fci)->bottom = \
291 ((fci)->next ? \
292 ((fci)->frame == (fci)->next_frame ? \
293 (fci)->next->bottom : (fci)->next->frame) : \
294 read_register (SP_REGNUM)); \
295 (fci)->frame_cfp = \
296 read_register (CFP_REGNUM); \
297 /***fprintf (stderr, \
298 "[[creating new frame for %0x,pc=%0x,csp=%0x]]\n", \
299 (fci)->frame, (fci)->pc,(fci)->frame_cfp);*/ \
300 } while (0);
301
302 /* FRAME_CHAIN takes a frame's nominal address
303 and produces the frame's chain-pointer. */
304
305 /* In the case of the pyr, the frame's nominal address is the address
306 of parameter register 0. The previous frame is found 32 words up. */
307
308 #define FRAME_CHAIN(thisframe) \
309 ( (thisframe) -> frame - CONTROL_STACK_FRAME_SIZE)
310
311 /*((thisframe) >= CONTROL_STACK_ADDR))*/
312
313 /* Define other aspects of the stack frame. */
314
315 /* A macro that tells us whether the function invocation represented
316 by FI does not have a frame on the stack associated with it. If it
317 does not, FRAMELESS is set to 1, else 0.
318
319 I do not understand what this means on a Pyramid, where functions
320 *always* have a control-stack frame, but may or may not have a
321 frame on the data stack. Since GBD uses the value of the
322 control stack pointer as its "address" of a frame, FRAMELESS
323 is always 1, so does not need to be defined. */
324
325
326 /* Where is the PC for a specific frame */
327
328 #define FRAME_SAVED_PC(fi) \
329 ((CORE_ADDR) (read_memory_integer ( (fi) -> frame + 60, 4)))
330
331 /* There may be bugs in FRAME_ARGS_ADDRESS and FRAME_LOCALS_ADDRESS;
332 or there may be bugs in accessing the registers that break
333 their definitions.
334 Having the macros expand into functions makes them easier to debug.
335 When the bug is finally located, the inline macro defintions can
336 be un-#if 0ed, and frame_args_addr and frame_locals_address can
337 be deleted from pyr-dep.c */
338
339 /* If the argument is on the stack, it will be here. */
340 #define FRAME_ARGS_ADDRESS(fi) \
341 frame_args_addr(fi)
342
343 #define FRAME_LOCALS_ADDRESS(fi) \
344 frame_locals_address(fi)
345
346 /* The following definitions doesn't seem to work.
347 I don't understand why. */
348 #if 0
349 #define FRAME_ARGS_ADDRESS(fi) \
350 /*(FRAME_FP(fi) + (13*4))*/ (read_register (CFP_REGNUM))
351
352 #define FRAME_LOCALS_ADDRESS(fi) \
353 ((fi)->frame +(16*4))
354
355 #endif /* 0 */
356
357 /* Return number of args passed to a frame.
358 Can return -1, meaning no way to tell. */
359
360 #define FRAME_NUM_ARGS(val, fi) (val = -1)
361
362 /* Return number of bytes at start of arglist that are not really args. */
363
364 #define FRAME_ARGS_SKIP 0
365
366 /* Put here the code to store, into a struct frame_saved_regs,
367 the addresses of the saved registers of frame described by FRAME_INFO.
368 This includes special registers such as pc and fp saved in special
369 ways in the stack frame. sp is even more special:
370 the address we return for it IS the sp for the next frame.
371
372 Note that on register window machines, we are currently making the
373 assumption that window registers are being saved somewhere in the
374 frame in which they are being used. If they are stored in an
375 inferior frame, find_saved_register will break.
376
377 On pyrs, frames of window registers are stored contiguously on a
378 separate stack. All window registers are always stored.
379 The pc and psw (gr15 and gr14) are also always saved: the call
380 insn saves them in pr15 and pr14 of the new frame (tr15,tr14 of the
381 old frame).
382 The data-stack frame pointer (CFP) is only saved in functions which
383 allocate a (data)stack frame (with "adsf"). We detect them by
384 looking at the first insn of the procedure.
385
386 Other non-window registers (gr0-gr11) are never saved. Pyramid's C
387 compiler and gcc currently ignore them, so it's not an issue. */
388
389 #define FRAME_FIND_SAVED_REGS(fi_p, frame_saved_regs) \
390 { register int regnum; \
391 register CORE_ADDR pc; \
392 register CORE_ADDR fn_start_pc; \
393 register int first_insn; \
394 register CORE_ADDR prev_cf_addr; \
395 register int window_ptr; \
396 FRAME fid = FRAME_INFO_ID (fi_p); \
397 if (!fid) fatal ("Bad frame info struct in FRAME_FIND_SAVED_REGS"); \
398 bzero (&(frame_saved_regs), sizeof (frame_saved_regs)); \
399 \
400 window_ptr = prev_cf_addr = FRAME_FP(fi_p); \
401 \
402 for (regnum = 16 ; regnum < 64; regnum++,window_ptr+=4) \
403 { \
404 (frame_saved_regs).regs[regnum] = window_ptr; \
405 } \
406 \
407 /* In each window, psw, and pc are "saved" in tr14,tr15. */ \
408 /*** psw is sometimes saved in gr12 (so sez <sys/pcb.h>) */ \
409 (frame_saved_regs).regs[PS_REGNUM] = FRAME_FP(fi_p) + (14*4); \
410 \
411 /*(frame_saved_regs).regs[PC_REGNUM] = (frame_saved_regs).regs[31];*/ \
412 (frame_saved_regs).regs[PC_REGNUM] = FRAME_FP(fi_p) + ((15+32)*4); \
413 \
414 /* Functions that allocate a frame save sp *where*? */ \
415 /*first_insn = read_memory_integer (get_pc_function_start ((fi_p)->pc),4); */ \
416 \
417 fn_start_pc = (get_pc_function_start ((fi_p)->pc)); \
418 first_insn = read_memory_integer(fn_start_pc, 4); \
419 \
420 if (0x08 == ((first_insn >> 20) &0x0ff)) { \
421 /* NB: because WINDOW_REGISTER_P(cfp) is false, a saved cfp \
422 in this frame is only visible in this frame's callers. \
423 That means the cfp we mark saved is my caller's cfp, ie pr13. \
424 I don't understand why we don't have to do that for pc, too. */ \
425 \
426 (frame_saved_regs).regs[CFP_REGNUM] = FRAME_FP(fi_p)+(13*4); \
427 \
428 (frame_saved_regs).regs[SP_REGNUM] = \
429 read_memory_integer (FRAME_FP(fi_p)+((13+32)*4),4); \
430 } \
431 \
432 /* \
433 *(frame_saved_regs).regs[CFP_REGNUM] = (frame_saved_regs).regs[61]; \
434 * (frame_saved_regs).regs[SP_REGNUM] = \
435 * read_memory_integer (FRAME_FP(fi_p)+((13+32)*4),4); \
436 */ \
437 \
438 (frame_saved_regs).regs[CSP_REGNUM] = prev_cf_addr; \
439 }
440 \f
441 /* Things needed for making the inferior call functions. */
442 #if 0
443 /* These are all lies. These macro definitions are appropriate for a
444 SPARC. On a pyramid, pushing a dummy frame will
445 surely involve writing the control stack pointer,
446 then saving the pc. This requires a privileged instruction.
447 Maybe one day Pyramid can be persuaded to add a syscall to do this.
448 Until then, we are out of luck. */
449
450 /* Push an empty stack frame, to record the current PC, etc. */
451
452 #define PUSH_DUMMY_FRAME \
453 { register CORE_ADDR sp = read_register (SP_REGNUM);\
454 register int regnum; \
455 sp = push_word (sp, 0); /* arglist */ \
456 for (regnum = 11; regnum >= 0; regnum--) \
457 sp = push_word (sp, read_register (regnum)); \
458 sp = push_word (sp, read_register (PC_REGNUM)); \
459 sp = push_word (sp, read_register (FP_REGNUM)); \
460 /* sp = push_word (sp, read_register (AP_REGNUM));*/ \
461 sp = push_word (sp, (read_register (PS_REGNUM) & 0xffef) \
462 + 0x2fff0000); \
463 sp = push_word (sp, 0); \
464 write_register (SP_REGNUM, sp); \
465 write_register (FP_REGNUM, sp); \
466 /* write_register (AP_REGNUM, sp + 17 * sizeof (int));*/ }
467
468 /* Discard from the stack the innermost frame, restoring all registers. */
469
470 #define POP_FRAME \
471 { register CORE_ADDR fp = read_register (FP_REGNUM); \
472 register int regnum; \
473 register int regmask = read_memory_integer (fp + 4, 4); \
474 write_register (PS_REGNUM, \
475 (regmask & 0xffff) \
476 | (read_register (PS_REGNUM) & 0xffff0000)); \
477 write_register (PC_REGNUM, read_memory_integer (fp + 16, 4)); \
478 write_register (FP_REGNUM, read_memory_integer (fp + 12, 4)); \
479 /* write_register (AP_REGNUM, read_memory_integer (fp + 8, 4));*/ \
480 fp += 16; \
481 for (regnum = 0; regnum < 12; regnum++) \
482 if (regmask & (0x10000 << regnum)) \
483 write_register (regnum, read_memory_integer (fp += 4, 4)); \
484 fp = fp + 4 + ((regmask >> 30) & 3); \
485 if (regmask & 0x20000000) \
486 { regnum = read_memory_integer (fp, 4); \
487 fp += (regnum + 1) * 4; } \
488 write_register (SP_REGNUM, fp); \
489 set_current_frame (read_register (FP_REGNUM)); }
490
491 /* This sequence of words is the instructions
492 calls #69, @#32323232
493 bpt
494 Note this is 8 bytes. */
495
496 #define CALL_DUMMY {0x329f69fb, 0x03323232}
497
498 #define CALL_DUMMY_START_OFFSET 0 /* Start execution at beginning of dummy */
499
500 /* Insert the specified number of args and function address
501 into a call sequence of the above form stored at DUMMYNAME. */
502
503 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \
504 { *((char *) dummyname + 1) = nargs; \
505 *(int *)((char *) dummyname + 3) = fun; }
506 #endif /* 0 */
507
508 #define POP_FRAME \
509 { error ("The return command is not supported on this machine."); }
This page took 0.038863 seconds and 4 git commands to generate.