Commit | Line | Data |
---|---|---|
ed9a39eb | 1 | /* GNU/Linux on ARM native support. |
6aba47ca | 2 | Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007 |
10d6c8cd | 3 | Free Software Foundation, Inc. |
ed9a39eb JM |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. */ | |
ed9a39eb JM |
21 | |
22 | #include "defs.h" | |
23 | #include "inferior.h" | |
24 | #include "gdbcore.h" | |
25 | #include "gdb_string.h" | |
4e052eda | 26 | #include "regcache.h" |
10d6c8cd DJ |
27 | #include "target.h" |
28 | #include "linux-nat.h" | |
05a4558a DJ |
29 | #include "target-descriptions.h" |
30 | #include "xml-support.h" | |
ed9a39eb | 31 | |
aeb98c60 | 32 | #include "arm-tdep.h" |
cb587d83 | 33 | #include "arm-linux-tdep.h" |
aeb98c60 | 34 | |
ed9a39eb JM |
35 | #include <sys/user.h> |
36 | #include <sys/ptrace.h> | |
37 | #include <sys/utsname.h> | |
41c49b06 | 38 | #include <sys/procfs.h> |
ed9a39eb | 39 | |
c60c0f5f MS |
40 | /* Prototypes for supply_gregset etc. */ |
41 | #include "gregset.h" | |
42 | ||
9308fc88 DJ |
43 | /* Defines ps_err_e, struct ps_prochandle. */ |
44 | #include "gdb_proc_service.h" | |
45 | ||
46 | #ifndef PTRACE_GET_THREAD_AREA | |
47 | #define PTRACE_GET_THREAD_AREA 22 | |
48 | #endif | |
49 | ||
05a4558a DJ |
50 | #ifndef PTRACE_GETWMMXREGS |
51 | #define PTRACE_GETWMMXREGS 18 | |
52 | #define PTRACE_SETWMMXREGS 19 | |
53 | #endif | |
54 | ||
55 | /* A flag for whether the WMMX registers are available. */ | |
56 | static int arm_linux_has_wmmx_registers; | |
57 | ||
ed9a39eb JM |
58 | extern int arm_apcs_32; |
59 | ||
ed9a39eb | 60 | /* The following variables are used to determine the version of the |
fdf39c9a | 61 | underlying GNU/Linux operating system. Examples: |
ed9a39eb | 62 | |
fdf39c9a | 63 | GNU/Linux 2.0.35 GNU/Linux 2.2.12 |
ed9a39eb JM |
64 | os_version = 0x00020023 os_version = 0x0002020c |
65 | os_major = 2 os_major = 2 | |
66 | os_minor = 0 os_minor = 2 | |
67 | os_release = 35 os_release = 12 | |
68 | ||
69 | Note: os_version = (os_major << 16) | (os_minor << 8) | os_release | |
70 | ||
71 | These are initialized using get_linux_version() from | |
72 | _initialize_arm_linux_nat(). */ | |
73 | ||
74 | static unsigned int os_version, os_major, os_minor, os_release; | |
75 | ||
fdf39c9a | 76 | /* On GNU/Linux, threads are implemented as pseudo-processes, in which |
41c49b06 | 77 | case we may be tracing more than one process at a time. In that |
39f77062 | 78 | case, inferior_ptid will contain the main process ID and the |
fdf39c9a RE |
79 | individual thread (process) ID. get_thread_id () is used to get |
80 | the thread id if it's available, and the process id otherwise. */ | |
41c49b06 SB |
81 | |
82 | int | |
39f77062 | 83 | get_thread_id (ptid_t ptid) |
41c49b06 | 84 | { |
39f77062 KB |
85 | int tid = TIDGET (ptid); |
86 | if (0 == tid) | |
87 | tid = PIDGET (ptid); | |
41c49b06 SB |
88 | return tid; |
89 | } | |
05a4558a | 90 | #define GET_THREAD_ID(PTID) get_thread_id (PTID) |
41c49b06 | 91 | |
41c49b06 | 92 | /* Get the value of a particular register from the floating point |
c6b92abd | 93 | state of the process and store it into regcache. */ |
41c49b06 SB |
94 | |
95 | static void | |
96 | fetch_fpregister (int regno) | |
97 | { | |
98 | int ret, tid; | |
cb587d83 | 99 | gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE]; |
41c49b06 SB |
100 | |
101 | /* Get the thread id for the ptrace call. */ | |
39f77062 | 102 | tid = GET_THREAD_ID (inferior_ptid); |
41c49b06 SB |
103 | |
104 | /* Read the floating point state. */ | |
cb587d83 | 105 | ret = ptrace (PT_GETFPREGS, tid, 0, fp); |
41c49b06 SB |
106 | if (ret < 0) |
107 | { | |
edefbb7c | 108 | warning (_("Unable to fetch floating point register.")); |
41c49b06 SB |
109 | return; |
110 | } | |
111 | ||
112 | /* Fetch fpsr. */ | |
34e8f22d | 113 | if (ARM_FPS_REGNUM == regno) |
cb587d83 DJ |
114 | regcache_raw_supply (current_regcache, ARM_FPS_REGNUM, |
115 | fp + NWFPE_FPSR_OFFSET); | |
41c49b06 SB |
116 | |
117 | /* Fetch the floating point register. */ | |
34e8f22d | 118 | if (regno >= ARM_F0_REGNUM && regno <= ARM_F7_REGNUM) |
cb587d83 | 119 | supply_nwfpe_register (current_regcache, regno, fp); |
41c49b06 SB |
120 | } |
121 | ||
122 | /* Get the whole floating point state of the process and store it | |
c6b92abd | 123 | into regcache. */ |
ed9a39eb JM |
124 | |
125 | static void | |
126 | fetch_fpregs (void) | |
127 | { | |
41c49b06 | 128 | int ret, regno, tid; |
cb587d83 | 129 | gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE]; |
ed9a39eb | 130 | |
41c49b06 | 131 | /* Get the thread id for the ptrace call. */ |
39f77062 | 132 | tid = GET_THREAD_ID (inferior_ptid); |
41c49b06 | 133 | |
ed9a39eb | 134 | /* Read the floating point state. */ |
cb587d83 | 135 | ret = ptrace (PT_GETFPREGS, tid, 0, fp); |
ed9a39eb JM |
136 | if (ret < 0) |
137 | { | |
edefbb7c | 138 | warning (_("Unable to fetch the floating point registers.")); |
ed9a39eb JM |
139 | return; |
140 | } | |
141 | ||
142 | /* Fetch fpsr. */ | |
cb587d83 DJ |
143 | regcache_raw_supply (current_regcache, ARM_FPS_REGNUM, |
144 | fp + NWFPE_FPSR_OFFSET); | |
ed9a39eb JM |
145 | |
146 | /* Fetch the floating point registers. */ | |
34e8f22d | 147 | for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++) |
cb587d83 | 148 | supply_nwfpe_register (current_regcache, regno, fp); |
ed9a39eb JM |
149 | } |
150 | ||
41c49b06 | 151 | /* Save a particular register into the floating point state of the |
c6b92abd | 152 | process using the contents from regcache. */ |
41c49b06 SB |
153 | |
154 | static void | |
155 | store_fpregister (int regno) | |
156 | { | |
157 | int ret, tid; | |
cb587d83 | 158 | gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE]; |
41c49b06 SB |
159 | |
160 | /* Get the thread id for the ptrace call. */ | |
39f77062 | 161 | tid = GET_THREAD_ID (inferior_ptid); |
41c49b06 SB |
162 | |
163 | /* Read the floating point state. */ | |
cb587d83 | 164 | ret = ptrace (PT_GETFPREGS, tid, 0, fp); |
41c49b06 SB |
165 | if (ret < 0) |
166 | { | |
edefbb7c | 167 | warning (_("Unable to fetch the floating point registers.")); |
41c49b06 SB |
168 | return; |
169 | } | |
170 | ||
171 | /* Store fpsr. */ | |
34e8f22d | 172 | if (ARM_FPS_REGNUM == regno && register_cached (ARM_FPS_REGNUM)) |
cb587d83 DJ |
173 | regcache_raw_collect (current_regcache, ARM_FPS_REGNUM, |
174 | fp + NWFPE_FPSR_OFFSET); | |
41c49b06 SB |
175 | |
176 | /* Store the floating point register. */ | |
34e8f22d | 177 | if (regno >= ARM_F0_REGNUM && regno <= ARM_F7_REGNUM) |
cb587d83 | 178 | collect_nwfpe_register (current_regcache, regno, fp); |
41c49b06 | 179 | |
cb587d83 | 180 | ret = ptrace (PTRACE_SETFPREGS, tid, 0, fp); |
41c49b06 SB |
181 | if (ret < 0) |
182 | { | |
edefbb7c | 183 | warning (_("Unable to store floating point register.")); |
41c49b06 SB |
184 | return; |
185 | } | |
186 | } | |
187 | ||
ed9a39eb | 188 | /* Save the whole floating point state of the process using |
c6b92abd | 189 | the contents from regcache. */ |
ed9a39eb JM |
190 | |
191 | static void | |
192 | store_fpregs (void) | |
193 | { | |
41c49b06 | 194 | int ret, regno, tid; |
cb587d83 | 195 | gdb_byte fp[ARM_LINUX_SIZEOF_NWFPE]; |
ed9a39eb | 196 | |
41c49b06 | 197 | /* Get the thread id for the ptrace call. */ |
39f77062 | 198 | tid = GET_THREAD_ID (inferior_ptid); |
41c49b06 SB |
199 | |
200 | /* Read the floating point state. */ | |
cb587d83 | 201 | ret = ptrace (PT_GETFPREGS, tid, 0, fp); |
41c49b06 SB |
202 | if (ret < 0) |
203 | { | |
edefbb7c | 204 | warning (_("Unable to fetch the floating point registers.")); |
41c49b06 SB |
205 | return; |
206 | } | |
207 | ||
ed9a39eb | 208 | /* Store fpsr. */ |
34e8f22d | 209 | if (register_cached (ARM_FPS_REGNUM)) |
cb587d83 DJ |
210 | regcache_raw_collect (current_regcache, ARM_FPS_REGNUM, |
211 | fp + NWFPE_FPSR_OFFSET); | |
ed9a39eb JM |
212 | |
213 | /* Store the floating point registers. */ | |
34e8f22d | 214 | for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++) |
cb587d83 DJ |
215 | if (register_cached (regno)) |
216 | collect_nwfpe_register (current_regcache, regno, fp); | |
ed9a39eb | 217 | |
cb587d83 | 218 | ret = ptrace (PTRACE_SETFPREGS, tid, 0, fp); |
ed9a39eb JM |
219 | if (ret < 0) |
220 | { | |
edefbb7c | 221 | warning (_("Unable to store floating point registers.")); |
ed9a39eb JM |
222 | return; |
223 | } | |
224 | } | |
225 | ||
41c49b06 | 226 | /* Fetch a general register of the process and store into |
c6b92abd | 227 | regcache. */ |
41c49b06 SB |
228 | |
229 | static void | |
230 | fetch_register (int regno) | |
231 | { | |
232 | int ret, tid; | |
c2152441 | 233 | elf_gregset_t regs; |
41c49b06 SB |
234 | |
235 | /* Get the thread id for the ptrace call. */ | |
39f77062 | 236 | tid = GET_THREAD_ID (inferior_ptid); |
41c49b06 SB |
237 | |
238 | ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); | |
239 | if (ret < 0) | |
240 | { | |
edefbb7c | 241 | warning (_("Unable to fetch general register.")); |
41c49b06 SB |
242 | return; |
243 | } | |
244 | ||
34e8f22d | 245 | if (regno >= ARM_A1_REGNUM && regno < ARM_PC_REGNUM) |
23a6d369 | 246 | regcache_raw_supply (current_regcache, regno, (char *) ®s[regno]); |
41c49b06 | 247 | |
34e8f22d | 248 | if (ARM_PS_REGNUM == regno) |
41c49b06 SB |
249 | { |
250 | if (arm_apcs_32) | |
23a6d369 AC |
251 | regcache_raw_supply (current_regcache, ARM_PS_REGNUM, |
252 | (char *) ®s[ARM_CPSR_REGNUM]); | |
41c49b06 | 253 | else |
23a6d369 AC |
254 | regcache_raw_supply (current_regcache, ARM_PS_REGNUM, |
255 | (char *) ®s[ARM_PC_REGNUM]); | |
41c49b06 SB |
256 | } |
257 | ||
34e8f22d | 258 | if (ARM_PC_REGNUM == regno) |
41c49b06 | 259 | { |
34e8f22d | 260 | regs[ARM_PC_REGNUM] = ADDR_BITS_REMOVE (regs[ARM_PC_REGNUM]); |
23a6d369 AC |
261 | regcache_raw_supply (current_regcache, ARM_PC_REGNUM, |
262 | (char *) ®s[ARM_PC_REGNUM]); | |
41c49b06 SB |
263 | } |
264 | } | |
265 | ||
ed9a39eb | 266 | /* Fetch all general registers of the process and store into |
c6b92abd | 267 | regcache. */ |
ed9a39eb JM |
268 | |
269 | static void | |
270 | fetch_regs (void) | |
271 | { | |
41c49b06 | 272 | int ret, regno, tid; |
c2152441 | 273 | elf_gregset_t regs; |
ed9a39eb | 274 | |
41c49b06 | 275 | /* Get the thread id for the ptrace call. */ |
39f77062 | 276 | tid = GET_THREAD_ID (inferior_ptid); |
41c49b06 SB |
277 | |
278 | ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); | |
ed9a39eb JM |
279 | if (ret < 0) |
280 | { | |
edefbb7c | 281 | warning (_("Unable to fetch general registers.")); |
ed9a39eb JM |
282 | return; |
283 | } | |
284 | ||
34e8f22d | 285 | for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++) |
23a6d369 | 286 | regcache_raw_supply (current_regcache, regno, (char *) ®s[regno]); |
ed9a39eb JM |
287 | |
288 | if (arm_apcs_32) | |
23a6d369 AC |
289 | regcache_raw_supply (current_regcache, ARM_PS_REGNUM, |
290 | (char *) ®s[ARM_CPSR_REGNUM]); | |
ed9a39eb | 291 | else |
23a6d369 AC |
292 | regcache_raw_supply (current_regcache, ARM_PS_REGNUM, |
293 | (char *) ®s[ARM_PC_REGNUM]); | |
ed9a39eb | 294 | |
34e8f22d | 295 | regs[ARM_PC_REGNUM] = ADDR_BITS_REMOVE (regs[ARM_PC_REGNUM]); |
23a6d369 AC |
296 | regcache_raw_supply (current_regcache, ARM_PC_REGNUM, |
297 | (char *) ®s[ARM_PC_REGNUM]); | |
ed9a39eb JM |
298 | } |
299 | ||
300 | /* Store all general registers of the process from the values in | |
c6b92abd | 301 | regcache. */ |
ed9a39eb | 302 | |
41c49b06 SB |
303 | static void |
304 | store_register (int regno) | |
305 | { | |
306 | int ret, tid; | |
c2152441 | 307 | elf_gregset_t regs; |
41c49b06 | 308 | |
c6b92abd | 309 | if (!register_cached (regno)) |
41c49b06 SB |
310 | return; |
311 | ||
312 | /* Get the thread id for the ptrace call. */ | |
39f77062 | 313 | tid = GET_THREAD_ID (inferior_ptid); |
41c49b06 SB |
314 | |
315 | /* Get the general registers from the process. */ | |
316 | ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); | |
317 | if (ret < 0) | |
318 | { | |
edefbb7c | 319 | warning (_("Unable to fetch general registers.")); |
41c49b06 SB |
320 | return; |
321 | } | |
322 | ||
34e8f22d | 323 | if (regno >= ARM_A1_REGNUM && regno <= ARM_PC_REGNUM) |
822c9732 | 324 | regcache_raw_collect (current_regcache, regno, (char *) ®s[regno]); |
adb8a87c DJ |
325 | else if (arm_apcs_32 && regno == ARM_PS_REGNUM) |
326 | regcache_raw_collect (current_regcache, regno, | |
327 | (char *) ®s[ARM_CPSR_REGNUM]); | |
328 | else if (!arm_apcs_32 && regno == ARM_PS_REGNUM) | |
329 | regcache_raw_collect (current_regcache, ARM_PC_REGNUM, | |
330 | (char *) ®s[ARM_PC_REGNUM]); | |
41c49b06 SB |
331 | |
332 | ret = ptrace (PTRACE_SETREGS, tid, 0, ®s); | |
333 | if (ret < 0) | |
334 | { | |
edefbb7c | 335 | warning (_("Unable to store general register.")); |
41c49b06 SB |
336 | return; |
337 | } | |
338 | } | |
339 | ||
ed9a39eb JM |
340 | static void |
341 | store_regs (void) | |
342 | { | |
41c49b06 | 343 | int ret, regno, tid; |
c2152441 | 344 | elf_gregset_t regs; |
ed9a39eb | 345 | |
41c49b06 | 346 | /* Get the thread id for the ptrace call. */ |
39f77062 | 347 | tid = GET_THREAD_ID (inferior_ptid); |
41c49b06 SB |
348 | |
349 | /* Fetch the general registers. */ | |
350 | ret = ptrace (PTRACE_GETREGS, tid, 0, ®s); | |
ed9a39eb JM |
351 | if (ret < 0) |
352 | { | |
edefbb7c | 353 | warning (_("Unable to fetch general registers.")); |
ed9a39eb JM |
354 | return; |
355 | } | |
356 | ||
34e8f22d | 357 | for (regno = ARM_A1_REGNUM; regno <= ARM_PC_REGNUM; regno++) |
ed9a39eb | 358 | { |
c6b92abd | 359 | if (register_cached (regno)) |
822c9732 | 360 | regcache_raw_collect (current_regcache, regno, (char *) ®s[regno]); |
ed9a39eb JM |
361 | } |
362 | ||
adb8a87c DJ |
363 | if (arm_apcs_32 && register_cached (ARM_PS_REGNUM)) |
364 | regcache_raw_collect (current_regcache, ARM_PS_REGNUM, | |
365 | (char *) ®s[ARM_CPSR_REGNUM]); | |
366 | ||
41c49b06 | 367 | ret = ptrace (PTRACE_SETREGS, tid, 0, ®s); |
ed9a39eb JM |
368 | |
369 | if (ret < 0) | |
370 | { | |
edefbb7c | 371 | warning (_("Unable to store general registers.")); |
ed9a39eb JM |
372 | return; |
373 | } | |
374 | } | |
375 | ||
05a4558a DJ |
376 | /* Fetch all WMMX registers of the process and store into |
377 | regcache. */ | |
378 | ||
379 | #define IWMMXT_REGS_SIZE (16 * 8 + 6 * 4) | |
380 | ||
381 | static void | |
382 | fetch_wmmx_regs (void) | |
383 | { | |
384 | char regbuf[IWMMXT_REGS_SIZE]; | |
385 | int ret, regno, tid; | |
386 | ||
387 | /* Get the thread id for the ptrace call. */ | |
388 | tid = GET_THREAD_ID (inferior_ptid); | |
389 | ||
390 | ret = ptrace (PTRACE_GETWMMXREGS, tid, 0, regbuf); | |
391 | if (ret < 0) | |
392 | { | |
393 | warning (_("Unable to fetch WMMX registers.")); | |
394 | return; | |
395 | } | |
396 | ||
397 | for (regno = 0; regno < 16; regno++) | |
398 | regcache_raw_supply (current_regcache, regno + ARM_WR0_REGNUM, | |
399 | ®buf[regno * 8]); | |
400 | ||
401 | for (regno = 0; regno < 2; regno++) | |
402 | regcache_raw_supply (current_regcache, regno + ARM_WCSSF_REGNUM, | |
403 | ®buf[16 * 8 + regno * 4]); | |
404 | ||
405 | for (regno = 0; regno < 4; regno++) | |
406 | regcache_raw_supply (current_regcache, regno + ARM_WCGR0_REGNUM, | |
407 | ®buf[16 * 8 + 2 * 4 + regno * 4]); | |
408 | } | |
409 | ||
410 | static void | |
411 | store_wmmx_regs (void) | |
412 | { | |
413 | char regbuf[IWMMXT_REGS_SIZE]; | |
414 | int ret, regno, tid; | |
415 | ||
416 | /* Get the thread id for the ptrace call. */ | |
417 | tid = GET_THREAD_ID (inferior_ptid); | |
418 | ||
419 | ret = ptrace (PTRACE_GETWMMXREGS, tid, 0, regbuf); | |
420 | if (ret < 0) | |
421 | { | |
422 | warning (_("Unable to fetch WMMX registers.")); | |
423 | return; | |
424 | } | |
425 | ||
426 | for (regno = 0; regno < 16; regno++) | |
427 | if (register_cached (regno + ARM_WR0_REGNUM)) | |
428 | regcache_raw_collect (current_regcache, regno + ARM_WR0_REGNUM, | |
429 | ®buf[regno * 8]); | |
430 | ||
431 | for (regno = 0; regno < 2; regno++) | |
432 | if (register_cached (regno + ARM_WCSSF_REGNUM)) | |
433 | regcache_raw_collect (current_regcache, regno + ARM_WCSSF_REGNUM, | |
434 | ®buf[16 * 8 + regno * 4]); | |
435 | ||
436 | for (regno = 0; regno < 4; regno++) | |
437 | if (register_cached (regno + ARM_WCGR0_REGNUM)) | |
438 | regcache_raw_collect (current_regcache, regno + ARM_WCGR0_REGNUM, | |
439 | ®buf[16 * 8 + 2 * 4 + regno * 4]); | |
440 | ||
441 | ret = ptrace (PTRACE_SETWMMXREGS, tid, 0, regbuf); | |
442 | ||
443 | if (ret < 0) | |
444 | { | |
445 | warning (_("Unable to store WMMX registers.")); | |
446 | return; | |
447 | } | |
448 | } | |
449 | ||
ed9a39eb JM |
450 | /* Fetch registers from the child process. Fetch all registers if |
451 | regno == -1, otherwise fetch all general registers or all floating | |
452 | point registers depending upon the value of regno. */ | |
453 | ||
10d6c8cd DJ |
454 | static void |
455 | arm_linux_fetch_inferior_registers (int regno) | |
ed9a39eb | 456 | { |
41c49b06 SB |
457 | if (-1 == regno) |
458 | { | |
459 | fetch_regs (); | |
460 | fetch_fpregs (); | |
05a4558a DJ |
461 | if (arm_linux_has_wmmx_registers) |
462 | fetch_wmmx_regs (); | |
41c49b06 SB |
463 | } |
464 | else | |
465 | { | |
05a4558a | 466 | if (regno < ARM_F0_REGNUM || regno == ARM_PS_REGNUM) |
41c49b06 | 467 | fetch_register (regno); |
05a4558a | 468 | else if (regno >= ARM_F0_REGNUM && regno <= ARM_FPS_REGNUM) |
41c49b06 | 469 | fetch_fpregister (regno); |
05a4558a DJ |
470 | else if (arm_linux_has_wmmx_registers |
471 | && regno >= ARM_WR0_REGNUM && regno <= ARM_WCGR7_REGNUM) | |
472 | fetch_wmmx_regs (); | |
41c49b06 | 473 | } |
ed9a39eb JM |
474 | } |
475 | ||
476 | /* Store registers back into the inferior. Store all registers if | |
477 | regno == -1, otherwise store all general registers or all floating | |
478 | point registers depending upon the value of regno. */ | |
479 | ||
10d6c8cd DJ |
480 | static void |
481 | arm_linux_store_inferior_registers (int regno) | |
ed9a39eb | 482 | { |
41c49b06 SB |
483 | if (-1 == regno) |
484 | { | |
485 | store_regs (); | |
486 | store_fpregs (); | |
05a4558a DJ |
487 | if (arm_linux_has_wmmx_registers) |
488 | store_wmmx_regs (); | |
41c49b06 SB |
489 | } |
490 | else | |
491 | { | |
05a4558a | 492 | if (regno < ARM_F0_REGNUM || regno == ARM_PS_REGNUM) |
41c49b06 | 493 | store_register (regno); |
05a4558a | 494 | else if ((regno >= ARM_F0_REGNUM) && (regno <= ARM_FPS_REGNUM)) |
41c49b06 | 495 | store_fpregister (regno); |
05a4558a DJ |
496 | else if (arm_linux_has_wmmx_registers |
497 | && regno >= ARM_WR0_REGNUM && regno <= ARM_WCGR7_REGNUM) | |
498 | store_wmmx_regs (); | |
41c49b06 | 499 | } |
ed9a39eb JM |
500 | } |
501 | ||
cb587d83 DJ |
502 | /* Wrapper functions for the standard regset handling, used by |
503 | thread debugging. */ | |
41c49b06 SB |
504 | |
505 | void | |
713f0374 | 506 | fill_gregset (gdb_gregset_t *gregsetp, int regno) |
41c49b06 | 507 | { |
cb587d83 | 508 | arm_linux_collect_gregset (NULL, current_regcache, regno, gregsetp, 0); |
41c49b06 SB |
509 | } |
510 | ||
41c49b06 | 511 | void |
713f0374 | 512 | supply_gregset (gdb_gregset_t *gregsetp) |
41c49b06 | 513 | { |
cb587d83 | 514 | arm_linux_supply_gregset (NULL, current_regcache, -1, gregsetp, 0); |
41c49b06 SB |
515 | } |
516 | ||
41c49b06 | 517 | void |
713f0374 | 518 | fill_fpregset (gdb_fpregset_t *fpregsetp, int regno) |
41c49b06 | 519 | { |
cb587d83 | 520 | arm_linux_collect_nwfpe (NULL, current_regcache, regno, fpregsetp, 0); |
41c49b06 SB |
521 | } |
522 | ||
523 | /* Fill GDB's register array with the floating-point register values | |
524 | in *fpregsetp. */ | |
525 | ||
526 | void | |
713f0374 | 527 | supply_fpregset (gdb_fpregset_t *fpregsetp) |
ed9a39eb | 528 | { |
cb587d83 | 529 | arm_linux_supply_nwfpe (NULL, current_regcache, -1, fpregsetp, 0); |
ed9a39eb JM |
530 | } |
531 | ||
532 | int | |
533 | arm_linux_kernel_u_size (void) | |
534 | { | |
535 | return (sizeof (struct user)); | |
536 | } | |
537 | ||
9308fc88 DJ |
538 | /* Fetch the thread-local storage pointer for libthread_db. */ |
539 | ||
540 | ps_err_e | |
541 | ps_get_thread_area (const struct ps_prochandle *ph, | |
542 | lwpid_t lwpid, int idx, void **base) | |
543 | { | |
544 | if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0) | |
545 | return PS_ERR; | |
546 | ||
547 | /* IDX is the bias from the thread pointer to the beginning of the | |
548 | thread descriptor. It has to be subtracted due to implementation | |
549 | quirks in libthread_db. */ | |
550 | *base = (void *) ((char *)*base - idx); | |
551 | ||
552 | return PS_OK; | |
553 | } | |
554 | ||
ed9a39eb JM |
555 | static unsigned int |
556 | get_linux_version (unsigned int *vmajor, | |
557 | unsigned int *vminor, | |
558 | unsigned int *vrelease) | |
559 | { | |
560 | struct utsname info; | |
561 | char *pmajor, *pminor, *prelease, *tail; | |
562 | ||
563 | if (-1 == uname (&info)) | |
564 | { | |
edefbb7c | 565 | warning (_("Unable to determine GNU/Linux version.")); |
ed9a39eb JM |
566 | return -1; |
567 | } | |
568 | ||
569 | pmajor = strtok (info.release, "."); | |
570 | pminor = strtok (NULL, "."); | |
571 | prelease = strtok (NULL, "."); | |
572 | ||
573 | *vmajor = (unsigned int) strtoul (pmajor, &tail, 0); | |
574 | *vminor = (unsigned int) strtoul (pminor, &tail, 0); | |
575 | *vrelease = (unsigned int) strtoul (prelease, &tail, 0); | |
576 | ||
577 | return ((*vmajor << 16) | (*vminor << 8) | *vrelease); | |
578 | } | |
579 | ||
05a4558a DJ |
580 | static LONGEST (*super_xfer_partial) (struct target_ops *, enum target_object, |
581 | const char *, gdb_byte *, const gdb_byte *, | |
582 | ULONGEST, LONGEST); | |
583 | ||
584 | static LONGEST | |
585 | arm_linux_xfer_partial (struct target_ops *ops, | |
586 | enum target_object object, | |
587 | const char *annex, | |
588 | gdb_byte *readbuf, const gdb_byte *writebuf, | |
589 | ULONGEST offset, LONGEST len) | |
590 | { | |
591 | if (object == TARGET_OBJECT_AVAILABLE_FEATURES) | |
592 | { | |
593 | if (annex != NULL && strcmp (annex, "target.xml") == 0) | |
594 | { | |
595 | int ret; | |
596 | char regbuf[IWMMXT_REGS_SIZE]; | |
597 | ||
598 | ret = ptrace (PTRACE_GETWMMXREGS, GET_THREAD_ID (inferior_ptid), | |
599 | 0, regbuf); | |
600 | if (ret < 0) | |
601 | arm_linux_has_wmmx_registers = 0; | |
602 | else | |
603 | arm_linux_has_wmmx_registers = 1; | |
604 | ||
605 | if (arm_linux_has_wmmx_registers) | |
606 | annex = "arm-with-iwmmxt.xml"; | |
607 | else | |
608 | return -1; | |
609 | } | |
610 | ||
611 | return xml_builtin_xfer_partial (annex, readbuf, writebuf, offset, len); | |
612 | } | |
613 | ||
614 | return super_xfer_partial (ops, object, annex, readbuf, writebuf, | |
615 | offset, len); | |
616 | } | |
617 | ||
10d6c8cd DJ |
618 | void _initialize_arm_linux_nat (void); |
619 | ||
ed9a39eb JM |
620 | void |
621 | _initialize_arm_linux_nat (void) | |
622 | { | |
10d6c8cd DJ |
623 | struct target_ops *t; |
624 | ||
ed9a39eb | 625 | os_version = get_linux_version (&os_major, &os_minor, &os_release); |
10d6c8cd DJ |
626 | |
627 | /* Fill in the generic GNU/Linux methods. */ | |
628 | t = linux_target (); | |
629 | ||
630 | /* Add our register access methods. */ | |
631 | t->to_fetch_registers = arm_linux_fetch_inferior_registers; | |
632 | t->to_store_registers = arm_linux_store_inferior_registers; | |
633 | ||
05a4558a DJ |
634 | /* Override the default to_xfer_partial. */ |
635 | super_xfer_partial = t->to_xfer_partial; | |
636 | t->to_xfer_partial = arm_linux_xfer_partial; | |
637 | ||
10d6c8cd | 638 | /* Register the target. */ |
f973ed9c | 639 | linux_nat_add_target (t); |
ed9a39eb | 640 | } |