]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/config/arm/tm-arm.h
bcopy -> memcpy
[thirdparty/binutils-gdb.git] / gdb / config / arm / tm-arm.h
CommitLineData
ade40d31
RP
1/* Definitions to make GDB target for an ARM under RISCiX (4.3bsd).
2 Copyright 1986, 1987, 1989, 1991, 1993 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
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
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#define TARGET_BYTE_ORDER LITTLE_ENDIAN
21
22/* IEEE format floating point */
23
24#define IEEE_FLOAT
25
26/* I provide my own xfer_core_file to cope with shared libraries */
27
28#define XFER_CORE_FILE
29
30/* Offset from address of function to start of its code.
31 Zero on most machines. */
32
33#define FUNCTION_START_OFFSET 0
34
35/* Advance PC across any function entry prologue instructions
36 to reach some "real" code. */
37
38#define SKIP_PROLOGUE(pc) pc = skip_prologue(pc)
39
40/* Immediately after a function call, return the saved pc.
41 Can't always go through the frames for this because on some machines
42 the new frame is not set up until the new function executes
43 some instructions. */
44
45#define SAVED_PC_AFTER_CALL(frame) (read_register (LR_REGNUM) & 0x03fffffc)
46
47/* I don't know the real values for these. */
48#define TARGET_UPAGES UPAGES
49#define TARGET_NBPG NBPG
50
51/* Address of end of stack space. */
52
53#define STACK_END_ADDR (0x01000000 - (TARGET_UPAGES * TARGET_NBPG))
54
55/* Stack grows downward. */
56
57#define INNER_THAN <
58
59/* Sequence of bytes for breakpoint instruction. */
60
61#define BREAKPOINT {0x00,0x00,0x18,0xef} /* BKPT_SWI from <sys/ptrace.h> */
62
63/* Amount PC must be decremented by after a breakpoint.
64 This is often the number of bytes in BREAKPOINT
65 but not always. */
66
67#define DECR_PC_AFTER_BREAK 0
68
69/* Nonzero if instruction at PC is a return instruction. */
70
71#define ABOUT_TO_RETURN(pc) \
72 ((read_memory_integer(pc, 4) & 0x0fffffff == 0x01b0f00e) || \
73 (read_memory_integer(pc, 4) & 0x0ffff800 == 0x09eba800))
74
75/* Return 1 if P points to an invalid floating point value.
76 LEN is the length in bytes. */
77
78#define INVALID_FLOAT(p, len) 0
79
80/* code to execute to print interesting information about the
81 * floating point processor (if any)
82 * No need to define if there is nothing to do.
83 */
84#define FLOAT_INFO { arm_float_info (); }
85
86/* Say how long (ordinary) registers are. */
87
88#define REGISTER_TYPE long
89
90/* Number of machine registers */
91
92/* Note: I make a fake copy of the pc in register 25 (calling it ps) so
93 that I can clear the status bits from pc (register 15) */
94
95#define NUM_REGS 26
96
97/* Initializer for an array of names of registers.
98 There should be NUM_REGS strings in this initializer. */
99
100#define REGISTER_NAMES \
101 { "a1", "a2", "a3", "a4", \
102 "v1", "v2", "v3", "v4", "v5", "v6", \
103 "sl", "fp", "ip", "sp", "lr", "pc", \
104 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "fps", "ps" }
105
106/* Register numbers of various important registers.
107 Note that some of these values are "real" register numbers,
108 and correspond to the general registers of the machine,
109 and some are "phony" register numbers which are too large
110 to be actual register numbers as far as the user is concerned
111 but do serve to get the desired values when passed to read_register. */
112
113#define AP_REGNUM 11
114#define FP_REGNUM 11 /* Contains address of executing stack frame */
115#define SP_REGNUM 13 /* Contains address of top of stack */
116#define LR_REGNUM 14 /* address to return to from a function call */
117#define PC_REGNUM 15 /* Contains program counter */
118#define F0_REGNUM 16 /* first floating point register */
119#define FPS_REGNUM 24 /* floating point status register */
120#define PS_REGNUM 25 /* Contains processor status */
121
122
123/* Total amount of space needed to store our copies of the machine's
124 register state, the array `registers'. */
125#define REGISTER_BYTES (16*4 + 12*8 + 4 + 4)
126
127/* Index within `registers' of the first byte of the space for
128 register N. */
129
130#define REGISTER_BYTE(N) (((N) < F0_REGNUM) ? (N)*4 : \
131 (((N) < PS_REGNUM) ? 16*4 + ((N) - 16)*12 : \
132 16*4 + 8*12 + ((N) - FPS_REGNUM) * 4))
133
134/* Number of bytes of storage in the actual machine representation
135 for register N. On the vax, all regs are 4 bytes. */
136
137#define REGISTER_RAW_SIZE(N) (((N) < F0_REGNUM || (N) >= FPS_REGNUM) ? 4 : 12)
138
139/* Number of bytes of storage in the program's representation
140 for register N. On the vax, all regs are 4 bytes. */
141
142#define REGISTER_VIRTUAL_SIZE(N) (((N) < F0_REGNUM || (N) >= FPS_REGNUM) ? 4 : 8)
143
144/* Largest value REGISTER_RAW_SIZE can have. */
145
146#define MAX_REGISTER_RAW_SIZE 12
147
148/* Largest value REGISTER_VIRTUAL_SIZE can have. */
149
150#define MAX_REGISTER_VIRTUAL_SIZE 8
151
152/* Nonzero if register N requires conversion
153 from raw format to virtual format. */
154
155#define REGISTER_CONVERTIBLE(N) ((unsigned)(N) - F0_REGNUM < 8)
156
157/* Convert data from raw format for register REGNUM
158 to virtual format for register REGNUM. */
159
160#define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
161 if (REGISTER_CONVERTIBLE(REGNUM)) \
162 convert_from_extended((FROM), (TO)); \
163 else \
164 memcpy ((TO), (FROM), 4);
165
166/* Convert data from virtual format for register REGNUM
167 to raw format for register REGNUM. */
168
169#define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
170 if (REGISTER_CONVERTIBLE(REGNUM)) \
171 convert_to_extended((FROM), (TO)); \
172 else \
173 memcpy ((TO), (FROM), 4);
174
175/* Return the GDB type object for the "standard" data type
176 of data in register N. */
177
178#define REGISTER_VIRTUAL_TYPE(N) \
179 (((unsigned)(N) - F0_REGNUM) < 8 ? builtin_type_double : builtin_type_int)
180\f
181/* The system C compiler uses a similar structure return convention to gcc */
182
183#define USE_STRUCT_CONVENTION(gcc_p, type) (TYPE_LENGTH (type) > 4)
184
185/* Store the address of the place in which to copy the structure the
186 subroutine will return. This is called from call_function. */
187
188#define STORE_STRUCT_RETURN(ADDR, SP) \
189 { write_register (0, (ADDR)); }
190
191/* Extract from an array REGBUF containing the (raw) register state
192 a function return value of type TYPE, and copy that, in virtual format,
193 into VALBUF. */
194
195#define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
196 if (TYPE_CODE (TYPE) == TYPE_CODE_FLT) \
197 convert_from_extended(REGBUF + REGISTER_BYTE (F0_REGNUM), VALBUF); \
198 else \
199 memcpy (VALBUF, REGBUF, TYPE_LENGTH (TYPE))
200
201/* Write into appropriate registers a function return value
202 of type TYPE, given in virtual format. */
203
204#define STORE_RETURN_VALUE(TYPE,VALBUF) \
205 if (TYPE_CODE (TYPE) == TYPE_CODE_FLT) { \
206 char _buf[MAX_REGISTER_RAW_SIZE]; \
207 convert_to_extended(VALBUF, _buf); \
208 write_register_bytes (REGISTER_BYTE (F0_REGNUM), _buf, MAX_REGISTER_RAW_SIZE); \
209 } else \
210 write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
211
212/* Extract from an array REGBUF containing the (raw) register state
213 the address in which a function should return its structure value,
214 as a CORE_ADDR (or an expression that can be used as one). */
215
216#define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
217
218/* Specify that for the native compiler variables for a particular
219 lexical context are listed after the beginning LBRAC instead of
220 before in the executables list of symbols. */
221#define VARIABLES_INSIDE_BLOCK(desc, gcc_p) (!(gcc_p))
222
223\f
224/* Describe the pointer in each stack frame to the previous stack frame
225 (its caller). */
226
227/* FRAME_CHAIN takes a frame's nominal address
228 and produces the frame's chain-pointer.
229
230 However, if FRAME_CHAIN_VALID returns zero,
231 it means the given frame is the outermost one and has no caller. */
232
233/* In the case of the ARM, the frame's nominal address is the FP value,
234 and 12 bytes before comes the saved previous FP value as a 4-byte word. */
235
236#define FRAME_CHAIN(thisframe) \
237 ((thisframe)->pc >= first_object_file_end ? \
238 read_memory_integer ((thisframe)->frame - 12, 4) :\
239 0)
240
241#define FRAME_CHAIN_VALID(chain, thisframe) \
242 (chain != 0 && (FRAME_SAVED_PC (thisframe) >= first_object_file_end))
243
244/* Define other aspects of the stack frame. */
245
246/* A macro that tells us whether the function invocation represented
247 by FI does not have a frame on the stack associated with it. If it
248 does not, FRAMELESS is set to 1, else 0. */
249#define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
250{ \
251 CORE_ADDR func_start, after_prologue; \
252 func_start = (get_pc_function_start ((FI)->pc) + \
253 FUNCTION_START_OFFSET); \
254 after_prologue = func_start; \
255 SKIP_PROLOGUE (after_prologue); \
256 (FRAMELESS) = (after_prologue == func_start); \
257}
258
259/* Saved Pc. */
260
261#define FRAME_SAVED_PC(FRAME) \
262 (read_memory_integer ((FRAME)->frame - 4, 4) & 0x03fffffc)
263
264#define FRAME_ARGS_ADDRESS(fi) (fi->frame)
265
266#define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
267
268/* Return number of args passed to a frame.
269 Can return -1, meaning no way to tell. */
270
271#define FRAME_NUM_ARGS(numargs, fi) (numargs = -1)
272
273/* Return number of bytes at start of arglist that are not really args. */
274
275#define FRAME_ARGS_SKIP 0
276
277/* Put here the code to store, into a struct frame_saved_regs,
278 the addresses of the saved registers of frame described by FRAME_INFO.
279 This includes special registers such as pc and fp saved in special
280 ways in the stack frame. sp is even more special:
281 the address we return for it IS the sp for the next frame. */
282
283#define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
284{ \
285 register int regnum; \
286 register int frame; \
287 register int next_addr; \
288 register int return_data_save; \
289 register int saved_register_mask; \
290 bzero (&frame_saved_regs, sizeof frame_saved_regs); \
291 frame = (frame_info)->frame; \
292 return_data_save = read_memory_integer(frame, 4) & 0x03fffffc - 12; \
293 saved_register_mask = \
294 read_memory_integer(return_data_save, 4); \
295 next_addr = frame - 12; \
296 for (regnum = 4; regnum < 10; regnum++) \
297 if (saved_register_mask & (1<<regnum)) { \
298 next_addr -= 4; \
299 (frame_saved_regs).regs[regnum] = next_addr; \
300 } \
301 if (read_memory_integer(return_data_save + 4, 4) == 0xed6d7103) { \
302 next_addr -= 12; \
303 (frame_saved_regs).regs[F0_REGNUM + 7] = next_addr; \
304 } \
305 if (read_memory_integer(return_data_save + 8, 4) == 0xed6d6103) { \
306 next_addr -= 12; \
307 (frame_saved_regs).regs[F0_REGNUM + 6] = next_addr; \
308 } \
309 if (read_memory_integer(return_data_save + 12, 4) == 0xed6d5103) { \
310 next_addr -= 12; \
311 (frame_saved_regs).regs[F0_REGNUM + 5] = next_addr; \
312 } \
313 if (read_memory_integer(return_data_save + 16, 4) == 0xed6d4103) { \
314 next_addr -= 12; \
315 (frame_saved_regs).regs[F0_REGNUM + 4] = next_addr; \
316 } \
317 (frame_saved_regs).regs[SP_REGNUM] = next_addr; \
318 (frame_saved_regs).regs[PC_REGNUM] = frame - 4; \
319 (frame_saved_regs).regs[PS_REGNUM] = frame - 4; \
320 (frame_saved_regs).regs[FP_REGNUM] = frame - 12; \
321}
322\f
323/* Things needed for making the inferior call functions. */
324
325/* Push an empty stack frame, to record the current PC, etc. */
326
327#define PUSH_DUMMY_FRAME \
328{ \
329 register CORE_ADDR sp = read_register (SP_REGNUM); \
330 register int regnum; \
331 /* opcode for ldmdb fp,{v1-v6,fp,ip,lr,pc}^ */ \
332 sp = push_word(sp, 0xe92dbf0); /* dummy return_data_save ins */ \
333 /* push a pointer to the dummy instruction minus 12 */ \
334 sp = push_word(sp, read_register (SP_REGNUM) - 16); \
335 sp = push_word(sp, read_register (PS_REGNUM)); \
336 sp = push_word(sp, read_register (SP_REGNUM)); \
337 sp = push_word(sp, read_register (FP_REGNUM)); \
338 for (regnum = 9; regnum >= 4; regnum --) \
339 sp = push_word(sp, read_register (regnum)); \
340 write_register (FP_REGNUM, read_register (SP_REGNUM) - 8); \
341 write_register (SP_REGNUM, sp); }
342
343/* Discard from the stack the innermost frame, restoring all registers. */
344
345#define POP_FRAME \
346{ \
347 register CORE_ADDR fp = read_register (FP_REGNUM); \
348 register unsigned long return_data_save = \
349 read_memory_integer ( (read_memory_integer (fp, 4) & \
350 0x03fffffc) - 12, 4); \
351 register int regnum; \
352 write_register (PS_REGNUM, read_memory_integer (fp - 4, 4)); \
353 write_register (PC_REGNUM, read_register (PS_REGNUM) & 0x03fffffc); \
354 write_register (SP_REGNUM, read_memory_integer (fp - 8, 4)); \
355 write_register (FP_REGNUM, read_memory_integer (fp - 12, 4)); \
356 fp -= 12; \
357 for (regnum = 9; regnum >= 4; regnum--) \
358 if (return_data_save & (1<<regnum)) { \
359 fp -= 4; \
360 write_register (regnum, read_memory_integer(fp, 4)); \
361 } \
362 flush_cached_frames (); \
363 set_current_frame (create_new_frame (read_register (FP_REGNUM), \
364 read_pc ())); \
365}
366
367/* This sequence of words is the instructions
368
369 ldmia sp!,{a1-a4}
370 mov lk,pc
371 bl *+8
372 swi bkpt_swi
373
374 Note this is 16 bytes. */
375
376#define CALL_DUMMY {0xe8bd000f, 0xe1a0e00f, 0xeb000000, 0xef180000}
377
378#define CALL_DUMMY_START_OFFSET 0 /* Start execution at beginning of dummy */
379
380/* Insert the specified number of args and function address
381 into a call sequence of the above form stored at DUMMYNAME. */
382
383#define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \
384{ \
385 register enum type_code code = TYPE_CODE (type); \
386 register nargs_in_registers, struct_return = 0; \
387 /* fix the load-arguments mask to move the first 4 or less arguments \
388 into a1-a4 but make sure the structure return address in a1 is \
389 not disturbed if the function is returning a structure */ \
390 if ((code == TYPE_CODE_STRUCT || \
391 code == TYPE_CODE_UNION || \
392 code == TYPE_CODE_ARRAY) && \
393 TYPE_LENGTH (type) > 4) { \
394 nargs_in_registers = min(nargs + 1, 4); \
395 struct_return = 1; \
396 } else \
397 nargs_in_registers = min(nargs, 4); \
398 *(char *) dummyname = (1 << nargs_in_registers) - 1 - struct_return; \
399 *(int *)((char *) dummyname + 8) = \
400 (((fun - (pc + 16)) / 4) & 0x00ffffff) | 0xeb000000; }