| 1 | /* Native-dependent code for Unix SVR4 running on i386's. |
| 2 | |
| 3 | Copyright 1988, 1989, 1991, 1992, 1996, 1997, 1998, 1999, 2000, |
| 4 | 2001, 2002, 2004 |
| 5 | Free Software Foundation, Inc. |
| 6 | |
| 7 | This file is part of GDB. |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 22 | Boston, MA 02111-1307, USA. */ |
| 23 | |
| 24 | #include "defs.h" |
| 25 | #include "value.h" |
| 26 | #include "inferior.h" |
| 27 | #include "regcache.h" |
| 28 | |
| 29 | #ifdef HAVE_SYS_REG_H |
| 30 | #include <sys/reg.h> |
| 31 | #endif |
| 32 | |
| 33 | #include "i386-tdep.h" |
| 34 | #include "i387-tdep.h" |
| 35 | |
| 36 | #ifdef HAVE_SYS_PROCFS_H |
| 37 | |
| 38 | #include <sys/procfs.h> |
| 39 | |
| 40 | /* Prototypes for supply_gregset etc. */ |
| 41 | #include "gregset.h" |
| 42 | |
| 43 | /* The `/proc' interface divides the target machine's register set up |
| 44 | into two different sets, the general purpose register set (gregset) |
| 45 | and the floating-point register set (fpregset). For each set, |
| 46 | there is an ioctl to get the current register set and another ioctl |
| 47 | to set the current values. |
| 48 | |
| 49 | The actual structure passed through the ioctl interface is, of |
| 50 | course, naturally machine dependent, and is different for each set |
| 51 | of registers. For the i386 for example, the general-purpose |
| 52 | register set is typically defined by: |
| 53 | |
| 54 | typedef int gregset_t[19]; (in <sys/regset.h>) |
| 55 | |
| 56 | #define GS 0 (in <sys/reg.h>) |
| 57 | #define FS 1 |
| 58 | ... |
| 59 | #define UESP 17 |
| 60 | #define SS 18 |
| 61 | |
| 62 | and the floating-point set by: |
| 63 | |
| 64 | typedef struct fpregset { |
| 65 | union { |
| 66 | struct fpchip_state // fp extension state // |
| 67 | { |
| 68 | int state[27]; // 287/387 saved state // |
| 69 | int status; // status word saved at // |
| 70 | // exception // |
| 71 | } fpchip_state; |
| 72 | struct fp_emul_space // for emulators // |
| 73 | { |
| 74 | char fp_emul[246]; |
| 75 | char fp_epad[2]; |
| 76 | } fp_emul_space; |
| 77 | int f_fpregs[62]; // union of the above // |
| 78 | } fp_reg_set; |
| 79 | long f_wregs[33]; // saved weitek state // |
| 80 | } fpregset_t; |
| 81 | |
| 82 | Incidentally fpchip_state contains the FPU state in the same format |
| 83 | as used by the "fsave" instruction, and that's the only thing we |
| 84 | support here. I don't know how the emulator stores it state. The |
| 85 | Weitek stuff definitely isn't supported. |
| 86 | |
| 87 | The routines defined here, provide the packing and unpacking of |
| 88 | gregset_t and fpregset_t formatted data. */ |
| 89 | |
| 90 | #ifdef HAVE_GREGSET_T |
| 91 | |
| 92 | /* Mapping between the general-purpose registers in `/proc' |
| 93 | format and GDB's register array layout. */ |
| 94 | static int regmap[] = |
| 95 | { |
| 96 | EAX, ECX, EDX, EBX, |
| 97 | UESP, EBP, ESI, EDI, |
| 98 | EIP, EFL, CS, SS, |
| 99 | DS, ES, FS, GS |
| 100 | }; |
| 101 | |
| 102 | /* Fill GDB's register array with the general-purpose register values |
| 103 | in *GREGSETP. */ |
| 104 | |
| 105 | void |
| 106 | supply_gregset (gregset_t *gregsetp) |
| 107 | { |
| 108 | greg_t *regp = (greg_t *) gregsetp; |
| 109 | int regnum; |
| 110 | |
| 111 | for (regnum = 0; regnum < I386_NUM_GREGS; regnum++) |
| 112 | regcache_raw_supply (current_regcache, regnum, regp + regmap[regnum]); |
| 113 | } |
| 114 | |
| 115 | /* Fill register REGNUM (if it is a general-purpose register) in |
| 116 | *GREGSETPS with the value in GDB's register array. If REGNUM is -1, |
| 117 | do this for all registers. */ |
| 118 | |
| 119 | void |
| 120 | fill_gregset (gregset_t *gregsetp, int regnum) |
| 121 | { |
| 122 | greg_t *regp = (greg_t *) gregsetp; |
| 123 | int i; |
| 124 | |
| 125 | for (i = 0; i < I386_NUM_GREGS; i++) |
| 126 | if (regnum == -1 || regnum == i) |
| 127 | regcache_raw_collect (current_regcache, i, regp + regmap[i]); |
| 128 | } |
| 129 | |
| 130 | #endif /* HAVE_GREGSET_T */ |
| 131 | |
| 132 | #ifdef HAVE_FPREGSET_T |
| 133 | |
| 134 | /* Fill GDB's register array with the floating-point register values in |
| 135 | *FPREGSETP. */ |
| 136 | |
| 137 | void |
| 138 | supply_fpregset (fpregset_t *fpregsetp) |
| 139 | { |
| 140 | if (FP0_REGNUM == 0) |
| 141 | return; |
| 142 | |
| 143 | i387_supply_fsave (current_regcache, -1, fpregsetp); |
| 144 | } |
| 145 | |
| 146 | /* Fill register REGNO (if it is a floating-point register) in |
| 147 | *FPREGSETP with the value in GDB's register array. If REGNO is -1, |
| 148 | do this for all registers. */ |
| 149 | |
| 150 | void |
| 151 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
| 152 | { |
| 153 | if (FP0_REGNUM == 0) |
| 154 | return; |
| 155 | |
| 156 | i387_fill_fsave ((char *) fpregsetp, regno); |
| 157 | } |
| 158 | |
| 159 | #endif /* HAVE_FPREGSET_T */ |
| 160 | |
| 161 | #endif /* HAVE_SYS_PROCFS_H */ |