*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / m32r-linux-nat.c
CommitLineData
9b32d526
KI
1/* Native-dependent code for GNU/Linux m32r.
2
6aba47ca 3 Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
9b32d526
KI
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. */
9b32d526
KI
21
22#include "defs.h"
23#include "inferior.h"
24#include "gdbcore.h"
25#include "regcache.h"
26#include "linux-nat.h"
10d6c8cd 27#include "target.h"
9b32d526
KI
28
29#include "gdb_assert.h"
30#include "gdb_string.h"
31#include <sys/ptrace.h>
32#include <sys/user.h>
33#include <sys/procfs.h>
34
35/* Prototypes for supply_gregset etc. */
36#include "gregset.h"
37
38#include "m32r-tdep.h"
39\f
40
41
42
43/* Since EVB register is not available for native debug, we reduce
44 the number of registers. */
45#define M32R_LINUX_NUM_REGS (M32R_NUM_REGS - 1)
46
47/* Mapping between the general-purpose registers in `struct user'
48 format and GDB's register array layout. */
49static int regmap[] = {
50 4, 5, 6, 7, 0, 1, 2, 8,
51 9, 10, 11, 12, 13, 24, 25, 23,
52 19, 19, 26, 23, 22, 20, 16, 15
53};
54
55#define PSW_REGMAP 19
56#define BBPSW_REGMAP 21
57#define SPU_REGMAP 23
58#define SPI_REGMAP 26
59
60/* Doee apply to the corresponding SET requests as well. */
61#define GETREGS_SUPPLIES(regno) (0 <= (regno) && (regno) <= M32R_LINUX_NUM_REGS)
62\f
63
64
65/* Transfering the general-purpose registers between GDB, inferiors
66 and core files. */
67
68/* Fill GDB's register array with the general-purpose register values
69 in *GREGSETP. */
70
71void
7f7fe91e 72supply_gregset (struct regcache *regcache, const elf_gregset_t * gregsetp)
9b32d526 73{
7f7fe91e 74 const elf_greg_t *regp = (const elf_greg_t *) gregsetp;
9b32d526
KI
75 int i;
76 unsigned long psw, bbpsw;
77
78 psw = *(regp + PSW_REGMAP);
79 bbpsw = *(regp + BBPSW_REGMAP);
80
81 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
82 {
d817e083
UW
83 elf_greg_t regval;
84
9b32d526
KI
85 switch (i)
86 {
87 case PSW_REGNUM:
d817e083 88 regval = ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8);
9b32d526
KI
89 break;
90 case CBR_REGNUM:
d817e083
UW
91 regval = ((psw >> 8) & 1);
92 break;
93 default:
94 regval = *(regp + regmap[i]);
9b32d526
KI
95 break;
96 }
97
98 if (i != M32R_SP_REGNUM)
7f7fe91e 99 regcache_raw_supply (regcache, i, &regval);
9b32d526 100 else if (psw & 0x8000)
7f7fe91e 101 regcache_raw_supply (regcache, i, regp + SPU_REGMAP);
9b32d526 102 else
7f7fe91e 103 regcache_raw_supply (regcache, i, regp + SPI_REGMAP);
9b32d526
KI
104 }
105}
106
107/* Fetch all general-purpose registers from process/thread TID and
108 store their values in GDB's register array. */
109
110static void
56be3814 111fetch_regs (struct regcache *regcache, int tid)
9b32d526
KI
112{
113 elf_gregset_t regs;
114
115 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
e2e0b3e5 116 perror_with_name (_("Couldn't get registers"));
9b32d526 117
56be3814 118 supply_gregset (regcache, (const elf_gregset_t *) &regs);
9b32d526
KI
119}
120
121/* Fill register REGNO (if it is a general-purpose register) in
122 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
123 do this for all registers. */
124
125void
7f7fe91e
UW
126fill_gregset (const struct regcache *regcache,
127 elf_gregset_t * gregsetp, int regno)
9b32d526
KI
128{
129 elf_greg_t *regp = (elf_greg_t *) gregsetp;
130 int i;
131 unsigned long psw, bbpsw, tmp;
132
133 psw = *(regp + PSW_REGMAP);
134 bbpsw = *(regp + BBPSW_REGMAP);
135
136 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
137 {
138 if (regno != -1 && regno != i)
139 continue;
140
141 if (i == CBR_REGNUM || i == PSW_REGNUM)
142 continue;
143
144 if (i == SPU_REGNUM || i == SPI_REGNUM)
145 continue;
146
147 if (i != M32R_SP_REGNUM)
7f7fe91e 148 regcache_raw_collect (regcache, i, regp + regmap[i]);
9b32d526 149 else if (psw & 0x8000)
7f7fe91e 150 regcache_raw_collect (regcache, i, regp + SPU_REGMAP);
9b32d526 151 else
7f7fe91e 152 regcache_raw_collect (regcache, i, regp + SPI_REGMAP);
9b32d526
KI
153 }
154}
155
156/* Store all valid general-purpose registers in GDB's register array
157 into the process/thread specified by TID. */
158
159static void
56be3814 160store_regs (const struct regcache *regcache, int tid, int regno)
9b32d526
KI
161{
162 elf_gregset_t regs;
163
164 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
e2e0b3e5 165 perror_with_name (_("Couldn't get registers"));
9b32d526 166
56be3814 167 fill_gregset (regcache, &regs, regno);
9b32d526
KI
168
169 if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
e2e0b3e5 170 perror_with_name (_("Couldn't write registers"));
9b32d526
KI
171}
172\f
173
174
175/* Transfering floating-point registers between GDB, inferiors and cores.
176 Since M32R has no floating-point registers, these functions do nothing. */
177
178void
7f7fe91e 179supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregs)
9b32d526
KI
180{
181}
182
183void
7f7fe91e
UW
184fill_fpregset (const struct regcache *regcache,
185 gdb_fpregset_t *fpregs, int regno)
9b32d526
KI
186{
187}
188\f
189
190
191/* Transferring arbitrary registers between GDB and inferior. */
192
193/* Fetch register REGNO from the child process. If REGNO is -1, do
194 this for all registers (including the floating point and SSE
195 registers). */
196
10d6c8cd 197static void
56be3814 198m32r_linux_fetch_inferior_registers (struct regcache *regcache, int regno)
9b32d526
KI
199{
200 int tid;
201
202 /* GNU/Linux LWP ID's are process ID's. */
203 tid = TIDGET (inferior_ptid);
204 if (tid == 0)
205 tid = PIDGET (inferior_ptid); /* Not a threaded program. */
206
207 /* Use the PTRACE_GETREGS request whenever possible, since it
208 transfers more registers in one system call, and we'll cache the
209 results. */
210 if (regno == -1 || GETREGS_SUPPLIES (regno))
211 {
56be3814 212 fetch_regs (regcache, tid);
9b32d526
KI
213 return;
214 }
215
216 internal_error (__FILE__, __LINE__,
e2e0b3e5 217 _("Got request for bad register number %d."), regno);
9b32d526
KI
218}
219
220/* Store register REGNO back into the child process. If REGNO is -1,
221 do this for all registers (including the floating point and SSE
222 registers). */
10d6c8cd 223static void
56be3814 224m32r_linux_store_inferior_registers (struct regcache *regcache, int regno)
9b32d526
KI
225{
226 int tid;
227
228 /* GNU/Linux LWP ID's are process ID's. */
229 if ((tid = TIDGET (inferior_ptid)) == 0)
230 tid = PIDGET (inferior_ptid); /* Not a threaded program. */
231
232 /* Use the PTRACE_SETREGS request whenever possible, since it
233 transfers more registers in one system call. */
234 if (regno == -1 || GETREGS_SUPPLIES (regno))
235 {
56be3814 236 store_regs (regcache, tid, regno);
9b32d526
KI
237 return;
238 }
239
240 internal_error (__FILE__, __LINE__,
e2e0b3e5 241 _("Got request to store bad register number %d."), regno);
9b32d526 242}
10d6c8cd
DJ
243
244void _initialize_m32r_linux_nat (void);
245
246void
247_initialize_m32r_linux_nat (void)
248{
249 struct target_ops *t;
250
251 /* Fill in the generic GNU/Linux methods. */
252 t = linux_target ();
253
254 /* Add our register access methods. */
255 t->to_fetch_registers = m32r_linux_fetch_inferior_registers;
256 t->to_store_registers = m32r_linux_store_inferior_registers;
257
258 /* Register the target. */
f973ed9c 259 linux_nat_add_target (t);
10d6c8cd 260}
This page took 0.197832 seconds and 4 git commands to generate.