Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Definitions to make GDB run on a vax under 4.2bsd. |
b6ba6518 KB |
2 | Copyright 1986, 1987, 1989, 1991, 1993, 1994, 1996, 1998, 1999, 2000 |
3 | Free Software Foundation, Inc. | |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | ||
23 | #define TARGET_BYTE_ORDER LITTLE_ENDIAN | |
24 | ||
25 | /* Offset from address of function to start of its code. | |
26 | Zero on most machines. */ | |
27 | ||
28 | #define FUNCTION_START_OFFSET 2 | |
29 | ||
30 | /* Advance PC across any function entry prologue instructions | |
31 | to reach some "real" code. */ | |
32 | ||
a14ed312 | 33 | extern CORE_ADDR vax_skip_prologue (CORE_ADDR); |
b83266a0 | 34 | #define SKIP_PROLOGUE(pc) (vax_skip_prologue (pc)) |
c906108c SS |
35 | |
36 | /* Immediately after a function call, return the saved pc. | |
37 | Can't always go through the frames for this because on some machines | |
38 | the new frame is not set up until the new function executes | |
39 | some instructions. */ | |
40 | ||
41 | #define SAVED_PC_AFTER_CALL(frame) FRAME_SAVED_PC(frame) | |
42 | ||
43 | #define TARGET_UPAGES 14 | |
44 | #define TARGET_NBPG 512 | |
45 | #define STACK_END_ADDR (0x80000000 - (TARGET_UPAGES * TARGET_NBPG)) | |
46 | ||
47 | /* On the VAX, sigtramp is in the u area. Can't check the exact | |
48 | addresses because for cross-debugging we don't have VAX include | |
49 | files around. This should be close enough. */ | |
50 | #define SIGTRAMP_START(pc) STACK_END_ADDR | |
51 | #define SIGTRAMP_END(pc) 0x80000000 | |
52 | ||
53 | /* Stack grows downward. */ | |
54 | ||
55 | #define INNER_THAN(lhs,rhs) ((lhs) < (rhs)) | |
56 | ||
57 | /* Sequence of bytes for breakpoint instruction. */ | |
58 | ||
59 | #define BREAKPOINT {3} | |
60 | ||
61 | /* Amount PC must be decremented by after a breakpoint. | |
62 | This is often the number of bytes in BREAKPOINT | |
63 | but not always. */ | |
64 | ||
65 | #define DECR_PC_AFTER_BREAK 0 | |
66 | ||
67 | /* Return 1 if P points to an invalid floating point value. | |
68 | LEN is the length in bytes -- not relevant on the Vax. */ | |
69 | ||
70 | #define INVALID_FLOAT(p, len) ((*(short *) p & 0xff80) == 0x8000) | |
71 | ||
72 | /* Say how long (ordinary) registers are. This is a piece of bogosity | |
73 | used in push_word and a few other places; REGISTER_RAW_SIZE is the | |
74 | real way to know how big a register is. */ | |
75 | ||
76 | #define REGISTER_SIZE 4 | |
77 | ||
78 | /* Number of machine registers */ | |
79 | ||
80 | #define NUM_REGS 17 | |
81 | ||
82 | /* Initializer for an array of names of registers. | |
83 | There should be NUM_REGS strings in this initializer. */ | |
84 | ||
85 | #define REGISTER_NAMES {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc", "ps"} | |
86 | ||
87 | /* Register numbers of various important registers. | |
88 | Note that some of these values are "real" register numbers, | |
89 | and correspond to the general registers of the machine, | |
90 | and some are "phony" register numbers which are too large | |
91 | to be actual register numbers as far as the user is concerned | |
92 | but do serve to get the desired values when passed to read_register. */ | |
93 | ||
94 | #define AP_REGNUM 12 | |
95 | #define FP_REGNUM 13 /* Contains address of executing stack frame */ | |
96 | #define SP_REGNUM 14 /* Contains address of top of stack */ | |
97 | #define PC_REGNUM 15 /* Contains program counter */ | |
98 | #define PS_REGNUM 16 /* Contains processor status */ | |
99 | ||
100 | /* Total amount of space needed to store our copies of the machine's | |
101 | register state, the array `registers'. */ | |
102 | #define REGISTER_BYTES (17*4) | |
103 | ||
104 | /* Index within `registers' of the first byte of the space for | |
105 | register N. */ | |
106 | ||
107 | #define REGISTER_BYTE(N) ((N) * 4) | |
108 | ||
109 | /* Number of bytes of storage in the actual machine representation | |
110 | for register N. On the vax, all regs are 4 bytes. */ | |
111 | ||
112 | #define REGISTER_RAW_SIZE(N) 4 | |
113 | ||
114 | /* Number of bytes of storage in the program's representation | |
115 | for register N. On the vax, all regs are 4 bytes. */ | |
116 | ||
117 | #define REGISTER_VIRTUAL_SIZE(N) 4 | |
118 | ||
119 | /* Largest value REGISTER_RAW_SIZE can have. */ | |
120 | ||
121 | #define MAX_REGISTER_RAW_SIZE 4 | |
122 | ||
123 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ | |
124 | ||
125 | #define MAX_REGISTER_VIRTUAL_SIZE 4 | |
126 | ||
127 | /* Return the GDB type object for the "standard" data type | |
128 | of data in register N. */ | |
129 | ||
130 | #define REGISTER_VIRTUAL_TYPE(N) builtin_type_int | |
131 | ||
132 | /* Store the address of the place in which to copy the structure the | |
133 | subroutine will return. This is called from call_function. */ | |
134 | ||
135 | #define STORE_STRUCT_RETURN(ADDR, SP) \ | |
136 | { write_register (1, (ADDR)); } | |
137 | ||
138 | /* Extract from an array REGBUF containing the (raw) register state | |
139 | a function return value of type TYPE, and copy that, in virtual format, | |
140 | into VALBUF. */ | |
141 | ||
142 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ | |
143 | memcpy (VALBUF, REGBUF, TYPE_LENGTH (TYPE)) | |
144 | ||
145 | /* Write into appropriate registers a function return value | |
146 | of type TYPE, given in virtual format. */ | |
147 | ||
148 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ | |
149 | write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE)) | |
150 | ||
151 | /* Extract from an array REGBUF containing the (raw) register state | |
152 | the address in which a function should return its structure value, | |
153 | as a CORE_ADDR (or an expression that can be used as one). */ | |
154 | ||
155 | #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF)) | |
c906108c | 156 | \f |
c5aa993b | 157 | |
c906108c SS |
158 | /* Describe the pointer in each stack frame to the previous stack frame |
159 | (its caller). */ | |
160 | ||
161 | /* FRAME_CHAIN takes a frame's nominal address | |
162 | and produces the frame's chain-pointer. */ | |
163 | ||
164 | /* In the case of the Vax, the frame's nominal address is the FP value, | |
165 | and 12 bytes later comes the saved previous FP value as a 4-byte word. */ | |
166 | ||
167 | #define FRAME_CHAIN(thisframe) \ | |
168 | (!inside_entry_file ((thisframe)->pc) ? \ | |
169 | read_memory_integer ((thisframe)->frame + 12, 4) :\ | |
170 | 0) | |
171 | ||
172 | /* Define other aspects of the stack frame. */ | |
173 | ||
174 | /* A macro that tells us whether the function invocation represented | |
175 | by FI does not have a frame on the stack associated with it. If it | |
176 | does not, FRAMELESS is set to 1, else 0. */ | |
177 | /* On the vax, all functions have frames. */ | |
392a587b | 178 | #define FRAMELESS_FUNCTION_INVOCATION(FI) (0) |
c906108c SS |
179 | |
180 | /* Saved Pc. Get it from sigcontext if within sigtramp. */ | |
181 | ||
182 | /* Offset to saved PC in sigcontext, from <sys/signal.h>. */ | |
183 | #define SIGCONTEXT_PC_OFFSET 12 | |
184 | ||
185 | #define FRAME_SAVED_PC(FRAME) \ | |
186 | (((FRAME)->signal_handler_caller \ | |
187 | ? sigtramp_saved_pc (FRAME) \ | |
188 | : read_memory_integer ((FRAME)->frame + 16, 4)) \ | |
189 | ) | |
190 | ||
191 | /* Cannot find the AP register value directly from the FP value. Must | |
192 | find it saved in the frame called by this one, or in the AP | |
193 | register for the innermost frame. However, there is no way to tell | |
194 | the difference between the innermost frame and a frame for which we | |
195 | just don't know the frame that it called (e.g. "info frame | |
196 | 0x7ffec789"). For the sake of argument suppose that the stack is | |
197 | somewhat trashed (which is one reason that "info frame" exists). | |
198 | So return 0 (indicating we don't know the address of | |
199 | the arglist) if we don't know what frame this frame calls. */ | |
200 | #define FRAME_ARGS_ADDRESS_CORRECT(fi) \ | |
201 | (((fi)->next \ | |
202 | ? read_memory_integer ((fi)->next->frame + 8, 4) \ | |
203 | : /* read_register (AP_REGNUM) */ 0)) | |
204 | ||
205 | /* In most of GDB, getting the args address is too important to | |
206 | just say "I don't know". This is sometimes wrong for functions | |
207 | that aren't on top of the stack, but c'est la vie. */ | |
208 | #define FRAME_ARGS_ADDRESS(fi) \ | |
209 | (((fi)->next \ | |
210 | ? read_memory_integer ((fi)->next->frame + 8, 4) \ | |
211 | : read_register (AP_REGNUM) /* 0 */)) | |
212 | ||
213 | #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) | |
214 | ||
215 | /* Return number of args passed to a frame. | |
216 | Can return -1, meaning no way to tell. */ | |
217 | ||
a14ed312 | 218 | extern int vax_frame_num_args (struct frame_info *fi); |
392a587b | 219 | #define FRAME_NUM_ARGS(fi) (vax_frame_num_args ((fi))) |
c906108c SS |
220 | |
221 | /* Return number of bytes at start of arglist that are not really args. */ | |
222 | ||
223 | #define FRAME_ARGS_SKIP 4 | |
224 | ||
225 | /* Put here the code to store, into a struct frame_saved_regs, | |
226 | the addresses of the saved registers of frame described by FRAME_INFO. | |
227 | This includes special registers such as pc and fp saved in special | |
228 | ways in the stack frame. sp is even more special: | |
229 | the address we return for it IS the sp for the next frame. */ | |
230 | ||
231 | #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ | |
232 | { register int regnum; \ | |
233 | register int regmask = read_memory_integer ((frame_info)->frame+4, 4) >> 16; \ | |
234 | register CORE_ADDR next_addr; \ | |
235 | memset (&frame_saved_regs, '\0', sizeof frame_saved_regs); \ | |
236 | next_addr = (frame_info)->frame + 16; \ | |
237 | /* Regmask's low bit is for register 0, \ | |
238 | which is the first one that would be pushed. */ \ | |
239 | for (regnum = 0; regnum < 12; regnum++, regmask >>= 1) \ | |
240 | (frame_saved_regs).regs[regnum] = (regmask & 1) ? (next_addr += 4) : 0; \ | |
241 | (frame_saved_regs).regs[SP_REGNUM] = next_addr + 4; \ | |
242 | if (read_memory_integer ((frame_info)->frame + 4, 4) & 0x20000000) \ | |
243 | (frame_saved_regs).regs[SP_REGNUM] += 4 + 4 * read_memory_integer (next_addr + 4, 4); \ | |
244 | (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 16; \ | |
245 | (frame_saved_regs).regs[FP_REGNUM] = (frame_info)->frame + 12; \ | |
246 | (frame_saved_regs).regs[AP_REGNUM] = (frame_info)->frame + 8; \ | |
247 | (frame_saved_regs).regs[PS_REGNUM] = (frame_info)->frame + 4; \ | |
248 | } | |
249 | \f | |
250 | /* Things needed for making the inferior call functions. */ | |
251 | ||
252 | /* Push an empty stack frame, to record the current PC, etc. */ | |
253 | ||
254 | #define PUSH_DUMMY_FRAME \ | |
255 | { register CORE_ADDR sp = read_register (SP_REGNUM);\ | |
256 | register int regnum; \ | |
257 | sp = push_word (sp, 0); /* arglist */ \ | |
258 | for (regnum = 11; regnum >= 0; regnum--) \ | |
259 | sp = push_word (sp, read_register (regnum)); \ | |
260 | sp = push_word (sp, read_register (PC_REGNUM)); \ | |
261 | sp = push_word (sp, read_register (FP_REGNUM)); \ | |
262 | sp = push_word (sp, read_register (AP_REGNUM)); \ | |
263 | sp = push_word (sp, (read_register (PS_REGNUM) & 0xffef) \ | |
264 | + 0x2fff0000); \ | |
265 | sp = push_word (sp, 0); \ | |
266 | write_register (SP_REGNUM, sp); \ | |
267 | write_register (FP_REGNUM, sp); \ | |
268 | write_register (AP_REGNUM, sp + 17 * sizeof (int)); } | |
269 | ||
270 | /* Discard from the stack the innermost frame, restoring all registers. */ | |
271 | ||
272 | #define POP_FRAME \ | |
273 | { register CORE_ADDR fp = read_register (FP_REGNUM); \ | |
274 | register int regnum; \ | |
275 | register int regmask = read_memory_integer (fp + 4, 4); \ | |
276 | write_register (PS_REGNUM, \ | |
277 | (regmask & 0xffff) \ | |
278 | | (read_register (PS_REGNUM) & 0xffff0000)); \ | |
279 | write_register (PC_REGNUM, read_memory_integer (fp + 16, 4)); \ | |
280 | write_register (FP_REGNUM, read_memory_integer (fp + 12, 4)); \ | |
281 | write_register (AP_REGNUM, read_memory_integer (fp + 8, 4)); \ | |
282 | fp += 16; \ | |
283 | for (regnum = 0; regnum < 12; regnum++) \ | |
284 | if (regmask & (0x10000 << regnum)) \ | |
285 | write_register (regnum, read_memory_integer (fp += 4, 4)); \ | |
286 | fp = fp + 4 + ((regmask >> 30) & 3); \ | |
287 | if (regmask & 0x20000000) \ | |
288 | { regnum = read_memory_integer (fp, 4); \ | |
289 | fp += (regnum + 1) * 4; } \ | |
290 | write_register (SP_REGNUM, fp); \ | |
291 | flush_cached_frames (); \ | |
292 | } | |
293 | ||
294 | /* This sequence of words is the instructions | |
c5aa993b JM |
295 | calls #69, @#32323232 |
296 | bpt | |
c906108c SS |
297 | Note this is 8 bytes. */ |
298 | ||
299 | #define CALL_DUMMY {0x329f69fb, 0x03323232} | |
300 | ||
c5aa993b | 301 | #define CALL_DUMMY_START_OFFSET 0 /* Start execution at beginning of dummy */ |
c906108c SS |
302 | |
303 | #define CALL_DUMMY_BREAKPOINT_OFFSET 7 | |
304 | ||
305 | /* Insert the specified number of args and function address | |
306 | into a call sequence of the above form stored at DUMMYNAME. */ | |
307 | ||
308 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
309 | { *((char *) dummyname + 1) = nargs; \ | |
310 | *(int *)((char *) dummyname + 3) = fun; } | |
311 | ||
312 | /* If vax pcc says CHAR or SHORT, it provides the correct address. */ | |
313 | ||
314 | #define BELIEVE_PCC_PROMOTION 1 |