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