Commit | Line | Data |
---|---|---|
424f3115 | 1 | /* Target-dependent code for NetBSD/arm. |
527ca6bb | 2 | |
b811d2c2 | 3 | Copyright (C) 2002-2020 Free Software Foundation, Inc. |
66e810cd RE |
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
66e810cd RE |
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 | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
66e810cd RE |
19 | |
20 | #include "defs.h" | |
4de283e4 | 21 | #include "osabi.h" |
66e810cd | 22 | |
cba7e83f | 23 | #include "arch/arm.h" |
8dd8e1c7 | 24 | #include "arm-nbsd-tdep.h" |
66e810cd | 25 | #include "arm-tdep.h" |
8dd8e1c7 | 26 | #include "regset.h" |
9eeef8ef | 27 | #include "solib-svr4.h" |
66e810cd | 28 | |
9df628e0 | 29 | /* Description of the longjmp buffer. */ |
625602f2 | 30 | #define ARM_NBSD_JB_PC 24 |
f0452268 | 31 | #define ARM_NBSD_JB_ELEMENT_SIZE ARM_INT_REGISTER_SIZE |
9df628e0 | 32 | |
85102364 | 33 | /* For compatibility with previous implementations of GDB on arm/NetBSD, |
66e810cd | 34 | override the default little-endian breakpoint. */ |
948f8e3d PA |
35 | static const gdb_byte arm_nbsd_arm_le_breakpoint[] = {0x11, 0x00, 0x00, 0xe6}; |
36 | static const gdb_byte arm_nbsd_arm_be_breakpoint[] = {0xe6, 0x00, 0x00, 0x11}; | |
37 | static const gdb_byte arm_nbsd_thumb_le_breakpoint[] = {0xfe, 0xde}; | |
38 | static const gdb_byte arm_nbsd_thumb_be_breakpoint[] = {0xde, 0xfe}; | |
66e810cd | 39 | |
8dd8e1c7 CB |
40 | /* This matches struct reg from NetBSD's sys/arch/arm/include/reg.h: |
41 | https://github.com/NetBSD/src/blob/7c13e6e6773bb171f4ed3ed53013e9d24b3c1eac/sys/arch/arm/include/reg.h#L39 | |
42 | */ | |
43 | struct arm_nbsd_reg | |
44 | { | |
45 | uint32_t reg[13]; | |
46 | uint32_t sp; | |
47 | uint32_t lr; | |
48 | uint32_t pc; | |
49 | uint32_t cpsr; | |
50 | }; | |
51 | ||
52 | void | |
53 | arm_nbsd_supply_gregset (const struct regset *regset, struct regcache *regcache, | |
54 | int regnum, const void *gregs, size_t len) | |
55 | { | |
56 | const arm_nbsd_reg *gregset = static_cast<const arm_nbsd_reg *>(gregs); | |
57 | gdb_assert (len >= sizeof (arm_nbsd_reg)); | |
58 | ||
59 | /* Integer registers. */ | |
60 | for (int i = ARM_A1_REGNUM; i < ARM_SP_REGNUM; i++) | |
61 | if (regnum == -1 || regnum == i) | |
62 | regcache->raw_supply (i, (char *) &gregset->reg[i]); | |
63 | ||
64 | if (regnum == -1 || regnum == ARM_SP_REGNUM) | |
65 | regcache->raw_supply (ARM_SP_REGNUM, (char *) &gregset->sp); | |
66 | ||
67 | if (regnum == -1 || regnum == ARM_LR_REGNUM) | |
68 | regcache->raw_supply (ARM_LR_REGNUM, (char *) &gregset->lr); | |
69 | ||
70 | if (regnum == -1 || regnum == ARM_PC_REGNUM) | |
71 | { | |
72 | CORE_ADDR r_pc = gdbarch_addr_bits_remove (regcache->arch (), gregset->pc); | |
73 | regcache->raw_supply (ARM_PC_REGNUM, (char *) &r_pc); | |
74 | } | |
75 | ||
76 | if (regnum == -1 || regnum == ARM_PS_REGNUM) | |
77 | { | |
78 | if (arm_apcs_32) | |
79 | regcache->raw_supply (ARM_PS_REGNUM, (char *) &gregset->cpsr); | |
80 | else | |
81 | regcache->raw_supply (ARM_PS_REGNUM, (char *) &gregset->pc); | |
82 | } | |
83 | } | |
84 | ||
85 | static const struct regset arm_nbsd_regset = { | |
86 | nullptr, | |
87 | arm_nbsd_supply_gregset, | |
88 | /* We don't need a collect function because we only use this reading registers | |
89 | (via iterate_over_regset_sections and fetch_regs/fetch_register). */ | |
90 | nullptr, | |
91 | 0 | |
92 | }; | |
93 | ||
94 | static void | |
95 | arm_nbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, | |
96 | iterate_over_regset_sections_cb *cb, | |
97 | void *cb_data, | |
98 | const struct regcache *regcache) | |
99 | { | |
100 | cb (".reg", sizeof (arm_nbsd_reg), sizeof (arm_nbsd_reg), &arm_nbsd_regset, | |
101 | NULL, cb_data); | |
102 | /* cbiesinger/2020-02-12 -- as far as I can tell, ARM/NetBSD does | |
103 | not write any floating point registers into the core file (tested | |
104 | with NetBSD 9.1_RC1). When it does, this function will need to read them, | |
105 | and the arm-netbsd gdbarch will need a core_read_description function | |
106 | to return the right description for them. */ | |
107 | } | |
108 | ||
66e810cd RE |
109 | static void |
110 | arm_netbsd_init_abi_common (struct gdbarch_info info, | |
111 | struct gdbarch *gdbarch) | |
112 | { | |
113 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
114 | ||
115 | tdep->lowest_pc = 0x8000; | |
2afeb6b8 RE |
116 | switch (info.byte_order) |
117 | { | |
118 | case BFD_ENDIAN_LITTLE: | |
119 | tdep->arm_breakpoint = arm_nbsd_arm_le_breakpoint; | |
120 | tdep->thumb_breakpoint = arm_nbsd_thumb_le_breakpoint; | |
121 | tdep->arm_breakpoint_size = sizeof (arm_nbsd_arm_le_breakpoint); | |
122 | tdep->thumb_breakpoint_size = sizeof (arm_nbsd_thumb_le_breakpoint); | |
123 | break; | |
124 | ||
125 | case BFD_ENDIAN_BIG: | |
126 | tdep->arm_breakpoint = arm_nbsd_arm_be_breakpoint; | |
127 | tdep->thumb_breakpoint = arm_nbsd_thumb_be_breakpoint; | |
128 | tdep->arm_breakpoint_size = sizeof (arm_nbsd_arm_be_breakpoint); | |
129 | tdep->thumb_breakpoint_size = sizeof (arm_nbsd_thumb_be_breakpoint); | |
130 | break; | |
131 | ||
132 | default: | |
133 | internal_error (__FILE__, __LINE__, | |
edefbb7c | 134 | _("arm_gdbarch_init: bad byte order for float format")); |
2afeb6b8 | 135 | } |
9df628e0 | 136 | |
625602f2 RE |
137 | tdep->jb_pc = ARM_NBSD_JB_PC; |
138 | tdep->jb_elt_size = ARM_NBSD_JB_ELEMENT_SIZE; | |
190dce09 | 139 | |
8dd8e1c7 CB |
140 | set_gdbarch_iterate_over_regset_sections |
141 | (gdbarch, arm_nbsd_iterate_over_regset_sections); | |
190dce09 UW |
142 | /* Single stepping. */ |
143 | set_gdbarch_software_single_step (gdbarch, arm_software_single_step); | |
66e810cd | 144 | } |
8dd8e1c7 | 145 | |
66e810cd | 146 | static void |
424f3115 | 147 | arm_netbsd_elf_init_abi (struct gdbarch_info info, |
66e810cd RE |
148 | struct gdbarch *gdbarch) |
149 | { | |
08216dd7 RE |
150 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
151 | ||
66e810cd | 152 | arm_netbsd_init_abi_common (info, gdbarch); |
28e97307 DJ |
153 | if (tdep->fp_model == ARM_FLOAT_AUTO) |
154 | tdep->fp_model = ARM_FLOAT_SOFT_VFP; | |
a4ab4a25 MK |
155 | |
156 | /* NetBSD ELF uses SVR4-style shared libraries. */ | |
157 | set_solib_svr4_fetch_link_map_offsets | |
424f3115 | 158 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); |
66e810cd RE |
159 | } |
160 | ||
6c265988 | 161 | void _initialize_arm_netbsd_tdep (); |
66e810cd | 162 | void |
6c265988 | 163 | _initialize_arm_netbsd_tdep () |
66e810cd | 164 | { |
1736a7bd | 165 | gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_NETBSD, |
70f80edf | 166 | arm_netbsd_elf_init_abi); |
66e810cd | 167 | } |