Commit | Line | Data |
---|---|---|
dd3b648e | 1 | /* Parameters for target machine of AMD 29000, for GDB, the GNU debugger. |
58dbaabd | 2 | Copyright 1990, 1991, 1993 Free Software Foundation, Inc. |
dd3b648e RP |
3 | Contributed by Cygnus Support. Written by Jim Kingdon. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
99a7de40 | 7 | This program is free software; you can redistribute it and/or modify |
dd3b648e | 8 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
dd3b648e | 11 | |
99a7de40 | 12 | This program is distributed in the hope that it will be useful, |
dd3b648e RP |
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
dd3b648e RP |
20 | |
21 | /* Parameters for an EB29K (a board which plugs into a PC and is | |
22 | accessed through EBMON software running on the PC, which we | |
23 | use as we'd use a remote stub (see remote-eb.c). | |
24 | ||
25 | If gdb is ported to other 29k machines/systems, the | |
26 | machine/system-specific parts should be removed from this file (a | |
27 | la tm-68k.h). */ | |
28 | ||
29 | /* Byte order is configurable, but this machine runs big-endian. */ | |
30 | #define TARGET_BYTE_ORDER BIG_ENDIAN | |
31 | ||
32 | /* Floating point uses IEEE representations. */ | |
33 | #define IEEE_FLOAT | |
34 | ||
dd3b648e | 35 | /* Recognize our magic number. */ |
2b05a37a | 36 | #define BADMAG(x) ((x).f_magic != 0572) |
dd3b648e | 37 | |
dd3b648e RP |
38 | /* Offset from address of function to start of its code. |
39 | Zero on most machines. */ | |
40 | ||
41 | #define FUNCTION_START_OFFSET 0 | |
42 | ||
43 | /* Advance PC across any function entry prologue instructions | |
44 | to reach some "real" code. */ | |
45 | ||
46 | #define SKIP_PROLOGUE(pc) \ | |
47 | { pc = skip_prologue (pc); } | |
48 | CORE_ADDR skip_prologue (); | |
49 | ||
50 | /* Immediately after a function call, return the saved pc. | |
51 | Can't go through the frames for this because on some machines | |
52 | the new frame is not set up until the new function executes | |
53 | some instructions. */ | |
54 | ||
55 | #define SAVED_PC_AFTER_CALL(frame) (read_register (LR0_REGNUM)) | |
56 | ||
57 | /* I'm not sure about the exact value of this, but based on looking | |
58 | at the stack pointer when we get to main this seems to be right. | |
59 | ||
60 | This is the register stack; We call it "CONTROL" in GDB for consistency | |
61 | with Pyramid. */ | |
62 | #define CONTROL_END_ADDR 0x80200000 | |
63 | ||
64 | /* Memory stack. This is for the default register stack size, which is | |
65 | only 0x800 bytes. Perhaps we should let the user specify stack sizes | |
66 | (and tell EBMON with the "ZS" command). */ | |
67 | #define STACK_END_ADDR 0x801ff800 | |
68 | ||
69 | /* Stack grows downward. */ | |
70 | ||
71 | #define INNER_THAN < | |
72 | ||
73 | /* Stack must be aligned on 32-bit word boundaries. */ | |
74 | #define STACK_ALIGN(ADDR) (((ADDR) + 3) & ~3) | |
75 | ||
76 | /* Sequence of bytes for breakpoint instruction. */ | |
77 | /* ASNEQ 0x50, gr1, gr1 | |
c47793da JG |
78 | The trap number 0x50 is chosen arbitrarily. |
79 | We let the command line (or previously included files) override this | |
80 | setting. */ | |
81 | #ifndef BREAKPOINT | |
dd3b648e RP |
82 | #if TARGET_BYTE_ORDER == BIG_ENDIAN |
83 | #define BREAKPOINT {0x72, 0x50, 0x01, 0x01} | |
84 | #else /* Target is little-endian. */ | |
85 | #define BREAKPOINT {0x01, 0x01, 0x50, 0x72} | |
86 | #endif /* Target is little-endian. */ | |
c47793da | 87 | #endif /* BREAKPOINT */ |
dd3b648e RP |
88 | |
89 | /* Amount PC must be decremented by after a breakpoint. | |
90 | This is often the number of bytes in BREAKPOINT | |
91 | but not always. */ | |
92 | ||
66a8a9b4 | 93 | #define DECR_PC_AFTER_BREAK 0 |
dd3b648e RP |
94 | |
95 | /* Nonzero if instruction at PC is a return instruction. | |
96 | On the 29k, this is a "jmpi l0" instruction. */ | |
97 | ||
98 | #define ABOUT_TO_RETURN(pc) \ | |
99 | ((read_memory_integer (pc, 4) & 0xff0000ff) == 0xc0000080) | |
100 | ||
101 | /* Return 1 if P points to an invalid floating point value. */ | |
102 | ||
103 | #define INVALID_FLOAT(p, len) 0 /* Just a first guess; not checked */ | |
104 | ||
105 | /* Say how long (ordinary) registers are. */ | |
106 | ||
107 | #define REGISTER_TYPE long | |
108 | ||
2b05a37a JG |
109 | /* Allow the register declarations here to be overridden for remote |
110 | kernel debugging. */ | |
111 | #if !defined (REGISTER_NAMES) | |
112 | ||
dd3b648e RP |
113 | /* Number of machine registers */ |
114 | ||
115 | #define NUM_REGS 205 | |
116 | ||
117 | /* Initializer for an array of names of registers. | |
118 | There should be NUM_REGS strings in this initializer. | |
119 | ||
120 | FIXME, add floating point registers and support here. | |
121 | ||
122 | Also note that this list does not attempt to deal with kernel | |
123 | debugging (in which the first 32 registers are gr64-gr95). */ | |
124 | ||
125 | #define REGISTER_NAMES \ | |
126 | {"gr96", "gr97", "gr98", "gr99", "gr100", "gr101", "gr102", "gr103", "gr104", \ | |
127 | "gr105", "gr106", "gr107", "gr108", "gr109", "gr110", "gr111", "gr112", \ | |
128 | "gr113", "gr114", "gr115", "gr116", "gr117", "gr118", "gr119", "gr120", \ | |
129 | "gr121", "gr122", "gr123", "gr124", "gr125", "gr126", "gr127", \ | |
130 | "lr0", "lr1", "lr2", "lr3", "lr4", "lr5", "lr6", "lr7", "lr8", "lr9", \ | |
131 | "lr10", "lr11", "lr12", "lr13", "lr14", "lr15", "lr16", "lr17", "lr18", \ | |
132 | "lr19", "lr20", "lr21", "lr22", "lr23", "lr24", "lr25", "lr26", "lr27", \ | |
133 | "lr28", "lr29", "lr30", "lr31", "lr32", "lr33", "lr34", "lr35", "lr36", \ | |
134 | "lr37", "lr38", "lr39", "lr40", "lr41", "lr42", "lr43", "lr44", "lr45", \ | |
135 | "lr46", "lr47", "lr48", "lr49", "lr50", "lr51", "lr52", "lr53", "lr54", \ | |
136 | "lr55", "lr56", "lr57", "lr58", "lr59", "lr60", "lr61", "lr62", "lr63", \ | |
137 | "lr64", "lr65", "lr66", "lr67", "lr68", "lr69", "lr70", "lr71", "lr72", \ | |
138 | "lr73", "lr74", "lr75", "lr76", "lr77", "lr78", "lr79", "lr80", "lr81", \ | |
139 | "lr82", "lr83", "lr84", "lr85", "lr86", "lr87", "lr88", "lr89", "lr90", \ | |
140 | "lr91", "lr92", "lr93", "lr94", "lr95", "lr96", "lr97", "lr98", "lr99", \ | |
141 | "lr100", "lr101", "lr102", "lr103", "lr104", "lr105", "lr106", "lr107", \ | |
142 | "lr108", "lr109", "lr110", "lr111", "lr112", "lr113", "lr114", "lr115", \ | |
143 | "lr116", "lr117", "lr118", "lr119", "lr120", "lr121", "lr122", "lr123", \ | |
144 | "lr124", "lr125", "lr126", "lr127", \ | |
145 | "AI0", "AI1", "AI2", "AI3", "AI4", "AI5", "AI6", "AI7", "AI8", "AI9", \ | |
146 | "AI10", "AI11", "AI12", "AI13", "AI14", "AI15", "FP", \ | |
147 | "bp", "fc", "cr", "q", \ | |
148 | "vab", "ops", "cps", "cfg", "cha", "chd", "chc", "rbp", "tmc", "tmr", \ | |
d0b04c6a | 149 | "pc0", "pc1", "pc2", "mmu", "lru", "fpe", "inte", "fps", "exo", "gr1", \ |
dd3b648e RP |
150 | "alu", "ipc", "ipa", "ipb" } |
151 | ||
e95bfbf1 JG |
152 | /* |
153 | * Converts an sdb register number to an internal gdb register number. | |
154 | * Currently under epi, gr96->0...gr127->31...lr0->32...lr127->159, or... | |
155 | * gr64->0...gr95->31, lr0->32...lr127->159. | |
156 | */ | |
157 | #define SDB_REG_TO_REGNUM(value) \ | |
158 | (((value) >= 96 && (value) <= 127) ? ((value) - 96) : \ | |
159 | ((value) >= 128 && (value) <= 255) ? ((value) - 128 + LR0_REGNUM) : \ | |
160 | (value)) | |
161 | ||
d0b04c6a SG |
162 | /* |
163 | * Provide the processor register numbers of some registers that are | |
164 | * expected/written in instructions that might change under different | |
165 | * register sets. Namely, gcc can compile (-mkernel-registers) so that | |
166 | * it uses gr64-gr95 in stead of gr96-gr127. | |
167 | */ | |
168 | #define MSP_HW_REGNUM 125 /* gr125 */ | |
169 | #define RAB_HW_REGNUM 126 /* gr126 */ | |
170 | ||
2b05a37a | 171 | /* Convert Processor Special register #x to REGISTER_NAMES register # */ |
dd3b648e RP |
172 | #define SR_REGNUM(x) \ |
173 | ((x) < 15 ? VAB_REGNUM + (x) \ | |
2b05a37a | 174 | : (x) >= 128 && (x) < 131 ? IPC_REGNUM + (x) - 128 \ |
dd3b648e RP |
175 | : (x) == 131 ? Q_REGNUM \ |
176 | : (x) == 132 ? ALU_REGNUM \ | |
2b05a37a JG |
177 | : (x) >= 133 && (x) < 136 ? BP_REGNUM + (x) - 133 \ |
178 | : (x) >= 160 && (x) < 163 ? FPE_REGNUM + (x) - 160 \ | |
dd3b648e RP |
179 | : (x) == 164 ? EXO_REGNUM \ |
180 | : (error ("Internal error in SR_REGNUM"), 0)) | |
181 | #define GR96_REGNUM 0 | |
2b05a37a JG |
182 | /* Define the return register separately, so it can be overridden for |
183 | kernel procedure calling conventions. */ | |
184 | #define RETURN_REGNUM GR96_REGNUM | |
dd3b648e RP |
185 | #define GR1_REGNUM 200 |
186 | /* This needs to be the memory stack pointer, not the register stack pointer, | |
187 | to make call_function work right. */ | |
188 | #define SP_REGNUM MSP_REGNUM | |
189 | #define FP_REGNUM 33 /* lr1 */ | |
190 | /* Large Return Pointer (gr123). */ | |
191 | #define LRP_REGNUM (123 - 96 + GR96_REGNUM) | |
192 | /* Static link pointer (gr124). */ | |
193 | #define SLP_REGNUM (124 - 96 + GR96_REGNUM) | |
194 | /* Memory Stack Pointer (gr125). */ | |
195 | #define MSP_REGNUM (125 - 96 + GR96_REGNUM) | |
196 | /* Register allocate bound (gr126). */ | |
197 | #define RAB_REGNUM (126 - 96 + GR96_REGNUM) | |
198 | /* Register Free Bound (gr127). */ | |
199 | #define RFB_REGNUM (127 - 96 + GR96_REGNUM) | |
200 | /* Register Stack Pointer. */ | |
201 | #define RSP_REGNUM GR1_REGNUM | |
202 | #define LR0_REGNUM 32 | |
dd3b648e RP |
203 | #define BP_REGNUM 177 |
204 | #define FC_REGNUM 178 | |
205 | #define CR_REGNUM 179 | |
206 | #define Q_REGNUM 180 | |
207 | #define VAB_REGNUM 181 | |
2b05a37a JG |
208 | #define OPS_REGNUM (VAB_REGNUM + 1) |
209 | #define CPS_REGNUM (VAB_REGNUM + 2) | |
210 | #define CFG_REGNUM (VAB_REGNUM + 3) | |
211 | #define CHA_REGNUM (VAB_REGNUM + 4) | |
212 | #define CHD_REGNUM (VAB_REGNUM + 5) | |
213 | #define CHC_REGNUM (VAB_REGNUM + 6) | |
214 | #define RBP_REGNUM (VAB_REGNUM + 7) | |
215 | #define TMC_REGNUM (VAB_REGNUM + 8) | |
216 | #define TMR_REGNUM (VAB_REGNUM + 9) | |
217 | #define NPC_REGNUM (VAB_REGNUM + 10) /* pc0 */ | |
218 | #define PC_REGNUM (VAB_REGNUM + 11) /* pc1 */ | |
219 | #define PC2_REGNUM (VAB_REGNUM + 12) | |
220 | #define MMU_REGNUM (VAB_REGNUM + 13) | |
221 | #define LRU_REGNUM (VAB_REGNUM + 14) | |
222 | #define FPE_REGNUM (VAB_REGNUM + 15) | |
d0b04c6a | 223 | #define INTE_REGNUM (VAB_REGNUM + 16) |
2b05a37a JG |
224 | #define FPS_REGNUM (VAB_REGNUM + 17) |
225 | #define EXO_REGNUM (VAB_REGNUM + 18) | |
226 | /* gr1 is defined above as 200 = VAB_REGNUM + 19 */ | |
227 | #define ALU_REGNUM (VAB_REGNUM + 20) | |
228 | #define PS_REGNUM ALU_REGNUM | |
229 | #define IPC_REGNUM (VAB_REGNUM + 21) | |
230 | #define IPA_REGNUM (VAB_REGNUM + 22) | |
231 | #define IPB_REGNUM (VAB_REGNUM + 23) | |
232 | ||
233 | #endif /* !defined(REGISTER_NAMES) */ | |
dd3b648e RP |
234 | |
235 | /* Total amount of space needed to store our copies of the machine's | |
236 | register state, the array `registers'. */ | |
237 | #define REGISTER_BYTES (NUM_REGS * 4) | |
238 | ||
239 | /* Index within `registers' of the first byte of the space for | |
240 | register N. */ | |
241 | #define REGISTER_BYTE(N) ((N)*4) | |
242 | ||
243 | /* Number of bytes of storage in the actual machine representation | |
244 | for register N. */ | |
245 | ||
246 | /* All regs are 4 bytes. */ | |
247 | ||
248 | #define REGISTER_RAW_SIZE(N) (4) | |
249 | ||
250 | /* Number of bytes of storage in the program's representation | |
251 | for register N. */ | |
252 | ||
253 | /* All regs are 4 bytes. */ | |
254 | ||
255 | #define REGISTER_VIRTUAL_SIZE(N) (4) | |
256 | ||
257 | /* Largest value REGISTER_RAW_SIZE can have. */ | |
258 | ||
259 | #define MAX_REGISTER_RAW_SIZE (4) | |
260 | ||
261 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ | |
262 | ||
263 | #define MAX_REGISTER_VIRTUAL_SIZE (4) | |
264 | ||
265 | /* Nonzero if register N requires conversion | |
266 | from raw format to virtual format. */ | |
267 | ||
268 | #define REGISTER_CONVERTIBLE(N) (0) | |
269 | ||
270 | /* Convert data from raw format for register REGNUM | |
271 | to virtual format for register REGNUM. */ | |
272 | ||
273 | #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \ | |
274 | { bcopy ((FROM), (TO), 4); } | |
275 | ||
276 | /* Convert data from virtual format for register REGNUM | |
277 | to raw format for register REGNUM. */ | |
278 | ||
279 | #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \ | |
280 | { bcopy ((FROM), (TO), 4); } | |
281 | ||
282 | /* Return the GDB type object for the "standard" data type | |
283 | of data in register N. */ | |
284 | ||
285 | #define REGISTER_VIRTUAL_TYPE(N) \ | |
286 | (((N) == PC_REGNUM || (N) == LRP_REGNUM || (N) == SLP_REGNUM \ | |
287 | || (N) == MSP_REGNUM || (N) == RAB_REGNUM || (N) == RFB_REGNUM \ | |
288 | || (N) == GR1_REGNUM || (N) == FP_REGNUM || (N) == LR0_REGNUM \ | |
289 | || (N) == NPC_REGNUM || (N) == PC2_REGNUM) \ | |
290 | ? lookup_pointer_type (builtin_type_void) : builtin_type_int) | |
291 | \f | |
292 | /* Store the address of the place in which to copy the structure the | |
293 | subroutine will return. This is called from call_function. */ | |
294 | /* On the 29k the LRP points to the part of the structure beyond the first | |
295 | 16 words. */ | |
296 | #define STORE_STRUCT_RETURN(ADDR, SP) \ | |
297 | write_register (LRP_REGNUM, (ADDR) + 16 * 4); | |
298 | ||
299 | /* Should call_function allocate stack space for a struct return? */ | |
300 | /* On the 29k objects over 16 words require the caller to allocate space. */ | |
301 | #define USE_STRUCT_CONVENTION(gcc_p, type) (TYPE_LENGTH (type) > 16 * 4) | |
302 | ||
303 | /* Extract from an array REGBUF containing the (raw) register state | |
304 | a function return value of type TYPE, and copy that, in virtual format, | |
305 | into VALBUF. */ | |
306 | ||
307 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ | |
308 | { \ | |
309 | int reg_length = TYPE_LENGTH (TYPE); \ | |
310 | if (reg_length > 16 * 4) \ | |
311 | { \ | |
312 | reg_length = 16 * 4; \ | |
313 | read_memory (*((int *)(REGBUF) + LRP_REGNUM), (VALBUF) + 16 * 4, \ | |
314 | TYPE_LENGTH (TYPE) - 16 * 4); \ | |
315 | } \ | |
2b05a37a | 316 | bcopy (((int *)(REGBUF))+RETURN_REGNUM, (VALBUF), reg_length); \ |
dd3b648e RP |
317 | } |
318 | ||
319 | /* Write into appropriate registers a function return value | |
320 | of type TYPE, given in virtual format. */ | |
321 | ||
322 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ | |
323 | { \ | |
324 | int reg_length = TYPE_LENGTH (TYPE); \ | |
325 | if (reg_length > 16 * 4) \ | |
326 | { \ | |
327 | reg_length = 16 * 4; \ | |
328 | write_memory (read_register (LRP_REGNUM), \ | |
329 | (char *)(VALBUF) + 16 * 4, \ | |
330 | TYPE_LENGTH (TYPE) - 16 * 4); \ | |
331 | } \ | |
2b05a37a | 332 | write_register_bytes (REGISTER_BYTE (RETURN_REGNUM), (char *)(VALBUF), \ |
dd3b648e RP |
333 | TYPE_LENGTH (TYPE)); \ |
334 | } | |
335 | \f | |
336 | /* The am29k user's guide documents well what the stacks look like. | |
337 | But what isn't so clear there is how this interracts with the | |
338 | symbols, or with GDB. | |
339 | In the following saved_msp, saved memory stack pointer (which functions | |
340 | as a memory frame pointer), means either | |
341 | a register containing the memory frame pointer or, in the case of | |
342 | functions with fixed size memory frames (i.e. those who don't use | |
343 | alloca()), the result of the calculation msp + msize. | |
344 | ||
345 | LOC_ARG, LOC_LOCAL - For GCC, these are relative to saved_msp. | |
346 | For high C, these are relative to msp (making alloca impossible). | |
347 | LOC_REGISTER, LOC_REGPARM - The register number is the number at the | |
348 | time the function is running (after the prologue), or in the case | |
349 | of LOC_REGPARM, may be a register number in the range 160-175. | |
350 | ||
351 | The compilers do things like store an argument into memory, and then put out | |
352 | a LOC_ARG for it, or put it into global registers and put out a | |
353 | LOC_REGPARM. Thus is it important to execute the first line of | |
354 | code (i.e. the line of the open brace, i.e. the prologue) of a function | |
355 | before trying to print arguments or anything. | |
356 | ||
357 | The following diagram attempts to depict what is going on in memory | |
358 | (see also the _am29k user's guide_) and also how that interacts with | |
359 | GDB frames. We arbitrarily pick fci->frame to point the same place | |
360 | as the register stack pointer; since we set it ourself in | |
361 | INIT_EXTRA_FRAME_INFO, and access it only through the FRAME_* | |
362 | macros, it doesn't really matter exactly how we | |
363 | do it. However, note that FRAME_FP is used in two ways in GDB: | |
364 | (1) as a "magic cookie" which uniquely identifies frames (even over | |
841c051c | 365 | calls to the inferior), (2) (in PC_IN_CALL_DUMMY [ON_STACK]) |
dd3b648e | 366 | as the value of SP_REGNUM before the dummy frame was pushed. These |
841c051c JG |
367 | two meanings would be incompatible for the 29k if we defined |
368 | CALL_DUMMY_LOCATION == ON_STACK (but we don't, so don't worry about it). | |
dd3b648e RP |
369 | Also note that "lr1" below, while called a frame pointer |
370 | in the user's guide, has only one function: To determine whether | |
371 | registers need to be filled in the function epilogue. | |
372 | ||
373 | Consider the code: | |
374 | < call bar> | |
375 | loc1: . . . | |
376 | bar: sub gr1,gr1,rsize_b | |
377 | . . . | |
378 | add mfp,msp,0 | |
379 | sub msp,msp,msize_b | |
380 | . . . | |
381 | < call foo > | |
382 | loc2: . . . | |
383 | foo: sub gr1,gr1,rsize_f | |
384 | . . . | |
385 | add mfp,msp,0 | |
386 | sub msp,msp,msize_f | |
387 | . . . | |
388 | loc3: < suppose the inferior stops here > | |
389 | ||
390 | memory stack register stack | |
391 | | | |____________| | |
392 | | | |____loc1____| | |
393 | +------->|___________| | | ^ | |
394 | | | ^ | | locals_b | | | |
395 | | | | | |____________| | | |
396 | | | | | | | | rsize_b | |
397 | | | | msize_b | | args_to_f | | | |
398 | | | | | |____________| | | |
399 | | | | | |____lr1_____| V | |
400 | | | V | |____loc2____|<----------------+ | |
401 | | +--->|___________|<---------mfp | ^ | | |
402 | | | | ^ | | locals_f | | | | |
403 | | | | | msize_f | |____________| | | | |
404 | | | | | | | | | rsize_f | | |
405 | | | | V | | args | | | | |
406 | | | |___________|<msp |____________| | | | |
407 | | | |_____lr1____| V | | |
408 | | | |___garbage__| <- gr1 <----+ | | |
409 | | | | | | |
410 | | | | | | |
411 | | | pc=loc3 | | | |
412 | | | | | | |
413 | | | | | | |
414 | | | frame cache | | | |
415 | | | |_________________| | | | |
416 | | | |rsize=rsize_b | | | | |
417 | | | |msize=msize_b | | | | |
418 | +---|--------saved_msp | | | | |
419 | | |frame------------------------------------|---+ | |
420 | | |pc=loc2 | | | |
421 | | |_________________| | | |
422 | | |rsize=rsize_f | | | |
423 | | |msize=msize_f | | | |
424 | +--------saved_msp | | | |
425 | |frame------------------------------------+ | |
426 | |pc=loc3 | | |
427 | |_________________| | |
428 | ||
429 | So, is that sufficiently confusing? Welcome to the 29000. | |
430 | Notes: | |
431 | * The frame for foo uses a memory frame pointer but the frame for | |
432 | bar does not. In the latter case the saved_msp is | |
433 | computed by adding msize to the saved_msp of the | |
434 | next frame. | |
435 | * msize is in the frame cache only for high C's sake. */ | |
436 | ||
437 | void read_register_stack (); | |
438 | long read_register_stack_integer (); | |
439 | \f | |
440 | #define EXTRA_FRAME_INFO \ | |
441 | CORE_ADDR saved_msp; \ | |
442 | unsigned int rsize; \ | |
d0b04c6a SG |
443 | unsigned int msize; \ |
444 | unsigned char flags; | |
445 | ||
446 | /* Bits for flags in EXTRA_FRAME_INFO */ | |
447 | #define TRANSPARENT 0x1 /* This is a transparent frame */ | |
448 | #define MFP_USED 0x2 /* A memory frame pointer is used */ | |
dd3b648e RP |
449 | |
450 | /* Because INIT_FRAME_PC gets passed fromleaf, that's where we init | |
451 | not only ->pc and ->frame, but all the extra stuff, when called from | |
452 | get_prev_frame_info, that is. */ | |
d0b04c6a | 453 | #define INIT_EXTRA_FRAME_INFO(fromleaf, fci) init_extra_frame_info(fci) |
dd3b648e | 454 | void init_extra_frame_info (); |
d0b04c6a SG |
455 | |
456 | #define INIT_FRAME_PC(fromleaf, fci) init_frame_pc(fromleaf, fci) | |
dd3b648e | 457 | void init_frame_pc (); |
d0b04c6a | 458 | |
dd3b648e RP |
459 | \f |
460 | /* FRAME_CHAIN takes a FRAME | |
461 | and produces the frame's chain-pointer. | |
462 | ||
dd3b648e | 463 | However, if FRAME_CHAIN_VALID returns zero, |
e140f1da | 464 | it means the given frame is the outermost one and has no caller. */ |
dd3b648e RP |
465 | |
466 | /* On the 29k, the nominal address of a frame is the address on the | |
467 | register stack of the return address (the one next to the incoming | |
468 | arguments, not down at the bottom so nominal address == stack pointer). | |
469 | ||
470 | GDB expects "nominal address" to equal contents of FP_REGNUM, | |
471 | at least when it comes time to create the innermost frame. | |
472 | However, that doesn't work for us, so when creating the innermost | |
473 | frame we set ->frame ourselves in INIT_EXTRA_FRAME_INFO. */ | |
474 | ||
475 | /* These are mostly dummies for the 29k because INIT_FRAME_PC | |
476 | sets prev->frame instead. */ | |
d0b04c6a SG |
477 | #define FRAME_CHAIN(thisframe) ((thisframe)->frame + (thisframe)->rsize) |
478 | ||
479 | /* Determine if the frame has a 'previous' and back-traceable frame. */ | |
480 | #define FRAME_IS_UNCHAINED(frame) ((frame)->flags & TRANSPARENT) | |
dd3b648e | 481 | |
d0b04c6a SG |
482 | /* Find the previous frame of a transparent routine. |
483 | * For now lets not try and trace through a transparent routine (we might | |
484 | * have to assume that all transparent routines are traps). | |
485 | */ | |
486 | #define FIND_PREV_UNCHAINED_FRAME(frame) 0 | |
dd3b648e | 487 | |
dd3b648e RP |
488 | /* Define other aspects of the stack frame. */ |
489 | ||
490 | /* A macro that tells us whether the function invocation represented | |
491 | by FI does not have a frame on the stack associated with it. If it | |
492 | does not, FRAMELESS is set to 1, else 0. */ | |
493 | #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \ | |
494 | (FRAMELESS) = frameless_look_for_prologue(FI) | |
495 | ||
496 | /* Saved pc (i.e. return address). */ | |
497 | #define FRAME_SAVED_PC(fraim) \ | |
498 | (read_register_stack_integer ((fraim)->frame + (fraim)->rsize, 4)) | |
499 | ||
500 | /* Local variables (i.e. LOC_LOCAL) are on the memory stack, with their | |
501 | offsets being relative to the memory stack pointer (high C) or | |
502 | saved_msp (gcc). */ | |
503 | ||
504 | #define FRAME_LOCALS_ADDRESS(fi) frame_locals_address (fi) | |
505 | extern CORE_ADDR frame_locals_address (); | |
506 | ||
507 | /* Return number of args passed to a frame. | |
508 | Can return -1, meaning no way to tell. */ | |
509 | /* While we could go the effort of finding the tags word and getting | |
510 | the argcount field from it, | |
511 | (1) It only counts arguments in registers, i.e. the first 16 words | |
512 | of arguments | |
513 | (2) It gives the number of arguments the function was declared with | |
514 | not how many it was called with (or some variation, like all 16 | |
515 | words for varadic functions). This makes argcount pretty much | |
516 | redundant with -g info, even for varadic functions. | |
517 | So don't bother. */ | |
518 | #define FRAME_NUM_ARGS(numargs, fi) ((numargs) = -1) | |
519 | ||
520 | #define FRAME_ARGS_ADDRESS(fi) FRAME_LOCALS_ADDRESS (fi) | |
521 | ||
522 | /* Return number of bytes at start of arglist that are not really args. */ | |
523 | ||
524 | #define FRAME_ARGS_SKIP 0 | |
525 | ||
526 | /* Provide our own get_saved_register. HAVE_REGISTER_WINDOWS is insufficient | |
527 | because registers get renumbered on the 29k without getting saved. */ | |
528 | ||
529 | #define GET_SAVED_REGISTER | |
530 | \f | |
531 | /* Call function stuff. */ | |
532 | ||
533 | /* The dummy frame looks like this (see also the general frame picture | |
534 | above): | |
535 | ||
536 | register stack | |
537 | ||
538 | | | frame for function | |
539 | | locals_sproc | executing at time | |
540 | |________________| of call_function. | |
541 | | | We must not disturb | |
542 | | args_out_sproc | it. | |
543 | memory stack |________________| | |
d0b04c6a SG |
544 | |____lr1_sproc___|<-+ |
545 | | | |__retaddr_sproc_| | <-- gr1 (at start) | |
546 | |____________|<-msp 0 <-----------mfp_dummy_____| | | |
547 | | | (at start) | save regs | | | |
548 | | arg_slop | | pc0,pc1 | | | |
549 | | (16 words) | | gr96-gr124 | | | |
550 | |____________|<-msp 1--after | sr160-sr162 | | | |
551 | | | PUSH_DUMMY_FRAME| sr128-sr135 | | | |
552 | | struct ret | |________________| | | |
553 | | 17+ | | | | | |
554 | |____________|<- lrp | args_out_dummy | | | |
555 | | struct ret | | (16 words) | | | |
556 | | 16 | |________________| | | |
557 | | (16 words) | |____lr1_dummy___|--+ | |
dd3b648e RP |
558 | |____________|<- msp 2--after |_retaddr_dummy__|<- gr1 after |
559 | | | struct ret | | PUSH_DUMMY_FRAME | |
560 | | margs17+ | area allocated | locals_inf | | |
561 | | | |________________| called | |
562 | |____________|<- msp 4--when | | function's | |
563 | | | inf called | args_out_inf | frame (set up | |
564 | | margs16 | |________________| by called | |
565 | | (16 words) | |_____lr1_inf____| function). | |
566 | |____________|<- msp 3--after | . | | |
567 | | | args pushed | . | | |
568 | | | | . | | |
569 | | | | |
570 | ||
571 | arg_slop: This area is so that when the call dummy adds 16 words to | |
572 | the msp, it won't end up larger than mfp_dummy (it is needed in the | |
573 | case where margs and struct_ret do not add up to at least 16 words). | |
574 | struct ret: This area is allocated by GDB if the return value is more | |
575 | than 16 words. struct ret_16 is not used on the 29k. | |
576 | margs: Pushed by GDB. The call dummy copies the first 16 words to | |
577 | args_out_dummy. | |
578 | retaddr_sproc: Contains the PC at the time we call the function. | |
579 | set by PUSH_DUMMY_FRAME and read by POP_FRAME. | |
580 | retaddr_dummy: This points to a breakpoint instruction in the dummy. */ | |
581 | \f | |
582 | /* Rsize for dummy frame, in bytes. */ | |
583 | ||
584 | /* Bytes for outgoing args, lr1, and retaddr. */ | |
585 | #define DUMMY_ARG (2 * 4 + 16 * 4) | |
586 | ||
587 | /* Number of special registers (sr128-) to save. */ | |
588 | #define DUMMY_SAVE_SR128 8 | |
d0b04c6a SG |
589 | /* Number of special registers (sr160-) to save. */ |
590 | #define DUMMY_SAVE_SR160 3 | |
2b05a37a JG |
591 | /* Number of general (gr96- or gr64-) registers to save. */ |
592 | #define DUMMY_SAVE_GREGS 29 | |
dd3b648e RP |
593 | |
594 | #define DUMMY_FRAME_RSIZE \ | |
d0b04c6a SG |
595 | (4 /* mfp_dummy */ \ |
596 | + 2 * 4 /* pc0, pc1 */ \ | |
597 | + DUMMY_SAVE_GREGS * 4 \ | |
598 | + DUMMY_SAVE_SR160 * 4 \ | |
599 | + DUMMY_SAVE_SR128 * 4 \ | |
600 | + DUMMY_ARG \ | |
aa1dea48 | 601 | + 4 /* pad to doubleword */ ) |
dd3b648e RP |
602 | |
603 | /* Push an empty stack frame, to record the current PC, etc. */ | |
604 | ||
d0b04c6a | 605 | #define PUSH_DUMMY_FRAME push_dummy_frame() |
dd3b648e RP |
606 | extern void push_dummy_frame (); |
607 | ||
608 | /* Discard from the stack the innermost frame, | |
609 | restoring all saved registers. */ | |
610 | ||
d0b04c6a | 611 | #define POP_FRAME pop_frame() |
dd3b648e RP |
612 | extern void pop_frame (); |
613 | ||
614 | /* This sequence of words is the instructions | |
615 | mtsrim cr, 15 | |
616 | loadm 0, 0, lr2, msp ; load first 16 words of arguments into registers | |
617 | add msp, msp, 16 * 4 ; point to the remaining arguments | |
6872cfda JG |
618 | CONST_INSN: |
619 | const lr0,inf ; (replaced by half of target addr) | |
620 | consth lr0,inf ; (replaced by other half of target addr) | |
d0b04c6a | 621 | calli lr0, lr0 |
dd3b648e | 622 | aseq 0x40,gr1,gr1 ; nop |
6872cfda JG |
623 | BREAKPT_INSN: |
624 | asneq 0x50,gr1,gr1 ; breakpoint (replaced by local breakpoint insn) | |
dd3b648e RP |
625 | */ |
626 | ||
dd3b648e | 627 | #if TARGET_BYTE_ORDER == HOST_BYTE_ORDER |
6872cfda JG |
628 | #define BS(const) const |
629 | #else | |
630 | #define BS(const) (((const) & 0xff) << 24) | \ | |
631 | (((const) & 0xff00) << 8) | \ | |
632 | (((const) & 0xff0000) >> 8) | \ | |
633 | (((const) & 0xff000000) >> 24) | |
634 | #endif | |
635 | ||
636 | /* Position of the "const" and blkt instructions within CALL_DUMMY in bytes. */ | |
637 | #define CONST_INSN (3 * 4) | |
638 | #define BREAKPT_INSN (7 * 4) | |
639 | #define CALL_DUMMY { \ | |
640 | BS(0x0400870f),\ | |
641 | BS(0x36008200|(MSP_HW_REGNUM)), \ | |
642 | BS(0x15000040|(MSP_HW_REGNUM<<8)|(MSP_HW_REGNUM<<16)), \ | |
643 | BS(0x03ff80ff), \ | |
644 | BS(0x02ff80ff), \ | |
645 | BS(0xc8008080), \ | |
646 | BS(0x70400101), \ | |
647 | BS(0x72500101)} | |
dd3b648e RP |
648 | #define CALL_DUMMY_LENGTH (8 * 4) |
649 | ||
650 | #define CALL_DUMMY_START_OFFSET 0 /* Start execution at beginning of dummy */ | |
651 | ||
652 | /* Helper macro for FIX_CALL_DUMMY. WORDP is a long * which points to a | |
653 | word in target byte order; bits 0-7 and 16-23 of *WORDP are replaced with | |
654 | bits 0-7 and 8-15 of DATA (which is in host byte order). */ | |
655 | ||
656 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
657 | #define STUFF_I16(WORDP, DATA) \ | |
658 | { \ | |
659 | *((char *)(WORDP) + 3) = ((DATA) & 0xff);\ | |
660 | *((char *)(WORDP) + 1) = (((DATA) >> 8) & 0xff);\ | |
661 | } | |
662 | #else /* Target is little endian. */ | |
663 | #define STUFF_I16(WORDP, DATA) \ | |
664 | { | |
665 | *(char *)(WORDP) = ((DATA) & 0xff); | |
666 | *((char *)(WORDP) + 2) = (((DATA) >> 8) & 0xff); | |
667 | } | |
668 | #endif /* Target is little endian. */ | |
669 | ||
670 | /* Insert the specified number of args and function address | |
671 | into a call sequence of the above form stored at DUMMYNAME. */ | |
672 | ||
673 | /* Currently this stuffs in the address of the function that we are calling. | |
6872cfda JG |
674 | Since different 29k systems use different breakpoint instructions, it |
675 | also stuffs BREAKPOINT in the right place (to avoid having to | |
dd3b648e RP |
676 | duplicate CALL_DUMMY in each tm-*.h file). */ |
677 | ||
678 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
679 | {\ | |
6872cfda JG |
680 | STUFF_I16((char *)dummyname + CONST_INSN, fun); \ |
681 | STUFF_I16((char *)dummyname + CONST_INSN + 4, fun >> 16); \ | |
682 | /* FIXME memcpy ((char *)(dummyname) + BREAKPT_INSN, break_insn, 4); */ \ | |
dd3b648e RP |
683 | } |
684 | ||
841c051c JG |
685 | /* 29k architecture has separate data & instruction memories -- wired to |
686 | different pins on the chip -- and can't execute the data memory. | |
687 | Also, there should be space after text_end; | |
dd3b648e RP |
688 | we won't get a SIGSEGV or scribble on data space. */ |
689 | ||
690 | #define CALL_DUMMY_LOCATION AFTER_TEXT_END | |
691 | ||
841c051c JG |
692 | /* Because of this, we need (as a kludge) to know the addresses of the |
693 | text section. */ | |
694 | ||
695 | #define NEED_TEXT_START_END | |
696 | ||
dd3b648e RP |
697 | /* How to translate register numbers in the .stab's into gdb's internal register |
698 | numbers. We don't translate them, but we warn if an invalid register | |
699 | number is seen. Note that FIXME, we use the value "sym" as an implicit | |
700 | argument in printing the error message. It happens to be available where | |
701 | this macro is used. (This macro definition appeared in a late revision | |
702 | of gdb-3.91.6 and is not well tested. Also, it should be a "complaint".) */ | |
703 | ||
704 | #define STAB_REG_TO_REGNUM(num) \ | |
705 | (((num) > LR0_REGNUM + 127) \ | |
706 | ? fprintf(stderr, \ | |
707 | "Invalid register number %d in symbol table entry for %s\n", \ | |
2e4964ad | 708 | (num), SYMBOL_SOURCE_NAME (sym)), (num) \ |
dd3b648e | 709 | : (num)) |