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