import gdb-19990504 snapshot
[deliverable/binutils-gdb.git] / gdb / config / convex / tm-convex.h
1 /* Definitions to make GDB run on Convex Unix (4bsd)
2 Copyright 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 /* There is come problem with the debugging symbols generated by the
23 compiler such that the debugging symbol for the first line of a
24 function overlap with the function prologue. */
25 #define PROLOGUE_FIRSTLINE_OVERLAP
26
27 /* When convex pcc says CHAR or SHORT, it provides the correct address. */
28
29 #define BELIEVE_PCC_PROMOTION 1
30
31 /* Symbol types to ignore. */
32 /* 0xc4 is N_MONPT. Use the numeric value for the benefit of people
33 with (rather) old OS's. */
34 #define IGNORE_SYMBOL(TYPE) \
35 (((TYPE) & ~N_EXT) == N_TBSS \
36 || ((TYPE) & ~N_EXT) == N_TDATA \
37 || ((TYPE) & ~N_EXT) == 0xc4)
38
39 /* Offset from address of function to start of its code.
40 Zero on most machines. */
41
42 #define FUNCTION_START_OFFSET 0
43
44 /* Advance PC across any function entry prologue instructions
45 to reach some "real" code.
46 Convex prolog is:
47 [sub.w #-,sp] in one of 3 possible sizes
48 [mov psw,- fc/vc main program prolog
49 and #-,- (skip it because the "mov psw" saves the
50 mov -,psw] T bit, so continue gets a surprise trap)
51 [and #-,sp] fc/vc O2 main program prolog
52 [ld.- -(ap),-] pcc/gcc register arg loads
53 */
54
55 extern CORE_ADDR convex_skip_prologue PARAMS ((CORE_ADDR pc));
56 #define SKIP_PROLOGUE(pc) (convex_skip_prologue (pc))
57
58 /* Immediately after a function call, return the saved pc.
59 (ignore frame and return *$sp so we can handle both calls and callq) */
60
61 #define SAVED_PC_AFTER_CALL(frame) \
62 read_memory_integer (read_register (SP_REGNUM), 4)
63
64 /* Address of end of stack space.
65 This is ((USRSTACK + 0xfff) & -0x1000)) from <convex/vmparam.h> but
66 that expression depends on the kernel version; instead, fetch a
67 page-zero pointer and get it from that. This will be invalid if
68 they ever change the way bkpt signals are delivered. */
69
70 #define STACK_END_ADDR (0xfffff000 & *(unsigned *) 0x80000050)
71
72 /* User-mode traps push an extended rtn block,
73 then fault with one of the following PCs */
74
75 #define is_trace_pc(pc) ((unsigned) ((pc) - (*(int *) 0x80000040)) <= 4)
76 #define is_arith_pc(pc) ((unsigned) ((pc) - (*(int *) 0x80000044)) <= 4)
77 #define is_break_pc(pc) ((unsigned) ((pc) - (*(int *) 0x80000050)) <= 4)
78
79 /* We need to manipulate trap bits in the psw */
80
81 #define PSW_TRAP_FLAGS 0x69670000
82 #define PSW_T_BIT 0x08000000
83 #define PSW_S_BIT 0x01000000
84
85 /* Stack grows downward. */
86
87 #define INNER_THAN(lhs,rhs) ((lhs) < (rhs))
88
89 /* Sequence of bytes for breakpoint instruction. (bkpt) */
90
91 #define BREAKPOINT {0x7d,0x50}
92
93 /* Amount PC must be decremented by after a breakpoint.
94 This is often the number of bytes in BREAKPOINT but not always.
95 (The break PC needs to be decremented by 2, but we do it when the
96 break frame is recognized and popped. That way gdb can tell breaks
97 from trace traps with certainty.) */
98
99 #define DECR_PC_AFTER_BREAK 0
100
101 /* Say how long (ordinary) registers are. This is a piece of bogosity
102 used in push_word and a few other places; REGISTER_RAW_SIZE is the
103 real way to know how big a register is. */
104
105 #define REGISTER_SIZE 8
106
107 /* Number of machine registers */
108
109 #define NUM_REGS 26
110
111 /* Initializer for an array of names of registers.
112 There should be NUM_REGS strings in this initializer. */
113
114 #define REGISTER_NAMES {"pc","psw","fp","ap","a5","a4","a3","a2","a1","sp",\
115 "s7","s6","s5","s4","s3","s2","s1","s0",\
116 "S7","S6","S5","S4","S3","S2","S1","S0"}
117
118 /* Register numbers of various important registers.
119 Note that some of these values are "real" register numbers,
120 and correspond to the general registers of the machine,
121 and some are "phony" register numbers which are too large
122 to be actual register numbers as far as the user is concerned
123 but do serve to get the desired values when passed to read_register. */
124
125 #define S0_REGNUM 25 /* the real S regs */
126 #define S7_REGNUM 18
127 #define s0_REGNUM 17 /* low-order halves of S regs */
128 #define s7_REGNUM 10
129 #define SP_REGNUM 9 /* A regs */
130 #define A1_REGNUM 8
131 #define A5_REGNUM 4
132 #define AP_REGNUM 3
133 #define FP_REGNUM 2 /* Contains address of executing stack frame */
134 #define PS_REGNUM 1 /* Contains processor status */
135 #define PC_REGNUM 0 /* Contains program counter */
136
137 /* convert dbx stab register number (from `r' declaration) to a gdb REGNUM */
138
139 #define STAB_REG_TO_REGNUM(value) \
140 ((value) < 8 ? S0_REGNUM - (value) : SP_REGNUM - ((value) - 8))
141
142 /* Vector register numbers, not handled as ordinary regs.
143 They are treated as convenience variables whose values are read
144 from the inferior when needed. */
145
146 #define V0_REGNUM 0
147 #define V7_REGNUM 7
148 #define VM_REGNUM 8
149 #define VS_REGNUM 9
150 #define VL_REGNUM 10
151
152 /* Total amount of space needed to store our copies of the machine's
153 register state, the array `registers'. */
154 #define REGISTER_BYTES (4*10 + 8*8)
155
156 /* Index within `registers' of the first byte of the space for
157 register N.
158 NB: must match structure of struct syscall_context for correct operation */
159
160 #define REGISTER_BYTE(N) ((N) < s7_REGNUM ? 4*(N) : \
161 (N) < S7_REGNUM ? 44 + 8 * ((N)-s7_REGNUM) : \
162 40 + 8 * ((N)-S7_REGNUM))
163
164 /* Number of bytes of storage in the actual machine representation
165 for register N. */
166
167 #define REGISTER_RAW_SIZE(N) ((N) < S7_REGNUM ? 4 : 8)
168
169 /* Number of bytes of storage in the program's representation
170 for register N. */
171
172 #define REGISTER_VIRTUAL_SIZE(N) REGISTER_RAW_SIZE(N)
173
174 /* Largest value REGISTER_RAW_SIZE can have. */
175
176 #define MAX_REGISTER_RAW_SIZE 8
177
178 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
179
180 #define MAX_REGISTER_VIRTUAL_SIZE 8
181
182 /* Return the GDB type object for the "standard" data type
183 of data in register N. */
184
185 #define REGISTER_VIRTUAL_TYPE(N) \
186 ((N) < S7_REGNUM ? builtin_type_int : builtin_type_long_long)
187
188 /* Store the address of the place in which to copy the structure the
189 subroutine will return. This is called from call_function. */
190
191 #define STORE_STRUCT_RETURN(ADDR, SP) \
192 { write_register (A1_REGNUM, (ADDR)); }
193
194 /* Extract from an array REGBUF containing the (raw) register state
195 a function return value of type TYPE, and copy that, in virtual format,
196 into VALBUF. */
197
198 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
199 memcpy (VALBUF, &((char *) REGBUF) [REGISTER_BYTE (S0_REGNUM) + \
200 8 - TYPE_LENGTH (TYPE)],\
201 TYPE_LENGTH (TYPE))
202
203 /* Write into appropriate registers a function return value
204 of type TYPE, given in virtual format. */
205
206 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
207 write_register_bytes (REGISTER_BYTE (S0_REGNUM), VALBUF, 8)
208
209 /* Extract from an array REGBUF containing the (raw) register state
210 the address in which a function should return its structure value,
211 as a CORE_ADDR (or an expression that can be used as one). */
212
213 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) \
214 (*(int *) & ((char *) REGBUF) [REGISTER_BYTE (s0_REGNUM)])
215
216 /* Define trapped internal variable hooks to read and write
217 vector and communication registers. */
218
219 #define IS_TRAPPED_INTERNALVAR is_trapped_internalvar
220 #define VALUE_OF_TRAPPED_INTERNALVAR value_of_trapped_internalvar
221 #define SET_TRAPPED_INTERNALVAR set_trapped_internalvar
222
223 extern struct value *value_of_trapped_internalvar ();
224
225 /* Hooks to read data from soff exec and core files,
226 and to describe the files. */
227
228 #define FILES_INFO_HOOK print_maps
229
230 /* Hook to call to print a typeless integer value, normally printed in decimal.
231 For convex, use hex instead if the number looks like an address. */
232
233 #define PRINT_TYPELESS_INTEGER decout
234
235 /* For the native compiler, variables for a particular lexical context
236 are listed after the beginning LBRAC instead of before in the
237 executables list of symbols. Using "gcc_compiled." to distinguish
238 between GCC and native compiler doesn't work on Convex because the
239 linker sorts the symbols to put "gcc_compiled." in the wrong place.
240 desc is nonzero for native, zero for gcc. */
241 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) (desc != 0)
242
243 /* Pcc occaisionally puts an SO where there should be an SOL. */
244 #define PCC_SOL_BROKEN
245 \f
246 /* Describe the pointer in each stack frame to the previous stack frame
247 (its caller). */
248
249 /* FRAME_CHAIN takes a frame_info with a frame's nominal address in fi->frame,
250 and produces the frame's chain-pointer. */
251
252 /* (caller fp is saved at 8(fp)) */
253
254 #define FRAME_CHAIN(fi) (read_memory_integer ((fi)->frame + 8, 4))
255
256 /* Define other aspects of the stack frame. */
257
258 /* We need the boundaries of the text in the exec file, as a kludge,
259 for FRAMELESS_FUNCTION_INVOCATION and CALL_DUMMY_LOCATION. */
260
261 #define NEED_TEXT_START_END 1
262
263 /* A macro that tells us whether the function invocation represented
264 by FI does not have a frame on the stack associated with it. If it
265 does not, FRAMELESS is set to 1, else 0.
266 On convex, check at the return address for `callq' -- if so, frameless,
267 otherwise, not. */
268
269 #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
270 { \
271 extern CORE_ADDR text_start, text_end; \
272 CORE_ADDR call_addr = SAVED_PC_AFTER_CALL (FI); \
273 (FRAMELESS) = (call_addr >= text_start && call_addr < text_end \
274 && read_memory_integer (call_addr - 6, 1) == 0x22); \
275 }
276
277 #define FRAME_SAVED_PC(fi) (read_memory_integer ((fi)->frame, 4))
278
279 #define FRAME_ARGS_ADDRESS(fi) (read_memory_integer ((fi)->frame + 12, 4))
280
281 #define FRAME_LOCALS_ADDRESS(fi) (fi)->frame
282
283 /* Return number of args passed to a frame.
284 Can return -1, meaning no way to tell. */
285
286 #define FRAME_NUM_ARGS(numargs, fi) \
287 { numargs = read_memory_integer (FRAME_ARGS_ADDRESS (fi) - 4, 4); \
288 if (numargs < 0 || numargs >= 256) numargs = -1;}
289
290 /* Return number of bytes at start of arglist that are not really args. */
291
292 #define FRAME_ARGS_SKIP 0
293
294 /* Put here the code to store, into a struct frame_saved_regs,
295 the addresses of the saved registers of frame described by FRAME_INFO.
296 This includes special registers such as pc and fp saved in special
297 ways in the stack frame. sp is even more special:
298 the address we return for it IS the sp for the next frame. */
299
300 /* Normal (short) frames save only PC, FP, (callee's) AP. To reasonably
301 handle gcc and pcc register variables, scan the code following the
302 call for the instructions the compiler inserts to reload register
303 variables from stack slots and record the stack slots as the saved
304 locations of those registers. This will occasionally identify some
305 random load as a saved register; this is harmless. vc does not
306 declare its register allocation actions in the stabs. */
307
308 #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
309 { register int regnum; \
310 register int frame_length = /* 3 short, 2 long, 1 extended, 0 context */\
311 (read_memory_integer ((frame_info)->frame + 4, 4) >> 25) & 3; \
312 register CORE_ADDR frame_fp = \
313 read_memory_integer ((frame_info)->frame + 8, 4); \
314 register CORE_ADDR next_addr; \
315 memset (&frame_saved_regs, '\0', sizeof frame_saved_regs); \
316 (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 0; \
317 (frame_saved_regs).regs[PS_REGNUM] = (frame_info)->frame + 4; \
318 (frame_saved_regs).regs[FP_REGNUM] = (frame_info)->frame + 8; \
319 (frame_saved_regs).regs[AP_REGNUM] = frame_fp + 12; \
320 next_addr = (frame_info)->frame + 12; \
321 if (frame_length < 3) \
322 for (regnum = A5_REGNUM; regnum < SP_REGNUM; ++regnum) \
323 (frame_saved_regs).regs[regnum] = (next_addr += 4); \
324 if (frame_length < 2) \
325 (frame_saved_regs).regs[SP_REGNUM] = (next_addr += 4); \
326 next_addr -= 4; \
327 if (frame_length < 3) \
328 for (regnum = S7_REGNUM; regnum < S0_REGNUM; ++regnum) \
329 (frame_saved_regs).regs[regnum] = (next_addr += 8); \
330 if (frame_length < 2) \
331 (frame_saved_regs).regs[S0_REGNUM] = (next_addr += 8); \
332 else \
333 (frame_saved_regs).regs[SP_REGNUM] = next_addr + 8; \
334 if (frame_length == 3) { \
335 CORE_ADDR pc = read_memory_integer ((frame_info)->frame, 4); \
336 int op, ix, disp; \
337 op = read_memory_integer (pc, 2); \
338 if ((op & 0xffc7) == 0x1480) pc += 4; /* add.w #-,sp */ \
339 else if ((op & 0xffc7) == 0x58c0) pc += 2; /* add.w #-,sp */ \
340 op = read_memory_integer (pc, 2); \
341 if ((op & 0xffc7) == 0x2a06) pc += 4; /* ld.w -,ap */ \
342 for (;;) { \
343 op = read_memory_integer (pc, 2); \
344 ix = (op >> 3) & 7; \
345 if ((op & 0xfcc0) == 0x2800) { /* ld.- -,ak */ \
346 regnum = SP_REGNUM - (op & 7); \
347 disp = read_memory_integer (pc + 2, 2); \
348 pc += 4;} \
349 else if ((op & 0xfcc0) == 0x2840) { /* ld.- -,ak */ \
350 regnum = SP_REGNUM - (op & 7); \
351 disp = read_memory_integer (pc + 2, 4); \
352 pc += 6;} \
353 if ((op & 0xfcc0) == 0x3000) { /* ld.- -,sk */ \
354 regnum = S0_REGNUM - (op & 7); \
355 disp = read_memory_integer (pc + 2, 2); \
356 pc += 4;} \
357 else if ((op & 0xfcc0) == 0x3040) { /* ld.- -,sk */ \
358 regnum = S0_REGNUM - (op & 7); \
359 disp = read_memory_integer (pc + 2, 4); \
360 pc += 6;} \
361 else if ((op & 0xff00) == 0x7100) { /* br crossjump */ \
362 pc += 2 * (char) op; \
363 continue;} \
364 else if (op == 0x0140) { /* jmp crossjump */ \
365 pc = read_memory_integer (pc + 2, 4); \
366 continue;} \
367 else break; \
368 if ((frame_saved_regs).regs[regnum]) \
369 break; \
370 if (ix == 7) disp += frame_fp; \
371 else if (ix == 6) disp += read_memory_integer (frame_fp + 12, 4); \
372 else if (ix != 0) break; \
373 (frame_saved_regs).regs[regnum] = \
374 disp - 8 + (1 << ((op >> 8) & 3)); \
375 if (regnum >= S7_REGNUM) \
376 (frame_saved_regs).regs[regnum - S0_REGNUM + s0_REGNUM] = \
377 disp - 4 + (1 << ((op >> 8) & 3)); \
378 } \
379 } \
380 }
381 \f
382 /* Things needed for making the inferior call functions. */
383
384 #define CALL_DUMMY_LOCATION BEFORE_TEXT_END
385
386 /* Push an empty stack frame, to record the current PC, etc. */
387
388 #define PUSH_DUMMY_FRAME \
389 { register CORE_ADDR sp = read_register (SP_REGNUM); \
390 register int regnum; \
391 char buf[8]; \
392 long word; \
393 for (regnum = S0_REGNUM; regnum >= S7_REGNUM; --regnum) { \
394 read_register_bytes (REGISTER_BYTE (regnum), buf, 8); \
395 sp = push_bytes (sp, buf, 8);} \
396 for (regnum = SP_REGNUM; regnum >= FP_REGNUM; --regnum) { \
397 word = read_register (regnum); \
398 sp = push_bytes (sp, &word, 4);} \
399 word = (read_register (PS_REGNUM) &~ (3<<25)) | (1<<25); \
400 sp = push_bytes (sp, &word, 4); \
401 word = read_register (PC_REGNUM); \
402 sp = push_bytes (sp, &word, 4); \
403 write_register (SP_REGNUM, sp); \
404 write_register (FP_REGNUM, sp); \
405 write_register (AP_REGNUM, sp);}
406
407 /* Discard from the stack the innermost frame, restoring all registers. */
408
409 #define POP_FRAME do {\
410 register CORE_ADDR fp = read_register (FP_REGNUM); \
411 register int regnum; \
412 register int frame_length = /* 3 short, 2 long, 1 extended, 0 context */ \
413 (read_memory_integer (fp + 4, 4) >> 25) & 3; \
414 char buf[8]; \
415 write_register (PC_REGNUM, read_memory_integer (fp, 4)); \
416 write_register (PS_REGNUM, read_memory_integer (fp += 4, 4)); \
417 write_register (FP_REGNUM, read_memory_integer (fp += 4, 4)); \
418 write_register (AP_REGNUM, read_memory_integer (fp += 4, 4)); \
419 if (frame_length < 3) \
420 for (regnum = A5_REGNUM; regnum < SP_REGNUM; ++regnum) \
421 write_register (regnum, read_memory_integer (fp += 4, 4)); \
422 if (frame_length < 2) \
423 write_register (SP_REGNUM, read_memory_integer (fp += 4, 4)); \
424 fp -= 4; \
425 if (frame_length < 3) \
426 for (regnum = S7_REGNUM; regnum < S0_REGNUM; ++regnum) { \
427 read_memory (fp += 8, buf, 8); \
428 write_register_bytes (REGISTER_BYTE (regnum), buf, 8);} \
429 if (frame_length < 2) { \
430 read_memory (fp += 8, buf, 8); \
431 write_register_bytes (REGISTER_BYTE (regnum), buf, 8);} \
432 else write_register (SP_REGNUM, fp + 8); \
433 flush_cached_frames (); \
434 } while (0)
435
436 /* This sequence of words is the instructions
437 mov sp,ap
438 pshea 69696969
439 calls 32323232
440 bkpt
441 Note this is 16 bytes. */
442
443 #define CALL_DUMMY {0x50860d4069696969LL,0x2140323232327d50LL}
444
445 #define CALL_DUMMY_LENGTH 16
446
447 #define CALL_DUMMY_START_OFFSET 0
448
449 /* Insert the specified number of args and function address
450 into a call sequence of the above form stored at DUMMYNAME. */
451
452 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \
453 { *(int *)((char *) dummyname + 4) = nargs; \
454 *(int *)((char *) dummyname + 10) = fun; }
455 \f
456 /* Defs to read soff symbol tables, see dbxread.c */
457
458 #define NUMBER_OF_SYMBOLS ((long) opthdr.o_nsyms)
459 #define STRING_TABLE_OFFSET ((long) filehdr.h_strptr)
460 #define SYMBOL_TABLE_OFFSET ((long) opthdr.o_symptr)
461 #define STRING_TABLE_SIZE ((long) filehdr.h_strsiz)
462 #define SIZE_OF_TEXT_SEGMENT ((long) txthdr.s_size)
463 #define ENTRY_POINT ((long) opthdr.o_entry)
464
465 #define READ_STRING_TABLE_SIZE(BUFFER) \
466 (BUFFER = STRING_TABLE_SIZE)
467
468 #define DECLARE_FILE_HEADERS \
469 FILEHDR filehdr; \
470 OPTHDR opthdr; \
471 SCNHDR txthdr
472
473 #define READ_FILE_HEADERS(DESC,NAME) \
474 { \
475 int n; \
476 val = myread (DESC, &filehdr, sizeof filehdr); \
477 if (val < 0) \
478 perror_with_name (NAME); \
479 if (! IS_SOFF_MAGIC (filehdr.h_magic)) \
480 error ("%s: not an executable file.", NAME); \
481 lseek (DESC, 0L, 0); \
482 if (myread (DESC, &filehdr, sizeof filehdr) < 0) \
483 perror_with_name (NAME); \
484 if (myread (DESC, &opthdr, filehdr.h_opthdr) <= 0) \
485 perror_with_name (NAME); \
486 for (n = 0; n < filehdr.h_nscns; n++) \
487 { \
488 if (myread (DESC, &txthdr, sizeof txthdr) < 0) \
489 perror_with_name (NAME); \
490 if ((txthdr.s_flags & S_TYPMASK) == S_TEXT) \
491 break; \
492 } \
493 }
This page took 0.04098 seconds and 5 git commands to generate.