7c64e0d6a7f89903bd61c610ec8e827361e5cac1
[binutils-gdb.git] / gdb / config / m88k / tm-m88k.h
1 /* Target machine description for generic Motorola 88000, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include "ieee-float.h"
22
23 /* g++ support is not yet included. */
24
25 /* Define the bit, byte, and word ordering of the machine. */
26 #define TARGET_BYTE_ORDER BIG_ENDIAN
27
28 /* We cache information about saved registers in the frame structure,
29 to save us from having to re-scan function prologues every time
30 a register in a non-current frame is accessed. */
31
32 #define EXTRA_FRAME_INFO \
33 struct frame_saved_regs *fsr; \
34 CORE_ADDR locals_pointer; \
35 CORE_ADDR args_pointer;
36
37 /* Zero the frame_saved_regs pointer when the frame is initialized,
38 so that FRAME_FIND_SAVED_REGS () will know to allocate and
39 initialize a frame_saved_regs struct the first time it is called.
40 Set the arg_pointer to -1, which is not valid; 0 and other values
41 indicate real, cached values. */
42
43 #define INIT_EXTRA_FRAME_INFO(fromleaf, fi) \
44 init_extra_frame_info (fromleaf, fi)
45 extern void init_extra_frame_info ();
46
47 #define IEEE_FLOAT
48
49 /* Offset from address of function to start of its code.
50 Zero on most machines. */
51
52 #define FUNCTION_START_OFFSET 0
53
54 /* Advance PC across any function entry prologue instructions
55 to reach some "real" code. */
56
57 #define SKIP_PROLOGUE(frompc) \
58 { (frompc) = skip_prologue (frompc); }
59 extern CORE_ADDR skip_prologue ();
60
61 /* The m88k kernel aligns all instructions on 4-byte boundaries. The
62 kernel also uses the least significant two bits for its own hocus
63 pocus. When gdb receives an address from the kernel, it needs to
64 preserve those right-most two bits, but gdb also needs to be careful
65 to realize that those two bits are not really a part of the address
66 of an instruction. Shrug. */
67
68 #define ADDR_BITS_REMOVE(addr) ((addr) & ~3)
69 #define ADDR_BITS_SET(addr) (((addr) | 0x00000002) - 4)
70
71 /* Immediately after a function call, return the saved pc.
72 Can't always go through the frames for this because on some machines
73 the new frame is not set up until the new function executes
74 some instructions. */
75
76 #define SAVED_PC_AFTER_CALL(frame) \
77 (ADDR_BITS_REMOVE (read_register (SRP_REGNUM)))
78
79 /* Stack grows downward. */
80
81 #define INNER_THAN <
82
83 /* Sequence of bytes for breakpoint instruction. */
84
85 /* instruction 0xF000D1FF is 'tb0 0,r0,511'
86 If Bit bit 0 of r0 is clear (always true),
87 initiate exception processing (trap).
88 */
89 #define BREAKPOINT {0xF0, 0x00, 0xD1, 0xFF}
90
91 /* Amount PC must be decremented by after a breakpoint.
92 This is often the number of bytes in BREAKPOINT
93 but not always. */
94
95 #define DECR_PC_AFTER_BREAK 0
96
97 /* Nonzero if instruction at PC is a return instruction. */
98 /* 'jmp r1' or 'jmp.n r1' is used to return from a subroutine. */
99
100 #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 2) == 0xF800)
101
102 /* This is taken care of in print_floating [IEEE_FLOAT]. */
103
104 #define INVALID_FLOAT(p,len) 0
105
106 /* Say how long (ordinary) registers are. */
107
108 #define REGISTER_TYPE long
109
110 /* Number of machine registers */
111
112 #define GP_REGS (38)
113 #define FP_REGS (32)
114 #define NUM_REGS (GP_REGS + FP_REGS)
115
116 /* Initializer for an array of names of registers.
117 There should be NUM_REGS strings in this initializer. */
118
119 #define REGISTER_NAMES {\
120 "r0",\
121 "r1",\
122 "r2",\
123 "r3",\
124 "r4",\
125 "r5",\
126 "r6",\
127 "r7",\
128 "r8",\
129 "r9",\
130 "r10",\
131 "r11",\
132 "r12",\
133 "r13",\
134 "r14",\
135 "r15",\
136 "r16",\
137 "r17",\
138 "r18",\
139 "r19",\
140 "r20",\
141 "r21",\
142 "r22",\
143 "r23",\
144 "r24",\
145 "r25",\
146 "r26",\
147 "r27",\
148 "r28",\
149 "r29",\
150 "r30",\
151 "r31",\
152 "psr",\
153 "fpsr",\
154 "fpcr",\
155 "sxip",\
156 "snip",\
157 "sfip",\
158 "x0",\
159 "x1",\
160 "x2",\
161 "x3",\
162 "x4",\
163 "x5",\
164 "x6",\
165 "x7",\
166 "x8",\
167 "x9",\
168 "x10",\
169 "x11",\
170 "x12",\
171 "x13",\
172 "x14",\
173 "x15",\
174 "x16",\
175 "x17",\
176 "x18",\
177 "x19",\
178 "x20",\
179 "x21",\
180 "x22",\
181 "x23",\
182 "x24",\
183 "x25",\
184 "x26",\
185 "x27",\
186 "x28",\
187 "x29",\
188 "x30",\
189 "x31",\
190 "vbr",\
191 "dmt0",\
192 "dmd0",\
193 "dma0",\
194 "dmt1",\
195 "dmd1",\
196 "dma1",\
197 "dmt2",\
198 "dmd2",\
199 "dma2",\
200 "sr0",\
201 "sr1",\
202 "sr2",\
203 "sr3",\
204 "fpecr",\
205 "fphs1",\
206 "fpls1",\
207 "fphs2",\
208 "fpls2",\
209 "fppt",\
210 "fprh",\
211 "fprl",\
212 "fpit",\
213 "fpsr",\
214 "fpcr",\
215 }
216
217
218 /* Register numbers of various important registers.
219 Note that some of these values are "real" register numbers,
220 and correspond to the general registers of the machine,
221 and some are "phony" register numbers which are too large
222 to be actual register numbers as far as the user is concerned
223 but do serve to get the desired values when passed to read_register. */
224
225 #define R0_REGNUM 0 /* Contains the constant zero */
226 #define SRP_REGNUM 1 /* Contains subroutine return pointer */
227 #define RV_REGNUM 2 /* Contains simple return values */
228 #define SRA_REGNUM 12 /* Contains address of struct return values */
229 #define SP_REGNUM 31 /* Contains address of top of stack */
230
231 /* Instruction pointer notes...
232
233 On the m88100:
234
235 * cr04 = sxip. On exception, contains the excepting pc (probably).
236 On rte, is ignored.
237
238 * cr05 = snip. On exception, contains the NPC (next pc). On rte,
239 pc is loaded from here.
240
241 * cr06 = sfip. On exception, contains the NNPC (next next pc). On
242 rte, the NPC is loaded from here.
243
244 * lower two bits of each are flag bits. Bit 1 is V means address
245 is valid. If address is not valid, bit 0 is ignored. Otherwise,
246 bit 0 is E and asks for an exception to be taken if this
247 instruction is executed.
248
249 On the m88110:
250
251 * cr04 = exip. On exception, contains the address of the excepting
252 pc (always). On rte, pc is loaded from here. Bit 0, aka the D
253 bit, is a flag saying that the offending instruction was in a
254 branch delay slot. If set, then cr05 contains the NPC.
255
256 * cr05 = enip. On exception, if the instruction pointed to by cr04
257 was in a delay slot as indicated by the bit 0 of cr04, aka the D
258 bit, the cr05 contains the NPC. Otherwise ignored.
259
260 * cr06 is invalid */
261
262 #define SXIP_REGNUM 35 /* On m88100, Contains Shadow Execute
263 Instruction Pointer. */
264 #define SNIP_REGNUM 36 /* On m88100, Contains Shadow Next
265 Instruction Pointer. */
266 #define SFIP_REGNUM 37 /* On m88100, Contains Shadow Fetched
267 Intruction pointer. */
268
269 #define EXIP_REGNUM 35 /* On m88110, Contains Exception
270 Executing Instruction Pointer. */
271 #define ENIP_REGNUM 36 /* On m88110, Contains the Exception
272 Next Instruction Pointer. */
273
274 #define PC_REGNUM SXIP_REGNUM /* Program Counter */
275 #define NPC_REGNUM SNIP_REGNUM /* Next Program Counter */
276 #define NNPC_REGNUM SFIP_REGNUM /* Next Next Program Counter */
277
278 #define PSR_REGNUM 32 /* Processor Status Register */
279 #define FPSR_REGNUM 33 /* Floating Point Status Register */
280 #define FPCR_REGNUM 34 /* Floating Point Control Register */
281 #define XFP_REGNUM 38 /* First Extended Float Register */
282 #define X0_REGNUM XFP_REGNUM /* Which also contains the constant zero */
283
284 /* This is rather a confusing lie. Our m88k port using a stack pointer value
285 for the frame address. Hence, the frame address and the frame pointer are
286 only indirectly related. The value of this macro is the register number
287 fetched by the machine "independent" portions of gdb when they want to know
288 about a frame address. Thus, we lie here and claim that FP_REGNUM is
289 SP_REGNUM. */
290 #define FP_REGNUM SP_REGNUM /* Reg fetched to locate frame when pgm stops */
291 #define ACTUAL_FP_REGNUM 30
292
293 /* PSR status bit definitions. */
294
295 #define PSR_MODE 0x80000000
296 #define PSR_BYTE_ORDER 0x40000000
297 #define PSR_SERIAL_MODE 0x20000000
298 #define PSR_CARRY 0x10000000
299 #define PSR_SFU_DISABLE 0x000003f0
300 #define PSR_SFU1_DISABLE 0x00000008
301 #define PSR_MXM 0x00000004
302 #define PSR_IND 0x00000002
303 #define PSR_SFRZ 0x00000001
304
305
306
307 /* The following two comments come from the days prior to the m88110
308 port. The m88110 handles the instruction pointers differently. I
309 do not know what any m88110 kernels do as the m88110 port I'm
310 working with is for an embedded system. rich@cygnus.com
311 13-sept-93. */
312
313 /* BCS requires that the SXIP_REGNUM (or PC_REGNUM) contain the
314 address of the next instr to be executed when a breakpoint occurs.
315 Because the kernel gets the next instr (SNIP_REGNUM), the instr in
316 SNIP needs to be put back into SFIP, and the instr in SXIP should
317 be shifted to SNIP */
318
319 /* Are you sitting down? It turns out that the 88K BCS (binary
320 compatibility standard) folks originally felt that the debugger
321 should be responsible for backing up the IPs, not the kernel (as is
322 usually done). Well, they have reversed their decision, and in
323 future releases our kernel will be handling the backing up of the
324 IPs. So, eventually, we won't need to do the SHIFT_INST_REGS
325 stuff. But, for now, since there are 88K systems out there that do
326 need the debugger to do the IP shifting, and since there will be
327 systems where the kernel does the shifting, the code is a little
328 more complex than perhaps it needs to be (we still go inside
329 SHIFT_INST_REGS, and if the shifting hasn't occurred then gdb goes
330 ahead and shifts). */
331
332 extern int target_is_m88110;
333 #define SHIFT_INST_REGS() \
334 if (!target_is_m88110) \
335 { \
336 CORE_ADDR pc = read_register (PC_REGNUM); \
337 CORE_ADDR npc = read_register (NPC_REGNUM); \
338 if (pc != npc) \
339 { \
340 write_register (NNPC_REGNUM, npc); \
341 write_register (NPC_REGNUM, pc); \
342 } \
343 }
344
345 /* Storing the following registers is a no-op. */
346 #define CANNOT_STORE_REGISTER(regno) (((regno) == R0_REGNUM) \
347 || ((regno) == X0_REGNUM))
348
349 /* Number of bytes of storage in the actual machine representation
350 for register N. On the m88k, the general purpose registers are 4
351 bytes and the 88110 extended registers are 10 bytes. */
352
353 #define REGISTER_RAW_SIZE(N) ((N) < XFP_REGNUM ? 4 : 10)
354
355 /* Total amount of space needed to store our copies of the machine's
356 register state, the array `registers'. */
357
358 #define REGISTER_BYTES ((GP_REGS * REGISTER_RAW_SIZE(0)) \
359 + (FP_REGS * REGISTER_RAW_SIZE(XFP_REGNUM)))
360
361 /* Index within `registers' of the first byte of the space for
362 register N. */
363
364 #define REGISTER_BYTE(N) (((N) * REGISTER_RAW_SIZE(0)) \
365 + ((N) >= XFP_REGNUM \
366 ? (((N) - XFP_REGNUM) \
367 * REGISTER_RAW_SIZE(XFP_REGNUM)) \
368 : 0))
369
370 /* Number of bytes of storage in the program's representation for
371 register N. On the m88k, all registers are 4 bytes excepting the
372 m88110 extended registers which are 8 byte doubles. */
373
374 #define REGISTER_VIRTUAL_SIZE(N) ((N) < XFP_REGNUM ? 4 : 8)
375
376 /* Largest value REGISTER_RAW_SIZE can have. */
377
378 #define MAX_REGISTER_RAW_SIZE (REGISTER_RAW_SIZE(XFP_REGNUM))
379
380 /* Largest value REGISTER_VIRTUAL_SIZE can have.
381 Are FPS1, FPS2, FPR "virtual" regisers? */
382
383 #define MAX_REGISTER_VIRTUAL_SIZE (REGISTER_RAW_SIZE(XFP_REGNUM))
384
385 /* Nonzero if register N requires conversion
386 from raw format to virtual format. */
387
388 #define REGISTER_CONVERTIBLE(N) ((N) >= XFP_REGNUM)
389
390 /* Convert data from raw format for register REGNUM
391 to virtual format for register REGNUM. */
392
393 extern const struct ext_format ext_format_m88110;
394 #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
395 { \
396 if ((REGNUM) < XFP_REGNUM) \
397 memcpy ((TO), (FROM), REGISTER_RAW_SIZE (REGNUM)); \
398 else ieee_extended_to_double(&ext_format_m88110, \
399 (FROM), (double *)(TO)); \
400 }
401
402 /* Convert data from virtual format for register REGNUM
403 to raw format for register REGNUM. */
404
405 #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
406 { \
407 if ((REGNUM) < XFP_REGNUM) \
408 memcpy ((TO), (FROM), REGISTER_RAW_SIZE (REGNUM)); \
409 else double_to_ieee_extended (&ext_format_m88110, \
410 (double *)(FROM), (TO)); \
411 }
412
413 /* Return the GDB type object for the "standard" data type
414 of data in register N. */
415
416 #define REGISTER_VIRTUAL_TYPE(N) \
417 ((N) >= XFP_REGNUM \
418 ? builtin_type_double \
419 : ((N) == PC_REGNUM || (N) == FP_REGNUM || (N) == SP_REGNUM \
420 ? lookup_pointer_type (builtin_type_void) : builtin_type_int))
421
422 /* The 88k call/return conventions call for "small" values to be returned
423 into consecutive registers starting from r2. */
424
425 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
426 memcpy ((VALBUF), &(((char *)REGBUF)[REGISTER_BYTE(RV_REGNUM)]), TYPE_LENGTH (TYPE))
427
428 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
429
430 /* Write into appropriate registers a function return value
431 of type TYPE, given in virtual format. */
432
433 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
434 write_register_bytes (2*REGISTER_RAW_SIZE(0), (VALBUF), TYPE_LENGTH (TYPE))
435
436 /* In COFF, if PCC says a parameter is a short or a char, do not
437 change it to int (it seems the convention is to change it). */
438
439 #define BELIEVE_PCC_PROMOTION 1
440
441 /* Describe the pointer in each stack frame to the previous stack frame
442 (its caller). */
443
444 /* FRAME_CHAIN takes a frame's nominal address
445 and produces the frame's chain-pointer.
446
447 However, if FRAME_CHAIN_VALID returns zero,
448 it means the given frame is the outermost one and has no caller. */
449
450 extern CORE_ADDR frame_chain ();
451 extern int frame_chain_valid ();
452 extern int frameless_function_invocation ();
453
454 #define FRAME_CHAIN(thisframe) \
455 frame_chain (thisframe)
456
457 #define FRAMELESS_FUNCTION_INVOCATION(frame, fromleaf) \
458 fromleaf = frameless_function_invocation (frame)
459
460 /* Define other aspects of the stack frame. */
461
462 #define FRAME_SAVED_PC(FRAME) \
463 frame_saved_pc (FRAME)
464 extern CORE_ADDR frame_saved_pc ();
465
466 #define FRAME_ARGS_ADDRESS(fi) \
467 frame_args_address (fi)
468 extern CORE_ADDR frame_args_address ();
469
470 #define FRAME_LOCALS_ADDRESS(fi) \
471 frame_locals_address (fi)
472 extern CORE_ADDR frame_locals_address ();
473
474 /* Return number of args passed to a frame.
475 Can return -1, meaning no way to tell. */
476
477 #define FRAME_NUM_ARGS(numargs, fi) ((numargs) = -1)
478
479 /* Return number of bytes at start of arglist that are not really args. */
480
481 #define FRAME_ARGS_SKIP 0
482
483 /* Put here the code to store, into a struct frame_saved_regs,
484 the addresses of the saved registers of frame described by FRAME_INFO.
485 This includes special registers such as pc and fp saved in special
486 ways in the stack frame. sp is even more special:
487 the address we return for it IS the sp for the next frame. */
488
489 /* On the 88k, parameter registers get stored into the so called "homing"
490 area. This *always* happens when you compiled with GCC and use -g.
491 Also, (with GCC and -g) the saving of the parameter register values
492 always happens right within the function prologue code, so these register
493 values can generally be relied upon to be already copied into their
494 respective homing slots by the time you will normally try to look at
495 them (we hope).
496
497 Note that homing area stack slots are always at *positive* offsets from
498 the frame pointer. Thus, the homing area stack slots for the parameter
499 registers (passed values) for a given function are actually part of the
500 frame area of the caller. This is unusual, but it should not present
501 any special problems for GDB.
502
503 Note also that on the 88k, we are only interested in finding the
504 registers that might have been saved in memory. This is a subset of
505 the whole set of registers because the standard calling sequence allows
506 the called routine to clobber many registers.
507
508 We could manage to locate values for all of the so called "preserved"
509 registers (some of which may get saved within any particular frame) but
510 that would require decoding all of the tdesc information. That would be
511 nice information for GDB to have, but it is not strictly manditory if we
512 can live without the ability to look at values within (or backup to)
513 previous frames.
514 */
515
516 struct frame_saved_regs;
517 struct frame_info;
518
519 void frame_find_saved_regs PARAMS((struct frame_info *fi,
520 struct frame_saved_regs *fsr));
521
522 #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
523 frame_find_saved_regs (frame_info, &frame_saved_regs)
524
525 \f
526 /* There is not currently a functioning way to call functions in the
527 inferior. */
528
529 /* But if there was this is where we'd put the call dummy. */
530 /* #define CALL_DUMMY_LOCATION AFTER_TEXT_END */
531
532 /* When popping a frame on the 88k (say when doing a return command), the
533 calling function only expects to have the "preserved" registers restored.
534 Thus, those are the only ones that we even try to restore here. */
535
536 #define POP_FRAME pop_frame ()
537 extern void pop_frame ();