1 /* Native-dependent code for GNU/Linux m32r.
3 Copyright (C) 2004-2014 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 3 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, see <http://www.gnu.org/licenses/>. */
24 #include "linux-nat.h"
26 #include <sys/ptrace.h>
28 #include <sys/procfs.h>
30 /* Prototypes for supply_gregset etc. */
33 #include "m32r-tdep.h"
38 /* Since EVB register is not available for native debug, we reduce
39 the number of registers. */
40 #define M32R_LINUX_NUM_REGS (M32R_NUM_REGS - 1)
42 /* Mapping between the general-purpose registers in `struct user'
43 format and GDB's register array layout. */
44 static int regmap
[] = {
45 4, 5, 6, 7, 0, 1, 2, 8,
46 9, 10, 11, 12, 13, 24, 25, 23,
47 19, 19, 26, 23, 22, 20, 16, 15
51 #define BBPSW_REGMAP 21
55 /* Doee (??) apply to the corresponding SET requests as well. */
56 #define GETREGS_SUPPLIES(regno) (0 <= (regno) \
57 && (regno) <= M32R_LINUX_NUM_REGS)
61 /* Transfering the general-purpose registers between GDB, inferiors
64 /* Fill GDB's register array with the general-purpose register values
68 supply_gregset (struct regcache
*regcache
, const elf_gregset_t
* gregsetp
)
70 const elf_greg_t
*regp
= (const elf_greg_t
*) gregsetp
;
72 unsigned long psw
, bbpsw
;
74 psw
= *(regp
+ PSW_REGMAP
);
75 bbpsw
= *(regp
+ BBPSW_REGMAP
);
77 for (i
= 0; i
< M32R_LINUX_NUM_REGS
; i
++)
84 regval
= ((0x00c1 & bbpsw
) << 8) | ((0xc100 & psw
) >> 8);
87 regval
= ((psw
>> 8) & 1);
90 regval
= *(regp
+ regmap
[i
]);
94 if (i
!= M32R_SP_REGNUM
)
95 regcache_raw_supply (regcache
, i
, ®val
);
96 else if (psw
& 0x8000)
97 regcache_raw_supply (regcache
, i
, regp
+ SPU_REGMAP
);
99 regcache_raw_supply (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. */
107 fetch_regs (struct regcache
*regcache
, int tid
)
111 if (ptrace (PTRACE_GETREGS
, tid
, 0, (int) ®s
) < 0)
112 perror_with_name (_("Couldn't get registers"));
114 supply_gregset (regcache
, (const elf_gregset_t
*) ®s
);
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. */
122 fill_gregset (const struct regcache
*regcache
,
123 elf_gregset_t
* gregsetp
, int regno
)
125 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
127 unsigned long psw
, bbpsw
, tmp
;
129 psw
= *(regp
+ PSW_REGMAP
);
130 bbpsw
= *(regp
+ BBPSW_REGMAP
);
132 for (i
= 0; i
< M32R_LINUX_NUM_REGS
; i
++)
134 if (regno
!= -1 && regno
!= i
)
137 if (i
== CBR_REGNUM
|| i
== PSW_REGNUM
)
140 if (i
== SPU_REGNUM
|| i
== SPI_REGNUM
)
143 if (i
!= M32R_SP_REGNUM
)
144 regcache_raw_collect (regcache
, i
, regp
+ regmap
[i
]);
145 else if (psw
& 0x8000)
146 regcache_raw_collect (regcache
, i
, regp
+ SPU_REGMAP
);
148 regcache_raw_collect (regcache
, i
, regp
+ SPI_REGMAP
);
152 /* Store all valid general-purpose registers in GDB's register array
153 into the process/thread specified by TID. */
156 store_regs (const struct regcache
*regcache
, int tid
, int regno
)
160 if (ptrace (PTRACE_GETREGS
, tid
, 0, (int) ®s
) < 0)
161 perror_with_name (_("Couldn't get registers"));
163 fill_gregset (regcache
, ®s
, regno
);
165 if (ptrace (PTRACE_SETREGS
, tid
, 0, (int) ®s
) < 0)
166 perror_with_name (_("Couldn't write registers"));
171 /* Transfering floating-point registers between GDB, inferiors and cores.
172 Since M32R has no floating-point registers, these functions do nothing. */
175 supply_fpregset (struct regcache
*regcache
, const gdb_fpregset_t
*fpregs
)
180 fill_fpregset (const struct regcache
*regcache
,
181 gdb_fpregset_t
*fpregs
, int regno
)
187 /* Transferring arbitrary registers between GDB and inferior. */
189 /* Fetch register REGNO from the child process. If REGNO is -1, do
190 this for all registers (including the floating point and SSE
194 m32r_linux_fetch_inferior_registers (struct target_ops
*ops
,
195 struct regcache
*regcache
, int regno
)
199 /* GNU/Linux LWP ID's are process ID's. */
200 tid
= ptid_get_lwp (inferior_ptid
);
202 tid
= ptid_get_pid (inferior_ptid
); /* Not a threaded program. */
204 /* Use the PTRACE_GETREGS request whenever possible, since it
205 transfers more registers in one system call, and we'll cache the
207 if (regno
== -1 || GETREGS_SUPPLIES (regno
))
209 fetch_regs (regcache
, tid
);
213 internal_error (__FILE__
, __LINE__
,
214 _("Got request for bad register number %d."), regno
);
217 /* Store register REGNO back into the child process. If REGNO is -1,
218 do this for all registers (including the floating point and SSE
221 m32r_linux_store_inferior_registers (struct target_ops
*ops
,
222 struct regcache
*regcache
, int regno
)
226 /* GNU/Linux LWP ID's are process ID's. */
227 if ((tid
= ptid_get_lwp (inferior_ptid
)) == 0)
228 tid
= ptid_get_pid (inferior_ptid
); /* Not a threaded program. */
230 /* Use the PTRACE_SETREGS request whenever possible, since it
231 transfers more registers in one system call. */
232 if (regno
== -1 || GETREGS_SUPPLIES (regno
))
234 store_regs (regcache
, tid
, regno
);
238 internal_error (__FILE__
, __LINE__
,
239 _("Got request to store bad register number %d."), regno
);
242 void _initialize_m32r_linux_nat (void);
245 _initialize_m32r_linux_nat (void)
247 struct target_ops
*t
;
249 /* Fill in the generic GNU/Linux methods. */
252 /* Add our register access methods. */
253 t
->to_fetch_registers
= m32r_linux_fetch_inferior_registers
;
254 t
->to_store_registers
= m32r_linux_store_inferior_registers
;
256 /* Register the target. */
257 linux_nat_add_target (t
);