GDBserver

lynx-i386-low.c
Go to the documentation of this file.
1 /* Copyright (C) 2010-2018 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
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.
9
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.
14
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/>. */
17
18 #include "server.h"
19 #include "lynx-low.h"
20 #include <limits.h>
21 #include <sys/ptrace.h>
22 #include "x86-xstate.h"
23 #include "arch/i386.h"
24
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. */
28
29 /* General register context */
30 typedef struct usr_econtext {
31
32 uint32_t uec_fault;
33 uint32_t uec_es;
34 uint32_t uec_ds;
35 uint32_t uec_edi;
36 uint32_t uec_esi;
37 uint32_t uec_ebp;
38 uint32_t uec_temp;
39 uint32_t uec_ebx;
40 uint32_t uec_edx;
41 uint32_t uec_ecx;
42 uint32_t uec_eax;
43 uint32_t uec_inum;
44 uint32_t uec_ecode;
45 uint32_t uec_eip;
46 uint32_t uec_cs;
47 uint32_t uec_eflags;
48 uint32_t uec_esp;
49 uint32_t uec_ss;
50 uint32_t uec_fs;
51 uint32_t uec_gs;
52 } usr_econtext_t;
53
54 /* Floating point and SIMD register context */
55 typedef struct usr_fcontext {
56 uint16_t ufc_control;
57 uint16_t ufc_status;
58 uint16_t ufc_tag;
59 uint16_t ufc_opcode;
60 uint8_t *ufc_inst_off;
61 uint32_t ufc_inst_sel;
62 uint8_t *ufc_data_off;
63 uint32_t ufc_data_sel;
64 uint32_t usse_mxcsr;
65 uint32_t usse_mxcsr_mask;
66 struct ufp387_real {
67 uint16_t umant4;
68 uint16_t umant3;
69 uint16_t umant2;
70 uint16_t umant1;
71 uint16_t us_and_e;
72 uint16_t ureserved_1;
73 uint16_t ureserved_2;
74 uint16_t ureserved_3;
75 } ufc_reg[8];
76 struct uxmm_register {
77 uint16_t uchunk_1;
78 uint16_t uchunk_2;
79 uint16_t uchunk_3;
80 uint16_t uchunk_4;
81 uint16_t uchunk_5;
82 uint16_t uchunk_6;
83 uint16_t uchunk_7;
84 uint16_t uchunk_8;
85 } uxmm_reg[8];
86 char ureserved[16][14];
87 } usr_fcontext_t;
88
89 /* The index of various registers inside the regcache. */
90
91 enum lynx_i386_gdb_regnum
92 {
93 I386_EAX_REGNUM,
94 I386_ECX_REGNUM,
95 I386_EDX_REGNUM,
96 I386_EBX_REGNUM,
97 I386_ESP_REGNUM,
98 I386_EBP_REGNUM,
99 I386_ESI_REGNUM,
100 I386_EDI_REGNUM,
101 I386_EIP_REGNUM,
102 I386_EFLAGS_REGNUM,
103 I386_CS_REGNUM,
104 I386_SS_REGNUM,
105 I386_DS_REGNUM,
106 I386_ES_REGNUM,
107 I386_FS_REGNUM,
108 I386_GS_REGNUM,
109 I386_ST0_REGNUM,
110 I386_FCTRL_REGNUM = I386_ST0_REGNUM + 8,
111 I386_FSTAT_REGNUM,
112 I386_FTAG_REGNUM,
113 I386_FISEG_REGNUM,
114 I386_FIOFF_REGNUM,
115 I386_FOSEG_REGNUM,
116 I386_FOOFF_REGNUM,
117 I386_FOP_REGNUM,
118 I386_XMM0_REGNUM = 32,
119 I386_MXCSR_REGNUM = I386_XMM0_REGNUM + 8,
120 I386_SENTINEL_REGUM
121 };
122
123 /* The fill_function for the general-purpose register set. */
124
125 static void
126 lynx_i386_fill_gregset (struct regcache *regcache, char *buf)
127 {
128 #define lynx_i386_collect_gp(regnum, fld) \
129 collect_register (regcache, regnum, \
130 buf + offsetof (usr_econtext_t, uec_##fld))
131
132 lynx_i386_collect_gp (I386_EAX_REGNUM, eax);
133 lynx_i386_collect_gp (I386_ECX_REGNUM, ecx);
134 lynx_i386_collect_gp (I386_EDX_REGNUM, edx);
135 lynx_i386_collect_gp (I386_EBX_REGNUM, ebx);
136 lynx_i386_collect_gp (I386_ESP_REGNUM, esp);
137 lynx_i386_collect_gp (I386_EBP_REGNUM, ebp);
138 lynx_i386_collect_gp (I386_ESI_REGNUM, esi);
139 lynx_i386_collect_gp (I386_EDI_REGNUM, edi);
140 lynx_i386_collect_gp (I386_EIP_REGNUM, eip);
141 lynx_i386_collect_gp (I386_EFLAGS_REGNUM, eflags);
142 lynx_i386_collect_gp (I386_CS_REGNUM, cs);
143 lynx_i386_collect_gp (I386_SS_REGNUM, ss);
144 lynx_i386_collect_gp (I386_DS_REGNUM, ds);
145 lynx_i386_collect_gp (I386_ES_REGNUM, es);
146 lynx_i386_collect_gp (I386_FS_REGNUM, fs);
147 lynx_i386_collect_gp (I386_GS_REGNUM, gs);
148 }
149
150 /* The store_function for the general-purpose register set. */
151
152 static void
153 lynx_i386_store_gregset (struct regcache *regcache, const char *buf)
154 {
155 #define lynx_i386_supply_gp(regnum, fld) \
156 supply_register (regcache, regnum, \
157 buf + offsetof (usr_econtext_t, uec_##fld))
158
159 lynx_i386_supply_gp (I386_EAX_REGNUM, eax);
160 lynx_i386_supply_gp (I386_ECX_REGNUM, ecx);
161 lynx_i386_supply_gp (I386_EDX_REGNUM, edx);
162 lynx_i386_supply_gp (I386_EBX_REGNUM, ebx);
163 lynx_i386_supply_gp (I386_ESP_REGNUM, esp);
164 lynx_i386_supply_gp (I386_EBP_REGNUM, ebp);
165 lynx_i386_supply_gp (I386_ESI_REGNUM, esi);
166 lynx_i386_supply_gp (I386_EDI_REGNUM, edi);
167 lynx_i386_supply_gp (I386_EIP_REGNUM, eip);
168 lynx_i386_supply_gp (I386_EFLAGS_REGNUM, eflags);
169 lynx_i386_supply_gp (I386_CS_REGNUM, cs);
170 lynx_i386_supply_gp (I386_SS_REGNUM, ss);
171 lynx_i386_supply_gp (I386_DS_REGNUM, ds);
172 lynx_i386_supply_gp (I386_ES_REGNUM, es);
173 lynx_i386_supply_gp (I386_FS_REGNUM, fs);
174 lynx_i386_supply_gp (I386_GS_REGNUM, gs);
175 }
176
177 /* Extract the first 16 bits of register REGNUM in the REGCACHE,
178 and store these 2 bytes at DEST.
179
180 This is useful to collect certain 16bit registers which are known
181 by GDBserver as 32bit registers (such as the Control Register
182 for instance). */
183
184 static void
185 collect_16bit_register (struct regcache *regcache, int regnum, char *dest)
186 {
187 gdb_byte word[4];
188
189 collect_register (regcache, regnum, word);
190 memcpy (dest, word, 2);
191 }
192
193 /* The fill_function for the floating-point register set. */
194
195 static void
196 lynx_i386_fill_fpregset (struct regcache *regcache, char *buf)
197 {
198 int i;
199
200 /* Collect %st0 .. %st7. */
201 for (i = 0; i < 8; i++)
202 collect_register (regcache, I386_ST0_REGNUM + i,
203 buf + offsetof (usr_fcontext_t, ufc_reg)
204 + i * sizeof (struct ufp387_real));
205
206 /* Collect the other FPU registers. */
207 collect_16bit_register (regcache, I386_FCTRL_REGNUM,
208 buf + offsetof (usr_fcontext_t, ufc_control));
209 collect_16bit_register (regcache, I386_FSTAT_REGNUM,
210 buf + offsetof (usr_fcontext_t, ufc_status));
211 collect_16bit_register (regcache, I386_FTAG_REGNUM,
212 buf + offsetof (usr_fcontext_t, ufc_tag));
213 collect_register (regcache, I386_FISEG_REGNUM,
214 buf + offsetof (usr_fcontext_t, ufc_inst_sel));
215 collect_register (regcache, I386_FIOFF_REGNUM,
216 buf + offsetof (usr_fcontext_t, ufc_inst_off));
217 collect_register (regcache, I386_FOSEG_REGNUM,
218 buf + offsetof (usr_fcontext_t, ufc_data_sel));
219 collect_register (regcache, I386_FOOFF_REGNUM,
220 buf + offsetof (usr_fcontext_t, ufc_data_off));
221 collect_16bit_register (regcache, I386_FOP_REGNUM,
222 buf + offsetof (usr_fcontext_t, ufc_opcode));
223
224 /* Collect the XMM registers. */
225 for (i = 0; i < 8; i++)
226 collect_register (regcache, I386_XMM0_REGNUM + i,
227 buf + offsetof (usr_fcontext_t, uxmm_reg)
228 + i * sizeof (struct uxmm_register));
229 collect_register (regcache, I386_MXCSR_REGNUM,
230 buf + offsetof (usr_fcontext_t, usse_mxcsr));
231 }
232
233 /* This is the supply counterpart for collect_16bit_register:
234 It extracts a 2byte value from BUF, and uses that value to
235 set REGNUM's value in the regcache.
236
237 This is useful to supply the value of certain 16bit registers
238 which are known by GDBserver as 32bit registers (such as the Control
239 Register for instance). */
240
241 static void
242 supply_16bit_register (struct regcache *regcache, int regnum, const char *buf)
243 {
244 gdb_byte word[4];
245
246 memcpy (word, buf, 2);
247 memset (word + 2, 0, 2);
248 supply_register (regcache, regnum, word);
249 }
250
251 /* The store_function for the floating-point register set. */
252
253 static void
254 lynx_i386_store_fpregset (struct regcache *regcache, const char *buf)
255 {
256 int i;
257
258 /* Store the %st0 .. %st7 registers. */
259 for (i = 0; i < 8; i++)
260 supply_register (regcache, I386_ST0_REGNUM + i,
261 buf + offsetof (usr_fcontext_t, ufc_reg)
262 + i * sizeof (struct ufp387_real));
263
264 /* Store the other FPU registers. */
265 supply_16bit_register (regcache, I386_FCTRL_REGNUM,
266 buf + offsetof (usr_fcontext_t, ufc_control));
267 supply_16bit_register (regcache, I386_FSTAT_REGNUM,
268 buf + offsetof (usr_fcontext_t, ufc_status));
269 supply_16bit_register (regcache, I386_FTAG_REGNUM,
270 buf + offsetof (usr_fcontext_t, ufc_tag));
271 supply_register (regcache, I386_FISEG_REGNUM,
272 buf + offsetof (usr_fcontext_t, ufc_inst_sel));
273 supply_register (regcache, I386_FIOFF_REGNUM,
274 buf + offsetof (usr_fcontext_t, ufc_inst_off));
275 supply_register (regcache, I386_FOSEG_REGNUM,
276 buf + offsetof (usr_fcontext_t, ufc_data_sel));
277 supply_register (regcache, I386_FOOFF_REGNUM,
278 buf + offsetof (usr_fcontext_t, ufc_data_off));
279 supply_16bit_register (regcache, I386_FOP_REGNUM,
280 buf + offsetof (usr_fcontext_t, ufc_opcode));
281
282 /* Store the XMM registers. */
283 for (i = 0; i < 8; i++)
284 supply_register (regcache, I386_XMM0_REGNUM + i,
285 buf + offsetof (usr_fcontext_t, uxmm_reg)
286 + i * sizeof (struct uxmm_register));
287 supply_register (regcache, I386_MXCSR_REGNUM,
288 buf + offsetof (usr_fcontext_t, usse_mxcsr));
289 }
290
291 /* Implements the lynx_target_ops.arch_setup routine. */
292
293 static void
294 lynx_i386_arch_setup (void)
295 {
296 struct target_desc *tdesc
297 = i386_create_target_description (X86_XSTATE_SSE_MASK, false);
298
299 init_target_desc (tdesc);
300
301 lynx_tdesc = tdesc;
302 }
303
304 /* Description of all the x86-lynx register sets. */
305
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 }
315 };
316
317 /* The lynx_target_ops vector for x86-lynx. */
318
319 struct lynx_target_ops the_low_target = {
320 lynx_i386_arch_setup,
321 };
usr_econtext::uec_edi
uint32_t uec_edi
Definition: lynx-i386-low.c:35
usr_fcontext::uxmm_register::uchunk_8
uint16_t uchunk_8
Definition: lynx-i386-low.c:84
collect_register
void collect_register(struct regcache *regcache, int n, void *buf)
Definition: regcache.c:402
usr_fcontext::ufc_opcode
uint16_t ufc_opcode
Definition: lynx-i386-low.c:59
usr_fcontext::usse_mxcsr_mask
uint32_t usse_mxcsr_mask
Definition: lynx-i386-low.c:65
usr_fcontext::uxmm_register::uchunk_5
uint16_t uchunk_5
Definition: lynx-i386-low.c:81
usr_fcontext::uxmm_register::uchunk_6
uint16_t uchunk_6
Definition: lynx-i386-low.c:82
usr_fcontext::ufc_tag
uint16_t ufc_tag
Definition: lynx-i386-low.c:58
usr_econtext::uec_cs
uint32_t uec_cs
Definition: lynx-i386-low.c:46
I386_SENTINEL_REGUM
Definition: lynx-i386-low.c:120
X86_XSTATE_SSE_MASK
#define X86_XSTATE_SSE_MASK
Definition: x86-xstate.h:42
I386_FS_REGNUM
Definition: lynx-i386-low.c:107
usr_fcontext::ufp387_real::umant4
uint16_t umant4
Definition: lynx-i386-low.c:67
usr_econtext::uec_esi
uint32_t uec_esi
Definition: lynx-i386-low.c:36
usr_econtext::uec_eflags
uint32_t uec_eflags
Definition: lynx-i386-low.c:47
usr_fcontext::ufp387_real::us_and_e
uint16_t us_and_e
Definition: lynx-i386-low.c:71
usr_fcontext::usse_mxcsr
uint32_t usse_mxcsr
Definition: lynx-i386-low.c:64
lynx_i386_supply_gp
#define lynx_i386_supply_gp(regnum, fld)
I386_FCTRL_REGNUM
Definition: lynx-i386-low.c:110
usr_fcontext::ufp387_real::umant2
uint16_t umant2
Definition: lynx-i386-low.c:69
I386_EIP_REGNUM
Definition: lynx-i386-low.c:101
usr_fcontext::ufc_data_sel
uint32_t ufc_data_sel
Definition: lynx-i386-low.c:63
I386_DS_REGNUM
Definition: lynx-i386-low.c:105
usr_econtext::uec_ebx
uint32_t uec_ebx
Definition: lynx-i386-low.c:39
memset
void * memset(T *s, int c, size_t n)=delete
usr_fcontext::ufc_data_off
uint8_t * ufc_data_off
Definition: lynx-i386-low.c:62
usr_fcontext::ufp387_real::ureserved_2
uint16_t ureserved_2
Definition: lynx-i386-low.c:73
I386_GS_REGNUM
Definition: lynx-i386-low.c:108
usr_econtext::uec_fs
uint32_t uec_fs
Definition: lynx-i386-low.c:50
I386_ESP_REGNUM
Definition: lynx-i386-low.c:97
usr_econtext::uec_fault
uint32_t uec_fault
Definition: lynx-i386-low.c:32
I386_ES_REGNUM
Definition: lynx-i386-low.c:106
usr_fcontext::ufc_inst_sel
uint32_t ufc_inst_sel
Definition: lynx-i386-low.c:61
x86-xstate.h
I386_CS_REGNUM
Definition: lynx-i386-low.c:103
usr_econtext::uec_edx
uint32_t uec_edx
Definition: lynx-i386-low.c:40
lynx_i386_collect_gp
#define lynx_i386_collect_gp(regnum, fld)
I386_ECX_REGNUM
Definition: lynx-i386-low.c:94
regnum
regnum
Definition: linux-xtensa-low.c:34
usr_fcontext::ufc_inst_off
uint8_t * ufc_inst_off
Definition: lynx-i386-low.c:60
usr_fcontext::ufp387_real::ureserved_1
uint16_t ureserved_1
Definition: lynx-i386-low.c:72
lynx_i386_gdb_regnum
lynx_i386_gdb_regnum
Definition: lynx-i386-low.c:91
lynx_i386_store_fpregset
static void lynx_i386_store_fpregset(struct regcache *regcache, const char *buf)
Definition: lynx-i386-low.c:254
regcache
Definition: regcache.h:31
usr_econtext::uec_gs
uint32_t uec_gs
Definition: lynx-i386-low.c:51
I386_FOP_REGNUM
Definition: lynx-i386-low.c:117
I386_EDI_REGNUM
Definition: lynx-i386-low.c:100
I386_ST0_REGNUM
Definition: lynx-i386-low.c:109
usr_econtext::uec_ebp
uint32_t uec_ebp
Definition: lynx-i386-low.c:37
lynx_i386_arch_setup
static void lynx_i386_arch_setup(void)
Definition: lynx-i386-low.c:294
I386_FIOFF_REGNUM
Definition: lynx-i386-low.c:114
I386_SS_REGNUM
Definition: lynx-i386-low.c:104
lynx_target_ops
Definition: lynx-low.h:44
lynx_i386_fill_gregset
static void lynx_i386_fill_gregset(struct regcache *regcache, char *buf)
Definition: lynx-i386-low.c:126
I386_FOSEG_REGNUM
Definition: lynx-i386-low.c:115
usr_fcontext::ureserved
char ureserved[16][14]
Definition: lynx-i386-low.c:86
lynx_tdesc
const struct target_desc * lynx_tdesc
Definition: lynx-low.c:36
usr_econtext::uec_ds
uint32_t uec_ds
Definition: lynx-i386-low.c:34
usr_econtext::uec_ecode
uint32_t uec_ecode
Definition: lynx-i386-low.c:44
usr_econtext::uec_temp
uint32_t uec_temp
Definition: lynx-i386-low.c:38
usr_econtext::uec_es
uint32_t uec_es
Definition: lynx-i386-low.c:33
usr_fcontext::ufc_control
uint16_t ufc_control
Definition: lynx-i386-low.c:56
I386_EDX_REGNUM
Definition: lynx-i386-low.c:95
usr_fcontext::ufp387_real
Definition: lynx-i386-low.c:66
usr_econtext::uec_ss
uint32_t uec_ss
Definition: lynx-i386-low.c:49
I386_EFLAGS_REGNUM
Definition: lynx-i386-low.c:102
server.h
usr_econtext::uec_inum
uint32_t uec_inum
Definition: lynx-i386-low.c:43
I386_EBP_REGNUM
Definition: lynx-i386-low.c:98
usr_fcontext::ufp387_real::umant3
uint16_t umant3
Definition: lynx-i386-low.c:68
I386_EBX_REGNUM
Definition: lynx-i386-low.c:96
usr_fcontext::ufc_reg
struct usr_fcontext::ufp387_real ufc_reg[8]
I386_FISEG_REGNUM
Definition: lynx-i386-low.c:113
usr_fcontext_t
struct usr_fcontext usr_fcontext_t
usr_fcontext::uxmm_register::uchunk_4
uint16_t uchunk_4
Definition: lynx-i386-low.c:80
I386_XMM0_REGNUM
Definition: lynx-i386-low.c:118
I386_FSTAT_REGNUM
Definition: lynx-i386-low.c:111
init_target_desc
void init_target_desc(struct target_desc *tdesc)
Definition: tdesc.c:23
usr_econtext::uec_esp
uint32_t uec_esp
Definition: lynx-i386-low.c:48
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
usr_econtext::uec_ecx
uint32_t uec_ecx
Definition: lynx-i386-low.c:41
usr_fcontext::uxmm_reg
struct usr_fcontext::uxmm_register uxmm_reg[8]
supply_16bit_register
static void supply_16bit_register(struct regcache *regcache, int regnum, const char *buf)
Definition: lynx-i386-low.c:242
lynx_target_regsets
struct lynx_regset_info lynx_target_regsets[]
Definition: lynx-i386-low.c:306
usr_fcontext::ufc_status
uint16_t ufc_status
Definition: lynx-i386-low.c:57
I386_FTAG_REGNUM
Definition: lynx-i386-low.c:112
usr_econtext::uec_eip
uint32_t uec_eip
Definition: lynx-i386-low.c:45
target_desc
Definition: tdesc.h:33
lynx-low.h
usr_fcontext
Definition: lynx-i386-low.c:55
limits.h
usr_fcontext::ufp387_real::umant1
uint16_t umant1
Definition: lynx-i386-low.c:70
lynx_i386_store_gregset
static void lynx_i386_store_gregset(struct regcache *regcache, const char *buf)
Definition: lynx-i386-low.c:153
I386_FOOFF_REGNUM
Definition: lynx-i386-low.c:116
usr_fcontext::uxmm_register::uchunk_7
uint16_t uchunk_7
Definition: lynx-i386-low.c:83
I386_MXCSR_REGNUM
Definition: lynx-i386-low.c:119
usr_econtext::uec_eax
uint32_t uec_eax
Definition: lynx-i386-low.c:42
usr_fcontext::uxmm_register::uchunk_1
uint16_t uchunk_1
Definition: lynx-i386-low.c:77
I386_EAX_REGNUM
Definition: lynx-i386-low.c:93
collect_16bit_register
static void collect_16bit_register(struct regcache *regcache, int regnum, char *dest)
Definition: lynx-i386-low.c:185
usr_fcontext::uxmm_register
Definition: lynx-i386-low.c:76
usr_fcontext::uxmm_register::uchunk_2
uint16_t uchunk_2
Definition: lynx-i386-low.c:78
usr_econtext_t
struct usr_econtext usr_econtext_t
lynx_regset_info
Definition: lynx-low.h:23
supply_register
void supply_register(struct regcache *regcache, int n, const void *buf)
Definition: regcache.c:318
usr_econtext
Definition: lynx-i386-low.c:30
I386_ESI_REGNUM
Definition: lynx-i386-low.c:99
usr_fcontext::ufp387_real::ureserved_3
uint16_t ureserved_3
Definition: lynx-i386-low.c:74
the_low_target
struct lynx_target_ops the_low_target
Definition: lynx-i386-low.c:319
usr_fcontext::uxmm_register::uchunk_3
uint16_t uchunk_3
Definition: lynx-i386-low.c:79
lynx_i386_fill_fpregset
static void lynx_i386_fill_fpregset(struct regcache *regcache, char *buf)
Definition: lynx-i386-low.c:196