1 /* Copyright (C) 2020-2024 Free Software Foundation, Inc. 2 3 This file is part of GDB. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 #include <sys/types.h> 19 #include <sys/ptrace.h> 20 #include <limits.h> 21 22 #include "netbsd-low.h" 23 #include "arch/aarch64.h" 24 #include "arch/aarch64-insn.h" 25 #include "tdesc.h" 26 27 /* The fill_function for the general-purpose register set. */ 28 29 static void 30 netbsd_aarch64_fill_gregset (struct regcache *regcache, char *buf) 31 { 32 struct reg *r = (struct reg *) buf; 33 34 #define netbsd_aarch64_collect_gp(regnum, fld) do { \ 35 collect_register (regcache, regnum, &r->fld); \ 36 } while (0) 37 38 for (size_t i = 0; i < ARRAY_SIZE (r->r_reg); i++) 39 netbsd_aarch64_collect_gp (AARCH64_X0_REGNUM + i, r_reg[i]); 40 41 netbsd_aarch64_collect_gp (AARCH64_SP_REGNUM, r_sp); 42 netbsd_aarch64_collect_gp (AARCH64_PC_REGNUM, r_pc); 43 } 44 45 /* The store_function for the general-purpose register set. */ 46 47 static void 48 netbsd_aarch64_store_gregset (struct regcache *regcache, const char *buf) 49 { 50 struct reg *r = (struct reg *) buf; 51 52 #define netbsd_aarch64_supply_gp(regnum, fld) do { \ 53 supply_register (regcache, regnum, &r->fld); \ 54 } while(0) 55 56 for (size_t i = 0; i < ARRAY_SIZE (r->r_reg); i++) 57 netbsd_aarch64_supply_gp (AARCH64_X0_REGNUM + i, r_reg[i]); 58 59 netbsd_aarch64_supply_gp (AARCH64_SP_REGNUM, r_sp); 60 netbsd_aarch64_supply_gp (AARCH64_PC_REGNUM, r_pc); 61 } 62 63 /* Description of all the aarch64-netbsd register sets. */ 64 65 static const struct netbsd_regset_info netbsd_target_regsets[] = 66 { 67 /* General Purpose Registers. */ 68 {PT_GETREGS, PT_SETREGS, sizeof (struct reg), 69 netbsd_aarch64_fill_gregset, netbsd_aarch64_store_gregset}, 70 /* End of list marker. */ 71 {0, 0, -1, NULL, NULL } 72 }; 73 74 /* NetBSD target op definitions for the aarch64 architecture. */ 75 76 class netbsd_aarch64_target : public netbsd_process_target 77 { 78 protected: 79 const netbsd_regset_info *get_regs_info () override; 80 81 void low_arch_setup () override; 82 }; 83 84 /* Return the information to access registers. */ 85 86 const netbsd_regset_info * 87 netbsd_aarch64_target::get_regs_info () 88 { 89 return netbsd_target_regsets; 90 } 91 92 /* Architecture-specific setup for the current process. */ 93 94 void 95 netbsd_aarch64_target::low_arch_setup () 96 { 97 target_desc *tdesc 98 = aarch64_create_target_description ({}); 99 100 static const char *expedite_regs_aarch64[] = { "x29", "sp", "pc", NULL }; 101 init_target_desc (tdesc, expedite_regs_aarch64); 102 103 current_process ()->tdesc = tdesc; 104 } 105 106 /* The singleton target ops object. */ 107 108 static netbsd_aarch64_target the_netbsd_aarch64_target; 109 110 /* The NetBSD target ops object. */ 111 112 netbsd_process_target *the_netbsd_target = &the_netbsd_aarch64_target; 113