* command.c (shell_escape, make_command, _initialze_command):
[deliverable/binutils-gdb.git] / gdb / tm-np1.h
CommitLineData
dd3b648e 1/* Parameters for targeting on a Gould NP1, for GDB, the GNU debugger.
fbcb5095 2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
dd3b648e
RP
3
4This file is part of GDB.
5
99a7de40 6This program is free software; you can redistribute it and/or modify
dd3b648e 7it under the terms of the GNU General Public License as published by
99a7de40
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
dd3b648e 10
99a7de40 11This program is distributed in the hope that it will be useful,
dd3b648e
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
99a7de40
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
dd3b648e
RP
19
20#define GOULD_NPL
21
22#define TARGET_BYTE_ORDER BIG_ENDIAN
23
24/* N_ENTRY appears in libraries on Gould machines.
25 Don't know what 0xa4 is; it's mentioned in stab.h
26 but only in the sdb symbol list. */
27#define IGNORE_SYMBOL(type) (type == N_ENTRY || type == 0xa4)
28
29/* We don't want the extra gnu symbols on the machine;
30 they will interfere with the shared segment symbols. */
31#define NO_GNU_STABS
32
33/* Macro for text-offset and data info (in NPL a.out format). */
34#define TEXTINFO \
35 text_offset = N_TXTOFF (exec_coffhdr, exec_aouthdr); \
36 exec_data_offset = N_TXTOFF (exec_coffhdr, exec_aouthdr)\
37 + exec_aouthdr.a_text
38
39/* Macro for number of symbol table entries */
40#define NUMBER_OF_SYMBOLS \
41 (coffhdr.f_nsyms)
42
43/* Macro for file-offset of symbol table (in NPL a.out format). */
44#define SYMBOL_TABLE_OFFSET \
45 N_SYMOFF (coffhdr)
46
47/* Macro for file-offset of string table (in NPL a.out format). */
48#define STRING_TABLE_OFFSET \
49 (N_STROFF (coffhdr))
50
51/* Macro to store the length of the string table data in INTO. */
52#define READ_STRING_TABLE_SIZE(INTO) \
53 { INTO = hdr.a_stsize; }
54
55/* Macro to declare variables to hold the file's header data. */
56#define DECLARE_FILE_HEADERS struct exec hdr; \
57 FILHDR coffhdr
58
59/* Macro to read the header data from descriptor DESC and validate it.
60 NAME is the file name, for error messages. */
61#define READ_FILE_HEADERS(DESC, NAME) \
62{ val = myread (DESC, &coffhdr, sizeof coffhdr); \
63 if (val < 0) \
64 perror_with_name (NAME); \
65 val = myread (DESC, &hdr, sizeof hdr); \
66 if (val < 0) \
67 perror_with_name (NAME); \
68 if (coffhdr.f_magic != GNP1MAGIC) \
69 error ("File \"%s\" not in coff executable format.", NAME); \
70 if (N_BADMAG (hdr)) \
71 error ("File \"%s\" not in executable format.", NAME); }
72
73/* Define COFF and other symbolic names needed on NP1 */
74#define NS32GMAGIC GNP1MAGIC
75#define NS32SMAGIC GPNMAGIC
76
77/* Define this if the C compiler puts an underscore at the front
78 of external names before giving them to the linker. */
79#define NAMES_HAVE_UNDERSCORE
80
dd3b648e
RP
81/* Address of blocks in N_LBRAC and N_RBRAC symbols are absolute addresses,
82 not relative to start of source address. */
83#define BLOCK_ADDRESS_ABSOLUTE
84
85/* Offset from address of function to start of its code.
86 Zero on most machines. */
87#define FUNCTION_START_OFFSET 8
88
89/* Advance PC across any function entry prologue instructions
90 to reach some "real" code. One NPL we can have one two startup
91 sequences depending on the size of the local stack:
92
93 Either:
94 "suabr b2, #"
95 of
96 "lil r4, #", "suabr b2, #(r4)"
97
98 "lwbr b6, #", "stw r1, 8(b2)"
99 Optional "stwbr b3, c(b2)"
100 Optional "trr r2,r7" (Gould first argument register passing)
101 or
102 Optional "stw r2,8(b3)" (Gould first argument register passing)
103 */
104#define SKIP_PROLOGUE(pc) { \
105 register int op = read_memory_integer ((pc), 4); \
106 if ((op & 0xffff0000) == 0xFA0B0000) { \
107 pc += 4; \
108 op = read_memory_integer ((pc), 4); \
109 if ((op & 0xffff0000) == 0x59400000) { \
110 pc += 4; \
111 op = read_memory_integer ((pc), 4); \
112 if ((op & 0xffff0000) == 0x5F000000) { \
113 pc += 4; \
114 op = read_memory_integer ((pc), 4); \
115 if (op == 0xD4820008) { \
116 pc += 4; \
117 op = read_memory_integer ((pc), 4); \
118 if (op == 0x5582000C) { \
119 pc += 4; \
120 op = read_memory_integer ((pc), 2); \
121 if (op == 0x2fa0) { \
122 pc += 2; \
123 } else { \
124 op = read_memory_integer ((pc), 4); \
125 if (op == 0xd5030008) { \
126 pc += 4; \
127 } \
128 } \
129 } else { \
130 op = read_memory_integer ((pc), 2); \
131 if (op == 0x2fa0) { \
132 pc += 2; \
133 } \
134 } \
135 } \
136 } \
137 } \
138 } \
139 if ((op & 0xffff0000) == 0x59000000) { \
140 pc += 4; \
141 op = read_memory_integer ((pc), 4); \
142 if ((op & 0xffff0000) == 0x5F000000) { \
143 pc += 4; \
144 op = read_memory_integer ((pc), 4); \
145 if (op == 0xD4820008) { \
146 pc += 4; \
147 op = read_memory_integer ((pc), 4); \
148 if (op == 0x5582000C) { \
149 pc += 4; \
150 op = read_memory_integer ((pc), 2); \
151 if (op == 0x2fa0) { \
152 pc += 2; \
153 } else { \
154 op = read_memory_integer ((pc), 4); \
155 if (op == 0xd5030008) { \
156 pc += 4; \
157 } \
158 } \
159 } else { \
160 op = read_memory_integer ((pc), 2); \
161 if (op == 0x2fa0) { \
162 pc += 2; \
163 } \
164 } \
165 } \
166 } \
167 } \
168}
169
170/* Immediately after a function call, return the saved pc.
171 Can't go through the frames for this because on some machines
172 the new frame is not set up until the new function executes
173 some instructions. True on NPL! Return address is in R1.
174 The true return address is REALLY 4 past that location! */
175#define SAVED_PC_AFTER_CALL(frame) \
176 (read_register(R1_REGNUM) + 4)
177
178/* Address of end of stack space. */
179#define STACK_END_ADDR 0x7fffc000
180
181/* Stack grows downward. */
182#define INNER_THAN <
183
184/* Sequence of bytes for breakpoint instruction.
185 This is padded out to the size of a machine word. When it was just
186 {0x28, 0x09} it gave problems if hit breakpoint on returning from a
187 function call. */
188#define BREAKPOINT {0x28, 0x09, 0x0, 0x0}
189
190/* Amount PC must be decremented by after a breakpoint.
191 This is often the number of bytes in BREAKPOINT
192 but not always. */
193#define DECR_PC_AFTER_BREAK 2
194
195/* Nonzero if instruction at PC is a return instruction. "bu 4(r1)" */
196#define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 4) == 0x40100004)
197
198/* Return 1 if P points to an invalid floating point value. */
199#define INVALID_FLOAT(p, len) ((*(short *)p & 0xff80) == 0x8000)
200
201/* Say how long (ordinary) registers are. */
202#define REGISTER_TYPE long
203
204/* Size of bytes of vector register (NP1 only), 32 elements * sizeof(int) */
205#define VR_SIZE 128
206
207/* Number of machine registers */
208#define NUM_REGS 27
209#define NUM_GEN_REGS 16
210#define NUM_CPU_REGS 4
211#define NUM_VECTOR_REGS 7
212
213/* Initializer for an array of names of registers.
214 There should be NUM_REGS strings in this initializer. */
215#define REGISTER_NAMES { \
216 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
217 "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", \
218 "sp", "ps", "pc", "ve", \
219 "v1", "v2", "v3", "v4", "v5", "v6", "v7", \
220}
221
222/* Register numbers of various important registers.
223 Note that some of these values are "real" register numbers,
224 and correspond to the general registers of the machine,
225 and some are "phony" register numbers which are too large
226 to be actual register numbers as far as the user is concerned
227 but do serve to get the desired values when passed to read_register. */
228#define R1_REGNUM 1 /* Gr1 => return address of caller */
229#define R2_REGNUM 2 /* Gr2 => return value from function */
230#define R4_REGNUM 4 /* Gr4 => register save area */
231#define R5_REGNUM 5 /* Gr5 => register save area */
232#define R6_REGNUM 6 /* Gr6 => register save area */
233#define R7_REGNUM 7 /* Gr7 => register save area */
234#define B1_REGNUM 9 /* Br1 => start of this code routine */
235#define SP_REGNUM 10 /* Br2 == (sp) */
236#define AP_REGNUM 11 /* Br3 == (ap) */
237#define FP_REGNUM 16 /* A copy of Br2 saved in trap */
238#define PS_REGNUM 17 /* Contains processor status */
239#define PC_REGNUM 18 /* Contains program counter */
240#define VE_REGNUM 19 /* Vector end (user setup) register */
241#define V1_REGNUM 20 /* First vector register */
242#define V7_REGNUM 26 /* First vector register */
243
244/* Total amount of space needed to store our copies of the machine's
245 register state, the array `registers'. */
246#define REGISTER_BYTES \
247 (NUM_GEN_REGS*4 + NUM_VECTOR_REGS*VR_SIZE + NUM_CPU_REGS*4)
248
249/* Index within `registers' of the first byte of the space for
250 register N. */
251#define REGISTER_BYTE(N) \
252 (((N) < V1_REGNUM) ? ((N) * 4) : (((N) - V1_REGNUM) * VR_SIZE) + 80)
253
254/* Number of bytes of storage in the actual machine representation
255 for register N. On the NP1, all normal regs are 4 bytes, but
256 the vector registers are VR_SIZE*4 bytes long. */
257#define REGISTER_RAW_SIZE(N) \
258 (((N) < V1_REGNUM) ? 4 : VR_SIZE)
259
260/* Number of bytes of storage in the program's representation
261 for register N. On the NP1, all regs are 4 bytes. */
262#define REGISTER_VIRTUAL_SIZE(N) \
263 (((N) < V1_REGNUM) ? 4 : VR_SIZE)
264
265/* Largest value REGISTER_RAW_SIZE can have. */
266#define MAX_REGISTER_RAW_SIZE VR_SIZE
267
268/* Largest value REGISTER_VIRTUAL_SIZE can have. */
269#define MAX_REGISTER_VIRTUAL_SIZE VR_SIZE
270
271/* Nonzero if register N requires conversion
272 from raw format to virtual format. */
273#define REGISTER_CONVERTIBLE(N) (0)
274
275/* Convert data from raw format for register REGNUM
276 to virtual format for register REGNUM. */
277#define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
278 bcopy ((FROM), (TO), REGISTER_RAW_SIZE(REGNUM));
279
280/* Convert data from virtual format for register REGNUM
281 to raw format for register REGNUM. */
282#define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
283 bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM));
284
285/* Return the GDB type object for the "standard" data type
286 of data in register N. */
287#define REGISTER_VIRTUAL_TYPE(N) \
288 ((N) > VE_REGNUM ? builtin_type_np1_vector : builtin_type_int)
289extern struct type *builtin_type_np1_vector;
290
291/* Store the address of the place in which to copy the structure the
292 subroutine will return. This is called from call_function.
293
294 On this machine this is a no-op, because gcc isn't used on it
295 yet. So this calling convention is not used. */
296
297#define STORE_STRUCT_RETURN(ADDR, SP) push_word(SP + 8, ADDR)
298
299/* Extract from an arrary REGBUF containing the (raw) register state
300 a function return value of type TYPE, and copy that, in virtual format,
301 into VALBUF. */
302
303#define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
304 bcopy (((int *)(REGBUF)) + 2, VALBUF, TYPE_LENGTH (TYPE))
305
306/* Write into appropriate registers a function return value
307 of type TYPE, given in virtual format. */
308
309#define STORE_RETURN_VALUE(TYPE,VALBUF) \
310 write_register_bytes (REGISTER_BYTE (R2_REGNUM), VALBUF, \
311 TYPE_LENGTH (TYPE))
312
313/* Extract from an array REGBUF containing the (raw) register state
314 the address in which a function should return its structure value,
315 as a CORE_ADDR (or an expression that can be used as one). */
316
317#define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*((int *)(REGBUF) + 2))
318
319/* Both gcc and cc return small structs in registers (i.e. in GDB
320 terminology, small structs don't use the struct return convention). */
321#define USE_STRUCT_CONVENTION(gcc_p, type) (TYPE_LENGTH(type) > 8)
322\f
323/* Describe the pointer in each stack frame to the previous stack frame
324 (its caller). */
325
326/* FRAME_CHAIN takes a frame's nominal address
327 and produces the frame's chain-pointer.
328
dd3b648e 329 However, if FRAME_CHAIN_VALID returns zero,
e140f1da 330 it means the given frame is the outermost one and has no caller. */
dd3b648e
RP
331
332/* In the case of the NPL, the frame's norminal address is Br2 and the
333 previous routines frame is up the stack X bytes, where X is the
334 value stored in the code function header xA(Br1). */
335#define FRAME_CHAIN(thisframe) (findframe(thisframe))
336
337#define FRAME_CHAIN_VALID(chain, thisframe) \
338 (chain != 0 && chain != (thisframe)->frame)
339
dd3b648e
RP
340/* Define other aspects of the stack frame on NPL. */
341#define FRAME_SAVED_PC(FRAME) \
342 (read_memory_integer ((FRAME)->frame + 8, 4))
343
344#define FRAME_ARGS_ADDRESS(fi) \
345 ((fi)->next_frame ? \
346 read_memory_integer ((fi)->frame + 12, 4) : \
347 read_register (AP_REGNUM))
348
349#define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
350
351/* Set VAL to the number of args passed to frame described by FI.
352 Can set VAL to -1, meaning no way to tell. */
353
354/* We can check the stab info to see how
355 many arg we have. No info in stack will tell us */
356#define FRAME_NUM_ARGS(val,fi) (val = findarg(fi))
357
358/* Return number of bytes at start of arglist that are not really args. */
359#define FRAME_ARGS_SKIP 8
360
361/* Put here the code to store, into a struct frame_saved_regs,
362 the addresses of the saved registers of frame described by FRAME_INFO.
363 This includes special registers such as pc and fp saved in special
364 ways in the stack frame. sp is even more special:
365 the address we return for it IS the sp for the next frame. */
366
367#define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
368{ \
369 bzero (&frame_saved_regs, sizeof frame_saved_regs); \
370 (frame_saved_regs).regs[SP_REGNUM] = framechain (frame_info); \
371 (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 8; \
372 (frame_saved_regs).regs[R4_REGNUM] = (frame_info)->frame + 0x30; \
373 (frame_saved_regs).regs[R5_REGNUM] = (frame_info)->frame + 0x34; \
374 (frame_saved_regs).regs[R6_REGNUM] = (frame_info)->frame + 0x38; \
375 (frame_saved_regs).regs[R7_REGNUM] = (frame_info)->frame + 0x3C; \
376}
377\f
378/* Things needed for making the inferior call functions. */
379
841c051c
JG
380#define CALL_DUMMY_LOCATION BEFORE_TEXT_END
381#define NEED_TEXT_START_END
dd3b648e
RP
382
383/* Push an empty stack frame, to record the current PC, etc. */
384
385#define PUSH_DUMMY_FRAME \
386{ register CORE_ADDR sp = read_register (SP_REGNUM); \
387 register int regnum; \
388 for (regnum = 0; regnum < FP_REGNUM; regnum++) \
389 sp = push_word (sp, read_register (regnum)); \
390 sp = push_word (sp, read_register (PS_REGNUM)); \
391 sp = push_word (sp, read_register (PC_REGNUM)); \
392 write_register (SP_REGNUM, sp);}
393
394/* Discard from the stack the innermost frame,
395 restoring all saved registers. */
396
397#define POP_FRAME \
398{ CORE_ADDR sp = read_register(SP_REGNUM); \
399 REGISTER_TYPE reg; \
400 int regnum; \
401 for(regnum = 0;regnum < FP_REGNUM;regnum++){ \
402 sp-=sizeof(REGISTER_TYPE); \
403 read_memory(sp,&reg,sizeof(REGISTER_TYPE)); \
404 write_register(regnum,reg);} \
405 sp-=sizeof(REGISTER_TYPE); \
406 read_memory(sp,&reg,sizeof(REGISTER_TYPE)); \
407 write_register(PS_REGNUM,reg); \
408 sp-=sizeof(REGISTER_TYPE); \
409 read_memory(sp,&reg,sizeof(REGISTER_TYPE)); \
410 write_register(PC_REGNUM,reg);}
411
412/* MJD - Size of dummy frame pushed onto stack by PUSH_DUMMY_FRAME */
413
414#define DUMMY_FRAME_SIZE (0x48)
415
416/* MJD - The sequence of words in the instructions is
417 halt
418 halt
419 halt
420 halt
421 subr b2,stack size,0 grab stack space for dummy call
422 labr b3,x0(b2),0 set AP_REGNUM to point at arguments
423 lw r2,x8(b3),0 load r2 with first argument
424 lwbr b1,arguments size(b2),0 load address of function to be called
425 brlnk r1,x8(b1),0 call function
426 halt
427 halt
428 labr b2,stack size(b2),0 give back stack
429 break break
430 */
431
432#define CALL_DUMMY {0x00000000, \
433 0x00000000, \
434 0x59000000, \
435 0x598a0000, \
436 0xb5030008, \
437 0x5c820000, \
438 0x44810008, \
439 0x00000000, \
440 0x590a0000, \
441 0x28090000 }
442
443#define CALL_DUMMY_LENGTH 40
444
445#define CALL_DUMMY_START_OFFSET 8
446
447#define CALL_DUMMY_STACK_ADJUST 8
448
449/* MJD - Fixup CALL_DUMMY for the specific function call.
450 OK heres the problems
451 1) On a trap there are two copies of the stack pointer, one in SP_REGNUM
452 which is read/write and one in FP_REGNUM which is only read. It seems
453 that when restarting the GOULD NP1 uses FP_REGNUM's value.
454 2) Loading function address into b1 looks a bit difficult if bigger than
455 0x0000fffc, infact from what I can tell the compiler sets up table of
456 function address in base3 through which function calls are referenced.
457
458 OK my solutions
459 Calculate the size of the dummy stack frame and do adjustments of
460 SP_REGNUM in the dummy call.
461 Push function address onto the stack and load it in the dummy call
462 */
463
464#define FIX_CALL_DUMMY(dummyname, sp, fun, nargs, args, type, gcc_p) \
465 { int i;\
466 int arg_len = 0, total_len;\
467 old_sp = push_word(old_sp,fun);\
468 for(i = nargs - 1;i >= 0;i--)\
469 arg_len += TYPE_LENGTH (VALUE_TYPE (value_arg_coerce (args[i])));\
470 if(struct_return)\
471 arg_len += TYPE_LENGTH(value_type);\
472 total_len = DUMMY_FRAME_SIZE+CALL_DUMMY_STACK_ADJUST+4+arg_len;\
473 dummyname[0] += total_len;\
474 dummyname[2] += total_len;\
475 dummyname[5] += arg_len+CALL_DUMMY_STACK_ADJUST;\
476 dummyname[8] += total_len;}
477
478/* MJD - So the stack should end up looking like this
479
480 | Normal stack frame |
481 | from normal program |
482 | flow |
483 +---------------------+ <- Final sp - 0x08 - argument size
484 | | - 0x4 - dummy_frame_size
485 | Pushed dummy frame |
486 | b0-b7, r0-r7 |
487 | pc and ps |
488 | |
489 +---------------------+
490 | Function address |
491 +---------------------+ <- Final sp - 0x8 - arguments size
492 | |
493 | |
494 | |
495 | Arguments to |
496 | Function |
497 | |
498 | |
499 | |
500 +---------------------+ <- Final sp - 0x8
501 | Dummy_stack_adjust |
502 +---------------------+ <- Final sp
503 | |
504 | where call will |
505 | build frame |
506*/
This page took 0.102921 seconds and 4 git commands to generate.