Commit | Line | Data |
---|---|---|
e42180d7 | 1 | /* Native-dependent code for PowerPC's running NetBSD, for GDB. |
69e9e646 | 2 | Copyright 2002, 2004 Free Software Foundation, Inc. |
485721b1 | 3 | Contributed by Wasabi Systems, Inc. |
e42180d7 C |
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> | |
69e9e646 NW |
25 | #include <machine/frame.h> |
26 | #include <machine/pcb.h> | |
e42180d7 C |
27 | |
28 | #include "defs.h" | |
29 | #include "inferior.h" | |
383f0f5b | 30 | #include "gdb_assert.h" |
69e9e646 NW |
31 | #include "gdbcore.h" |
32 | #include "regcache.h" | |
33 | #include "bsd-kvm.h" | |
e42180d7 | 34 | |
485721b1 JT |
35 | #include "ppc-tdep.h" |
36 | #include "ppcnbsd-tdep.h" | |
e42180d7 | 37 | |
5bf970f9 AC |
38 | #include "inf-ptrace.h" |
39 | ||
485721b1 JT |
40 | /* Returns true if PT_GETREGS fetches this register. */ |
41 | static int | |
42 | getregs_supplies (int regno) | |
e42180d7 | 43 | { |
485721b1 JT |
44 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
45 | ||
cdf2c5f5 JB |
46 | return ((regno >= tdep->ppc_gp0_regnum |
47 | && regno < tdep->ppc_gp0_regnum + ppc_num_gprs) | |
485721b1 JT |
48 | || regno == tdep->ppc_lr_regnum |
49 | || regno == tdep->ppc_cr_regnum | |
50 | || regno == tdep->ppc_xer_regnum | |
51 | || regno == tdep->ppc_ctr_regnum | |
52 | || regno == PC_REGNUM); | |
e42180d7 C |
53 | } |
54 | ||
485721b1 JT |
55 | /* Like above, but for PT_GETFPREGS. */ |
56 | static int | |
57 | getfpregs_supplies (int regno) | |
e42180d7 | 58 | { |
485721b1 | 59 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
e42180d7 | 60 | |
383f0f5b JB |
61 | /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating |
62 | point registers. Traditionally, GDB's register set has still | |
63 | listed the floating point registers for such machines, so this | |
64 | code is harmless. However, the new E500 port actually omits the | |
65 | floating point registers entirely from the register set --- they | |
66 | don't even have register numbers assigned to them. | |
67 | ||
68 | It's not clear to me how best to update this code, so this assert | |
69 | will alert the first person to encounter the NetBSD/E500 | |
70 | combination to the problem. */ | |
71 | gdb_assert (ppc_floating_point_unit_p (current_gdbarch)); | |
72 | ||
366f009f JB |
73 | return ((regno >= tdep->ppc_fp0_regnum |
74 | && regno < tdep->ppc_fp0_regnum + ppc_num_fprs) | |
485721b1 JT |
75 | || regno == tdep->ppc_fpscr_regnum); |
76 | } | |
e42180d7 | 77 | |
5bf970f9 AC |
78 | static void |
79 | ppcnbsd_fetch_inferior_registers (int regno) | |
e42180d7 | 80 | { |
485721b1 JT |
81 | if (regno == -1 || getregs_supplies (regno)) |
82 | { | |
83 | struct reg regs; | |
84 | ||
85 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 86 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 87 | perror_with_name (_("Couldn't get registers")); |
485721b1 JT |
88 | |
89 | ppcnbsd_supply_reg ((char *) ®s, regno); | |
90 | if (regno != -1) | |
91 | return; | |
92 | } | |
93 | ||
94 | if (regno == -1 || getfpregs_supplies (regno)) | |
95 | { | |
96 | struct fpreg fpregs; | |
97 | ||
98 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 99 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 100 | perror_with_name (_("Couldn't get FP registers")); |
485721b1 JT |
101 | |
102 | ppcnbsd_supply_fpreg ((char *) &fpregs, regno); | |
103 | if (regno != -1) | |
104 | return; | |
105 | } | |
e42180d7 C |
106 | } |
107 | ||
5bf970f9 AC |
108 | static void |
109 | ppcnbsd_store_inferior_registers (int regno) | |
e42180d7 | 110 | { |
485721b1 JT |
111 | if (regno == -1 || getregs_supplies (regno)) |
112 | { | |
113 | struct reg regs; | |
114 | ||
115 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 116 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 117 | perror_with_name (_("Couldn't get registers")); |
485721b1 JT |
118 | |
119 | ppcnbsd_fill_reg ((char *) ®s, regno); | |
120 | ||
121 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 122 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 123 | perror_with_name (_("Couldn't write registers")); |
485721b1 JT |
124 | |
125 | if (regno != -1) | |
126 | return; | |
127 | } | |
128 | ||
129 | if (regno == -1 || getfpregs_supplies (regno)) | |
130 | { | |
131 | struct fpreg fpregs; | |
132 | ||
133 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 134 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 135 | perror_with_name (_("Couldn't get FP registers")); |
485721b1 JT |
136 | |
137 | ppcnbsd_fill_fpreg ((char *) &fpregs, regno); | |
138 | ||
139 | if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 140 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 141 | perror_with_name (_("Couldn't set FP registers")); |
485721b1 | 142 | } |
e42180d7 | 143 | } |
69e9e646 NW |
144 | |
145 | static int | |
146 | ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) | |
147 | { | |
148 | struct switchframe sf; | |
149 | struct callframe cf; | |
150 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
151 | int i; | |
152 | ||
153 | /* The stack pointer shouldn't be zero. */ | |
154 | if (pcb->pcb_sp == 0) | |
155 | return 0; | |
156 | ||
157 | read_memory (pcb->pcb_sp, (char *) &sf, sizeof sf); | |
158 | regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr); | |
159 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2); | |
160 | for (i = 0 ; i < 19 ; i++) | |
161 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 13 + i, | |
162 | &sf.fixreg[i]); | |
163 | ||
164 | read_memory(sf.sp, (char *)&cf, sizeof(cf)); | |
165 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30); | |
166 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31); | |
167 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 1, &cf.sp); | |
168 | ||
169 | read_memory(cf.sp, (char *)&cf, sizeof(cf)); | |
170 | regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr); | |
171 | regcache_raw_supply (regcache, PC_REGNUM, &cf.lr); | |
172 | ||
173 | return 1; | |
174 | } | |
175 | ||
176 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
177 | void _initialize_ppcnbsd_nat (void); | |
178 | ||
179 | void | |
180 | _initialize_ppcnbsd_nat (void) | |
181 | { | |
5bf970f9 | 182 | struct target_ops *t; |
69e9e646 NW |
183 | /* Support debugging kernel virtual memory images. */ |
184 | bsd_kvm_add_target (ppcnbsd_supply_pcb); | |
5bf970f9 AC |
185 | /* Add in local overrides. */ |
186 | t = inf_ptrace_target (); | |
187 | t->to_fetch_registers = ppcnbsd_fetch_inferior_registers; | |
188 | t->to_store_registers = ppcnbsd_store_inferior_registers; | |
189 | add_target (t); | |
69e9e646 | 190 | } |