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