* valops.c (call_function_by_hand, push_word), defs.h (push_word),
[deliverable/binutils-gdb.git] / gdb / config / ns32k / tm-merlin.h
1 /* Definitions to target GDB to a merlin under utek 2.1
2 Copyright 1986, 1987, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #define TARGET_BYTE_ORDER LITTLE_ENDIAN
21
22 /* Offset from address of function to start of its code.
23 Zero on most machines. */
24
25 #define FUNCTION_START_OFFSET 0
26
27 /* Advance PC across any function entry prologue instructions
28 to reach some "real" code. */
29
30 #define SKIP_PROLOGUE(pc) \
31 { register int op = read_memory_integer (pc, 1); \
32 if (op == 0x82) \
33 { op = read_memory_integer (pc+2,1); \
34 if ((op & 0x80) == 0) pc += 3; \
35 else if ((op & 0xc0) == 0x80) pc += 4; \
36 else pc += 6; \
37 }}
38
39 /* Immediately after a function call, return the saved pc.
40 Can't always go through the frames for this because on some machines
41 the new frame is not set up until the new function executes
42 some instructions. */
43
44 #define SAVED_PC_AFTER_CALL(frame) \
45 read_memory_integer (read_register (SP_REGNUM), 4)
46
47 /* Address of end of stack space. */
48
49 #define STACK_END_ADDR (0x800000)
50
51 /* Stack grows downward. */
52
53 #define INNER_THAN <
54
55 /* Sequence of bytes for breakpoint instruction. */
56
57 #define BREAKPOINT {0xf2}
58
59 /* Amount PC must be decremented by after a breakpoint.
60 This is often the number of bytes in BREAKPOINT
61 but not always. */
62
63 #define DECR_PC_AFTER_BREAK 0
64
65 /* Nonzero if instruction at PC is a return instruction. */
66
67 #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 1) == 0x12)
68
69 /* Return 1 if P points to an invalid floating point value. */
70
71 #define INVALID_FLOAT(p, len) 0
72
73 /* Define this to say that the "svc" insn is followed by
74 codes in memory saying which kind of system call it is. */
75
76 #define NS32K_SVC_IMMED_OPERANDS
77
78 /* Say how long (ordinary) registers are. This is a piece of bogosity
79 used in push_word and a few other places; REGISTER_RAW_SIZE is the
80 real way to know how big a register is. */
81
82 #define REGISTER_SIZE 4
83
84 /* Number of machine registers */
85
86 #define NUM_REGS 25
87
88 #define NUM_GENERAL_REGS 8
89
90 /* Initializer for an array of names of registers.
91 There should be NUM_REGS strings in this initializer. */
92
93 #define REGISTER_NAMES {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
94 "pc", "sp", "fp", "ps", \
95 "fsr", \
96 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
97 "l0", "l1", "l2", "l3", "l4", \
98 }
99
100 /* Register numbers of various important registers.
101 Note that some of these values are "real" register numbers,
102 and correspond to the general registers of the machine,
103 and some are "phony" register numbers which are too large
104 to be actual register numbers as far as the user is concerned
105 but do serve to get the desired values when passed to read_register. */
106
107 #define AP_REGNUM FP_REGNUM
108 #define FP_REGNUM 10 /* Contains address of executing stack frame */
109 #define SP_REGNUM 9 /* Contains address of top of stack */
110 #define PC_REGNUM 8 /* Contains program counter */
111 #define PS_REGNUM 11 /* Contains processor status */
112 #define FPS_REGNUM 12 /* Floating point status register */
113 #define FP0_REGNUM 13 /* Floating point register 0 */
114 #define LP0_REGNUM 21 /* Double register 0 (same as FP0) */
115
116 /* Total amount of space needed to store our copies of the machine's
117 register state, the array `registers'. */
118 #define REGISTER_BYTES ((NUM_REGS - 4) * sizeof (int) + 4 * sizeof (double))
119
120 /* Index within `registers' of the first byte of the space for
121 register N. */
122
123 #define REGISTER_BYTE(N) ((N) >= LP0_REGNUM ? \
124 LP0_REGNUM * 4 + ((N) - LP0_REGNUM) * 8 : (N) * 4)
125
126 /* Number of bytes of storage in the actual machine representation
127 for register N. On the 32000, all regs are 4 bytes
128 except for the doubled floating registers. */
129
130 #define REGISTER_RAW_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4)
131
132 /* Number of bytes of storage in the program's representation
133 for register N. On the 32000, all regs are 4 bytes
134 except for the doubled floating registers. */
135
136 #define REGISTER_VIRTUAL_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4)
137
138 /* Largest value REGISTER_RAW_SIZE can have. */
139
140 #define MAX_REGISTER_RAW_SIZE 8
141
142 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
143
144 #define MAX_REGISTER_VIRTUAL_SIZE 8
145
146 /* Return the GDB type object for the "standard" data type
147 of data in register N. */
148
149 #define REGISTER_VIRTUAL_TYPE(N) \
150 ((N) >= FP0_REGNUM ? \
151 ((N) >= LP0_REGNUM ? \
152 builtin_type_double \
153 : builtin_type_float) \
154 : builtin_type_int)
155
156 /* Store the address of the place in which to copy the structure the
157 subroutine will return. This is called from call_function.
158
159 On this machine this is a no-op, as gcc doesn't run on it yet.
160 This calling convention is not used. */
161
162 #define STORE_STRUCT_RETURN(ADDR, SP)
163
164 /* Extract from an array REGBUF containing the (raw) register state
165 a function return value of type TYPE, and copy that, in virtual format,
166 into VALBUF. */
167
168 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
169 memcpy (VALBUF, REGBUF, TYPE_LENGTH (TYPE))
170
171 /* Write into appropriate registers a function return value
172 of type TYPE, given in virtual format. */
173
174 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
175 write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
176
177 /* Extract from an array REGBUF containing the (raw) register state
178 the address in which a function should return its structure value,
179 as a CORE_ADDR (or an expression that can be used as one). */
180
181 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
182 \f
183 /* Describe the pointer in each stack frame to the previous stack frame
184 (its caller). */
185
186 /* FRAME_CHAIN takes a frame's nominal address
187 and produces the frame's chain-pointer. */
188
189 /* In the case of the Merlin, the frame's nominal address is the FP value,
190 and at that address is saved previous FP value as a 4-byte word. */
191
192 #define FRAME_CHAIN(thisframe) \
193 (!inside_entry_file ((thisframe)->pc) ? \
194 read_memory_integer ((thisframe)->frame, 4) :\
195 0)
196
197 /* Define other aspects of the stack frame. */
198
199 #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4))
200
201 /* compute base of arguments */
202 #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
203
204 #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
205
206 /* Return number of args passed to a frame.
207 Can return -1, meaning no way to tell. */
208
209 #define FRAME_NUM_ARGS(numargs, fi) \
210 { CORE_ADDR pc; \
211 int insn; \
212 int addr_mode; \
213 int width; \
214 \
215 pc = FRAME_SAVED_PC (fi); \
216 insn = read_memory_integer (pc,2); \
217 addr_mode = (insn >> 11) & 0x1f; \
218 insn = insn & 0x7ff; \
219 if ((insn & 0x7fc) == 0x57c \
220 && addr_mode == 0x14) /* immediate */ \
221 { if (insn == 0x57c) /* adjspb */ \
222 width = 1; \
223 else if (insn == 0x57d) /* adjspw */ \
224 width = 2; \
225 else if (insn == 0x57f) /* adjspd */ \
226 width = 4; \
227 numargs = read_memory_integer (pc+2,width); \
228 if (width > 1) \
229 flip_bytes (&numargs, width); \
230 numargs = - sign_extend (numargs, width*8) / 4; } \
231 else numargs = -1; \
232 }
233
234 /* Return number of bytes at start of arglist that are not really args. */
235
236 #define FRAME_ARGS_SKIP 8
237
238 /* Put here the code to store, into a struct frame_saved_regs,
239 the addresses of the saved registers of frame described by FRAME_INFO.
240 This includes special registers such as pc and fp saved in special
241 ways in the stack frame. sp is even more special:
242 the address we return for it IS the sp for the next frame. */
243
244 #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
245 { int regmask,regnum; \
246 int localcount; \
247 CORE_ADDR enter_addr; \
248 CORE_ADDR next_addr; \
249 \
250 enter_addr = get_pc_function_start ((frame_info)->pc); \
251 regmask = read_memory_integer (enter_addr+1, 1); \
252 localcount = ns32k_localcount (enter_addr); \
253 next_addr = (frame_info)->frame + localcount; \
254 for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) \
255 (frame_saved_regs).regs[regnum] \
256 = (regmask & 1) ? (next_addr -= 4) : 0; \
257 (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame + 4; \
258 (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 4; \
259 (frame_saved_regs).regs[FP_REGNUM] \
260 = read_memory_integer ((frame_info)->frame, 4); }
261
262 \f
263 /* Things needed for making the inferior call functions. */
264
265 /* Push an empty stack frame, to record the current PC, etc. */
266
267 #define PUSH_DUMMY_FRAME \
268 { register CORE_ADDR sp = read_register (SP_REGNUM); \
269 register int regnum; \
270 sp = push_word (sp, read_register (PC_REGNUM)); \
271 sp = push_word (sp, read_register (FP_REGNUM)); \
272 write_register (FP_REGNUM, sp); \
273 for (regnum = 0; regnum < 8; regnum++) \
274 sp = push_word (sp, read_register (regnum)); \
275 write_register (SP_REGNUM, sp); \
276 }
277
278 /* Discard from the stack the innermost frame, restoring all registers. */
279
280 #define POP_FRAME \
281 { register FRAME frame = get_current_frame (); \
282 register CORE_ADDR fp; \
283 register int regnum; \
284 struct frame_saved_regs fsr; \
285 struct frame_info *fi; \
286 fi = get_frame_info (frame); \
287 fp = fi->frame; \
288 get_frame_saved_regs (fi, &fsr); \
289 for (regnum = 0; regnum < 8; regnum++) \
290 if (fsr.regs[regnum]) \
291 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
292 write_register (FP_REGNUM, read_memory_integer (fp, 4)); \
293 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \
294 write_register (SP_REGNUM, fp + 8); \
295 flush_cached_frames (); \
296 set_current_frame (create_new_frame (read_register (FP_REGNUM),\
297 read_pc ())); \
298 }
299
300 /* This sequence of words is the instructions
301 enter 0xff,0 82 ff 00
302 jsr @0x00010203 7f ae c0 01 02 03
303 adjspd 0x69696969 7f a5 01 02 03 04
304 bpt f2
305 Note this is 16 bytes. */
306
307 #define CALL_DUMMY { 0x7f00ff82, 0x0201c0ae, 0x01a57f03, 0xf2040302 }
308
309 #define CALL_DUMMY_START_OFFSET 3
310 #define CALL_DUMMY_LENGTH 16
311 #define CALL_DUMMY_ADDR 5
312 #define CALL_DUMMY_NARGS 11
313
314 /* Insert the specified number of args and function address
315 into a call sequence of the above form stored at DUMMYNAME. */
316
317 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \
318 { int flipped = fun | 0xc0000000; \
319 flip_bytes (&flipped, 4); \
320 *((int *) (((char *) dummyname)+CALL_DUMMY_ADDR)) = flipped; \
321 flipped = - nargs * 4; \
322 flip_bytes (&flipped, 4); \
323 *((int *) (((char *) dummyname)+CALL_DUMMY_NARGS)) = flipped; \
324 }
This page took 0.035818 seconds and 5 git commands to generate.