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