OSDN Git Service

2004-01-02 Michael Chastain <mec.gnu@mindspring.com>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / config / sparc / tm-sparc.h
1 /* Target machine sub-parameters for SPARC, for GDB, the GNU debugger.
2    This is included by other tm-*.h files to define SPARC cpu-related info.
3    Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4    1998, 1999, 2000, 2001, 2002, 2003
5    Free Software Foundation, Inc.
6    Contributed by Michael Tiemann (tiemann@mcc.com)
7
8    This file is part of GDB.
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330,
23    Boston, MA 02111-1307, USA.  */
24
25 #include "regcache.h"
26
27 struct type;
28 struct value;
29 struct frame_info;
30
31 /*
32  * The following enums are purely for the convenience of the GDB 
33  * developer, when debugging GDB.
34  */
35
36 enum {  /* Sparc general registers, for all sparc versions.  */
37   G0_REGNUM, G1_REGNUM, G2_REGNUM, G3_REGNUM, 
38   G4_REGNUM, G5_REGNUM, G6_REGNUM, G7_REGNUM, 
39   O0_REGNUM, O1_REGNUM, O2_REGNUM, O3_REGNUM, 
40   O4_REGNUM, O5_REGNUM, O6_REGNUM, O7_REGNUM,
41   L0_REGNUM, L1_REGNUM, L2_REGNUM, L3_REGNUM, 
42   L4_REGNUM, L5_REGNUM, L6_REGNUM, L7_REGNUM, 
43   I0_REGNUM, I1_REGNUM, I2_REGNUM, I3_REGNUM, 
44   I4_REGNUM, I5_REGNUM, I6_REGNUM, I7_REGNUM,
45   FP0_REGNUM            /* Floating point register 0 */
46 };
47
48 enum {  /* Sparc general registers, alternate names.  */
49   R0_REGNUM,  R1_REGNUM,  R2_REGNUM,  R3_REGNUM, 
50   R4_REGNUM,  R5_REGNUM,  R6_REGNUM,  R7_REGNUM, 
51   R8_REGNUM,  R9_REGNUM,  R10_REGNUM, R11_REGNUM, 
52   R12_REGNUM, R13_REGNUM, R14_REGNUM, R15_REGNUM, 
53   R16_REGNUM, R17_REGNUM, R18_REGNUM, R19_REGNUM, 
54   R20_REGNUM, R21_REGNUM, R22_REGNUM, R23_REGNUM, 
55   R24_REGNUM, R25_REGNUM, R26_REGNUM, R27_REGNUM, 
56   R28_REGNUM, R29_REGNUM, R30_REGNUM, R31_REGNUM
57 };
58
59 enum {                  /* Sparc32 control registers.  */
60   PS_REGNUM  = 65,      /* PC, NPC, and Y are omitted because */
61   WIM_REGNUM = 66,      /* they have different values depending on */
62   TBR_REGNUM = 67,      /* 32-bit / 64-bit mode.  */
63   FPS_REGNUM = 70,
64   CPS_REGNUM = 71
65 };
66
67 /* v9 misc. and priv. regs */
68
69 /* Note: specifying values explicitly for documentation purposes.  */
70 enum {  /* Sparc64 control registers, excluding Y, PC, and NPC.  */
71   CCR_REGNUM = 82,              /* Condition Code Register (%xcc,%icc) */
72   FSR_REGNUM = 83,              /* Floating Point State */
73   FPRS_REGNUM = 84,             /* Floating Point Registers State */
74   ASI_REGNUM = 86,              /* Alternate Space Identifier */
75   VER_REGNUM = 87,              /* Version register */
76   TICK_REGNUM = 88,             /* Tick register */
77   PIL_REGNUM = 89,              /* Processor Interrupt Level */
78   PSTATE_REGNUM = 90,           /* Processor State */
79   TSTATE_REGNUM = 91,           /* Trap State */
80   TBA_REGNUM = 92,              /* Trap Base Address */
81   TL_REGNUM = 93,               /* Trap Level */
82   TT_REGNUM = 94,               /* Trap Type */
83   TPC_REGNUM = 95,              /* Trap pc */
84   TNPC_REGNUM = 96,             /* Trap npc */
85   WSTATE_REGNUM = 97,           /* Window State */
86   CWP_REGNUM = 98,              /* Current Window Pointer */
87   CANSAVE_REGNUM = 99,          /* Savable Windows */
88   CANRESTORE_REGNUM = 100,      /* Restorable Windows */
89   CLEANWIN_REGNUM = 101,        /* Clean Windows */
90   OTHERWIN_REGNUM = 102,        /* Other Windows */
91   ASR16_REGNUM = 103,           /* Ancillary State Registers */
92   ASR17_REGNUM = 104,
93   ASR18_REGNUM = 105,
94   ASR19_REGNUM = 106,
95   ASR20_REGNUM = 107,
96   ASR21_REGNUM = 108,
97   ASR22_REGNUM = 109,
98   ASR23_REGNUM = 110,
99   ASR24_REGNUM = 111,
100   ASR25_REGNUM = 112,
101   ASR26_REGNUM = 113,
102   ASR27_REGNUM = 114,
103   ASR28_REGNUM = 115,
104   ASR29_REGNUM = 116,
105   ASR30_REGNUM = 117,
106   ASR31_REGNUM = 118,
107   ICC_REGNUM   = 119,           /* 32 bit condition codes */
108   XCC_REGNUM   = 120,           /* 64 bit condition codes */
109   FCC0_REGNUM  = 121,           /* fp cc reg 0 */
110   FCC1_REGNUM  = 122,           /* fp cc reg 1 */
111   FCC2_REGNUM  = 123,           /* fp cc reg 2 */
112   FCC3_REGNUM  = 124            /* fp cc reg 3 */
113 };
114
115 /*
116  * Make sparc target multi-archable: April 2000
117  */
118
119 /* Multi-arch definition of TARGET_IS_SPARC64, TARGET_ELF64 */
120 #undef  GDB_TARGET_IS_SPARC64
121 #define GDB_TARGET_IS_SPARC64 \
122      (sparc_intreg_size () == 8)
123 #undef  TARGET_ELF64
124 #define TARGET_ELF64 \
125      (sparc_intreg_size () == 8)
126 extern int sparc_intreg_size (void);
127
128 /*
129  * The following defines should ONLY appear for MULTI_ARCH.
130  */
131
132 /* Multi-arch the nPC and Y registers.  */
133 #define Y_REGNUM              (sparc_y_regnum ())
134
135 /* On the Sun 4 under SunOS, the compile will leave a fake insn which
136    encodes the structure size being returned.  If we detect such
137    a fake insn, step past it.  */
138
139 #define PC_ADJUST(PC) sparc_pc_adjust (PC)
140 extern CORE_ADDR sparc_pc_adjust (CORE_ADDR);
141
142 /* If an argument is declared "register", Sun cc will keep it in a register,
143    never saving it onto the stack.  So we better not believe the "p" symbol
144    descriptor stab.  */
145
146 #define DEPRECATE_USE_REGISTER_NOT_ARG
147
148 /* For acc, there's no need to correct LBRAC entries by guessing how
149    they should work.  In fact, this is harmful because the LBRAC
150    entries now all appear at the end of the function, not intermixed
151    with the SLINE entries.  n_opt_found detects acc for Solaris binaries;
152    function_stab_type detects acc for SunOS4 binaries.
153
154    For binary from SunOS4 /bin/cc, need to correct LBRAC's.
155
156    For gcc, like acc, don't correct.  */
157
158 #define SUN_FIXED_LBRAC_BUG \
159   (n_opt_found \
160    || function_stab_type == N_STSYM \
161    || function_stab_type == N_GSYM \
162    || processing_gcc_compilation)
163
164 /* Do variables in the debug stabs occur after the N_LBRAC or before it?
165    acc: after, gcc: before, SunOS4 /bin/cc: before.  */
166
167 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) \
168   (!(gcc_p) \
169    && (n_opt_found \
170        || function_stab_type == N_STSYM \
171        || function_stab_type == N_GSYM))
172
173 /* Sequence of bytes for breakpoint instruction (ta 1). */
174
175 extern const unsigned char *sparc_breakpoint_from_pc (CORE_ADDR *pc, int *len);
176 #define BREAKPOINT_FROM_PC(PC,LEN) sparc_breakpoint_from_pc ((PC), (LEN))
177
178 /* Register numbers of various important registers.
179    Note that some of these values are "real" register numbers,
180    and correspond to the general registers of the machine,
181    and some are "phony" register numbers which are too large
182    to be actual register numbers as far as the user is concerned
183    but do serve to get the desired values when passed to read_register.  */
184
185 #define G0_REGNUM 0             /* %g0 */
186 #define G1_REGNUM 1             /* %g1 */
187 #define O0_REGNUM 8             /* %o0 */
188 #define RP_REGNUM 15            /* Contains return address value, *before* \
189                                    any windows get switched.  */
190 #define O7_REGNUM 15            /* Last local reg not saved on stack frame */
191 #define L0_REGNUM 16            /* First local reg that's saved on stack frame
192                                    rather than in machine registers */
193 #define I0_REGNUM 24            /* %i0 */
194 #define I7_REGNUM 31            /* Last local reg saved on stack frame */
195 #define PS_REGNUM 65            /* Contains processor status */
196 #define PS_FLAG_CARRY 0x100000  /* Carry bit in PS */
197 #define WIM_REGNUM 66           /* Window Invalid Mask (not really supported) */
198 #define TBR_REGNUM 67           /* Trap Base Register (not really supported) */
199 #define FPS_REGNUM 70           /* Floating point status register */
200 #define CPS_REGNUM 71           /* Coprocessor status register */
201
202 /* Writing to %g0 is a noop (not an error or exception or anything like
203    that, however).  */
204
205 #define CANNOT_STORE_REGISTER(regno) ((regno) == G0_REGNUM)
206
207 #define DEPRECATED_PRINT_EXTRA_FRAME_INFO(FI) \
208      sparc_print_extra_frame_info (FI)
209 extern void sparc_print_extra_frame_info (struct frame_info *);
210
211 /* DEPRECATED_INIT_EXTRA_FRAME_INFO needs the PC to detect flat
212    frames.  */
213
214 #define DEPRECATED_INIT_FRAME_PC_FIRST(FROMLEAF, PREV) \
215   ((FROMLEAF) ? DEPRECATED_SAVED_PC_AFTER_CALL ((PREV)->next) : \
216               (PREV)->next ? DEPRECATED_FRAME_SAVED_PC ((PREV)->next) : read_pc ())
217
218 /* Define other aspects of the stack frame.  */
219
220 /* The location of I0 w.r.t SP.  This is actually dependent on how the
221    system's window overflow/underflow routines are written.  Most
222    vendors save the L regs followed by the I regs (at the higher
223    address).  Some vendors get it wrong.  */
224
225 #define FRAME_SAVED_L0  0
226 #define FRAME_SAVED_I0  (8 * DEPRECATED_REGISTER_RAW_SIZE (L0_REGNUM))
227
228 /* Things needed for making the inferior call functions.  */
229 /*
230  * First of all, let me give my opinion of what the DUMMY_FRAME
231  * actually looks like.
232  *
233  *               |                                 |
234  *               |                                 |
235  *               + - - - - - - - - - - - - - - - - +<-- fp (level 0)
236  *               |                                 |
237  *               |                                 |
238  *               |                                 |
239  *               |                                 |
240  *               |  Frame of innermost program     |
241  *               |           function              |
242  *               |                                 |
243  *               |                                 |
244  *               |                                 |
245  *               |                                 |
246  *               |                                 |
247  *               |---------------------------------|<-- sp (level 0), fp (c)
248  *               |                                 |
249  *     DUMMY     |             fp0-31              |
250  *               |                                 |
251  *               |             ------              |<-- fp - 0x80
252  *     FRAME     |              g0-7               |<-- fp - 0xa0
253  *               |              i0-7               |<-- fp - 0xc0
254  *               |             other               |<-- fp - 0xe0
255  *               |               ?                 |
256  *               |               ?                 |
257  *               |---------------------------------|<-- sp' = fp - 0x140
258  *               |                                 |
259  * xcution start |                                 |
260  * sp' + 0x94 -->|        CALL_DUMMY (x code)      |
261  *               |                                 |
262  *               |                                 |
263  *               |---------------------------------|<-- sp'' = fp - 0x200
264  *               |  align sp to 8 byte boundary    |
265  *               |     ==> args to fn <==          |
266  *  Room for     |                                 |
267  * i & l's + agg | CALL_DUMMY_STACK_ADJUST = 0x0x44|
268  *               |---------------------------------|<-- final sp (variable)
269  *               |                                 |
270  *               |   Where function called will    |
271  *               |           build frame.          |
272  *               |                                 |
273  *               |                                 |
274  *
275  *   I understand everything in this picture except what the space
276  * between fp - 0xe0 and fp - 0x140 is used for.  Oh, and I don't
277  * understand why there's a large chunk of CALL_DUMMY that never gets
278  * executed (its function is superceeded by
279  * DEPRECATED_PUSH_DUMMY_FRAME; they are designed to do the same
280  * thing).
281  *
282  *   DEPRECATED_PUSH_DUMMY_FRAME saves the registers above sp' and
283  * pushes the * register file stack down one.
284  *
285  *   call_function then writes CALL_DUMMY, pushes the args onto the
286  * stack, and adjusts the stack pointer.
287  
288    call_function_by_hand then starts execution (in the middle of
289    CALL_DUMMY, as directed by call_function).  */
290
291 #ifndef CALL_DUMMY
292 /* This sequence of words is the instructions
293
294    00:   bc 10 00 01     mov  %g1, %fp
295    04:   9d e3 80 00     save  %sp, %g0, %sp
296    08:   bc 10 00 02     mov  %g2, %fp
297    0c:   be 10 00 03     mov  %g3, %i7
298    10:   da 03 a0 58     ld  [ %sp + 0x58 ], %o5
299    14:   d8 03 a0 54     ld  [ %sp + 0x54 ], %o4
300    18:   d6 03 a0 50     ld  [ %sp + 0x50 ], %o3
301    1c:   d4 03 a0 4c     ld  [ %sp + 0x4c ], %o2
302    20:   d2 03 a0 48     ld  [ %sp + 0x48 ], %o1
303    24:   40 00 00 00     call  <fun>
304    28:   d0 03 a0 44     ld  [ %sp + 0x44 ], %o0
305    2c:   01 00 00 00     nop 
306    30:   91 d0 20 01     ta  1
307    34:   01 00 00 00     nop
308
309    NOTES:
310    * the first four instructions are necessary only on the simulator.
311    * this is a multiple of 8 (not only 4) bytes.
312    * the `call' insn is a relative, not an absolute call.
313    * the `nop' at the end is needed to keep the trap from
314      clobbering things (if NPC pointed to garbage instead).
315  */
316
317 #endif /* CALL_DUMMY */
318
319 /* Sparc has no reliable single step ptrace call */
320
321 #define SOFTWARE_SINGLE_STEP_P() 1
322 extern void sparc_software_single_step (enum target_signal, int);
323 #define SOFTWARE_SINGLE_STEP(sig,bp_p) sparc_software_single_step (sig,bp_p)
324
325 /* We need more arguments in a frame specification for the
326    "frame" or "info frame" command.  */
327
328 #define SETUP_ARBITRARY_FRAME(argc, argv) setup_arbitrary_frame (argc, argv)
329 extern struct frame_info *setup_arbitrary_frame (int, CORE_ADDR *);
330
331 extern void sparc_do_registers_info (int regnum, int all);
332 #undef DEPRECATED_DO_REGISTERS_INFO
333 #define DEPRECATED_DO_REGISTERS_INFO(REGNUM,ALL) sparc_do_registers_info (REGNUM, ALL)
334
335 /* Optimization for storing registers to the inferior.  The hook
336    DO_DEFERRED_STORES
337    actually executes any deferred stores.  It is called any time
338    we are going to proceed the child, or read its registers.
339    The hook CLEAR_DEFERRED_STORES is called when we want to throw
340    away the inferior process, e.g. when it dies or we kill it.
341    FIXME, this does not handle remote debugging cleanly.  */
342
343 extern int deferred_stores;
344 #define DO_DEFERRED_STORES      \
345   if (deferred_stores)          \
346     target_store_registers (-2);
347 #define CLEAR_DEFERRED_STORES   \
348   deferred_stores = 0;
349
350 /* Select the sparc disassembler */
351
352 #define TM_PRINT_INSN_MACH bfd_mach_sparc
353
354 #define DEPRECATED_EXTRA_STACK_ALIGNMENT_NEEDED 1