1699b0f92Schristos /* Native-dependent code for OpenBSD/sparc64. 2699b0f92Schristos 3*6881a400Schristos Copyright (C) 2003-2023 Free Software Foundation, Inc. 4699b0f92Schristos 5699b0f92Schristos This file is part of GDB. 6699b0f92Schristos 7699b0f92Schristos This program is free software; you can redistribute it and/or modify 8699b0f92Schristos it under the terms of the GNU General Public License as published by 9699b0f92Schristos the Free Software Foundation; either version 3 of the License, or 10699b0f92Schristos (at your option) any later version. 11699b0f92Schristos 12699b0f92Schristos This program is distributed in the hope that it will be useful, 13699b0f92Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 14699b0f92Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15699b0f92Schristos GNU General Public License for more details. 16699b0f92Schristos 17699b0f92Schristos You should have received a copy of the GNU General Public License 18699b0f92Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19699b0f92Schristos 20699b0f92Schristos #include "defs.h" 21699b0f92Schristos #include "gdbcore.h" 22699b0f92Schristos #include "regcache.h" 23699b0f92Schristos #include "target.h" 24699b0f92Schristos 25699b0f92Schristos #include "sparc64-tdep.h" 26699b0f92Schristos #include "sparc-nat.h" 27699b0f92Schristos #include "obsd-nat.h" 28699b0f92Schristos 29699b0f92Schristos /* Determine whether `gregset_t' contains register REGNUM. */ 30699b0f92Schristos 31699b0f92Schristos static int 32699b0f92Schristos sparc64obsd_gregset_supplies_p (struct gdbarch *gdbarch, int regnum) 33699b0f92Schristos { 34699b0f92Schristos /* Integer registers. */ 35699b0f92Schristos if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_G7_REGNUM) 36699b0f92Schristos || (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM) 37699b0f92Schristos || (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_L7_REGNUM) 38699b0f92Schristos || (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I7_REGNUM)) 39699b0f92Schristos return 1; 40699b0f92Schristos 41699b0f92Schristos /* Control registers. */ 42699b0f92Schristos if (regnum == SPARC64_PC_REGNUM 43699b0f92Schristos || regnum == SPARC64_NPC_REGNUM 44699b0f92Schristos || regnum == SPARC64_STATE_REGNUM 45699b0f92Schristos || regnum == SPARC64_Y_REGNUM) 46699b0f92Schristos return 1; 47699b0f92Schristos 48699b0f92Schristos return 0; 49699b0f92Schristos } 50699b0f92Schristos 51699b0f92Schristos /* Determine whether `fpregset_t' contains register REGNUM. */ 52699b0f92Schristos 53699b0f92Schristos static int 54699b0f92Schristos sparc64obsd_fpregset_supplies_p (struct gdbarch *gdbarch, int regnum) 55699b0f92Schristos { 56699b0f92Schristos /* Floating-point registers. */ 57699b0f92Schristos if ((regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM) 58699b0f92Schristos || (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM)) 59699b0f92Schristos return 1; 60699b0f92Schristos 61699b0f92Schristos /* Control registers. */ 62699b0f92Schristos if (regnum == SPARC64_FSR_REGNUM) 63699b0f92Schristos return 1; 64699b0f92Schristos 65699b0f92Schristos return 0; 66699b0f92Schristos } 67699b0f92Schristos 68699b0f92Schristos 69699b0f92Schristos /* Support for debugging kernel virtual memory images. */ 70699b0f92Schristos 71699b0f92Schristos #include <sys/types.h> 72699b0f92Schristos #include <machine/pcb.h> 73699b0f92Schristos 74699b0f92Schristos #include "bsd-kvm.h" 75699b0f92Schristos 76699b0f92Schristos static int 77699b0f92Schristos sparc64obsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) 78699b0f92Schristos { 79699b0f92Schristos u_int64_t state; 80699b0f92Schristos int regnum; 81699b0f92Schristos 82699b0f92Schristos /* The following is true for OpenBSD 3.0: 83699b0f92Schristos 84699b0f92Schristos The pcb contains %sp and %pc, %pstate and %cwp. From this 85699b0f92Schristos information we reconstruct the register state as it would look 86699b0f92Schristos when we just returned from cpu_switch(). */ 87699b0f92Schristos 88699b0f92Schristos /* The stack pointer shouldn't be zero. */ 89699b0f92Schristos if (pcb->pcb_sp == 0) 90699b0f92Schristos return 0; 91699b0f92Schristos 92699b0f92Schristos /* If the program counter is zero, this is probably a core dump, and 93699b0f92Schristos we can get %pc from the stack. */ 94699b0f92Schristos if (pcb->pcb_pc == 0) 95699b0f92Schristos read_memory(pcb->pcb_sp + BIAS - 176 + (11 * 8), 96699b0f92Schristos (gdb_byte *)&pcb->pcb_pc, sizeof pcb->pcb_pc); 97699b0f92Schristos 987f2ac410Schristos regcache->raw_supply (SPARC_SP_REGNUM, &pcb->pcb_sp); 997f2ac410Schristos regcache->raw_supply (SPARC64_PC_REGNUM, &pcb->pcb_pc); 100699b0f92Schristos 101699b0f92Schristos state = pcb->pcb_pstate << 8 | pcb->pcb_cwp; 1027f2ac410Schristos regcache->raw_supply (SPARC64_STATE_REGNUM, &state); 103699b0f92Schristos 104699b0f92Schristos sparc_supply_rwindow (regcache, pcb->pcb_sp, -1); 105699b0f92Schristos 106699b0f92Schristos return 1; 107699b0f92Schristos } 108699b0f92Schristos 1097f2ac410Schristos /* Add some extra features to the generic SPARC target. */ 1107f2ac410Schristos static sparc_target<obsd_nat_target> the_sparc64_obsd_nat_target; 111699b0f92Schristos 1127d62b00eSchristos void _initialize_sparc64obsd_nat (); 113699b0f92Schristos void 1147d62b00eSchristos _initialize_sparc64obsd_nat () 115699b0f92Schristos { 116699b0f92Schristos sparc_supply_gregset = sparc64_supply_gregset; 117699b0f92Schristos sparc_collect_gregset = sparc64_collect_gregset; 118699b0f92Schristos sparc_supply_fpregset = sparc64_supply_fpregset; 119699b0f92Schristos sparc_collect_fpregset = sparc64_collect_fpregset; 120699b0f92Schristos sparc_gregset_supplies_p = sparc64obsd_gregset_supplies_p; 121699b0f92Schristos sparc_fpregset_supplies_p = sparc64obsd_fpregset_supplies_p; 122699b0f92Schristos 123699b0f92Schristos sparc_gregmap = &sparc64nbsd_gregmap; 124699b0f92Schristos sparc_fpregmap = &sparc64_bsd_fpregmap; 125699b0f92Schristos 126699b0f92Schristos /* Add some extra features to the generic SPARC target. */ 1277f2ac410Schristos add_inf_child_target (&the_sparc64_obsd_nat_target); 128699b0f92Schristos 129699b0f92Schristos /* Support debugging kernel virtual memory images. */ 130699b0f92Schristos bsd_kvm_add_target (sparc64obsd_supply_pcb); 131699b0f92Schristos } 132