Commit | Line | Data |
---|---|---|
def18405 | 1 | /* Target-dependent code for NetBSD/powerpc. |
476be15e | 2 | |
b811d2c2 | 3 | Copyright (C) 2002-2020 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" |
03b62bbb | 31 | #include "ppc-nbsd-tdep.h" |
485721b1 JT |
32 | #include "solib-svr4.h" |
33 | ||
def18405 MK |
34 | /* Register offsets from <machine/reg.h>. */ |
35 | struct ppc_reg_offsets ppcnbsd_reg_offsets; | |
36 | \f | |
485721b1 | 37 | |
def18405 | 38 | /* Core file support. */ |
485721b1 | 39 | |
1e17aef8 | 40 | /* NetBSD/powerpc register sets. */ |
485721b1 | 41 | |
3ca7dae4 | 42 | const struct regset ppcnbsd_gregset = |
485721b1 | 43 | { |
def18405 MK |
44 | &ppcnbsd_reg_offsets, |
45 | ppc_supply_gregset | |
46 | }; | |
485721b1 | 47 | |
3ca7dae4 | 48 | const struct regset ppcnbsd_fpregset = |
485721b1 | 49 | { |
def18405 MK |
50 | &ppcnbsd_reg_offsets, |
51 | ppc_supply_fpregset | |
52 | }; | |
485721b1 | 53 | |
23ea9aeb | 54 | /* Iterate over core file register note sections. */ |
485721b1 | 55 | |
23ea9aeb AA |
56 | static void |
57 | ppcnbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, | |
58 | iterate_over_regset_sections_cb *cb, | |
59 | void *cb_data, | |
60 | const struct regcache *regcache) | |
485721b1 | 61 | { |
a616bb94 AH |
62 | cb (".reg", 148, 148, &ppcnbsd_gregset, NULL, cb_data); |
63 | cb (".reg2", 264, 264, &ppcnbsd_fpregset, NULL, cb_data); | |
485721b1 | 64 | } |
def18405 | 65 | \f |
485721b1 | 66 | |
def18405 | 67 | /* NetBSD is confused. It appears that 1.5 was using the correct SVR4 |
957e27ac | 68 | convention but, 1.6 switched to the below broken convention. For |
0df8b418 | 69 | the moment use the broken convention. Ulgh! */ |
957e27ac | 70 | |
05580c65 | 71 | static enum return_value_convention |
6a3a010b | 72 | ppcnbsd_return_value (struct gdbarch *gdbarch, struct value *function, |
c055b101 CV |
73 | struct type *valtype, struct regcache *regcache, |
74 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
05580c65 | 75 | { |
def18405 | 76 | #if 0 |
05580c65 AC |
77 | if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT |
78 | || TYPE_CODE (valtype) == TYPE_CODE_UNION) | |
79 | && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8) | |
80 | && TYPE_VECTOR (valtype)) | |
81 | && !(TYPE_LENGTH (valtype) == 1 | |
82 | || TYPE_LENGTH (valtype) == 2 | |
83 | || TYPE_LENGTH (valtype) == 4 | |
84 | || TYPE_LENGTH (valtype) == 8)) | |
85 | return RETURN_VALUE_STRUCT_CONVENTION; | |
86 | else | |
def18405 | 87 | #endif |
6a3a010b | 88 | return ppc_sysv_abi_broken_return_value (gdbarch, function, valtype, |
c055b101 | 89 | regcache, readbuf, writebuf); |
957e27ac | 90 | } |
def18405 MK |
91 | \f |
92 | ||
93 | /* Signal trampolines. */ | |
94 | ||
e36122e9 | 95 | extern const struct tramp_frame ppcnbsd2_sigtramp; |
957e27ac | 96 | |
476be15e AC |
97 | static void |
98 | ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self, | |
5366653e | 99 | struct frame_info *this_frame, |
476be15e AC |
100 | struct trad_frame_cache *this_cache, |
101 | CORE_ADDR func) | |
102 | { | |
5366653e | 103 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
476be15e | 104 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
def18405 MK |
105 | CORE_ADDR addr, base; |
106 | int i; | |
476be15e | 107 | |
5366653e DJ |
108 | base = get_frame_register_unsigned (this_frame, |
109 | gdbarch_sp_regnum (gdbarch)); | |
def18405 MK |
110 | if (self == &ppcnbsd2_sigtramp) |
111 | addr = base + 0x10 + 2 * tdep->wordsize; | |
112 | else | |
113 | addr = base + 0x18 + 2 * tdep->wordsize; | |
114 | for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize) | |
476be15e AC |
115 | { |
116 | int regnum = i + tdep->ppc_gp0_regnum; | |
def18405 | 117 | trad_frame_set_reg_addr (this_cache, regnum, addr); |
476be15e | 118 | } |
def18405 MK |
119 | trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, addr); |
120 | addr += tdep->wordsize; | |
121 | trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, addr); | |
122 | addr += tdep->wordsize; | |
123 | trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, addr); | |
124 | addr += tdep->wordsize; | |
125 | trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, addr); | |
126 | addr += tdep->wordsize; | |
40a6adc1 | 127 | trad_frame_set_reg_addr (this_cache, gdbarch_pc_regnum (gdbarch), |
0df8b418 | 128 | addr); /* SRR0? */ |
def18405 | 129 | addr += tdep->wordsize; |
476be15e AC |
130 | |
131 | /* Construct the frame ID using the function start. */ | |
132 | trad_frame_set_id (this_cache, frame_id_build (base, func)); | |
133 | } | |
134 | ||
def18405 MK |
135 | static const struct tramp_frame ppcnbsd_sigtramp = |
136 | { | |
137 | SIGTRAMP_FRAME, | |
138 | 4, | |
139 | { | |
7bc02706 TT |
140 | { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */ |
141 | { 0x4e800021, ULONGEST_MAX }, /* blrl */ | |
142 | { 0x38610018, ULONGEST_MAX }, /* addi r3,r1,24 */ | |
143 | { 0x38000127, ULONGEST_MAX }, /* li r0,295 */ | |
144 | { 0x44000002, ULONGEST_MAX }, /* sc */ | |
145 | { 0x38000001, ULONGEST_MAX }, /* li r0,1 */ | |
146 | { 0x44000002, ULONGEST_MAX }, /* sc */ | |
147 | { TRAMP_SENTINEL_INSN, ULONGEST_MAX } | |
def18405 MK |
148 | }, |
149 | ppcnbsd_sigtramp_cache_init | |
150 | }; | |
151 | ||
152 | /* NetBSD 2.0 introduced a slightly different signal trampoline. */ | |
476be15e | 153 | |
e36122e9 | 154 | const struct tramp_frame ppcnbsd2_sigtramp = |
def18405 | 155 | { |
2cd8546d | 156 | SIGTRAMP_FRAME, |
def18405 MK |
157 | 4, |
158 | { | |
7bc02706 TT |
159 | { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */ |
160 | { 0x4e800021, ULONGEST_MAX }, /* blrl */ | |
161 | { 0x38610010, ULONGEST_MAX }, /* addi r3,r1,16 */ | |
162 | { 0x38000127, ULONGEST_MAX }, /* li r0,295 */ | |
163 | { 0x44000002, ULONGEST_MAX }, /* sc */ | |
164 | { 0x38000001, ULONGEST_MAX }, /* li r0,1 */ | |
165 | { 0x44000002, ULONGEST_MAX }, /* sc */ | |
166 | { TRAMP_SENTINEL_INSN, ULONGEST_MAX } | |
476be15e AC |
167 | }, |
168 | ppcnbsd_sigtramp_cache_init | |
169 | }; | |
def18405 | 170 | \f |
476be15e | 171 | |
485721b1 JT |
172 | static void |
173 | ppcnbsd_init_abi (struct gdbarch_info info, | |
174 | struct gdbarch *gdbarch) | |
175 | { | |
e754ae69 AC |
176 | /* For NetBSD, this is an on again, off again thing. Some systems |
177 | do use the broken struct convention, and some don't. */ | |
05580c65 | 178 | set_gdbarch_return_value (gdbarch, ppcnbsd_return_value); |
def18405 MK |
179 | |
180 | /* NetBSD uses SVR4-style shared libraries. */ | |
181 | set_solib_svr4_fetch_link_map_offsets | |
182 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); | |
183 | ||
23ea9aeb AA |
184 | set_gdbarch_iterate_over_regset_sections |
185 | (gdbarch, ppcnbsd_iterate_over_regset_sections); | |
def18405 | 186 | |
476be15e | 187 | tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp); |
def18405 | 188 | tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp); |
485721b1 JT |
189 | } |
190 | ||
6c265988 | 191 | void _initialize_ppcnbsd_tdep (); |
485721b1 | 192 | void |
6c265988 | 193 | _initialize_ppcnbsd_tdep () |
485721b1 | 194 | { |
1736a7bd | 195 | gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD, |
485721b1 JT |
196 | ppcnbsd_init_abi); |
197 | ||
def18405 | 198 | /* Avoid initializing the register offsets again if they were |
26c4b26f | 199 | already initialized by ppcnbsd-nat.c. */ |
def18405 MK |
200 | if (ppcnbsd_reg_offsets.pc_offset == 0) |
201 | { | |
202 | /* General-purpose registers. */ | |
203 | ppcnbsd_reg_offsets.r0_offset = 0; | |
f2db237a AM |
204 | ppcnbsd_reg_offsets.gpr_size = 4; |
205 | ppcnbsd_reg_offsets.xr_size = 4; | |
def18405 MK |
206 | ppcnbsd_reg_offsets.lr_offset = 128; |
207 | ppcnbsd_reg_offsets.cr_offset = 132; | |
208 | ppcnbsd_reg_offsets.xer_offset = 136; | |
209 | ppcnbsd_reg_offsets.ctr_offset = 140; | |
210 | ppcnbsd_reg_offsets.pc_offset = 144; | |
211 | ppcnbsd_reg_offsets.ps_offset = -1; | |
212 | ppcnbsd_reg_offsets.mq_offset = -1; | |
213 | ||
214 | /* Floating-point registers. */ | |
215 | ppcnbsd_reg_offsets.f0_offset = 0; | |
216 | ppcnbsd_reg_offsets.fpscr_offset = 256; | |
f2db237a | 217 | ppcnbsd_reg_offsets.fpscr_size = 4; |
def18405 | 218 | |
def18405 | 219 | } |
485721b1 | 220 | } |