xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/sparc-netbsd-nat.c (revision 4439cfd0acf9c7dc90625e5cd83b2317a9ab8967)
1 /* Native-dependent code for NetBSD/sparc.
2 
3    Copyright (C) 2002-2023 Free Software Foundation, 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 3 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, see <http://www.gnu.org/licenses/>.  */
19 
20 #include "defs.h"
21 #include "regcache.h"
22 #include "target.h"
23 
24 #include "sparc-tdep.h"
25 #include "sparc-nat.h"
26 #include "netbsd-nat.h"
27 
28 /* Support for debugging kernel virtual memory images.  */
29 
30 #include <sys/types.h>
31 #include <machine/pcb.h>
32 
33 #include "bsd-kvm.h"
34 
35 static int
36 sparc32nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
37 {
38   /* The following is true for NetBSD 1.6.2:
39 
40      The pcb contains %sp, %pc, %psr and %wim.  From this information
41      we reconstruct the register state as it would look when we just
42      returned from cpu_switch().  */
43 
44   /* The stack pointer shouldn't be zero.  */
45   if (pcb->pcb_sp == 0)
46     return 0;
47 
48   regcache->raw_supply (SPARC_SP_REGNUM, &pcb->pcb_sp);
49   regcache->raw_supply (SPARC_O7_REGNUM, &pcb->pcb_pc);
50   regcache->raw_supply (SPARC32_PSR_REGNUM, &pcb->pcb_psr);
51   regcache->raw_supply (SPARC32_WIM_REGNUM, &pcb->pcb_wim);
52   regcache->raw_supply (SPARC32_PC_REGNUM, &pcb->pcb_pc);
53 
54   sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
55 
56   return 1;
57 }
58 
59 static sparc_target<nbsd_nat_target> the_sparc_nbsd_nat_target;
60 
61 void _initialize_sparcnbsd_nat ();
62 void
63 _initialize_sparcnbsd_nat ()
64 {
65   sparc_gregmap = &sparc32nbsd_gregmap;
66   sparc_fpregmap = &sparc32_bsd_fpregmap;
67 
68   add_inf_child_target (&the_sparc_nbsd_nat_target);
69 
70   /* Support debugging kernel virtual memory images.  */
71   bsd_kvm_add_target (sparc32nbsd_supply_pcb);
72 }
73