No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / m32r-linux-nat.c
blob454147b27aa7f2a478f32f2438696b721598e11b
1 /* Native-dependent code for GNU/Linux m32r.
3 Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #include "defs.h"
23 #include "inferior.h"
24 #include "gdbcore.h"
25 #include "regcache.h"
26 #include "linux-nat.h"
27 #include "target.h"
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>
35 /* Prototypes for supply_gregset etc. */
36 #include "gregset.h"
38 #include "m32r-tdep.h"
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)
47 /* Mapping between the general-purpose registers in `struct user'
48 format and GDB's register array layout. */
49 static 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
55 #define PSW_REGMAP 19
56 #define BBPSW_REGMAP 21
57 #define SPU_REGMAP 23
58 #define SPI_REGMAP 26
60 /* Doee apply to the corresponding SET requests as well. */
61 #define GETREGS_SUPPLIES(regno) (0 <= (regno) && (regno) <= M32R_LINUX_NUM_REGS)
65 /* Transfering the general-purpose registers between GDB, inferiors
66 and core files. */
68 /* Fill GDB's register array with the general-purpose register values
69 in *GREGSETP. */
71 void
72 supply_gregset (elf_gregset_t * gregsetp)
74 elf_greg_t *regp = (elf_greg_t *) gregsetp;
75 int i;
76 unsigned long psw, bbpsw;
78 psw = *(regp + PSW_REGMAP);
79 bbpsw = *(regp + BBPSW_REGMAP);
81 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
83 switch (i)
85 case PSW_REGNUM:
86 *(regp + regmap[i]) =
87 ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8);
88 break;
89 case CBR_REGNUM:
90 *(regp + regmap[i]) = ((psw >> 8) & 1);
91 break;
94 if (i != M32R_SP_REGNUM)
95 regcache_raw_supply (current_regcache, i, regp + regmap[i]);
96 else if (psw & 0x8000)
97 regcache_raw_supply (current_regcache, i, regp + SPU_REGMAP);
98 else
99 regcache_raw_supply (current_regcache, i, regp + SPI_REGMAP);
103 /* Fetch all general-purpose registers from process/thread TID and
104 store their values in GDB's register array. */
106 static void
107 fetch_regs (int tid)
109 elf_gregset_t regs;
111 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
112 perror_with_name (_("Couldn't get registers"));
114 supply_gregset (&regs);
117 /* Fill register REGNO (if it is a general-purpose register) in
118 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
119 do this for all registers. */
121 void
122 fill_gregset (elf_gregset_t * gregsetp, int regno)
124 elf_greg_t *regp = (elf_greg_t *) gregsetp;
125 int i;
126 unsigned long psw, bbpsw, tmp;
128 psw = *(regp + PSW_REGMAP);
129 bbpsw = *(regp + BBPSW_REGMAP);
131 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
133 if (regno != -1 && regno != i)
134 continue;
136 if (i == CBR_REGNUM || i == PSW_REGNUM)
137 continue;
139 if (i == SPU_REGNUM || i == SPI_REGNUM)
140 continue;
142 if (i != M32R_SP_REGNUM)
143 regcache_raw_collect (current_regcache, i, regp + regmap[i]);
144 else if (psw & 0x8000)
145 regcache_raw_collect (current_regcache, i, regp + SPU_REGMAP);
146 else
147 regcache_raw_collect (current_regcache, i, regp + SPI_REGMAP);
151 /* Store all valid general-purpose registers in GDB's register array
152 into the process/thread specified by TID. */
154 static void
155 store_regs (int tid, int regno)
157 elf_gregset_t regs;
159 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
160 perror_with_name (_("Couldn't get registers"));
162 fill_gregset (&regs, regno);
164 if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
165 perror_with_name (_("Couldn't write registers"));
170 /* Transfering floating-point registers between GDB, inferiors and cores.
171 Since M32R has no floating-point registers, these functions do nothing. */
173 void
174 supply_fpregset (gdb_fpregset_t *fpregs)
178 void
179 fill_fpregset (gdb_fpregset_t *fpregs, int regno)
185 /* Transferring arbitrary registers between GDB and inferior. */
187 /* Fetch register REGNO from the child process. If REGNO is -1, do
188 this for all registers (including the floating point and SSE
189 registers). */
191 static void
192 m32r_linux_fetch_inferior_registers (int regno)
194 int tid;
196 /* GNU/Linux LWP ID's are process ID's. */
197 tid = TIDGET (inferior_ptid);
198 if (tid == 0)
199 tid = PIDGET (inferior_ptid); /* Not a threaded program. */
201 /* Use the PTRACE_GETREGS request whenever possible, since it
202 transfers more registers in one system call, and we'll cache the
203 results. */
204 if (regno == -1 || GETREGS_SUPPLIES (regno))
206 fetch_regs (tid);
207 return;
210 internal_error (__FILE__, __LINE__,
211 _("Got request for bad register number %d."), regno);
214 /* Store register REGNO back into the child process. If REGNO is -1,
215 do this for all registers (including the floating point and SSE
216 registers). */
217 static void
218 m32r_linux_store_inferior_registers (int regno)
220 int tid;
222 /* GNU/Linux LWP ID's are process ID's. */
223 if ((tid = TIDGET (inferior_ptid)) == 0)
224 tid = PIDGET (inferior_ptid); /* Not a threaded program. */
226 /* Use the PTRACE_SETREGS request whenever possible, since it
227 transfers more registers in one system call. */
228 if (regno == -1 || GETREGS_SUPPLIES (regno))
230 store_regs (tid, regno);
231 return;
234 internal_error (__FILE__, __LINE__,
235 _("Got request to store bad register number %d."), regno);
238 void _initialize_m32r_linux_nat (void);
240 void
241 _initialize_m32r_linux_nat (void)
243 struct target_ops *t;
245 /* Fill in the generic GNU/Linux methods. */
246 t = linux_target ();
248 /* Add our register access methods. */
249 t->to_fetch_registers = m32r_linux_fetch_inferior_registers;
250 t->to_store_registers = m32r_linux_store_inferior_registers;
252 /* Register the target. */
253 linux_nat_add_target (t);