]>
Commit | Line | Data |
---|---|---|
7b6bb8da | 1 | /* Copyright (C) 2010, 2011 Free Software Foundation, Inc. |
fa1bd1e4 JB |
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 | ||
21 | #include <stdint.h> | |
22 | #include <limits.h> | |
23 | #include <sys/ptrace.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 | /* Defined in auto-generated file i386.c. */ | |
124 | extern void init_registers_i386 (void); | |
125 | ||
126 | /* The fill_function for the general-purpose register set. */ | |
127 | ||
128 | static void | |
129 | lynx_i386_fill_gregset (struct regcache *regcache, char *buf) | |
130 | { | |
131 | #define lynx_i386_collect_gp(regnum, fld) \ | |
132 | collect_register (regcache, regnum, \ | |
133 | buf + offsetof (usr_econtext_t, uec_##fld)) | |
134 | ||
135 | lynx_i386_collect_gp (I386_EAX_REGNUM, eax); | |
136 | lynx_i386_collect_gp (I386_ECX_REGNUM, ecx); | |
137 | lynx_i386_collect_gp (I386_EDX_REGNUM, edx); | |
138 | lynx_i386_collect_gp (I386_EBX_REGNUM, ebx); | |
139 | lynx_i386_collect_gp (I386_ESP_REGNUM, esp); | |
140 | lynx_i386_collect_gp (I386_EBP_REGNUM, ebp); | |
141 | lynx_i386_collect_gp (I386_ESI_REGNUM, esi); | |
142 | lynx_i386_collect_gp (I386_EDI_REGNUM, edi); | |
143 | lynx_i386_collect_gp (I386_EIP_REGNUM, eip); | |
144 | lynx_i386_collect_gp (I386_EFLAGS_REGNUM, eflags); | |
145 | lynx_i386_collect_gp (I386_CS_REGNUM, cs); | |
146 | lynx_i386_collect_gp (I386_SS_REGNUM, ss); | |
147 | lynx_i386_collect_gp (I386_DS_REGNUM, ds); | |
148 | lynx_i386_collect_gp (I386_ES_REGNUM, es); | |
149 | lynx_i386_collect_gp (I386_FS_REGNUM, fs); | |
150 | lynx_i386_collect_gp (I386_GS_REGNUM, gs); | |
151 | } | |
152 | ||
153 | /* The store_function for the general-purpose register set. */ | |
154 | ||
155 | static void | |
156 | lynx_i386_store_gregset (struct regcache *regcache, const char *buf) | |
157 | { | |
158 | #define lynx_i386_supply_gp(regnum, fld) \ | |
159 | supply_register (regcache, regnum, \ | |
160 | buf + offsetof (usr_econtext_t, uec_##fld)) | |
161 | ||
162 | lynx_i386_supply_gp (I386_EAX_REGNUM, eax); | |
163 | lynx_i386_supply_gp (I386_ECX_REGNUM, ecx); | |
164 | lynx_i386_supply_gp (I386_EDX_REGNUM, edx); | |
165 | lynx_i386_supply_gp (I386_EBX_REGNUM, ebx); | |
166 | lynx_i386_supply_gp (I386_ESP_REGNUM, esp); | |
167 | lynx_i386_supply_gp (I386_EBP_REGNUM, ebp); | |
168 | lynx_i386_supply_gp (I386_ESI_REGNUM, esi); | |
169 | lynx_i386_supply_gp (I386_EDI_REGNUM, edi); | |
170 | lynx_i386_supply_gp (I386_EIP_REGNUM, eip); | |
171 | lynx_i386_supply_gp (I386_EFLAGS_REGNUM, eflags); | |
172 | lynx_i386_supply_gp (I386_CS_REGNUM, cs); | |
173 | lynx_i386_supply_gp (I386_SS_REGNUM, ss); | |
174 | lynx_i386_supply_gp (I386_DS_REGNUM, ds); | |
175 | lynx_i386_supply_gp (I386_ES_REGNUM, es); | |
176 | lynx_i386_supply_gp (I386_FS_REGNUM, fs); | |
177 | lynx_i386_supply_gp (I386_GS_REGNUM, gs); | |
178 | } | |
179 | ||
180 | /* Extract the first 16 bits of register REGNUM in the REGCACHE, | |
181 | and store these 2 bytes at DEST. | |
182 | ||
183 | This is useful to collect certain 16bit registers which are known | |
184 | by GDBserver as 32bit registers (such as the Control Register | |
185 | for instance). */ | |
186 | ||
187 | static void | |
188 | collect_16bit_register (struct regcache *regcache, int regnum, char *dest) | |
189 | { | |
190 | gdb_byte word[4]; | |
191 | ||
192 | collect_register (regcache, regnum, word); | |
193 | memcpy (dest, word, 2); | |
194 | } | |
195 | ||
196 | /* The fill_function for the floating-point register set. */ | |
197 | ||
198 | static void | |
199 | lynx_i386_fill_fpregset (struct regcache *regcache, char *buf) | |
200 | { | |
201 | int i; | |
202 | ||
203 | /* Collect %st0 .. %st7. */ | |
204 | for (i = 0; i < 8; i++) | |
205 | collect_register (regcache, I386_ST0_REGNUM + i, | |
206 | buf + offsetof (usr_fcontext_t, ufc_reg) | |
207 | + i * sizeof (struct ufp387_real)); | |
208 | ||
209 | /* Collect the other FPU registers. */ | |
210 | collect_16bit_register (regcache, I386_FCTRL_REGNUM, | |
211 | buf + offsetof (usr_fcontext_t, ufc_control)); | |
212 | collect_16bit_register (regcache, I386_FSTAT_REGNUM, | |
213 | buf + offsetof (usr_fcontext_t, ufc_status)); | |
214 | collect_16bit_register (regcache, I386_FTAG_REGNUM, | |
215 | buf + offsetof (usr_fcontext_t, ufc_tag)); | |
216 | collect_register (regcache, I386_FISEG_REGNUM, | |
217 | buf + offsetof (usr_fcontext_t, ufc_inst_sel)); | |
218 | collect_register (regcache, I386_FIOFF_REGNUM, | |
219 | buf + offsetof (usr_fcontext_t, ufc_inst_off)); | |
220 | collect_register (regcache, I386_FOSEG_REGNUM, | |
221 | buf + offsetof (usr_fcontext_t, ufc_data_sel)); | |
222 | collect_register (regcache, I386_FOOFF_REGNUM, | |
223 | buf + offsetof (usr_fcontext_t, ufc_data_off)); | |
224 | collect_16bit_register (regcache, I386_FOP_REGNUM, | |
225 | buf + offsetof (usr_fcontext_t, ufc_opcode)); | |
226 | ||
227 | /* Collect the XMM registers. */ | |
228 | for (i = 0; i < 8; i++) | |
229 | collect_register (regcache, I386_XMM0_REGNUM + i, | |
230 | buf + offsetof (usr_fcontext_t, uxmm_reg) | |
231 | + i * sizeof (struct uxmm_register)); | |
232 | collect_register (regcache, I386_MXCSR_REGNUM, | |
233 | buf + offsetof (usr_fcontext_t, usse_mxcsr)); | |
234 | } | |
235 | ||
236 | /* This is the supply counterpart for collect_16bit_register: | |
237 | It extracts a 2byte value from BUF, and uses that value to | |
238 | set REGNUM's value in the regcache. | |
239 | ||
240 | This is useful to supply the value of certain 16bit registers | |
241 | which are known by GDBserver as 32bit registers (such as the Control | |
242 | Register for instance). */ | |
243 | ||
244 | static void | |
245 | supply_16bit_register (struct regcache *regcache, int regnum, const char *buf) | |
246 | { | |
247 | gdb_byte word[4]; | |
248 | ||
249 | memcpy (word, buf, 2); | |
250 | memset (word + 2, 0, 2); | |
251 | supply_register (regcache, regnum, word); | |
252 | } | |
253 | ||
254 | /* The store_function for the floating-point register set. */ | |
255 | ||
256 | static void | |
257 | lynx_i386_store_fpregset (struct regcache *regcache, const char *buf) | |
258 | { | |
259 | int i; | |
260 | ||
261 | /* Store the %st0 .. %st7 registers. */ | |
262 | for (i = 0; i < 8; i++) | |
263 | supply_register (regcache, I386_ST0_REGNUM + i, | |
264 | buf + offsetof (usr_fcontext_t, ufc_reg) | |
265 | + i * sizeof (struct ufp387_real)); | |
266 | ||
267 | /* Store the other FPU registers. */ | |
268 | supply_16bit_register (regcache, I386_FCTRL_REGNUM, | |
269 | buf + offsetof (usr_fcontext_t, ufc_control)); | |
270 | supply_16bit_register (regcache, I386_FSTAT_REGNUM, | |
271 | buf + offsetof (usr_fcontext_t, ufc_status)); | |
272 | supply_16bit_register (regcache, I386_FTAG_REGNUM, | |
273 | buf + offsetof (usr_fcontext_t, ufc_tag)); | |
274 | supply_register (regcache, I386_FISEG_REGNUM, | |
275 | buf + offsetof (usr_fcontext_t, ufc_inst_sel)); | |
276 | supply_register (regcache, I386_FIOFF_REGNUM, | |
277 | buf + offsetof (usr_fcontext_t, ufc_inst_off)); | |
278 | supply_register (regcache, I386_FOSEG_REGNUM, | |
279 | buf + offsetof (usr_fcontext_t, ufc_data_sel)); | |
280 | supply_register (regcache, I386_FOOFF_REGNUM, | |
281 | buf + offsetof (usr_fcontext_t, ufc_data_off)); | |
282 | supply_16bit_register (regcache, I386_FOP_REGNUM, | |
283 | buf + offsetof (usr_fcontext_t, ufc_opcode)); | |
284 | ||
285 | /* Store the XMM registers. */ | |
286 | for (i = 0; i < 8; i++) | |
287 | supply_register (regcache, I386_XMM0_REGNUM + i, | |
288 | buf + offsetof (usr_fcontext_t, uxmm_reg) | |
289 | + i * sizeof (struct uxmm_register)); | |
290 | supply_register (regcache, I386_MXCSR_REGNUM, | |
291 | buf + offsetof (usr_fcontext_t, usse_mxcsr)); | |
292 | } | |
293 | ||
294 | /* Implements the lynx_target_ops.arch_setup routine. */ | |
295 | ||
296 | static void | |
297 | lynx_i386_arch_setup (void) | |
298 | { | |
299 | init_registers_i386 (); | |
300 | } | |
301 | ||
302 | /* Description of all the x86-lynx register sets. */ | |
303 | ||
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 } | |
313 | }; | |
314 | ||
315 | /* The lynx_target_ops vector for x86-lynx. */ | |
316 | ||
317 | struct lynx_target_ops the_low_target = { | |
318 | lynx_i386_arch_setup, | |
319 | }; |