* ppc-tdep.h (struct gdbarch_tdep): Change definition of
[external/binutils.git] / gdb / ppcnbsd-nat.c
1 /* Native-dependent code for PowerPC's running NetBSD, for GDB.
2    Copyright 2002 Free Software Foundation, Inc.
3    Contributed by Wasabi Systems, Inc.
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
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.  */
21
22 #include <sys/types.h>
23 #include <sys/ptrace.h>
24 #include <machine/reg.h>
25
26 #include "defs.h"
27 #include "inferior.h"
28 #include "gdb_assert.h"
29
30 #include "ppc-tdep.h"
31 #include "ppcnbsd-tdep.h"
32
33 /* Returns true if PT_GETREGS fetches this register.  */
34 static int
35 getregs_supplies (int regno)
36 {
37   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
38
39   return ((regno >= 0 && regno <= 31)
40           || regno == tdep->ppc_lr_regnum
41           || regno == tdep->ppc_cr_regnum
42           || regno == tdep->ppc_xer_regnum
43           || regno == tdep->ppc_ctr_regnum
44           || regno == PC_REGNUM);
45 }
46
47 /* Like above, but for PT_GETFPREGS.  */
48 static int
49 getfpregs_supplies (int regno)
50 {
51   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
52
53   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
54      point registers.  Traditionally, GDB's register set has still
55      listed the floating point registers for such machines, so this
56      code is harmless.  However, the new E500 port actually omits the
57      floating point registers entirely from the register set --- they
58      don't even have register numbers assigned to them.
59
60      It's not clear to me how best to update this code, so this assert
61      will alert the first person to encounter the NetBSD/E500
62      combination to the problem.  */
63   gdb_assert (ppc_floating_point_unit_p (current_gdbarch));
64
65   return ((regno >= tdep->ppc_fp0_regnum
66            && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
67           || regno == tdep->ppc_fpscr_regnum);
68 }
69
70 void
71 fetch_inferior_registers (int regno)
72 {
73   if (regno == -1 || getregs_supplies (regno))
74     {
75       struct reg regs;
76
77       if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
78                   (PTRACE_ARG3_TYPE) &regs, 0) == -1)
79         perror_with_name ("Couldn't get registers");
80
81       ppcnbsd_supply_reg ((char *) &regs, regno);
82       if (regno != -1)
83         return;
84     }
85
86   if (regno == -1 || getfpregs_supplies (regno))
87     {
88       struct fpreg fpregs;
89
90       if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
91                   (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
92         perror_with_name ("Couldn't get FP registers");
93
94       ppcnbsd_supply_fpreg ((char *) &fpregs, regno);
95       if (regno != -1)
96         return;
97     }
98 }
99
100 void
101 store_inferior_registers (int regno)
102 {
103   if (regno == -1 || getregs_supplies (regno))
104     {
105       struct reg regs;
106
107       if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
108                   (PTRACE_ARG3_TYPE) &regs, 0) == -1)
109         perror_with_name ("Couldn't get registers");
110
111       ppcnbsd_fill_reg ((char *) &regs, regno);
112
113       if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
114                   (PTRACE_ARG3_TYPE) &regs, 0) == -1)
115         perror_with_name ("Couldn't write registers");
116
117       if (regno != -1)
118         return;
119     }
120
121   if (regno == -1 || getfpregs_supplies (regno))
122     {
123       struct fpreg fpregs;
124
125       if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
126                   (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
127         perror_with_name ("Couldn't get FP registers");
128
129       ppcnbsd_fill_fpreg ((char *) &fpregs, regno);
130       
131       if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
132                   (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
133         perror_with_name ("Couldn't set FP registers");
134     }
135 }