1 /* Copyright (C) 2010-2013 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include <sys/ptrace.h>
25 /* The following two typedefs are defined in a .h file which is not
26 in the standard include path (/sys/include/family/x86/ucontext.h),
27 so we just duplicate them here. */
29 /* General register context */
30 typedef struct usr_econtext {
54 /* Floating point and SIMD register context */
55 typedef struct usr_fcontext {
60 uint8_t *ufc_inst_off;
61 uint32_t ufc_inst_sel;
62 uint8_t *ufc_data_off;
63 uint32_t ufc_data_sel;
65 uint32_t usse_mxcsr_mask;
76 struct uxmm_register {
86 char ureserved[16][14];
89 /* The index of various registers inside the regcache. */
91 enum lynx_i386_gdb_regnum
110 I386_FCTRL_REGNUM = I386_ST0_REGNUM + 8,
118 I386_XMM0_REGNUM = 32,
119 I386_MXCSR_REGNUM = I386_XMM0_REGNUM + 8,
123 /* Defined in auto-generated file i386.c. */
124 extern void init_registers_i386 (void);
125 extern const struct target_desc *tdesc_i386;
127 /* The fill_function for the general-purpose register set. */
130 lynx_i386_fill_gregset (struct regcache *regcache, char *buf)
132 #define lynx_i386_collect_gp(regnum, fld) \
133 collect_register (regcache, regnum, \
134 buf + offsetof (usr_econtext_t, uec_##fld))
136 lynx_i386_collect_gp (I386_EAX_REGNUM, eax);
137 lynx_i386_collect_gp (I386_ECX_REGNUM, ecx);
138 lynx_i386_collect_gp (I386_EDX_REGNUM, edx);
139 lynx_i386_collect_gp (I386_EBX_REGNUM, ebx);
140 lynx_i386_collect_gp (I386_ESP_REGNUM, esp);
141 lynx_i386_collect_gp (I386_EBP_REGNUM, ebp);
142 lynx_i386_collect_gp (I386_ESI_REGNUM, esi);
143 lynx_i386_collect_gp (I386_EDI_REGNUM, edi);
144 lynx_i386_collect_gp (I386_EIP_REGNUM, eip);
145 lynx_i386_collect_gp (I386_EFLAGS_REGNUM, eflags);
146 lynx_i386_collect_gp (I386_CS_REGNUM, cs);
147 lynx_i386_collect_gp (I386_SS_REGNUM, ss);
148 lynx_i386_collect_gp (I386_DS_REGNUM, ds);
149 lynx_i386_collect_gp (I386_ES_REGNUM, es);
150 lynx_i386_collect_gp (I386_FS_REGNUM, fs);
151 lynx_i386_collect_gp (I386_GS_REGNUM, gs);
154 /* The store_function for the general-purpose register set. */
157 lynx_i386_store_gregset (struct regcache *regcache, const char *buf)
159 #define lynx_i386_supply_gp(regnum, fld) \
160 supply_register (regcache, regnum, \
161 buf + offsetof (usr_econtext_t, uec_##fld))
163 lynx_i386_supply_gp (I386_EAX_REGNUM, eax);
164 lynx_i386_supply_gp (I386_ECX_REGNUM, ecx);
165 lynx_i386_supply_gp (I386_EDX_REGNUM, edx);
166 lynx_i386_supply_gp (I386_EBX_REGNUM, ebx);
167 lynx_i386_supply_gp (I386_ESP_REGNUM, esp);
168 lynx_i386_supply_gp (I386_EBP_REGNUM, ebp);
169 lynx_i386_supply_gp (I386_ESI_REGNUM, esi);
170 lynx_i386_supply_gp (I386_EDI_REGNUM, edi);
171 lynx_i386_supply_gp (I386_EIP_REGNUM, eip);
172 lynx_i386_supply_gp (I386_EFLAGS_REGNUM, eflags);
173 lynx_i386_supply_gp (I386_CS_REGNUM, cs);
174 lynx_i386_supply_gp (I386_SS_REGNUM, ss);
175 lynx_i386_supply_gp (I386_DS_REGNUM, ds);
176 lynx_i386_supply_gp (I386_ES_REGNUM, es);
177 lynx_i386_supply_gp (I386_FS_REGNUM, fs);
178 lynx_i386_supply_gp (I386_GS_REGNUM, gs);
181 /* Extract the first 16 bits of register REGNUM in the REGCACHE,
182 and store these 2 bytes at DEST.
184 This is useful to collect certain 16bit registers which are known
185 by GDBserver as 32bit registers (such as the Control Register
189 collect_16bit_register (struct regcache *regcache, int regnum, char *dest)
193 collect_register (regcache, regnum, word);
194 memcpy (dest, word, 2);
197 /* The fill_function for the floating-point register set. */
200 lynx_i386_fill_fpregset (struct regcache *regcache, char *buf)
204 /* Collect %st0 .. %st7. */
205 for (i = 0; i < 8; i++)
206 collect_register (regcache, I386_ST0_REGNUM + i,
207 buf + offsetof (usr_fcontext_t, ufc_reg)
208 + i * sizeof (struct ufp387_real));
210 /* Collect the other FPU registers. */
211 collect_16bit_register (regcache, I386_FCTRL_REGNUM,
212 buf + offsetof (usr_fcontext_t, ufc_control));
213 collect_16bit_register (regcache, I386_FSTAT_REGNUM,
214 buf + offsetof (usr_fcontext_t, ufc_status));
215 collect_16bit_register (regcache, I386_FTAG_REGNUM,
216 buf + offsetof (usr_fcontext_t, ufc_tag));
217 collect_register (regcache, I386_FISEG_REGNUM,
218 buf + offsetof (usr_fcontext_t, ufc_inst_sel));
219 collect_register (regcache, I386_FIOFF_REGNUM,
220 buf + offsetof (usr_fcontext_t, ufc_inst_off));
221 collect_register (regcache, I386_FOSEG_REGNUM,
222 buf + offsetof (usr_fcontext_t, ufc_data_sel));
223 collect_register (regcache, I386_FOOFF_REGNUM,
224 buf + offsetof (usr_fcontext_t, ufc_data_off));
225 collect_16bit_register (regcache, I386_FOP_REGNUM,
226 buf + offsetof (usr_fcontext_t, ufc_opcode));
228 /* Collect the XMM registers. */
229 for (i = 0; i < 8; i++)
230 collect_register (regcache, I386_XMM0_REGNUM + i,
231 buf + offsetof (usr_fcontext_t, uxmm_reg)
232 + i * sizeof (struct uxmm_register));
233 collect_register (regcache, I386_MXCSR_REGNUM,
234 buf + offsetof (usr_fcontext_t, usse_mxcsr));
237 /* This is the supply counterpart for collect_16bit_register:
238 It extracts a 2byte value from BUF, and uses that value to
239 set REGNUM's value in the regcache.
241 This is useful to supply the value of certain 16bit registers
242 which are known by GDBserver as 32bit registers (such as the Control
243 Register for instance). */
246 supply_16bit_register (struct regcache *regcache, int regnum, const char *buf)
250 memcpy (word, buf, 2);
251 memset (word + 2, 0, 2);
252 supply_register (regcache, regnum, word);
255 /* The store_function for the floating-point register set. */
258 lynx_i386_store_fpregset (struct regcache *regcache, const char *buf)
262 /* Store the %st0 .. %st7 registers. */
263 for (i = 0; i < 8; i++)
264 supply_register (regcache, I386_ST0_REGNUM + i,
265 buf + offsetof (usr_fcontext_t, ufc_reg)
266 + i * sizeof (struct ufp387_real));
268 /* Store the other FPU registers. */
269 supply_16bit_register (regcache, I386_FCTRL_REGNUM,
270 buf + offsetof (usr_fcontext_t, ufc_control));
271 supply_16bit_register (regcache, I386_FSTAT_REGNUM,
272 buf + offsetof (usr_fcontext_t, ufc_status));
273 supply_16bit_register (regcache, I386_FTAG_REGNUM,
274 buf + offsetof (usr_fcontext_t, ufc_tag));
275 supply_register (regcache, I386_FISEG_REGNUM,
276 buf + offsetof (usr_fcontext_t, ufc_inst_sel));
277 supply_register (regcache, I386_FIOFF_REGNUM,
278 buf + offsetof (usr_fcontext_t, ufc_inst_off));
279 supply_register (regcache, I386_FOSEG_REGNUM,
280 buf + offsetof (usr_fcontext_t, ufc_data_sel));
281 supply_register (regcache, I386_FOOFF_REGNUM,
282 buf + offsetof (usr_fcontext_t, ufc_data_off));
283 supply_16bit_register (regcache, I386_FOP_REGNUM,
284 buf + offsetof (usr_fcontext_t, ufc_opcode));
286 /* Store the XMM registers. */
287 for (i = 0; i < 8; i++)
288 supply_register (regcache, I386_XMM0_REGNUM + i,
289 buf + offsetof (usr_fcontext_t, uxmm_reg)
290 + i * sizeof (struct uxmm_register));
291 supply_register (regcache, I386_MXCSR_REGNUM,
292 buf + offsetof (usr_fcontext_t, usse_mxcsr));
295 /* Implements the lynx_target_ops.arch_setup routine. */
298 lynx_i386_arch_setup (void)
300 init_registers_i386 ();
301 lynx_tdesc = tdesc_i386;
304 /* Description of all the x86-lynx register sets. */
306 struct lynx_regset_info lynx_target_regsets[] = {
307 /* General Purpose Registers. */
308 {PTRACE_GETREGS, PTRACE_SETREGS, sizeof(usr_econtext_t),
309 lynx_i386_fill_gregset, lynx_i386_store_gregset},
310 /* Floating Point Registers. */
311 { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof(usr_fcontext_t),
312 lynx_i386_fill_fpregset, lynx_i386_store_fpregset },
313 /* End of list marker. */
314 {0, 0, -1, NULL, NULL }
317 /* The lynx_target_ops vector for x86-lynx. */
319 struct lynx_target_ops the_low_target = {
320 lynx_i386_arch_setup,