xref: /dragonfly/contrib/gdb-7/gdb/i386-tdep.h (revision 5796c8dc)
1*5796c8dcSSimon Schubert /* Target-dependent code for the i386.
2*5796c8dcSSimon Schubert 
3*5796c8dcSSimon Schubert    Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009
4*5796c8dcSSimon Schubert    Free Software Foundation, Inc.
5*5796c8dcSSimon Schubert 
6*5796c8dcSSimon Schubert    This file is part of GDB.
7*5796c8dcSSimon Schubert 
8*5796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
9*5796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
10*5796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
11*5796c8dcSSimon Schubert    (at your option) any later version.
12*5796c8dcSSimon Schubert 
13*5796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
14*5796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
15*5796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*5796c8dcSSimon Schubert    GNU General Public License for more details.
17*5796c8dcSSimon Schubert 
18*5796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
19*5796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20*5796c8dcSSimon Schubert 
21*5796c8dcSSimon Schubert #ifndef I386_TDEP_H
22*5796c8dcSSimon Schubert #define I386_TDEP_H
23*5796c8dcSSimon Schubert 
24*5796c8dcSSimon Schubert struct frame_info;
25*5796c8dcSSimon Schubert struct gdbarch;
26*5796c8dcSSimon Schubert struct reggroup;
27*5796c8dcSSimon Schubert struct regset;
28*5796c8dcSSimon Schubert struct regcache;
29*5796c8dcSSimon Schubert 
30*5796c8dcSSimon Schubert /* GDB's i386 target supports both the 32-bit Intel Architecture
31*5796c8dcSSimon Schubert    (IA-32) and the 64-bit AMD x86-64 architecture.  Internally it uses
32*5796c8dcSSimon Schubert    a similar register layout for both.
33*5796c8dcSSimon Schubert 
34*5796c8dcSSimon Schubert    - General purpose registers
35*5796c8dcSSimon Schubert    - FPU data registers
36*5796c8dcSSimon Schubert    - FPU control registers
37*5796c8dcSSimon Schubert    - SSE data registers
38*5796c8dcSSimon Schubert    - SSE control register
39*5796c8dcSSimon Schubert 
40*5796c8dcSSimon Schubert    The general purpose registers for the x86-64 architecture are quite
41*5796c8dcSSimon Schubert    different from IA-32.  Therefore, gdbarch_fp0_regnum
42*5796c8dcSSimon Schubert    determines the register number at which the FPU data registers
43*5796c8dcSSimon Schubert    start.  The number of FPU data and control registers is the same
44*5796c8dcSSimon Schubert    for both architectures.  The number of SSE registers however,
45*5796c8dcSSimon Schubert    differs and is determined by the num_xmm_regs member of `struct
46*5796c8dcSSimon Schubert    gdbarch_tdep'.  */
47*5796c8dcSSimon Schubert 
48*5796c8dcSSimon Schubert /* Convention for returning structures.  */
49*5796c8dcSSimon Schubert 
50*5796c8dcSSimon Schubert enum struct_return
51*5796c8dcSSimon Schubert {
52*5796c8dcSSimon Schubert   pcc_struct_return,		/* Return "short" structures in memory.  */
53*5796c8dcSSimon Schubert   reg_struct_return		/* Return "short" structures in registers.  */
54*5796c8dcSSimon Schubert };
55*5796c8dcSSimon Schubert 
56*5796c8dcSSimon Schubert /* i386 architecture specific information.  */
57*5796c8dcSSimon Schubert struct gdbarch_tdep
58*5796c8dcSSimon Schubert {
59*5796c8dcSSimon Schubert   /* General-purpose registers.  */
60*5796c8dcSSimon Schubert   struct regset *gregset;
61*5796c8dcSSimon Schubert   int *gregset_reg_offset;
62*5796c8dcSSimon Schubert   int gregset_num_regs;
63*5796c8dcSSimon Schubert   size_t sizeof_gregset;
64*5796c8dcSSimon Schubert 
65*5796c8dcSSimon Schubert   /* Floating-point registers.  */
66*5796c8dcSSimon Schubert   struct regset *fpregset;
67*5796c8dcSSimon Schubert   size_t sizeof_fpregset;
68*5796c8dcSSimon Schubert 
69*5796c8dcSSimon Schubert   /* Register number for %st(0).  The register numbers for the other
70*5796c8dcSSimon Schubert      registers follow from this one.  Set this to -1 to indicate the
71*5796c8dcSSimon Schubert      absence of an FPU.  */
72*5796c8dcSSimon Schubert   int st0_regnum;
73*5796c8dcSSimon Schubert 
74*5796c8dcSSimon Schubert   /* Register number for %mm0.  Set this to -1 to indicate the absence
75*5796c8dcSSimon Schubert      of MMX support.  */
76*5796c8dcSSimon Schubert   int mm0_regnum;
77*5796c8dcSSimon Schubert 
78*5796c8dcSSimon Schubert   /* Number of SSE registers.  */
79*5796c8dcSSimon Schubert   int num_xmm_regs;
80*5796c8dcSSimon Schubert 
81*5796c8dcSSimon Schubert   /* Offset of saved PC in jmp_buf.  */
82*5796c8dcSSimon Schubert   int jb_pc_offset;
83*5796c8dcSSimon Schubert 
84*5796c8dcSSimon Schubert   /* Convention for returning structures.  */
85*5796c8dcSSimon Schubert   enum struct_return struct_return;
86*5796c8dcSSimon Schubert 
87*5796c8dcSSimon Schubert   /* Address range where sigtramp lives.  */
88*5796c8dcSSimon Schubert   CORE_ADDR sigtramp_start;
89*5796c8dcSSimon Schubert   CORE_ADDR sigtramp_end;
90*5796c8dcSSimon Schubert 
91*5796c8dcSSimon Schubert   /* Detect sigtramp.  */
92*5796c8dcSSimon Schubert   int (*sigtramp_p) (struct frame_info *);
93*5796c8dcSSimon Schubert 
94*5796c8dcSSimon Schubert   /* Get address of sigcontext for sigtramp.  */
95*5796c8dcSSimon Schubert   CORE_ADDR (*sigcontext_addr) (struct frame_info *);
96*5796c8dcSSimon Schubert 
97*5796c8dcSSimon Schubert   /* Offset of registers in `struct sigcontext'.  */
98*5796c8dcSSimon Schubert   int *sc_reg_offset;
99*5796c8dcSSimon Schubert   int sc_num_regs;
100*5796c8dcSSimon Schubert 
101*5796c8dcSSimon Schubert   /* Offset of saved PC and SP in `struct sigcontext'.  Usage of these
102*5796c8dcSSimon Schubert      is deprecated, please use `sc_reg_offset' instead.  */
103*5796c8dcSSimon Schubert   int sc_pc_offset;
104*5796c8dcSSimon Schubert   int sc_sp_offset;
105*5796c8dcSSimon Schubert 
106*5796c8dcSSimon Schubert   /* ISA-specific data types.  */
107*5796c8dcSSimon Schubert   struct type *i386_eflags_type;
108*5796c8dcSSimon Schubert   struct type *i386_mxcsr_type;
109*5796c8dcSSimon Schubert   struct type *i386_mmx_type;
110*5796c8dcSSimon Schubert   struct type *i386_sse_type;
111*5796c8dcSSimon Schubert   struct type *i387_ext_type;
112*5796c8dcSSimon Schubert 
113*5796c8dcSSimon Schubert   /* Process record/replay target.  */
114*5796c8dcSSimon Schubert   /* The map for registers because the AMD64's registers order
115*5796c8dcSSimon Schubert      in GDB is not same as I386 instructions.  */
116*5796c8dcSSimon Schubert   const int *record_regmap;
117*5796c8dcSSimon Schubert   /* Parse intx80 args.  */
118*5796c8dcSSimon Schubert   int (*i386_intx80_record) (struct regcache *regcache);
119*5796c8dcSSimon Schubert   /* Parse sysenter args.  */
120*5796c8dcSSimon Schubert   int (*i386_sysenter_record) (struct regcache *regcache);
121*5796c8dcSSimon Schubert   /* Parse syscall args.  */
122*5796c8dcSSimon Schubert   int (*i386_syscall_record) (struct regcache *regcache);
123*5796c8dcSSimon Schubert };
124*5796c8dcSSimon Schubert 
125*5796c8dcSSimon Schubert /* Floating-point registers.  */
126*5796c8dcSSimon Schubert 
127*5796c8dcSSimon Schubert /* All FPU control regusters (except for FIOFF and FOOFF) are 16-bit
128*5796c8dcSSimon Schubert    (at most) in the FPU, but are zero-extended to 32 bits in GDB's
129*5796c8dcSSimon Schubert    register cache.  */
130*5796c8dcSSimon Schubert 
131*5796c8dcSSimon Schubert /* Return non-zero if REGNUM matches the FP register and the FP
132*5796c8dcSSimon Schubert    register set is active.  */
133*5796c8dcSSimon Schubert extern int i386_fp_regnum_p (struct gdbarch *, int);
134*5796c8dcSSimon Schubert extern int i386_fpc_regnum_p (struct gdbarch *, int);
135*5796c8dcSSimon Schubert 
136*5796c8dcSSimon Schubert /* Register numbers of various important registers.  */
137*5796c8dcSSimon Schubert 
138*5796c8dcSSimon Schubert enum i386_regnum
139*5796c8dcSSimon Schubert {
140*5796c8dcSSimon Schubert   I386_EAX_REGNUM,		/* %eax */
141*5796c8dcSSimon Schubert   I386_ECX_REGNUM,		/* %ecx */
142*5796c8dcSSimon Schubert   I386_EDX_REGNUM,		/* %edx */
143*5796c8dcSSimon Schubert   I386_EBX_REGNUM,		/* %ebx */
144*5796c8dcSSimon Schubert   I386_ESP_REGNUM,		/* %esp */
145*5796c8dcSSimon Schubert   I386_EBP_REGNUM,		/* %ebp */
146*5796c8dcSSimon Schubert   I386_ESI_REGNUM,		/* %esi */
147*5796c8dcSSimon Schubert   I386_EDI_REGNUM,		/* %edi */
148*5796c8dcSSimon Schubert   I386_EIP_REGNUM,		/* %eip */
149*5796c8dcSSimon Schubert   I386_EFLAGS_REGNUM,		/* %eflags */
150*5796c8dcSSimon Schubert   I386_CS_REGNUM,		/* %cs */
151*5796c8dcSSimon Schubert   I386_SS_REGNUM,		/* %ss */
152*5796c8dcSSimon Schubert   I386_DS_REGNUM,		/* %ds */
153*5796c8dcSSimon Schubert   I386_ES_REGNUM,		/* %es */
154*5796c8dcSSimon Schubert   I386_FS_REGNUM,		/* %fs */
155*5796c8dcSSimon Schubert   I386_GS_REGNUM,		/* %gs */
156*5796c8dcSSimon Schubert   I386_ST0_REGNUM		/* %st(0) */
157*5796c8dcSSimon Schubert };
158*5796c8dcSSimon Schubert 
159*5796c8dcSSimon Schubert /* Register numbers of RECORD_REGMAP.  */
160*5796c8dcSSimon Schubert 
161*5796c8dcSSimon Schubert enum record_i386_regnum
162*5796c8dcSSimon Schubert {
163*5796c8dcSSimon Schubert   X86_RECORD_REAX_REGNUM,
164*5796c8dcSSimon Schubert   X86_RECORD_RECX_REGNUM,
165*5796c8dcSSimon Schubert   X86_RECORD_REDX_REGNUM,
166*5796c8dcSSimon Schubert   X86_RECORD_REBX_REGNUM,
167*5796c8dcSSimon Schubert   X86_RECORD_RESP_REGNUM,
168*5796c8dcSSimon Schubert   X86_RECORD_REBP_REGNUM,
169*5796c8dcSSimon Schubert   X86_RECORD_RESI_REGNUM,
170*5796c8dcSSimon Schubert   X86_RECORD_REDI_REGNUM,
171*5796c8dcSSimon Schubert   X86_RECORD_R8_REGNUM,
172*5796c8dcSSimon Schubert   X86_RECORD_R9_REGNUM,
173*5796c8dcSSimon Schubert   X86_RECORD_R10_REGNUM,
174*5796c8dcSSimon Schubert   X86_RECORD_R11_REGNUM,
175*5796c8dcSSimon Schubert   X86_RECORD_R12_REGNUM,
176*5796c8dcSSimon Schubert   X86_RECORD_R13_REGNUM,
177*5796c8dcSSimon Schubert   X86_RECORD_R14_REGNUM,
178*5796c8dcSSimon Schubert   X86_RECORD_R15_REGNUM,
179*5796c8dcSSimon Schubert   X86_RECORD_REIP_REGNUM,
180*5796c8dcSSimon Schubert   X86_RECORD_EFLAGS_REGNUM,
181*5796c8dcSSimon Schubert   X86_RECORD_CS_REGNUM,
182*5796c8dcSSimon Schubert   X86_RECORD_SS_REGNUM,
183*5796c8dcSSimon Schubert   X86_RECORD_DS_REGNUM,
184*5796c8dcSSimon Schubert   X86_RECORD_ES_REGNUM,
185*5796c8dcSSimon Schubert   X86_RECORD_FS_REGNUM,
186*5796c8dcSSimon Schubert   X86_RECORD_GS_REGNUM,
187*5796c8dcSSimon Schubert };
188*5796c8dcSSimon Schubert 
189*5796c8dcSSimon Schubert #define I386_NUM_GREGS	16
190*5796c8dcSSimon Schubert #define I386_NUM_FREGS	16
191*5796c8dcSSimon Schubert #define I386_NUM_XREGS  9
192*5796c8dcSSimon Schubert 
193*5796c8dcSSimon Schubert #define I386_SSE_NUM_REGS	(I386_NUM_GREGS + I386_NUM_FREGS \
194*5796c8dcSSimon Schubert 				 + I386_NUM_XREGS)
195*5796c8dcSSimon Schubert 
196*5796c8dcSSimon Schubert /* Size of the largest register.  */
197*5796c8dcSSimon Schubert #define I386_MAX_REGISTER_SIZE	16
198*5796c8dcSSimon Schubert 
199*5796c8dcSSimon Schubert /* Types for i386-specific registers.  */
200*5796c8dcSSimon Schubert extern struct type *i386_eflags_type (struct gdbarch *gdbarch);
201*5796c8dcSSimon Schubert extern struct type *i386_mxcsr_type (struct gdbarch *gdbarch);
202*5796c8dcSSimon Schubert extern struct type *i386_mmx_type (struct gdbarch *gdbarch);
203*5796c8dcSSimon Schubert extern struct type *i386_sse_type (struct gdbarch *gdbarch);
204*5796c8dcSSimon Schubert extern struct type *i387_ext_type (struct gdbarch *gdbarch);
205*5796c8dcSSimon Schubert 
206*5796c8dcSSimon Schubert /* Segment selectors.  */
207*5796c8dcSSimon Schubert #define I386_SEL_RPL	0x0003  /* Requester's Privilege Level mask.  */
208*5796c8dcSSimon Schubert #define I386_SEL_UPL	0x0003	/* User Privilige Level. */
209*5796c8dcSSimon Schubert #define I386_SEL_KPL	0x0000	/* Kernel Privilige Level. */
210*5796c8dcSSimon Schubert 
211*5796c8dcSSimon Schubert /* The length of the longest i386 instruction (according to
212*5796c8dcSSimon Schubert    include/asm-i386/kprobes.h in Linux 2.6.  */
213*5796c8dcSSimon Schubert #define I386_MAX_INSN_LEN (16)
214*5796c8dcSSimon Schubert 
215*5796c8dcSSimon Schubert /* Functions exported from i386-tdep.c.  */
216*5796c8dcSSimon Schubert extern CORE_ADDR i386_pe_skip_trampoline_code (struct frame_info *frame,
217*5796c8dcSSimon Schubert 					       CORE_ADDR pc, char *name);
218*5796c8dcSSimon Schubert extern CORE_ADDR i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc);
219*5796c8dcSSimon Schubert 
220*5796c8dcSSimon Schubert /* Return whether the THIS_FRAME corresponds to a sigtramp routine.  */
221*5796c8dcSSimon Schubert extern int i386_sigtramp_p (struct frame_info *this_frame);
222*5796c8dcSSimon Schubert 
223*5796c8dcSSimon Schubert /* Return the name of register REGNUM.  */
224*5796c8dcSSimon Schubert extern char const *i386_register_name (struct gdbarch * gdbarch, int regnum);
225*5796c8dcSSimon Schubert 
226*5796c8dcSSimon Schubert /* Return non-zero if REGNUM is a member of the specified group.  */
227*5796c8dcSSimon Schubert extern int i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
228*5796c8dcSSimon Schubert 				     struct reggroup *group);
229*5796c8dcSSimon Schubert 
230*5796c8dcSSimon Schubert /* Supply register REGNUM from the general-purpose register set REGSET
231*5796c8dcSSimon Schubert    to register cache REGCACHE.  If REGNUM is -1, do this for all
232*5796c8dcSSimon Schubert    registers in REGSET.  */
233*5796c8dcSSimon Schubert extern void i386_supply_gregset (const struct regset *regset,
234*5796c8dcSSimon Schubert 				 struct regcache *regcache, int regnum,
235*5796c8dcSSimon Schubert 				 const void *gregs, size_t len);
236*5796c8dcSSimon Schubert 
237*5796c8dcSSimon Schubert /* Collect register REGNUM from the register cache REGCACHE and store
238*5796c8dcSSimon Schubert    it in the buffer specified by GREGS and LEN as described by the
239*5796c8dcSSimon Schubert    general-purpose register set REGSET.  If REGNUM is -1, do this for
240*5796c8dcSSimon Schubert    all registers in REGSET.  */
241*5796c8dcSSimon Schubert extern void i386_collect_gregset (const struct regset *regset,
242*5796c8dcSSimon Schubert 				  const struct regcache *regcache,
243*5796c8dcSSimon Schubert 				  int regnum, void *gregs, size_t len);
244*5796c8dcSSimon Schubert 
245*5796c8dcSSimon Schubert /* Return the appropriate register set for the core section identified
246*5796c8dcSSimon Schubert    by SECT_NAME and SECT_SIZE.  */
247*5796c8dcSSimon Schubert extern const struct regset *
248*5796c8dcSSimon Schubert   i386_regset_from_core_section (struct gdbarch *gdbarch,
249*5796c8dcSSimon Schubert 				 const char *sect_name, size_t sect_size);
250*5796c8dcSSimon Schubert 
251*5796c8dcSSimon Schubert 
252*5796c8dcSSimon Schubert extern void i386_displaced_step_fixup (struct gdbarch *gdbarch,
253*5796c8dcSSimon Schubert 				       struct displaced_step_closure *closure,
254*5796c8dcSSimon Schubert 				       CORE_ADDR from, CORE_ADDR to,
255*5796c8dcSSimon Schubert 				       struct regcache *regs);
256*5796c8dcSSimon Schubert 
257*5796c8dcSSimon Schubert /* Initialize a basic ELF architecture variant.  */
258*5796c8dcSSimon Schubert extern void i386_elf_init_abi (struct gdbarch_info, struct gdbarch *);
259*5796c8dcSSimon Schubert 
260*5796c8dcSSimon Schubert /* Initialize a SVR4 architecture variant.  */
261*5796c8dcSSimon Schubert extern void i386_svr4_init_abi (struct gdbarch_info, struct gdbarch *);
262*5796c8dcSSimon Schubert 
263*5796c8dcSSimon Schubert extern int i386_process_record (struct gdbarch *gdbarch,
264*5796c8dcSSimon Schubert                                 struct regcache *regcache, CORE_ADDR addr);
265*5796c8dcSSimon Schubert 
266*5796c8dcSSimon Schubert 
267*5796c8dcSSimon Schubert /* Functions and variables exported from i386bsd-tdep.c.  */
268*5796c8dcSSimon Schubert 
269*5796c8dcSSimon Schubert extern void i386bsd_init_abi (struct gdbarch_info, struct gdbarch *);
270*5796c8dcSSimon Schubert extern CORE_ADDR i386fbsd_sigtramp_start_addr;
271*5796c8dcSSimon Schubert extern CORE_ADDR i386fbsd_sigtramp_end_addr;
272*5796c8dcSSimon Schubert extern CORE_ADDR i386obsd_sigtramp_start_addr;
273*5796c8dcSSimon Schubert extern CORE_ADDR i386obsd_sigtramp_end_addr;
274*5796c8dcSSimon Schubert extern int i386fbsd4_sc_reg_offset[];
275*5796c8dcSSimon Schubert extern int i386fbsd_sc_reg_offset[];
276*5796c8dcSSimon Schubert extern int i386nbsd_sc_reg_offset[];
277*5796c8dcSSimon Schubert extern int i386obsd_sc_reg_offset[];
278*5796c8dcSSimon Schubert extern int i386bsd_sc_reg_offset[];
279*5796c8dcSSimon Schubert 
280*5796c8dcSSimon Schubert #endif /* i386-tdep.h */
281