Commit | Line | Data |
---|---|---|
bf2ca189 MK |
1 | /* Native-dependent code for Motorola 88000 BSD's. |
2 | ||
7b6bb8da JB |
3 | Copyright (C) 2004, 2007, 2008, 2009, 2010, 2011 |
4 | Free Software Foundation, Inc. | |
bf2ca189 MK |
5 | |
6 | This file is part of GDB. | |
7 | ||
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 |
bf2ca189 MK |
11 | (at your option) any later version. |
12 | ||
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. | |
17 | ||
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/>. */ |
bf2ca189 MK |
20 | |
21 | #include "defs.h" | |
22 | #include "inferior.h" | |
23 | #include "regcache.h" | |
bc8ffc12 | 24 | #include "target.h" |
bf2ca189 MK |
25 | |
26 | #include <sys/types.h> | |
27 | #include <sys/ptrace.h> | |
28 | #include <machine/reg.h> | |
29 | ||
30 | #include "m88k-tdep.h" | |
bc8ffc12 | 31 | #include "inf-ptrace.h" |
bf2ca189 MK |
32 | |
33 | /* Supply the general-purpose registers stored in GREGS to REGCACHE. */ | |
34 | ||
35 | static void | |
36 | m88kbsd_supply_gregset (struct regcache *regcache, const void *gregs) | |
37 | { | |
38 | const char *regs = gregs; | |
39 | int regnum; | |
40 | ||
41 | for (regnum = 0; regnum < M88K_NUM_REGS; regnum++) | |
42 | regcache_raw_supply (regcache, regnum, regs + regnum * 4); | |
43 | } | |
44 | ||
45 | /* Collect the general-purpose registers from REGCACHE and store them | |
46 | in GREGS. */ | |
47 | ||
48 | static void | |
49 | m88kbsd_collect_gregset (const struct regcache *regcache, | |
50 | void *gregs, int regnum) | |
51 | { | |
52 | char *regs = gregs; | |
53 | int i; | |
54 | ||
55 | for (i = 0; i < M88K_NUM_REGS; i++) | |
56 | { | |
57 | if (regnum == -1 || regnum == i) | |
58 | regcache_raw_collect (regcache, i, regs + i * 4); | |
59 | } | |
60 | } | |
61 | \f | |
62 | ||
63 | /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this | |
64 | for all registers. */ | |
65 | ||
bc8ffc12 | 66 | static void |
28439f5e PA |
67 | m88kbsd_fetch_inferior_registers (struct target_ops *ops, |
68 | struct regcache *regcache, int regnum) | |
bf2ca189 MK |
69 | { |
70 | struct reg regs; | |
71 | ||
72 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 73 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 74 | perror_with_name (_("Couldn't get registers")); |
bf2ca189 | 75 | |
56be3814 | 76 | m88kbsd_supply_gregset (regcache, ®s); |
bf2ca189 MK |
77 | } |
78 | ||
79 | /* Store register REGNUM back into the inferior. If REGNUM is -1, do | |
80 | this for all registers. */ | |
81 | ||
bc8ffc12 | 82 | static void |
28439f5e PA |
83 | m88kbsd_store_inferior_registers (struct target_ops *ops, |
84 | struct regcache *regcache, int regnum) | |
bf2ca189 MK |
85 | { |
86 | struct reg regs; | |
87 | ||
88 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 89 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 90 | perror_with_name (_("Couldn't get registers")); |
bf2ca189 | 91 | |
56be3814 | 92 | m88kbsd_collect_gregset (regcache, ®s, regnum); |
bf2ca189 MK |
93 | |
94 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 95 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 96 | perror_with_name (_("Couldn't write registers")); |
bf2ca189 | 97 | } |
bc8ffc12 MK |
98 | \f |
99 | ||
100 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
101 | void _initialize_m88kbsd_nat (void); | |
102 | ||
103 | void | |
104 | _initialize_m88kbsd_nat (void) | |
105 | { | |
106 | struct target_ops *t; | |
107 | ||
108 | t = inf_ptrace_target (); | |
109 | t->to_fetch_registers = m88kbsd_fetch_inferior_registers; | |
110 | t->to_store_registers = m88kbsd_store_inferior_registers; | |
111 | add_target (t); | |
112 | } |