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