1 /* Native-dependent code for NetBSD/sparc64.
3 Copyright (C) 2003, 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
27 #include "sparc64-tdep.h"
28 #include "sparc-nat.h"
32 /* NetBSD is different from the other OSes that support both SPARC and
33 UltraSPARC in that the result of ptrace(2) depends on whether the
34 traced process is 32-bit or 64-bit. */
37 sparc64nbsd_supply_gregset (const struct sparc_gregset
*gregset
,
38 struct regcache
*regcache
,
39 int regnum
, const void *gregs
)
41 int sparc32
= (gdbarch_ptr_bit (current_gdbarch
) == 32);
44 sparc32_supply_gregset (&sparc32nbsd_gregset
, regcache
, regnum
, gregs
);
46 sparc64_supply_gregset (&sparc64nbsd_gregset
, regcache
, regnum
, gregs
);
50 sparc64nbsd_collect_gregset (const struct sparc_gregset
*gregset
,
51 const struct regcache
*regcache
,
52 int regnum
, void *gregs
)
54 int sparc32
= (gdbarch_ptr_bit (current_gdbarch
) == 32);
57 sparc32_collect_gregset (&sparc32nbsd_gregset
, regcache
, regnum
, gregs
);
59 sparc64_collect_gregset (&sparc64nbsd_gregset
, regcache
, regnum
, gregs
);
63 sparc64nbsd_supply_fpregset (struct regcache
*regcache
,
64 int regnum
, const void *fpregs
)
66 int sparc32
= (gdbarch_ptr_bit (current_gdbarch
) == 32);
69 sparc32_supply_fpregset (regcache
, regnum
, fpregs
);
71 sparc64_supply_fpregset (regcache
, regnum
, fpregs
);
75 sparc64nbsd_collect_fpregset (const struct regcache
*regcache
,
76 int regnum
, void *fpregs
)
78 int sparc32
= (gdbarch_ptr_bit (current_gdbarch
) == 32);
81 sparc32_collect_fpregset (regcache
, regnum
, fpregs
);
83 sparc64_collect_fpregset (regcache
, regnum
, fpregs
);
86 /* Determine whether `gregset_t' contains register REGNUM. */
89 sparc64nbsd_gregset_supplies_p (int regnum
)
91 if (gdbarch_ptr_bit (current_gdbarch
) == 32)
92 return sparc32_gregset_supplies_p (regnum
);
94 /* Integer registers. */
95 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_G7_REGNUM
)
96 || (regnum
>= SPARC_O0_REGNUM
&& regnum
<= SPARC_O7_REGNUM
)
97 || (regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_L7_REGNUM
)
98 || (regnum
>= SPARC_I0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
))
101 /* Control registers. */
102 if (regnum
== SPARC64_PC_REGNUM
103 || regnum
== SPARC64_NPC_REGNUM
104 || regnum
== SPARC64_STATE_REGNUM
105 || regnum
== SPARC64_Y_REGNUM
)
111 /* Determine whether `fpregset_t' contains register REGNUM. */
114 sparc64nbsd_fpregset_supplies_p (int regnum
)
116 if (gdbarch_ptr_bit (current_gdbarch
) == 32)
117 return sparc32_fpregset_supplies_p (regnum
);
119 /* Floating-point registers. */
120 if ((regnum
>= SPARC_F0_REGNUM
&& regnum
<= SPARC_F31_REGNUM
)
121 || (regnum
>= SPARC64_F32_REGNUM
&& regnum
<= SPARC64_F62_REGNUM
))
124 /* Control registers. */
125 if (regnum
== SPARC64_FSR_REGNUM
)
132 /* Support for debugging kernel virtual memory images. */
134 #include <sys/types.h>
135 #include <machine/pcb.h>
140 sparc64nbsd_supply_pcb (struct regcache
*regcache
, struct pcb
*pcb
)
144 /* The following is true for NetBSD 1.6.2:
146 The pcb contains %sp and %pc, %psr and %wim. From this information
147 we reconstruct the register state as it would look when we just
148 returned from cpu_switch(). */
150 /* The stack pointer shouldn't be zero. */
151 if (pcb
->pcb_sp
== 0)
154 regcache_raw_supply (regcache
, SPARC_SP_REGNUM
, &pcb
->pcb_sp
);
155 regcache_raw_supply (regcache
, SPARC64_PC_REGNUM
, &pcb
->pcb_pc
);
157 sparc_supply_rwindow (regcache
, pcb
->pcb_sp
, -1);
163 /* Provide a prototype to silence -Wmissing-prototypes. */
164 void _initialize_sparc64nbsd_nat (void);
167 _initialize_sparc64nbsd_nat (void)
169 struct target_ops
*t
;
171 sparc_supply_gregset
= sparc64nbsd_supply_gregset
;
172 sparc_collect_gregset
= sparc64nbsd_collect_gregset
;
173 sparc_supply_fpregset
= sparc64nbsd_supply_fpregset
;
174 sparc_collect_fpregset
= sparc64nbsd_collect_fpregset
;
175 sparc_gregset_supplies_p
= sparc64nbsd_gregset_supplies_p
;
176 sparc_fpregset_supplies_p
= sparc64nbsd_fpregset_supplies_p
;
178 /* Add some extra features to the generic SPARC target. */
180 t
->to_pid_to_exec_file
= nbsd_pid_to_exec_file
;
183 /* Support debugging kernel virtual memory images. */
184 bsd_kvm_add_target (sparc64nbsd_supply_pcb
);