GDB (API)
/home/stan/gdb/src/gdb/i386-tdep.h
Go to the documentation of this file.
00001 /* Target-dependent code for the i386.
00002 
00003    Copyright (C) 2001-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #ifndef I386_TDEP_H
00021 #define I386_TDEP_H
00022 
00023 struct frame_info;
00024 struct gdbarch;
00025 struct reggroup;
00026 struct regset;
00027 struct regcache;
00028 
00029 /* GDB's i386 target supports both the 32-bit Intel Architecture
00030    (IA-32) and the 64-bit AMD x86-64 architecture.  Internally it uses
00031    a similar register layout for both.
00032 
00033    - General purpose registers
00034    - FPU data registers
00035    - FPU control registers
00036    - SSE data registers
00037    - SSE control register
00038 
00039    The general purpose registers for the x86-64 architecture are quite
00040    different from IA-32.  Therefore, gdbarch_fp0_regnum
00041    determines the register number at which the FPU data registers
00042    start.  The number of FPU data and control registers is the same
00043    for both architectures.  The number of SSE registers however,
00044    differs and is determined by the num_xmm_regs member of `struct
00045    gdbarch_tdep'.  */
00046 
00047 /* Convention for returning structures.  */
00048 
00049 enum struct_return
00050 {
00051   pcc_struct_return,            /* Return "short" structures in memory.  */
00052   reg_struct_return             /* Return "short" structures in registers.  */
00053 };
00054 
00055 /* i386 architecture specific information.  */
00056 struct gdbarch_tdep
00057 {
00058   /* General-purpose registers.  */
00059   struct regset *gregset;
00060   int *gregset_reg_offset;
00061   int gregset_num_regs;
00062   size_t sizeof_gregset;
00063 
00064   /* Floating-point registers.  */
00065   struct regset *fpregset;
00066   size_t sizeof_fpregset;
00067 
00068   /* XSAVE extended state.  */
00069   struct regset *xstateregset;
00070 
00071   /* Register number for %st(0).  The register numbers for the other
00072      registers follow from this one.  Set this to -1 to indicate the
00073      absence of an FPU.  */
00074   int st0_regnum;
00075 
00076   /* Number of MMX registers.  */
00077   int num_mmx_regs;
00078 
00079   /* Register number for %mm0.  Set this to -1 to indicate the absence
00080      of MMX support.  */
00081   int mm0_regnum;
00082 
00083   /* Number of pseudo YMM registers.  */
00084   int num_ymm_regs;
00085 
00086   /* Register number for %ymm0.  Set this to -1 to indicate the absence
00087      of pseudo YMM register support.  */
00088   int ymm0_regnum;
00089 
00090   /* Number of byte registers.  */
00091   int num_byte_regs;
00092 
00093   /* Register pseudo number for %al.  */
00094   int al_regnum;
00095 
00096   /* Number of pseudo word registers.  */
00097   int num_word_regs;
00098 
00099   /* Register number for %ax.  */
00100   int ax_regnum;
00101 
00102   /* Number of pseudo dword registers.  */
00103   int num_dword_regs;
00104 
00105   /* Register number for %eax.  Set this to -1 to indicate the absence
00106      of pseudo dword register support.  */
00107   int eax_regnum;
00108 
00109   /* Number of core registers.  */
00110   int num_core_regs;
00111 
00112   /* Number of SSE registers.  */
00113   int num_xmm_regs;
00114 
00115   /* Bits of the extended control register 0 (the XFEATURE_ENABLED_MASK
00116      register), excluding the x87 bit, which are supported by this GDB.  */
00117 
00118   uint64_t xcr0;
00119 
00120   /* Offset of XCR0 in XSAVE extended state.  */
00121   int xsave_xcr0_offset;
00122 
00123   /* Register names.  */
00124   const char **register_names;
00125 
00126   /* Register number for %ymm0h.  Set this to -1 to indicate the absence
00127      of upper YMM register support.  */
00128   int ymm0h_regnum;
00129 
00130   /* Upper YMM register names.  Only used for tdesc_numbered_register.  */
00131   const char **ymmh_register_names;
00132 
00133   /* Target description.  */
00134   const struct target_desc *tdesc;
00135 
00136   /* Register group function.  */
00137   const void *register_reggroup_p;
00138 
00139   /* Offset of saved PC in jmp_buf.  */
00140   int jb_pc_offset;
00141 
00142   /* Convention for returning structures.  */
00143   enum struct_return struct_return;
00144 
00145   /* Address range where sigtramp lives.  */
00146   CORE_ADDR sigtramp_start;
00147   CORE_ADDR sigtramp_end;
00148 
00149   /* Detect sigtramp.  */
00150   int (*sigtramp_p) (struct frame_info *);
00151 
00152   /* Get address of sigcontext for sigtramp.  */
00153   CORE_ADDR (*sigcontext_addr) (struct frame_info *);
00154 
00155   /* Offset of registers in `struct sigcontext'.  */
00156   int *sc_reg_offset;
00157   int sc_num_regs;
00158 
00159   /* Offset of saved PC and SP in `struct sigcontext'.  Usage of these
00160      is deprecated, please use `sc_reg_offset' instead.  */
00161   int sc_pc_offset;
00162   int sc_sp_offset;
00163 
00164   /* ISA-specific data types.  */
00165   struct type *i386_mmx_type;
00166   struct type *i386_ymm_type;
00167   struct type *i387_ext_type;
00168 
00169   /* Process record/replay target.  */
00170   /* The map for registers because the AMD64's registers order
00171      in GDB is not same as I386 instructions.  */
00172   const int *record_regmap;
00173   /* Parse intx80 args.  */
00174   int (*i386_intx80_record) (struct regcache *regcache);
00175   /* Parse sysenter args.  */
00176   int (*i386_sysenter_record) (struct regcache *regcache);
00177   /* Parse syscall args.  */
00178   int (*i386_syscall_record) (struct regcache *regcache);
00179 };
00180 
00181 /* Floating-point registers.  */
00182 
00183 /* All FPU control regusters (except for FIOFF and FOOFF) are 16-bit
00184    (at most) in the FPU, but are zero-extended to 32 bits in GDB's
00185    register cache.  */
00186 
00187 /* Return non-zero if REGNUM matches the FP register and the FP
00188    register set is active.  */
00189 extern int i386_fp_regnum_p (struct gdbarch *, int);
00190 extern int i386_fpc_regnum_p (struct gdbarch *, int);
00191 
00192 /* Register numbers of various important registers.  */
00193 
00194 enum i386_regnum
00195 {
00196   I386_EAX_REGNUM,              /* %eax */
00197   I386_ECX_REGNUM,              /* %ecx */
00198   I386_EDX_REGNUM,              /* %edx */
00199   I386_EBX_REGNUM,              /* %ebx */
00200   I386_ESP_REGNUM,              /* %esp */
00201   I386_EBP_REGNUM,              /* %ebp */
00202   I386_ESI_REGNUM,              /* %esi */
00203   I386_EDI_REGNUM,              /* %edi */
00204   I386_EIP_REGNUM,              /* %eip */
00205   I386_EFLAGS_REGNUM,           /* %eflags */
00206   I386_CS_REGNUM,               /* %cs */
00207   I386_SS_REGNUM,               /* %ss */
00208   I386_DS_REGNUM,               /* %ds */
00209   I386_ES_REGNUM,               /* %es */
00210   I386_FS_REGNUM,               /* %fs */
00211   I386_GS_REGNUM,               /* %gs */
00212   I386_ST0_REGNUM,              /* %st(0) */
00213   I386_MXCSR_REGNUM = 40,       /* %mxcsr */ 
00214   I386_YMM0H_REGNUM,            /* %ymm0h */
00215   I386_YMM7H_REGNUM = I386_YMM0H_REGNUM + 7
00216 };
00217 
00218 /* Register numbers of RECORD_REGMAP.  */
00219 
00220 enum record_i386_regnum
00221 {
00222   X86_RECORD_REAX_REGNUM,
00223   X86_RECORD_RECX_REGNUM,
00224   X86_RECORD_REDX_REGNUM,
00225   X86_RECORD_REBX_REGNUM,
00226   X86_RECORD_RESP_REGNUM,
00227   X86_RECORD_REBP_REGNUM,
00228   X86_RECORD_RESI_REGNUM,
00229   X86_RECORD_REDI_REGNUM,
00230   X86_RECORD_R8_REGNUM,
00231   X86_RECORD_R9_REGNUM,
00232   X86_RECORD_R10_REGNUM,
00233   X86_RECORD_R11_REGNUM,
00234   X86_RECORD_R12_REGNUM,
00235   X86_RECORD_R13_REGNUM,
00236   X86_RECORD_R14_REGNUM,
00237   X86_RECORD_R15_REGNUM,
00238   X86_RECORD_REIP_REGNUM,
00239   X86_RECORD_EFLAGS_REGNUM,
00240   X86_RECORD_CS_REGNUM,
00241   X86_RECORD_SS_REGNUM,
00242   X86_RECORD_DS_REGNUM,
00243   X86_RECORD_ES_REGNUM,
00244   X86_RECORD_FS_REGNUM,
00245   X86_RECORD_GS_REGNUM,
00246 };
00247 
00248 #define I386_NUM_GREGS  16
00249 #define I386_NUM_XREGS  9
00250 
00251 #define I386_SSE_NUM_REGS       (I386_MXCSR_REGNUM + 1)
00252 #define I386_AVX_NUM_REGS       (I386_YMM7H_REGNUM + 1)
00253 
00254 /* Size of the largest register.  */
00255 #define I386_MAX_REGISTER_SIZE  16
00256 
00257 /* Types for i386-specific registers.  */
00258 extern struct type *i387_ext_type (struct gdbarch *gdbarch);
00259 
00260 /* Checks of different pseudo-registers.  */
00261 extern int i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum);
00262 extern int i386_word_regnum_p (struct gdbarch *gdbarch, int regnum);
00263 extern int i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum);
00264 extern int i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum);
00265 extern int i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum);
00266 
00267 extern const char *i386_pseudo_register_name (struct gdbarch *gdbarch,
00268                                               int regnum);
00269 extern struct type *i386_pseudo_register_type (struct gdbarch *gdbarch,
00270                                                int regnum);
00271 
00272 extern void i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
00273                                                   struct regcache *regcache,
00274                                                   int regnum,
00275                                                   struct value *result);
00276 
00277 extern void i386_pseudo_register_write (struct gdbarch *gdbarch,
00278                                         struct regcache *regcache,
00279                                         int regnum, const gdb_byte *buf);
00280 
00281 /* Segment selectors.  */
00282 #define I386_SEL_RPL    0x0003  /* Requester's Privilege Level mask.  */
00283 #define I386_SEL_UPL    0x0003  /* User Privilige Level.  */
00284 #define I386_SEL_KPL    0x0000  /* Kernel Privilige Level.  */
00285 
00286 /* The length of the longest i386 instruction (according to
00287    include/asm-i386/kprobes.h in Linux 2.6.  */
00288 #define I386_MAX_INSN_LEN (16)
00289 
00290 /* Functions exported from i386-tdep.c.  */
00291 extern CORE_ADDR i386_pe_skip_trampoline_code (struct frame_info *frame,
00292                                                CORE_ADDR pc, char *name);
00293 extern CORE_ADDR i386_skip_main_prologue (struct gdbarch *gdbarch,
00294                                           CORE_ADDR pc);
00295 
00296 /* Return whether the THIS_FRAME corresponds to a sigtramp routine.  */
00297 extern int i386_sigtramp_p (struct frame_info *this_frame);
00298 
00299 /* Return non-zero if REGNUM is a member of the specified group.  */
00300 extern int i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
00301                                      struct reggroup *group);
00302 
00303 /* Supply register REGNUM from the general-purpose register set REGSET
00304    to register cache REGCACHE.  If REGNUM is -1, do this for all
00305    registers in REGSET.  */
00306 extern void i386_supply_gregset (const struct regset *regset,
00307                                  struct regcache *regcache, int regnum,
00308                                  const void *gregs, size_t len);
00309 
00310 /* Collect register REGNUM from the register cache REGCACHE and store
00311    it in the buffer specified by GREGS and LEN as described by the
00312    general-purpose register set REGSET.  If REGNUM is -1, do this for
00313    all registers in REGSET.  */
00314 extern void i386_collect_gregset (const struct regset *regset,
00315                                   const struct regcache *regcache,
00316                                   int regnum, void *gregs, size_t len);
00317 
00318 /* Return the appropriate register set for the core section identified
00319    by SECT_NAME and SECT_SIZE.  */
00320 extern const struct regset *
00321   i386_regset_from_core_section (struct gdbarch *gdbarch,
00322                                  const char *sect_name, size_t sect_size);
00323 
00324 
00325 extern struct displaced_step_closure *i386_displaced_step_copy_insn
00326   (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to,
00327    struct regcache *regs);
00328 extern void i386_displaced_step_fixup (struct gdbarch *gdbarch,
00329                                        struct displaced_step_closure *closure,
00330                                        CORE_ADDR from, CORE_ADDR to,
00331                                        struct regcache *regs);
00332 
00333 /* Initialize a basic ELF architecture variant.  */
00334 extern void i386_elf_init_abi (struct gdbarch_info, struct gdbarch *);
00335 
00336 /* Initialize a SVR4 architecture variant.  */
00337 extern void i386_svr4_init_abi (struct gdbarch_info, struct gdbarch *);
00338 
00339 extern int i386_process_record (struct gdbarch *gdbarch,
00340                                 struct regcache *regcache, CORE_ADDR addr);
00341 
00342 
00343 
00344 /* Functions and variables exported from i386bsd-tdep.c.  */
00345 
00346 extern void i386bsd_init_abi (struct gdbarch_info, struct gdbarch *);
00347 extern CORE_ADDR i386fbsd_sigtramp_start_addr;
00348 extern CORE_ADDR i386fbsd_sigtramp_end_addr;
00349 extern CORE_ADDR i386obsd_sigtramp_start_addr;
00350 extern CORE_ADDR i386obsd_sigtramp_end_addr;
00351 extern int i386fbsd4_sc_reg_offset[];
00352 extern int i386fbsd_sc_reg_offset[];
00353 extern int i386nbsd_sc_reg_offset[];
00354 extern int i386obsd_sc_reg_offset[];
00355 extern int i386bsd_sc_reg_offset[];
00356 
00357 /* SystemTap related functions.  */
00358 
00359 extern int i386_stap_is_single_operand (struct gdbarch *gdbarch,
00360                                         const char *s);
00361 
00362 extern int i386_stap_parse_special_token (struct gdbarch *gdbarch,
00363                                           struct stap_parse_info *p);
00364 
00365 #endif /* i386-tdep.h */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines