1*6881a400Schristos /* Target-dependent code for NetBSD/powerpc. 2*6881a400Schristos 3*6881a400Schristos Copyright (C) 2002-2023 Free Software Foundation, Inc. 4*6881a400Schristos 5*6881a400Schristos Contributed by Wasabi Systems, Inc. 6*6881a400Schristos 7*6881a400Schristos This file is part of GDB. 8*6881a400Schristos 9*6881a400Schristos This program is free software; you can redistribute it and/or modify 10*6881a400Schristos it under the terms of the GNU General Public License as published by 11*6881a400Schristos the Free Software Foundation; either version 3 of the License, or 12*6881a400Schristos (at your option) any later version. 13*6881a400Schristos 14*6881a400Schristos This program is distributed in the hope that it will be useful, 15*6881a400Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 16*6881a400Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*6881a400Schristos GNU General Public License for more details. 18*6881a400Schristos 19*6881a400Schristos You should have received a copy of the GNU General Public License 20*6881a400Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21*6881a400Schristos 22*6881a400Schristos #include "defs.h" 23*6881a400Schristos #include "gdbtypes.h" 24*6881a400Schristos #include "osabi.h" 25*6881a400Schristos #include "regcache.h" 26*6881a400Schristos #include "regset.h" 27*6881a400Schristos #include "trad-frame.h" 28*6881a400Schristos #include "tramp-frame.h" 29*6881a400Schristos 30*6881a400Schristos #include "ppc-tdep.h" 31*6881a400Schristos #include "netbsd-tdep.h" 32*6881a400Schristos #include "ppc-netbsd-tdep.h" 33*6881a400Schristos #include "ppc-tdep.h" 34*6881a400Schristos #include "solib-svr4.h" 35*6881a400Schristos 36*6881a400Schristos /* Register offsets from <machine/reg.h>. */ 37*6881a400Schristos static ppc_reg_offsets ppcnbsd_reg_offsets; 38*6881a400Schristos 39*6881a400Schristos 40*6881a400Schristos /* Core file support. */ 41*6881a400Schristos 42*6881a400Schristos /* NetBSD/powerpc register sets. */ 43*6881a400Schristos 44*6881a400Schristos const struct regset ppcnbsd_gregset = 45*6881a400Schristos { 46*6881a400Schristos &ppcnbsd_reg_offsets, 47*6881a400Schristos ppc_supply_gregset 48*6881a400Schristos }; 49*6881a400Schristos 50*6881a400Schristos const struct regset ppcnbsd_fpregset = 51*6881a400Schristos { 52*6881a400Schristos &ppcnbsd_reg_offsets, 53*6881a400Schristos ppc_supply_fpregset 54*6881a400Schristos }; 55*6881a400Schristos 56*6881a400Schristos /* Iterate over core file register note sections. */ 57*6881a400Schristos 58*6881a400Schristos static void 59*6881a400Schristos ppcnbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, 60*6881a400Schristos iterate_over_regset_sections_cb *cb, 61*6881a400Schristos void *cb_data, 62*6881a400Schristos const struct regcache *regcache) 63*6881a400Schristos { 64*6881a400Schristos cb (".reg", 148, 148, &ppcnbsd_gregset, NULL, cb_data); 65*6881a400Schristos cb (".reg2", 264, 264, &ppcnbsd_fpregset, NULL, cb_data); 66*6881a400Schristos } 67*6881a400Schristos 68*6881a400Schristos 69*6881a400Schristos /* NetBSD is confused. It appears that 1.5 was using the correct SVR4 70*6881a400Schristos convention but, 1.6 switched to the below broken convention. For 71*6881a400Schristos the moment use the broken convention. Ulgh! */ 72*6881a400Schristos 73*6881a400Schristos static enum return_value_convention 74*6881a400Schristos ppcnbsd_return_value (struct gdbarch *gdbarch, struct value *function, 75*6881a400Schristos struct type *valtype, struct regcache *regcache, 76*6881a400Schristos gdb_byte *readbuf, const gdb_byte *writebuf) 77*6881a400Schristos { 78*6881a400Schristos #if 0 79*6881a400Schristos if ((valtype->code () == TYPE_CODE_STRUCT 80*6881a400Schristos || valtype->code () == TYPE_CODE_UNION) 81*6881a400Schristos && !((valtype->length () == 16 || valtype->length () == 8) 82*6881a400Schristos && valtype->is_vector ()) 83*6881a400Schristos && !(valtype->length () == 1 84*6881a400Schristos || valtype->length () == 2 85*6881a400Schristos || valtype->length () == 4 86*6881a400Schristos || valtype->length () == 8)) 87*6881a400Schristos return RETURN_VALUE_STRUCT_CONVENTION; 88*6881a400Schristos else 89*6881a400Schristos #endif 90*6881a400Schristos return ppc_sysv_abi_broken_return_value (gdbarch, function, valtype, 91*6881a400Schristos regcache, readbuf, writebuf); 92*6881a400Schristos } 93*6881a400Schristos 94*6881a400Schristos 95*6881a400Schristos /* Signal trampolines. */ 96*6881a400Schristos 97*6881a400Schristos extern const struct tramp_frame ppcnbsd2_sigtramp; 98*6881a400Schristos 99*6881a400Schristos static void 100*6881a400Schristos ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self, 101*6881a400Schristos frame_info_ptr this_frame, 102*6881a400Schristos struct trad_frame_cache *this_cache, 103*6881a400Schristos CORE_ADDR func) 104*6881a400Schristos { 105*6881a400Schristos struct gdbarch *gdbarch = get_frame_arch (this_frame); 106*6881a400Schristos ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch); 107*6881a400Schristos CORE_ADDR addr, base; 108*6881a400Schristos int i; 109*6881a400Schristos 110*6881a400Schristos base = get_frame_register_unsigned (this_frame, 111*6881a400Schristos gdbarch_sp_regnum (gdbarch)); 112*6881a400Schristos if (self == &ppcnbsd2_sigtramp) 113*6881a400Schristos addr = base + 0x10 + 2 * tdep->wordsize; 114*6881a400Schristos else 115*6881a400Schristos addr = base + 0x18 + 2 * tdep->wordsize; 116*6881a400Schristos for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize) 117*6881a400Schristos { 118*6881a400Schristos int regnum = i + tdep->ppc_gp0_regnum; 119*6881a400Schristos trad_frame_set_reg_addr (this_cache, regnum, addr); 120*6881a400Schristos } 121*6881a400Schristos trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, addr); 122*6881a400Schristos addr += tdep->wordsize; 123*6881a400Schristos trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, addr); 124*6881a400Schristos addr += tdep->wordsize; 125*6881a400Schristos trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, addr); 126*6881a400Schristos addr += tdep->wordsize; 127*6881a400Schristos trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, addr); 128*6881a400Schristos addr += tdep->wordsize; 129*6881a400Schristos trad_frame_set_reg_addr (this_cache, gdbarch_pc_regnum (gdbarch), 130*6881a400Schristos addr); /* SRR0? */ 131*6881a400Schristos addr += tdep->wordsize; 132*6881a400Schristos 133*6881a400Schristos /* Construct the frame ID using the function start. */ 134*6881a400Schristos trad_frame_set_id (this_cache, frame_id_build (base, func)); 135*6881a400Schristos } 136*6881a400Schristos 137*6881a400Schristos static const struct tramp_frame ppcnbsd_sigtramp = 138*6881a400Schristos { 139*6881a400Schristos SIGTRAMP_FRAME, 140*6881a400Schristos 4, 141*6881a400Schristos { 142*6881a400Schristos { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */ 143*6881a400Schristos { 0x4e800021, ULONGEST_MAX }, /* blrl */ 144*6881a400Schristos { 0x38610018, ULONGEST_MAX }, /* addi r3,r1,24 */ 145*6881a400Schristos { 0x38000127, ULONGEST_MAX }, /* li r0,295 */ 146*6881a400Schristos { 0x44000002, ULONGEST_MAX }, /* sc */ 147*6881a400Schristos { 0x38000001, ULONGEST_MAX }, /* li r0,1 */ 148*6881a400Schristos { 0x44000002, ULONGEST_MAX }, /* sc */ 149*6881a400Schristos { TRAMP_SENTINEL_INSN, ULONGEST_MAX } 150*6881a400Schristos }, 151*6881a400Schristos ppcnbsd_sigtramp_cache_init 152*6881a400Schristos }; 153*6881a400Schristos 154*6881a400Schristos /* NetBSD 2.0 introduced a slightly different signal trampoline. */ 155*6881a400Schristos 156*6881a400Schristos const struct tramp_frame ppcnbsd2_sigtramp = 157*6881a400Schristos { 158*6881a400Schristos SIGTRAMP_FRAME, 159*6881a400Schristos 4, 160*6881a400Schristos { 161*6881a400Schristos { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */ 162*6881a400Schristos { 0x4e800021, ULONGEST_MAX }, /* blrl */ 163*6881a400Schristos { 0x38610010, ULONGEST_MAX }, /* addi r3,r1,16 */ 164*6881a400Schristos { 0x38000127, ULONGEST_MAX }, /* li r0,295 */ 165*6881a400Schristos { 0x44000002, ULONGEST_MAX }, /* sc */ 166*6881a400Schristos { 0x38000001, ULONGEST_MAX }, /* li r0,1 */ 167*6881a400Schristos { 0x44000002, ULONGEST_MAX }, /* sc */ 168*6881a400Schristos { TRAMP_SENTINEL_INSN, ULONGEST_MAX } 169*6881a400Schristos }, 170*6881a400Schristos ppcnbsd_sigtramp_cache_init 171*6881a400Schristos }; 172*6881a400Schristos 173*6881a400Schristos 174*6881a400Schristos static void 175*6881a400Schristos ppcnbsd_init_abi (struct gdbarch_info info, 176*6881a400Schristos struct gdbarch *gdbarch) 177*6881a400Schristos { 178*6881a400Schristos nbsd_init_abi (info, gdbarch); 179*6881a400Schristos 180*6881a400Schristos /* NetBSD doesn't support the 128-bit `long double' from the psABI. */ 181*6881a400Schristos set_gdbarch_long_double_bit (gdbarch, 64); 182*6881a400Schristos set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double); 183*6881a400Schristos 184*6881a400Schristos /* For NetBSD, this is an on again, off again thing. Some systems 185*6881a400Schristos do use the broken struct convention, and some don't. */ 186*6881a400Schristos set_gdbarch_return_value (gdbarch, ppcnbsd_return_value); 187*6881a400Schristos 188*6881a400Schristos /* NetBSD uses SVR4-style shared libraries. */ 189*6881a400Schristos set_solib_svr4_fetch_link_map_offsets 190*6881a400Schristos (gdbarch, svr4_ilp32_fetch_link_map_offsets); 191*6881a400Schristos 192*6881a400Schristos set_gdbarch_iterate_over_regset_sections 193*6881a400Schristos (gdbarch, ppcnbsd_iterate_over_regset_sections); 194*6881a400Schristos 195*6881a400Schristos tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp); 196*6881a400Schristos tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp); 197*6881a400Schristos } 198*6881a400Schristos 199*6881a400Schristos void _initialize_ppcnbsd_tdep (); 200*6881a400Schristos void 201*6881a400Schristos _initialize_ppcnbsd_tdep () 202*6881a400Schristos { 203*6881a400Schristos gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD, 204*6881a400Schristos ppcnbsd_init_abi); 205*6881a400Schristos 206*6881a400Schristos /* Register NetBSD OSABI also for rs6000, which is default target 207*6881a400Schristos used before any executable image is loaded. */ 208*6881a400Schristos gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_NETBSD, 209*6881a400Schristos ppcnbsd_init_abi); 210*6881a400Schristos 211*6881a400Schristos /* Avoid initializing the register offsets again if they were 212*6881a400Schristos already initialized by ppc-netbsd-nat.c. */ 213*6881a400Schristos if (ppcnbsd_reg_offsets.pc_offset == 0) 214*6881a400Schristos { 215*6881a400Schristos /* General-purpose registers. */ 216*6881a400Schristos ppcnbsd_reg_offsets.r0_offset = 0; 217*6881a400Schristos ppcnbsd_reg_offsets.gpr_size = 4; 218*6881a400Schristos ppcnbsd_reg_offsets.xr_size = 4; 219*6881a400Schristos ppcnbsd_reg_offsets.lr_offset = 128; 220*6881a400Schristos ppcnbsd_reg_offsets.cr_offset = 132; 221*6881a400Schristos ppcnbsd_reg_offsets.xer_offset = 136; 222*6881a400Schristos ppcnbsd_reg_offsets.ctr_offset = 140; 223*6881a400Schristos ppcnbsd_reg_offsets.pc_offset = 144; 224*6881a400Schristos ppcnbsd_reg_offsets.ps_offset = -1; 225*6881a400Schristos ppcnbsd_reg_offsets.mq_offset = -1; 226*6881a400Schristos 227*6881a400Schristos /* Floating-point registers. */ 228*6881a400Schristos ppcnbsd_reg_offsets.f0_offset = 0; 229*6881a400Schristos ppcnbsd_reg_offsets.fpscr_offset = 256; 230*6881a400Schristos ppcnbsd_reg_offsets.fpscr_size = 4; 231*6881a400Schristos 232*6881a400Schristos } 233*6881a400Schristos } 234