1e88b412bSchristos /* Native-dependent code for FreeBSD/sparc64.
2e88b412bSchristos 
3*56bb7041Schristos    Copyright (C) 2003-2020 Free Software Foundation, Inc.
4e88b412bSchristos 
5e88b412bSchristos    This file is part of GDB.
6e88b412bSchristos 
7e88b412bSchristos    This program is free software; you can redistribute it and/or modify
8e88b412bSchristos    it under the terms of the GNU General Public License as published by
9e88b412bSchristos    the Free Software Foundation; either version 3 of the License, or
10e88b412bSchristos    (at your option) any later version.
11e88b412bSchristos 
12e88b412bSchristos    This program is distributed in the hope that it will be useful,
13e88b412bSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14e88b412bSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e88b412bSchristos    GNU General Public License for more details.
16e88b412bSchristos 
17e88b412bSchristos    You should have received a copy of the GNU General Public License
18e88b412bSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19e88b412bSchristos 
20e88b412bSchristos #include "defs.h"
21e88b412bSchristos #include "regcache.h"
22e88b412bSchristos #include "target.h"
23e88b412bSchristos 
24e88b412bSchristos #include "fbsd-nat.h"
25e88b412bSchristos #include "sparc64-tdep.h"
26e88b412bSchristos #include "sparc-nat.h"
27e88b412bSchristos 
28e88b412bSchristos 
29e88b412bSchristos /* Support for debugging kernel virtual memory images.  */
30e88b412bSchristos 
31e88b412bSchristos #include <sys/types.h>
32e88b412bSchristos #include <machine/pcb.h>
33e88b412bSchristos 
34e88b412bSchristos #include "bsd-kvm.h"
35e88b412bSchristos 
36e88b412bSchristos static int
sparc64fbsd_kvm_supply_pcb(struct regcache * regcache,struct pcb * pcb)37e88b412bSchristos sparc64fbsd_kvm_supply_pcb (struct regcache *regcache, struct pcb *pcb)
38e88b412bSchristos {
39e88b412bSchristos   /* The following is true for FreeBSD 5.4:
40e88b412bSchristos 
41e88b412bSchristos      The pcb contains %sp and %pc.  Since the register windows are
42e88b412bSchristos      explicitly flushed, we can find the `local' and `in' registers on
43e88b412bSchristos      the stack.  */
44e88b412bSchristos 
45e88b412bSchristos   /* The stack pointer shouldn't be zero.  */
46e88b412bSchristos   if (pcb->pcb_sp == 0)
47e88b412bSchristos     return 0;
48e88b412bSchristos 
493aed4a8bSchristos   regcache->raw_supply (SPARC_SP_REGNUM, &pcb->pcb_sp);
503aed4a8bSchristos   regcache->raw_supply (SPARC64_PC_REGNUM, &pcb->pcb_pc);
51e88b412bSchristos 
52e88b412bSchristos   /* Synthesize %npc.  */
53e88b412bSchristos   pcb->pcb_pc += 4;
543aed4a8bSchristos   regcache->raw_supply (SPARC64_NPC_REGNUM, &pcb->pcb_pc);
55e88b412bSchristos 
56e88b412bSchristos   /* Read `local' and `in' registers from the stack.  */
57e88b412bSchristos   sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
58e88b412bSchristos 
59e88b412bSchristos   return 1;
60e88b412bSchristos }
61e88b412bSchristos 
623aed4a8bSchristos /* Add some extra features to the generic SPARC target.  */
633aed4a8bSchristos static sparc_target<fbsd_nat_target> the_sparc64_fbsd_nat_target;
64e88b412bSchristos 
65*56bb7041Schristos void _initialize_sparc64fbsd_nat ();
66e88b412bSchristos void
_initialize_sparc64fbsd_nat()67*56bb7041Schristos _initialize_sparc64fbsd_nat ()
68e88b412bSchristos {
693aed4a8bSchristos   add_inf_child_target (&the_sparc64_fbsd_nat_target);
70e88b412bSchristos 
71e88b412bSchristos   sparc_gregmap = &sparc64fbsd_gregmap;
72e88b412bSchristos 
73e88b412bSchristos   /* Support debugging kernel virtual memory images.  */
74e88b412bSchristos   bsd_kvm_add_target (sparc64fbsd_kvm_supply_pcb);
75e88b412bSchristos }
76