Commit | Line | Data |
---|---|---|
a4b6fc86 AC |
1 | /* Motorola m68k native support for GNU/Linux. |
2 | ||
6aba47ca | 3 | Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
10d6c8cd | 4 | Free Software Foundation, Inc. |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "frame.h" | |
23 | #include "inferior.h" | |
24 | #include "language.h" | |
25 | #include "gdbcore.h" | |
32eeb91a | 26 | #include "gdb_string.h" |
4e052eda | 27 | #include "regcache.h" |
10d6c8cd DJ |
28 | #include "target.h" |
29 | #include "linux-nat.h" | |
c906108c | 30 | |
32eeb91a AS |
31 | #include "m68k-tdep.h" |
32 | ||
c906108c SS |
33 | #include <sys/param.h> |
34 | #include <sys/dir.h> | |
35 | #include <signal.h> | |
0280a90a | 36 | #include <sys/ptrace.h> |
c906108c SS |
37 | #include <sys/user.h> |
38 | #include <sys/ioctl.h> | |
39 | #include <fcntl.h> | |
40 | #include <sys/procfs.h> | |
41 | ||
0280a90a AS |
42 | #ifdef HAVE_SYS_REG_H |
43 | #include <sys/reg.h> | |
44 | #endif | |
45 | ||
c906108c SS |
46 | #include <sys/file.h> |
47 | #include "gdb_stat.h" | |
48 | ||
49 | #include "floatformat.h" | |
50 | ||
51 | #include "target.h" | |
3e00823e UW |
52 | |
53 | /* Prototypes for supply_gregset etc. */ | |
54 | #include "gregset.h" | |
c906108c | 55 | \f |
c9f4d572 | 56 | /* This table must line up with gdbarch_register_name in "m68k-tdep.c". */ |
c5aa993b | 57 | static const int regmap[] = |
c906108c SS |
58 | { |
59 | PT_D0, PT_D1, PT_D2, PT_D3, PT_D4, PT_D5, PT_D6, PT_D7, | |
60 | PT_A0, PT_A1, PT_A2, PT_A3, PT_A4, PT_A5, PT_A6, PT_USP, | |
61 | PT_SR, PT_PC, | |
62 | /* PT_FP0, ..., PT_FP7 */ | |
63 | 21, 24, 27, 30, 33, 36, 39, 42, | |
64 | /* PT_FPCR, PT_FPSR, PT_FPIAR */ | |
65 | 45, 46, 47 | |
66 | }; | |
67 | ||
0280a90a AS |
68 | /* Which ptrace request retrieves which registers? |
69 | These apply to the corresponding SET requests as well. */ | |
70 | #define NUM_GREGS (18) | |
71 | #define MAX_NUM_REGS (NUM_GREGS + 11) | |
72 | ||
73 | int | |
74 | getregs_supplies (int regno) | |
75 | { | |
76 | return 0 <= regno && regno < NUM_GREGS; | |
77 | } | |
78 | ||
79 | int | |
80 | getfpregs_supplies (int regno) | |
81 | { | |
3e8c568d UW |
82 | return gdbarch_fp0_regnum (current_gdbarch) <= regno |
83 | && regno <= M68K_FPI_REGNUM; | |
0280a90a AS |
84 | } |
85 | ||
86 | /* Does the current host support the GETREGS request? */ | |
87 | int have_ptrace_getregs = | |
88 | #ifdef HAVE_PTRACE_GETREGS | |
89 | 1 | |
90 | #else | |
91 | 0 | |
92 | #endif | |
93 | ; | |
94 | ||
95 | \f | |
96 | ||
0280a90a AS |
97 | /* Fetching registers directly from the U area, one at a time. */ |
98 | ||
99 | /* FIXME: This duplicates code from `inptrace.c'. The problem is that we | |
100 | define FETCH_INFERIOR_REGISTERS since we want to use our own versions | |
101 | of {fetch,store}_inferior_registers that use the GETREGS request. This | |
102 | means that the code in `infptrace.c' is #ifdef'd out. But we need to | |
103 | fall back on that code when GDB is running on top of a kernel that | |
104 | doesn't support the GETREGS request. */ | |
105 | ||
106 | #ifndef PT_READ_U | |
107 | #define PT_READ_U PTRACE_PEEKUSR | |
108 | #endif | |
109 | #ifndef PT_WRITE_U | |
110 | #define PT_WRITE_U PTRACE_POKEUSR | |
111 | #endif | |
112 | ||
0280a90a AS |
113 | /* Fetch one register. */ |
114 | ||
115 | static void | |
56be3814 | 116 | fetch_register (struct regcache *regcache, int regno) |
0280a90a | 117 | { |
c984b7ff | 118 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
0280a90a AS |
119 | /* This isn't really an address. But ptrace thinks of it as one. */ |
120 | CORE_ADDR regaddr; | |
121 | char mess[128]; /* For messages */ | |
52f0bd74 | 122 | int i; |
123a958e | 123 | char buf[MAX_REGISTER_SIZE]; |
0280a90a AS |
124 | int tid; |
125 | ||
c984b7ff | 126 | if (gdbarch_cannot_fetch_register (gdbarch, regno)) |
0280a90a | 127 | { |
c984b7ff | 128 | memset (buf, '\0', register_size (gdbarch, regno)); /* Supply zeroes */ |
56be3814 | 129 | regcache_raw_supply (regcache, regno, buf); |
0280a90a AS |
130 | return; |
131 | } | |
132 | ||
133 | /* Overload thread id onto process id */ | |
8de307e0 AS |
134 | tid = TIDGET (inferior_ptid); |
135 | if (tid == 0) | |
0280a90a AS |
136 | tid = PIDGET (inferior_ptid); /* no thread id, just use process id */ |
137 | ||
de732108 | 138 | regaddr = 4 * regmap[regno]; |
c984b7ff | 139 | for (i = 0; i < register_size (gdbarch, regno); |
5f402660 | 140 | i += sizeof (PTRACE_TYPE_RET)) |
0280a90a AS |
141 | { |
142 | errno = 0; | |
5f402660 UW |
143 | *(PTRACE_TYPE_RET *) &buf[i] = ptrace (PT_READ_U, tid, |
144 | (PTRACE_TYPE_ARG3) regaddr, 0); | |
145 | regaddr += sizeof (PTRACE_TYPE_RET); | |
0280a90a AS |
146 | if (errno != 0) |
147 | { | |
148 | sprintf (mess, "reading register %s (#%d)", | |
c984b7ff | 149 | gdbarch_register_name (gdbarch, regno), regno); |
0280a90a AS |
150 | perror_with_name (mess); |
151 | } | |
152 | } | |
56be3814 | 153 | regcache_raw_supply (regcache, regno, buf); |
0280a90a AS |
154 | } |
155 | ||
156 | /* Fetch register values from the inferior. | |
157 | If REGNO is negative, do this for all registers. | |
158 | Otherwise, REGNO specifies which register (so we can save time). */ | |
c906108c | 159 | |
10d6c8cd | 160 | static void |
56be3814 | 161 | old_fetch_inferior_registers (struct regcache *regcache, int regno) |
0280a90a AS |
162 | { |
163 | if (regno >= 0) | |
164 | { | |
56be3814 | 165 | fetch_register (regcache, regno); |
0280a90a AS |
166 | } |
167 | else | |
168 | { | |
c984b7ff UW |
169 | for (regno = 0; |
170 | regno < gdbarch_num_regs (get_regcache_arch (regcache)); | |
171 | regno++) | |
0280a90a | 172 | { |
56be3814 | 173 | fetch_register (regcache, regno); |
0280a90a AS |
174 | } |
175 | } | |
176 | } | |
177 | ||
178 | /* Store one register. */ | |
179 | ||
180 | static void | |
56be3814 | 181 | store_register (const struct regcache *regcache, int regno) |
0280a90a | 182 | { |
c984b7ff | 183 | struct gdbarch *gdbarch = reg_regcache_arch (regcache); |
0280a90a AS |
184 | /* This isn't really an address. But ptrace thinks of it as one. */ |
185 | CORE_ADDR regaddr; | |
186 | char mess[128]; /* For messages */ | |
52f0bd74 | 187 | int i; |
0280a90a | 188 | int tid; |
d9d9c31f | 189 | char buf[MAX_REGISTER_SIZE]; |
0280a90a | 190 | |
c984b7ff | 191 | if (gdbarch_cannot_store_register (gdbarch, regno)) |
8d4c1ba3 | 192 | return; |
0280a90a AS |
193 | |
194 | /* Overload thread id onto process id */ | |
8de307e0 AS |
195 | tid = TIDGET (inferior_ptid); |
196 | if (tid == 0) | |
0280a90a AS |
197 | tid = PIDGET (inferior_ptid); /* no thread id, just use process id */ |
198 | ||
de732108 | 199 | regaddr = 4 * regmap[regno]; |
9852326a AS |
200 | |
201 | /* Put the contents of regno into a local buffer */ | |
56be3814 | 202 | regcache_raw_collect (regcache, regno, buf); |
9852326a AS |
203 | |
204 | /* Store the local buffer into the inferior a chunk at the time. */ | |
c984b7ff | 205 | for (i = 0; i < register_size (gdbarch, regno); |
5f402660 | 206 | i += sizeof (PTRACE_TYPE_RET)) |
0280a90a AS |
207 | { |
208 | errno = 0; | |
5f402660 UW |
209 | ptrace (PT_WRITE_U, tid, (PTRACE_TYPE_ARG3) regaddr, |
210 | *(PTRACE_TYPE_RET *) (buf + i)); | |
211 | regaddr += sizeof (PTRACE_TYPE_RET); | |
0280a90a AS |
212 | if (errno != 0) |
213 | { | |
214 | sprintf (mess, "writing register %s (#%d)", | |
c984b7ff | 215 | gdbarch_register_name (gdbarch, regno), regno); |
0280a90a AS |
216 | perror_with_name (mess); |
217 | } | |
218 | } | |
219 | } | |
220 | ||
221 | /* Store our register values back into the inferior. | |
222 | If REGNO is negative, do this for all registers. | |
223 | Otherwise, REGNO specifies which register (so we can save time). */ | |
224 | ||
10d6c8cd | 225 | static void |
56be3814 | 226 | old_store_inferior_registers (const struct regcache *regcache, int regno) |
0280a90a AS |
227 | { |
228 | if (regno >= 0) | |
229 | { | |
56be3814 | 230 | store_register (regcache, regno); |
0280a90a AS |
231 | } |
232 | else | |
233 | { | |
c984b7ff UW |
234 | for (regno = 0; |
235 | regno < gdbarch_num_regs (get_regcache_arch (regcache)); | |
236 | regno++) | |
0280a90a | 237 | { |
56be3814 | 238 | store_register (regcache, regno); |
0280a90a AS |
239 | } |
240 | } | |
241 | } | |
242 | \f | |
f175af98 DJ |
243 | /* Given a pointer to a general register set in /proc format |
244 | (elf_gregset_t *), unpack the register contents and supply | |
245 | them as gdb's idea of the current register values. */ | |
c906108c | 246 | |
c906108c | 247 | void |
7f7fe91e | 248 | supply_gregset (struct regcache *regcache, const elf_gregset_t *gregsetp) |
c906108c | 249 | { |
c984b7ff | 250 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
7f7fe91e | 251 | const elf_greg_t *regp = (const elf_greg_t *) gregsetp; |
c906108c SS |
252 | int regi; |
253 | ||
3e8c568d | 254 | for (regi = M68K_D0_REGNUM; |
c984b7ff | 255 | regi <= gdbarch_sp_regnum (gdbarch); |
3e8c568d | 256 | regi++) |
7f7fe91e | 257 | regcache_raw_supply (regcache, regi, ®p[regmap[regi]]); |
c984b7ff | 258 | regcache_raw_supply (regcache, gdbarch_ps_regnum (gdbarch), |
3e8c568d UW |
259 | ®p[PT_SR]); |
260 | regcache_raw_supply (regcache, | |
c984b7ff | 261 | gdbarch_pc_regnum (gdbarch), ®p[PT_PC]); |
0280a90a AS |
262 | } |
263 | ||
264 | /* Fill register REGNO (if it is a general-purpose register) in | |
265 | *GREGSETPS with the value in GDB's register array. If REGNO is -1, | |
266 | do this for all registers. */ | |
267 | void | |
7f7fe91e UW |
268 | fill_gregset (const struct regcache *regcache, |
269 | elf_gregset_t *gregsetp, int regno) | |
0280a90a AS |
270 | { |
271 | elf_greg_t *regp = (elf_greg_t *) gregsetp; | |
272 | int i; | |
273 | ||
274 | for (i = 0; i < NUM_GREGS; i++) | |
8de307e0 | 275 | if (regno == -1 || regno == i) |
7f7fe91e | 276 | regcache_raw_collect (regcache, i, regp + regmap[i]); |
0280a90a AS |
277 | } |
278 | ||
279 | #ifdef HAVE_PTRACE_GETREGS | |
280 | ||
281 | /* Fetch all general-purpose registers from process/thread TID and | |
282 | store their values in GDB's register array. */ | |
283 | ||
284 | static void | |
56be3814 | 285 | fetch_regs (struct regcache *regcache, int tid) |
0280a90a AS |
286 | { |
287 | elf_gregset_t regs; | |
288 | ||
289 | if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0) | |
290 | { | |
291 | if (errno == EIO) | |
292 | { | |
293 | /* The kernel we're running on doesn't support the GETREGS | |
294 | request. Reset `have_ptrace_getregs'. */ | |
295 | have_ptrace_getregs = 0; | |
296 | return; | |
297 | } | |
298 | ||
e2e0b3e5 | 299 | perror_with_name (_("Couldn't get registers")); |
0280a90a AS |
300 | } |
301 | ||
56be3814 | 302 | supply_gregset (regcache, (const elf_gregset_t *) ®s); |
c906108c SS |
303 | } |
304 | ||
0280a90a AS |
305 | /* Store all valid general-purpose registers in GDB's register array |
306 | into the process/thread specified by TID. */ | |
307 | ||
308 | static void | |
56be3814 | 309 | store_regs (const struct regcache *regcache, int tid, int regno) |
0280a90a AS |
310 | { |
311 | elf_gregset_t regs; | |
312 | ||
313 | if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0) | |
e2e0b3e5 | 314 | perror_with_name (_("Couldn't get registers")); |
0280a90a | 315 | |
56be3814 | 316 | fill_gregset (regcache, ®s, regno); |
0280a90a AS |
317 | |
318 | if (ptrace (PTRACE_SETREGS, tid, 0, (int) ®s) < 0) | |
e2e0b3e5 | 319 | perror_with_name (_("Couldn't write registers")); |
0280a90a AS |
320 | } |
321 | ||
322 | #else | |
323 | ||
56be3814 UW |
324 | static void fetch_regs (struct regcache *regcache, int tid) {} |
325 | static void store_regs (const struct regcache *regcache, int tid, int regno) {} | |
0280a90a AS |
326 | |
327 | #endif | |
328 | ||
329 | \f | |
330 | /* Transfering floating-point registers between GDB, inferiors and cores. */ | |
331 | ||
332 | /* What is the address of fpN within the floating-point register set F? */ | |
7f7fe91e | 333 | #define FPREG_ADDR(f, n) (&(f)->fpregs[(n) * 3]) |
0280a90a AS |
334 | |
335 | /* Fill GDB's register array with the floating-point register values in | |
336 | *FPREGSETP. */ | |
c906108c | 337 | |
c5aa993b | 338 | void |
7f7fe91e | 339 | supply_fpregset (struct regcache *regcache, const elf_fpregset_t *fpregsetp) |
c906108c | 340 | { |
c984b7ff | 341 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
c906108c SS |
342 | int regi; |
343 | ||
c984b7ff UW |
344 | for (regi = gdbarch_fp0_regnum (gdbarch); |
345 | regi < gdbarch_fp0_regnum (gdbarch) + 8; regi++) | |
7f7fe91e | 346 | regcache_raw_supply (regcache, regi, |
3e8c568d | 347 | FPREG_ADDR (fpregsetp, |
c984b7ff | 348 | regi - gdbarch_fp0_regnum (gdbarch))); |
7f7fe91e UW |
349 | regcache_raw_supply (regcache, M68K_FPC_REGNUM, &fpregsetp->fpcntl[0]); |
350 | regcache_raw_supply (regcache, M68K_FPS_REGNUM, &fpregsetp->fpcntl[1]); | |
351 | regcache_raw_supply (regcache, M68K_FPI_REGNUM, &fpregsetp->fpcntl[2]); | |
c906108c SS |
352 | } |
353 | ||
0280a90a AS |
354 | /* Fill register REGNO (if it is a floating-point register) in |
355 | *FPREGSETP with the value in GDB's register array. If REGNO is -1, | |
356 | do this for all registers. */ | |
357 | ||
358 | void | |
7f7fe91e UW |
359 | fill_fpregset (const struct regcache *regcache, |
360 | elf_fpregset_t *fpregsetp, int regno) | |
0280a90a | 361 | { |
c984b7ff | 362 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
0280a90a AS |
363 | int i; |
364 | ||
365 | /* Fill in the floating-point registers. */ | |
c984b7ff UW |
366 | for (i = gdbarch_fp0_regnum (gdbarch); |
367 | i < gdbarch_fp0_regnum (gdbarch) + 8; i++) | |
0280a90a | 368 | if (regno == -1 || regno == i) |
7f7fe91e | 369 | regcache_raw_collect (regcache, i, |
3e8c568d | 370 | FPREG_ADDR (fpregsetp, |
c984b7ff | 371 | i - gdbarch_fp0_regnum (gdbarch))); |
0280a90a AS |
372 | |
373 | /* Fill in the floating-point control registers. */ | |
32eeb91a | 374 | for (i = M68K_FPC_REGNUM; i <= M68K_FPI_REGNUM; i++) |
0280a90a | 375 | if (regno == -1 || regno == i) |
7f7fe91e UW |
376 | regcache_raw_collect (regcache, i, |
377 | &fpregsetp->fpcntl[i - M68K_FPC_REGNUM]); | |
0280a90a AS |
378 | } |
379 | ||
380 | #ifdef HAVE_PTRACE_GETREGS | |
381 | ||
382 | /* Fetch all floating-point registers from process/thread TID and store | |
383 | thier values in GDB's register array. */ | |
384 | ||
385 | static void | |
56be3814 | 386 | fetch_fpregs (struct regcache *regcache, int tid) |
0280a90a AS |
387 | { |
388 | elf_fpregset_t fpregs; | |
389 | ||
390 | if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0) | |
e2e0b3e5 | 391 | perror_with_name (_("Couldn't get floating point status")); |
0280a90a | 392 | |
56be3814 | 393 | supply_fpregset (regcache, (const elf_fpregset_t *) &fpregs); |
0280a90a AS |
394 | } |
395 | ||
396 | /* Store all valid floating-point registers in GDB's register array | |
397 | into the process/thread specified by TID. */ | |
398 | ||
399 | static void | |
56be3814 | 400 | store_fpregs (const struct regcache *regcache, int tid, int regno) |
0280a90a AS |
401 | { |
402 | elf_fpregset_t fpregs; | |
403 | ||
404 | if (ptrace (PTRACE_GETFPREGS, tid, 0, (int) &fpregs) < 0) | |
e2e0b3e5 | 405 | perror_with_name (_("Couldn't get floating point status")); |
0280a90a | 406 | |
56be3814 | 407 | fill_fpregset (regcache, &fpregs, regno); |
0280a90a AS |
408 | |
409 | if (ptrace (PTRACE_SETFPREGS, tid, 0, (int) &fpregs) < 0) | |
e2e0b3e5 | 410 | perror_with_name (_("Couldn't write floating point status")); |
0280a90a AS |
411 | } |
412 | ||
413 | #else | |
414 | ||
56be3814 UW |
415 | static void fetch_fpregs (struct regcache *regcache, int tid) {} |
416 | static void store_fpregs (const struct regcache *regcache, int tid, int regno) {} | |
0280a90a | 417 | |
c906108c | 418 | #endif |
0280a90a AS |
419 | \f |
420 | /* Transferring arbitrary registers between GDB and inferior. */ | |
421 | ||
422 | /* Fetch register REGNO from the child process. If REGNO is -1, do | |
423 | this for all registers (including the floating point and SSE | |
424 | registers). */ | |
425 | ||
10d6c8cd | 426 | static void |
56be3814 | 427 | m68k_linux_fetch_inferior_registers (struct regcache *regcache, int regno) |
0280a90a AS |
428 | { |
429 | int tid; | |
430 | ||
431 | /* Use the old method of peeking around in `struct user' if the | |
432 | GETREGS request isn't available. */ | |
433 | if (! have_ptrace_getregs) | |
434 | { | |
56be3814 | 435 | old_fetch_inferior_registers (regcache, regno); |
0280a90a AS |
436 | return; |
437 | } | |
438 | ||
a4b6fc86 | 439 | /* GNU/Linux LWP ID's are process ID's. */ |
8de307e0 AS |
440 | tid = TIDGET (inferior_ptid); |
441 | if (tid == 0) | |
0280a90a | 442 | tid = PIDGET (inferior_ptid); /* Not a threaded program. */ |
f175af98 | 443 | |
0280a90a AS |
444 | /* Use the PTRACE_GETFPXREGS request whenever possible, since it |
445 | transfers more registers in one system call, and we'll cache the | |
446 | results. But remember that fetch_fpxregs can fail, and return | |
447 | zero. */ | |
448 | if (regno == -1) | |
449 | { | |
56be3814 | 450 | fetch_regs (regcache, tid); |
0280a90a AS |
451 | |
452 | /* The call above might reset `have_ptrace_getregs'. */ | |
453 | if (! have_ptrace_getregs) | |
454 | { | |
56be3814 | 455 | old_fetch_inferior_registers (regcache, -1); |
0280a90a AS |
456 | return; |
457 | } | |
458 | ||
56be3814 | 459 | fetch_fpregs (regcache, tid); |
0280a90a AS |
460 | return; |
461 | } | |
462 | ||
463 | if (getregs_supplies (regno)) | |
464 | { | |
56be3814 | 465 | fetch_regs (regcache, tid); |
0280a90a AS |
466 | return; |
467 | } | |
468 | ||
469 | if (getfpregs_supplies (regno)) | |
470 | { | |
56be3814 | 471 | fetch_fpregs (regcache, tid); |
0280a90a AS |
472 | return; |
473 | } | |
474 | ||
475 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 476 | _("Got request for bad register number %d."), regno); |
0280a90a AS |
477 | } |
478 | ||
479 | /* Store register REGNO back into the child process. If REGNO is -1, | |
480 | do this for all registers (including the floating point and SSE | |
481 | registers). */ | |
10d6c8cd | 482 | static void |
56be3814 | 483 | m68k_linux_store_inferior_registers (struct regcache *regcache, int regno) |
0280a90a AS |
484 | { |
485 | int tid; | |
486 | ||
487 | /* Use the old method of poking around in `struct user' if the | |
488 | SETREGS request isn't available. */ | |
489 | if (! have_ptrace_getregs) | |
490 | { | |
56be3814 | 491 | old_store_inferior_registers (regcache, regno); |
0280a90a AS |
492 | return; |
493 | } | |
494 | ||
a4b6fc86 | 495 | /* GNU/Linux LWP ID's are process ID's. */ |
8de307e0 AS |
496 | tid = TIDGET (inferior_ptid); |
497 | if (tid == 0) | |
0280a90a AS |
498 | tid = PIDGET (inferior_ptid); /* Not a threaded program. */ |
499 | ||
500 | /* Use the PTRACE_SETFPREGS requests whenever possible, since it | |
501 | transfers more registers in one system call. But remember that | |
502 | store_fpregs can fail, and return zero. */ | |
503 | if (regno == -1) | |
504 | { | |
56be3814 UW |
505 | store_regs (regcache, tid, regno); |
506 | store_fpregs (regcache, tid, regno); | |
0280a90a AS |
507 | return; |
508 | } | |
509 | ||
510 | if (getregs_supplies (regno)) | |
511 | { | |
56be3814 | 512 | store_regs (regcache, tid, regno); |
0280a90a AS |
513 | return; |
514 | } | |
515 | ||
516 | if (getfpregs_supplies (regno)) | |
517 | { | |
56be3814 | 518 | store_fpregs (regcache, tid, regno); |
0280a90a AS |
519 | return; |
520 | } | |
521 | ||
522 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 523 | _("Got request to store bad register number %d."), regno); |
0280a90a | 524 | } |
f175af98 DJ |
525 | \f |
526 | /* Interpreting register set info found in core files. */ | |
527 | ||
528 | /* Provide registers to GDB from a core file. | |
529 | ||
530 | (We can't use the generic version of this function in | |
531 | core-regset.c, because we need to use elf_gregset_t instead of | |
532 | gregset_t.) | |
533 | ||
534 | CORE_REG_SECT points to an array of bytes, which are the contents | |
535 | of a `note' from a core file which BFD thinks might contain | |
536 | register contents. CORE_REG_SIZE is its size. | |
537 | ||
538 | WHICH says which register set corelow suspects this is: | |
539 | 0 --- the general-purpose register set, in elf_gregset_t format | |
540 | 2 --- the floating-point register set, in elf_fpregset_t format | |
541 | ||
a4b6fc86 | 542 | REG_ADDR isn't used on GNU/Linux. */ |
f175af98 DJ |
543 | |
544 | static void | |
9eefc95f UW |
545 | fetch_core_registers (struct regcache *regcache, |
546 | char *core_reg_sect, unsigned core_reg_size, | |
f175af98 DJ |
547 | int which, CORE_ADDR reg_addr) |
548 | { | |
549 | elf_gregset_t gregset; | |
550 | elf_fpregset_t fpregset; | |
551 | ||
552 | switch (which) | |
553 | { | |
554 | case 0: | |
555 | if (core_reg_size != sizeof (gregset)) | |
8a3fe4f8 | 556 | warning (_("Wrong size gregset in core file.")); |
f175af98 DJ |
557 | else |
558 | { | |
559 | memcpy (&gregset, core_reg_sect, sizeof (gregset)); | |
9eefc95f | 560 | supply_gregset (regcache, (const elf_gregset_t *) &gregset); |
f175af98 DJ |
561 | } |
562 | break; | |
563 | ||
564 | case 2: | |
565 | if (core_reg_size != sizeof (fpregset)) | |
8a3fe4f8 | 566 | warning (_("Wrong size fpregset in core file.")); |
f175af98 DJ |
567 | else |
568 | { | |
569 | memcpy (&fpregset, core_reg_sect, sizeof (fpregset)); | |
9eefc95f | 570 | supply_fpregset (regcache, (const elf_fpregset_t *) &fpregset); |
f175af98 DJ |
571 | } |
572 | break; | |
573 | ||
574 | default: | |
575 | /* We've covered all the kinds of registers we know about here, | |
576 | so this must be something we wouldn't know what to do with | |
577 | anyway. Just ignore it. */ | |
578 | break; | |
579 | } | |
580 | } | |
c906108c | 581 | \f |
c5aa993b | 582 | |
a4b6fc86 AC |
583 | /* Register that we are able to handle GNU/Linux ELF core file |
584 | formats. */ | |
f175af98 DJ |
585 | |
586 | static struct core_fns linux_elf_core_fns = | |
587 | { | |
588 | bfd_target_elf_flavour, /* core_flavour */ | |
589 | default_check_format, /* check_format */ | |
590 | default_core_sniffer, /* core_sniffer */ | |
591 | fetch_core_registers, /* core_read_registers */ | |
592 | NULL /* next */ | |
593 | }; | |
594 | ||
10d6c8cd DJ |
595 | void _initialize_m68k_linux_nat (void); |
596 | ||
f175af98 | 597 | void |
5ae5f592 | 598 | _initialize_m68k_linux_nat (void) |
f175af98 | 599 | { |
10d6c8cd DJ |
600 | struct target_ops *t; |
601 | ||
602 | /* Fill in the generic GNU/Linux methods. */ | |
603 | t = linux_target (); | |
604 | ||
605 | /* Add our register access methods. */ | |
606 | t->to_fetch_registers = m68k_linux_fetch_inferior_registers; | |
607 | t->to_store_registers = m68k_linux_store_inferior_registers; | |
608 | ||
609 | /* Register the target. */ | |
f973ed9c | 610 | linux_nat_add_target (t); |
10d6c8cd | 611 | |
00e32a35 | 612 | deprecated_add_core_fns (&linux_elf_core_fns); |
f175af98 | 613 | } |