OSDN Git Service

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