1 /* Copyright (C) 2010-2015 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/>. */
21 #include <sys/ptrace.h>
23 /* The following two typedefs are defined in a .h file which is not
24 in the standard include path (/sys/include/family/x86/ucontext.h),
25 so we just duplicate them here. */
27 /* General register context */
28 typedef struct usr_econtext
{
52 /* Floating point and SIMD register context */
53 typedef struct usr_fcontext
{
58 uint8_t *ufc_inst_off
;
59 uint32_t ufc_inst_sel
;
60 uint8_t *ufc_data_off
;
61 uint32_t ufc_data_sel
;
63 uint32_t usse_mxcsr_mask
;
74 struct uxmm_register
{
84 char ureserved
[16][14];
87 /* The index of various registers inside the regcache. */
89 enum lynx_i386_gdb_regnum
108 I386_FCTRL_REGNUM
= I386_ST0_REGNUM
+ 8,
116 I386_XMM0_REGNUM
= 32,
117 I386_MXCSR_REGNUM
= I386_XMM0_REGNUM
+ 8,
121 /* Defined in auto-generated file i386.c. */
122 extern void init_registers_i386 (void);
123 extern const struct target_desc
*tdesc_i386
;
125 /* The fill_function for the general-purpose register set. */
128 lynx_i386_fill_gregset (struct regcache
*regcache
, char *buf
)
130 #define lynx_i386_collect_gp(regnum, fld) \
131 collect_register (regcache, regnum, \
132 buf + offsetof (usr_econtext_t, uec_##fld))
134 lynx_i386_collect_gp (I386_EAX_REGNUM
, eax
);
135 lynx_i386_collect_gp (I386_ECX_REGNUM
, ecx
);
136 lynx_i386_collect_gp (I386_EDX_REGNUM
, edx
);
137 lynx_i386_collect_gp (I386_EBX_REGNUM
, ebx
);
138 lynx_i386_collect_gp (I386_ESP_REGNUM
, esp
);
139 lynx_i386_collect_gp (I386_EBP_REGNUM
, ebp
);
140 lynx_i386_collect_gp (I386_ESI_REGNUM
, esi
);
141 lynx_i386_collect_gp (I386_EDI_REGNUM
, edi
);
142 lynx_i386_collect_gp (I386_EIP_REGNUM
, eip
);
143 lynx_i386_collect_gp (I386_EFLAGS_REGNUM
, eflags
);
144 lynx_i386_collect_gp (I386_CS_REGNUM
, cs
);
145 lynx_i386_collect_gp (I386_SS_REGNUM
, ss
);
146 lynx_i386_collect_gp (I386_DS_REGNUM
, ds
);
147 lynx_i386_collect_gp (I386_ES_REGNUM
, es
);
148 lynx_i386_collect_gp (I386_FS_REGNUM
, fs
);
149 lynx_i386_collect_gp (I386_GS_REGNUM
, gs
);
152 /* The store_function for the general-purpose register set. */
155 lynx_i386_store_gregset (struct regcache
*regcache
, const char *buf
)
157 #define lynx_i386_supply_gp(regnum, fld) \
158 supply_register (regcache, regnum, \
159 buf + offsetof (usr_econtext_t, uec_##fld))
161 lynx_i386_supply_gp (I386_EAX_REGNUM
, eax
);
162 lynx_i386_supply_gp (I386_ECX_REGNUM
, ecx
);
163 lynx_i386_supply_gp (I386_EDX_REGNUM
, edx
);
164 lynx_i386_supply_gp (I386_EBX_REGNUM
, ebx
);
165 lynx_i386_supply_gp (I386_ESP_REGNUM
, esp
);
166 lynx_i386_supply_gp (I386_EBP_REGNUM
, ebp
);
167 lynx_i386_supply_gp (I386_ESI_REGNUM
, esi
);
168 lynx_i386_supply_gp (I386_EDI_REGNUM
, edi
);
169 lynx_i386_supply_gp (I386_EIP_REGNUM
, eip
);
170 lynx_i386_supply_gp (I386_EFLAGS_REGNUM
, eflags
);
171 lynx_i386_supply_gp (I386_CS_REGNUM
, cs
);
172 lynx_i386_supply_gp (I386_SS_REGNUM
, ss
);
173 lynx_i386_supply_gp (I386_DS_REGNUM
, ds
);
174 lynx_i386_supply_gp (I386_ES_REGNUM
, es
);
175 lynx_i386_supply_gp (I386_FS_REGNUM
, fs
);
176 lynx_i386_supply_gp (I386_GS_REGNUM
, gs
);
179 /* Extract the first 16 bits of register REGNUM in the REGCACHE,
180 and store these 2 bytes at DEST.
182 This is useful to collect certain 16bit registers which are known
183 by GDBserver as 32bit registers (such as the Control Register
187 collect_16bit_register (struct regcache
*regcache
, int regnum
, char *dest
)
191 collect_register (regcache
, regnum
, word
);
192 memcpy (dest
, word
, 2);
195 /* The fill_function for the floating-point register set. */
198 lynx_i386_fill_fpregset (struct regcache
*regcache
, char *buf
)
202 /* Collect %st0 .. %st7. */
203 for (i
= 0; i
< 8; i
++)
204 collect_register (regcache
, I386_ST0_REGNUM
+ i
,
205 buf
+ offsetof (usr_fcontext_t
, ufc_reg
)
206 + i
* sizeof (struct ufp387_real
));
208 /* Collect the other FPU registers. */
209 collect_16bit_register (regcache
, I386_FCTRL_REGNUM
,
210 buf
+ offsetof (usr_fcontext_t
, ufc_control
));
211 collect_16bit_register (regcache
, I386_FSTAT_REGNUM
,
212 buf
+ offsetof (usr_fcontext_t
, ufc_status
));
213 collect_16bit_register (regcache
, I386_FTAG_REGNUM
,
214 buf
+ offsetof (usr_fcontext_t
, ufc_tag
));
215 collect_register (regcache
, I386_FISEG_REGNUM
,
216 buf
+ offsetof (usr_fcontext_t
, ufc_inst_sel
));
217 collect_register (regcache
, I386_FIOFF_REGNUM
,
218 buf
+ offsetof (usr_fcontext_t
, ufc_inst_off
));
219 collect_register (regcache
, I386_FOSEG_REGNUM
,
220 buf
+ offsetof (usr_fcontext_t
, ufc_data_sel
));
221 collect_register (regcache
, I386_FOOFF_REGNUM
,
222 buf
+ offsetof (usr_fcontext_t
, ufc_data_off
));
223 collect_16bit_register (regcache
, I386_FOP_REGNUM
,
224 buf
+ offsetof (usr_fcontext_t
, ufc_opcode
));
226 /* Collect the XMM registers. */
227 for (i
= 0; i
< 8; i
++)
228 collect_register (regcache
, I386_XMM0_REGNUM
+ i
,
229 buf
+ offsetof (usr_fcontext_t
, uxmm_reg
)
230 + i
* sizeof (struct uxmm_register
));
231 collect_register (regcache
, I386_MXCSR_REGNUM
,
232 buf
+ offsetof (usr_fcontext_t
, usse_mxcsr
));
235 /* This is the supply counterpart for collect_16bit_register:
236 It extracts a 2byte value from BUF, and uses that value to
237 set REGNUM's value in the regcache.
239 This is useful to supply the value of certain 16bit registers
240 which are known by GDBserver as 32bit registers (such as the Control
241 Register for instance). */
244 supply_16bit_register (struct regcache
*regcache
, int regnum
, const char *buf
)
248 memcpy (word
, buf
, 2);
249 memset (word
+ 2, 0, 2);
250 supply_register (regcache
, regnum
, word
);
253 /* The store_function for the floating-point register set. */
256 lynx_i386_store_fpregset (struct regcache
*regcache
, const char *buf
)
260 /* Store the %st0 .. %st7 registers. */
261 for (i
= 0; i
< 8; i
++)
262 supply_register (regcache
, I386_ST0_REGNUM
+ i
,
263 buf
+ offsetof (usr_fcontext_t
, ufc_reg
)
264 + i
* sizeof (struct ufp387_real
));
266 /* Store the other FPU registers. */
267 supply_16bit_register (regcache
, I386_FCTRL_REGNUM
,
268 buf
+ offsetof (usr_fcontext_t
, ufc_control
));
269 supply_16bit_register (regcache
, I386_FSTAT_REGNUM
,
270 buf
+ offsetof (usr_fcontext_t
, ufc_status
));
271 supply_16bit_register (regcache
, I386_FTAG_REGNUM
,
272 buf
+ offsetof (usr_fcontext_t
, ufc_tag
));
273 supply_register (regcache
, I386_FISEG_REGNUM
,
274 buf
+ offsetof (usr_fcontext_t
, ufc_inst_sel
));
275 supply_register (regcache
, I386_FIOFF_REGNUM
,
276 buf
+ offsetof (usr_fcontext_t
, ufc_inst_off
));
277 supply_register (regcache
, I386_FOSEG_REGNUM
,
278 buf
+ offsetof (usr_fcontext_t
, ufc_data_sel
));
279 supply_register (regcache
, I386_FOOFF_REGNUM
,
280 buf
+ offsetof (usr_fcontext_t
, ufc_data_off
));
281 supply_16bit_register (regcache
, I386_FOP_REGNUM
,
282 buf
+ offsetof (usr_fcontext_t
, ufc_opcode
));
284 /* Store the XMM registers. */
285 for (i
= 0; i
< 8; i
++)
286 supply_register (regcache
, I386_XMM0_REGNUM
+ i
,
287 buf
+ offsetof (usr_fcontext_t
, uxmm_reg
)
288 + i
* sizeof (struct uxmm_register
));
289 supply_register (regcache
, I386_MXCSR_REGNUM
,
290 buf
+ offsetof (usr_fcontext_t
, usse_mxcsr
));
293 /* Implements the lynx_target_ops.arch_setup routine. */
296 lynx_i386_arch_setup (void)
298 init_registers_i386 ();
299 lynx_tdesc
= tdesc_i386
;
302 /* Description of all the x86-lynx register sets. */
304 struct lynx_regset_info lynx_target_regsets
[] = {
305 /* General Purpose Registers. */
306 {PTRACE_GETREGS
, PTRACE_SETREGS
, sizeof(usr_econtext_t
),
307 lynx_i386_fill_gregset
, lynx_i386_store_gregset
},
308 /* Floating Point Registers. */
309 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, sizeof(usr_fcontext_t
),
310 lynx_i386_fill_fpregset
, lynx_i386_store_fpregset
},
311 /* End of list marker. */
312 {0, 0, -1, NULL
, NULL
}
315 /* The lynx_target_ops vector for x86-lynx. */
317 struct lynx_target_ops the_low_target
= {
318 lynx_i386_arch_setup
,