1 /* Native-dependent code for GNU/Linux m32r.
3 Copyright 2004 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "linux-nat.h"
28 #include "gdb_assert.h"
29 #include "gdb_string.h"
30 #include <sys/ptrace.h>
32 #include <sys/procfs.h>
34 /* Prototypes for supply_gregset etc. */
37 #include "m32r-tdep.h"
42 /* Since EVB register is not available for native debug, we reduce
43 the number of registers. */
44 #define M32R_LINUX_NUM_REGS (M32R_NUM_REGS - 1)
46 /* Mapping between the general-purpose registers in `struct user'
47 format and GDB's register array layout. */
48 static int regmap
[] = {
49 4, 5, 6, 7, 0, 1, 2, 8,
50 9, 10, 11, 12, 13, 24, 25, 23,
51 19, 19, 26, 23, 22, 20, 16, 15
55 #define BBPSW_REGMAP 21
59 /* Doee apply to the corresponding SET requests as well. */
60 #define GETREGS_SUPPLIES(regno) (0 <= (regno) && (regno) <= M32R_LINUX_NUM_REGS)
64 /* Transfering the general-purpose registers between GDB, inferiors
67 /* Fill GDB's register array with the general-purpose register values
71 supply_gregset (elf_gregset_t
* gregsetp
)
73 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
75 unsigned long psw
, bbpsw
;
77 psw
= *(regp
+ PSW_REGMAP
);
78 bbpsw
= *(regp
+ BBPSW_REGMAP
);
80 for (i
= 0; i
< M32R_LINUX_NUM_REGS
; i
++)
86 ((0x00c1 & bbpsw
) << 8) | ((0xc100 & psw
) >> 8);
89 *(regp
+ regmap
[i
]) = ((psw
>> 8) & 1);
93 if (i
!= M32R_SP_REGNUM
)
94 regcache_raw_supply (current_regcache
, i
, regp
+ regmap
[i
]);
95 else if (psw
& 0x8000)
96 regcache_raw_supply (current_regcache
, i
, regp
+ SPU_REGMAP
);
98 regcache_raw_supply (current_regcache
, i
, regp
+ SPI_REGMAP
);
102 /* Fetch all general-purpose registers from process/thread TID and
103 store their values in GDB's register array. */
110 if (ptrace (PTRACE_GETREGS
, tid
, 0, (int) ®s
) < 0)
111 perror_with_name (_("Couldn't get registers"));
113 supply_gregset (®s
);
116 /* Fill register REGNO (if it is a general-purpose register) in
117 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
118 do this for all registers. */
121 fill_gregset (elf_gregset_t
* gregsetp
, int regno
)
123 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
125 unsigned long psw
, bbpsw
, tmp
;
127 psw
= *(regp
+ PSW_REGMAP
);
128 bbpsw
= *(regp
+ BBPSW_REGMAP
);
130 for (i
= 0; i
< M32R_LINUX_NUM_REGS
; i
++)
132 if (regno
!= -1 && regno
!= i
)
135 if (i
== CBR_REGNUM
|| i
== PSW_REGNUM
)
138 if (i
== SPU_REGNUM
|| i
== SPI_REGNUM
)
141 if (i
!= M32R_SP_REGNUM
)
142 regcache_raw_collect (current_regcache
, i
, regp
+ regmap
[i
]);
143 else if (psw
& 0x8000)
144 regcache_raw_collect (current_regcache
, i
, regp
+ SPU_REGMAP
);
146 regcache_raw_collect (current_regcache
, i
, regp
+ SPI_REGMAP
);
150 /* Store all valid general-purpose registers in GDB's register array
151 into the process/thread specified by TID. */
154 store_regs (int tid
, int regno
)
158 if (ptrace (PTRACE_GETREGS
, tid
, 0, (int) ®s
) < 0)
159 perror_with_name (_("Couldn't get registers"));
161 fill_gregset (®s
, regno
);
163 if (ptrace (PTRACE_SETREGS
, tid
, 0, (int) ®s
) < 0)
164 perror_with_name (_("Couldn't write registers"));
169 /* Transfering floating-point registers between GDB, inferiors and cores.
170 Since M32R has no floating-point registers, these functions do nothing. */
173 supply_fpregset (gdb_fpregset_t
*fpregs
)
178 fill_fpregset (gdb_fpregset_t
*fpregs
, int regno
)
184 /* Transferring arbitrary registers between GDB and inferior. */
186 /* Fetch register REGNO from the child process. If REGNO is -1, do
187 this for all registers (including the floating point and SSE
191 fetch_inferior_registers (int regno
)
195 /* GNU/Linux LWP ID's are process ID's. */
196 tid
= TIDGET (inferior_ptid
);
198 tid
= PIDGET (inferior_ptid
); /* Not a threaded program. */
200 /* Use the PTRACE_GETREGS request whenever possible, since it
201 transfers more registers in one system call, and we'll cache the
203 if (regno
== -1 || GETREGS_SUPPLIES (regno
))
209 internal_error (__FILE__
, __LINE__
,
210 _("Got request for bad register number %d."), regno
);
213 /* Store register REGNO back into the child process. If REGNO is -1,
214 do this for all registers (including the floating point and SSE
217 store_inferior_registers (int regno
)
221 /* GNU/Linux LWP ID's are process ID's. */
222 if ((tid
= TIDGET (inferior_ptid
)) == 0)
223 tid
= PIDGET (inferior_ptid
); /* Not a threaded program. */
225 /* Use the PTRACE_SETREGS request whenever possible, since it
226 transfers more registers in one system call. */
227 if (regno
== -1 || GETREGS_SUPPLIES (regno
))
229 store_regs (tid
, regno
);
233 internal_error (__FILE__
, __LINE__
,
234 _("Got request to store bad register number %d."), regno
);
This page took 0.036032 seconds and 4 git commands to generate.