xref: /netbsd-src/external/gpl3/gdb/dist/gdb/sparc64-fbsd-nat.c (revision 3ab27c2a5c5a428dcf317838e7805b6e621087cf)
1 /* Native-dependent code for FreeBSD/sparc64.
2 
3    Copyright (C) 2003-2024 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 "regcache.h"
21 #include "target.h"
22 
23 #include "fbsd-nat.h"
24 #include "sparc64-tdep.h"
25 #include "sparc-nat.h"
26 
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 sparc64fbsd_kvm_supply_pcb (struct regcache *regcache, struct pcb *pcb)
37 {
38   /* The following is true for FreeBSD 5.4:
39 
40      The pcb contains %sp and %pc.  Since the register windows are
41      explicitly flushed, we can find the `local' and `in' registers on
42      the stack.  */
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 (SPARC64_PC_REGNUM, &pcb->pcb_pc);
50 
51   /* Synthesize %npc.  */
52   pcb->pcb_pc += 4;
53   regcache->raw_supply (SPARC64_NPC_REGNUM, &pcb->pcb_pc);
54 
55   /* Read `local' and `in' registers from the stack.  */
56   sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
57 
58   return 1;
59 }
60 
61 /* Add some extra features to the generic SPARC target.  */
62 static sparc_target<fbsd_nat_target> the_sparc64_fbsd_nat_target;
63 
64 void _initialize_sparc64fbsd_nat ();
65 void
66 _initialize_sparc64fbsd_nat ()
67 {
68   add_inf_child_target (&the_sparc64_fbsd_nat_target);
69 
70   sparc_gregmap = &sparc64fbsd_gregmap;
71 
72   /* Support debugging kernel virtual memory images.  */
73   bsd_kvm_add_target (sparc64fbsd_kvm_supply_pcb);
74 }
75