GDB (xrefs)

/tmp/gdb-8.1/gdb/ppc-nbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for NetBSD/powerpc.
2
3 Copyright (C) 2002-2018 Free Software Foundation, Inc.
4
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
11 the Free Software Foundation; either version 3 of the License, or
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
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "gdbtypes.h"
24 #include "osabi.h"
25 #include "regcache.h"
26 #include "regset.h"
27 #include "trad-frame.h"
28 #include "tramp-frame.h"
29
30 #include "ppc-tdep.h"
31 #include "ppc-nbsd-tdep.h"
32 #include "solib-svr4.h"
33
34 /* Register offsets from <machine/reg.h>. */
35 struct ppc_reg_offsets ppcnbsd_reg_offsets;
36
37
38 /* Core file support. */
39
40 /* NetBSD/powerpc register sets. */
41
42 const struct regset ppcnbsd_gregset =
43 {
44 &ppcnbsd_reg_offsets,
45 ppc_supply_gregset
46 };
47
48 const struct regset ppcnbsd_fpregset =
49 {
50 &ppcnbsd_reg_offsets,
51 ppc_supply_fpregset
52 };
53
54 /* Iterate over core file register note sections. */
55
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)
61 {
62 cb (".reg", 148, &ppcnbsd_gregset, NULL, cb_data);
63 cb (".reg2", 264, &ppcnbsd_fpregset, NULL, cb_data);
64 }
65
66
67 /* NetBSD is confused. It appears that 1.5 was using the correct SVR4
68 convention but, 1.6 switched to the below broken convention. For
69 the moment use the broken convention. Ulgh! */
70
71 static enum return_value_convention
72 ppcnbsd_return_value (struct gdbarch *gdbarch, struct value *function,
73 struct type *valtype, struct regcache *regcache,
74 gdb_byte *readbuf, const gdb_byte *writebuf)
75 {
76 #if 0
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
87 #endif
88 return ppc_sysv_abi_broken_return_value (gdbarch, function, valtype,
89 regcache, readbuf, writebuf);
90 }
91
92
93 /* Signal trampolines. */
94
95 extern const struct tramp_frame ppcnbsd2_sigtramp;
96
97 static void
98 ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
99 struct frame_info *this_frame,
100 struct trad_frame_cache *this_cache,
101 CORE_ADDR func)
102 {
103 struct gdbarch *gdbarch = get_frame_arch (this_frame);
104 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
105 CORE_ADDR addr, base;
106 int i;
107
108 base = get_frame_register_unsigned (this_frame,
109 gdbarch_sp_regnum (gdbarch));
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)
115 {
116 int regnum = i + tdep->ppc_gp0_regnum;
117 trad_frame_set_reg_addr (this_cache, regnum, addr);
118 }
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;
127 trad_frame_set_reg_addr (this_cache, gdbarch_pc_regnum (gdbarch),
128 addr); /* SRR0? */
129 addr += tdep->wordsize;
130
131 /* Construct the frame ID using the function start. */
132 trad_frame_set_id (this_cache, frame_id_build (base, func));
133 }
134
135 static const struct tramp_frame ppcnbsd_sigtramp =
136 {
137 SIGTRAMP_FRAME,
138 4,
139 {
140 { 0x3821fff0, -1 }, /* add r1,r1,-16 */
141 { 0x4e800021, -1 }, /* blrl */
142 { 0x38610018, -1 }, /* addi r3,r1,24 */
143 { 0x38000127, -1 }, /* li r0,295 */
144 { 0x44000002, -1 }, /* sc */
145 { 0x38000001, -1 }, /* li r0,1 */
146 { 0x44000002, -1 }, /* sc */
147 { TRAMP_SENTINEL_INSN, -1 }
148 },
149 ppcnbsd_sigtramp_cache_init
150 };
151
152 /* NetBSD 2.0 introduced a slightly different signal trampoline. */
153
154 const struct tramp_frame ppcnbsd2_sigtramp =
155 {
156 SIGTRAMP_FRAME,
157 4,
158 {
159 { 0x3821fff0, -1 }, /* add r1,r1,-16 */
160 { 0x4e800021, -1 }, /* blrl */
161 { 0x38610010, -1 }, /* addi r3,r1,16 */
162 { 0x38000127, -1 }, /* li r0,295 */
163 { 0x44000002, -1 }, /* sc */
164 { 0x38000001, -1 }, /* li r0,1 */
165 { 0x44000002, -1 }, /* sc */
166 { TRAMP_SENTINEL_INSN, -1 }
167 },
168 ppcnbsd_sigtramp_cache_init
169 };
170
171
172 static void
173 ppcnbsd_init_abi (struct gdbarch_info info,
174 struct gdbarch *gdbarch)
175 {
176 /* For NetBSD, this is an on again, off again thing. Some systems
177 do use the broken struct convention, and some don't. */
178 set_gdbarch_return_value (gdbarch, ppcnbsd_return_value);
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
184 set_gdbarch_iterate_over_regset_sections
185 (gdbarch, ppcnbsd_iterate_over_regset_sections);
186
187 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp);
188 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp);
189 }
190
191 void
192 _initialize_ppcnbsd_tdep (void)
193 {
194 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD,
195 ppcnbsd_init_abi);
196
197 /* Avoid initializing the register offsets again if they were
198 already initialized by ppcnbsd-nat.c. */
199 if (ppcnbsd_reg_offsets.pc_offset == 0)
200 {
201 /* General-purpose registers. */
202 ppcnbsd_reg_offsets.r0_offset = 0;
203 ppcnbsd_reg_offsets.gpr_size = 4;
204 ppcnbsd_reg_offsets.xr_size = 4;
205 ppcnbsd_reg_offsets.lr_offset = 128;
206 ppcnbsd_reg_offsets.cr_offset = 132;
207 ppcnbsd_reg_offsets.xer_offset = 136;
208 ppcnbsd_reg_offsets.ctr_offset = 140;
209 ppcnbsd_reg_offsets.pc_offset = 144;
210 ppcnbsd_reg_offsets.ps_offset = -1;
211 ppcnbsd_reg_offsets.mq_offset = -1;
212
213 /* Floating-point registers. */
214 ppcnbsd_reg_offsets.f0_offset = 0;
215 ppcnbsd_reg_offsets.fpscr_offset = 256;
216 ppcnbsd_reg_offsets.fpscr_size = 4;
217
218 /* AltiVec registers. */
219 ppcnbsd_reg_offsets.vr0_offset = 0;
220 ppcnbsd_reg_offsets.vrsave_offset = 512;
221 ppcnbsd_reg_offsets.vscr_offset = 524;
222 }
223 }
ppc_reg_offsets::gpr_size
int gpr_size
Definition: ppc-tdep.h:89
gdbarch
Definition: gdbarch.c:127
trad_frame_set_reg_addr
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition: trad-frame.c:126
frame_id_build
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:624
ppc_sysv_abi_broken_return_value
enum return_value_convention ppc_sysv_abi_broken_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
Definition: ppc-sysv-tdep.c:1052
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
TRAMP_SENTINEL_INSN
#define TRAMP_SENTINEL_INSN
Definition: tramp-frame.h:44
ppcnbsd_iterate_over_regset_sections
static void ppcnbsd_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
Definition: ppc-nbsd-tdep.c:57
ppc_reg_offsets::vscr_offset
int vscr_offset
Definition: ppc-tdep.h:106
gdbarch_tdep::ppc_lr_regnum
int ppc_lr_regnum
Definition: ppc-tdep.h:231
ppc_reg_offsets::vrsave_offset
int vrsave_offset
Definition: ppc-tdep.h:107
func
void(* func)(char *)
Definition: remote-fileio.c:1104
iterate_over_regset_sections_cb
void() iterate_over_regset_sections_cb(const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: gdbarch.h:99
ppc_reg_offsets::xer_offset
int xer_offset
Definition: ppc-tdep.h:96
ppc_supply_fpregset
void ppc_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
Definition: rs6000-tdep.c:561
trad_frame_set_id
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition: trad-frame.c:171
RETURN_VALUE_STRUCT_CONVENTION
Definition: defs.h:258
ppc-tdep.h
gdbarch_tdep
Definition: aarch64-tdep.h:55
return_value_convention
return_value_convention
Definition: defs.h:247
SIGTRAMP_FRAME
Definition: frame.h:255
frame_info
Definition: frame.c:85
svr4_ilp32_fetch_link_map_offsets
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3183
ppc-nbsd-tdep.h
defs.h
gdbarch_tdep::ppc_cr_regnum
int ppc_cr_regnum
Definition: ppc-tdep.h:230
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
ppcnbsd2_sigtramp
const struct tramp_frame ppcnbsd2_sigtramp
Definition: ppc-nbsd-tdep.c:154
ppc_reg_offsets::fpscr_offset
int fpscr_offset
Definition: ppc-tdep.h:101
ppcnbsd_fpregset
const struct regset ppcnbsd_fpregset
Definition: ppc-nbsd-tdep.c:48
regset
Definition: regset.h:34
ppcnbsd_gregset
const struct regset ppcnbsd_gregset
Definition: ppc-nbsd-tdep.c:42
gdbarch_sp_regnum
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2146
trad-frame.h
ppc_reg_offsets::vr0_offset
int vr0_offset
Definition: ppc-tdep.h:105
ppc_reg_offsets::f0_offset
int f0_offset
Definition: ppc-tdep.h:100
solib-svr4.h
osabi.h
trad_frame_cache
Definition: trad-frame.c:27
regcache.h
gdbarch_tdep::ppc_gp0_regnum
int ppc_gp0_regnum
Definition: ppc-tdep.h:227
TYPE_VECTOR
#define TYPE_VECTOR(t)
Definition: gdbtypes.h:252
ppcnbsd_sigtramp_cache_init
static void ppcnbsd_sigtramp_cache_init(const struct tramp_frame *self, struct frame_info *this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
Definition: ppc-nbsd-tdep.c:98
TYPE_CODE_UNION
Definition: gdbtypes.h:107
set_solib_svr4_fetch_link_map_offsets
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3137
type
Definition: gdbtypes.h:749
ppc_reg_offsets
Definition: ppc-tdep.h:85
ppcnbsd_return_value
static enum return_value_convention ppcnbsd_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
Definition: ppc-nbsd-tdep.c:72
ppcnbsd_reg_offsets
struct ppc_reg_offsets ppcnbsd_reg_offsets
Definition: ppc-nbsd-tdep.c:35
ppc_reg_offsets::fpscr_size
int fpscr_size
Definition: ppc-tdep.h:102
regnum
int regnum
Definition: aarch64-tdep.c:77
get_frame_register_unsigned
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1308
gdbarch_register_osabi
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:143
TYPE_CODE_STRUCT
Definition: gdbtypes.h:106
value
Definition: value.c:169
tramp-frame.h
ppc_reg_offsets::mq_offset
int mq_offset
Definition: ppc-tdep.h:97
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
gdbarch_tdep::ppc_ctr_regnum
int ppc_ctr_regnum
Definition: ppc-tdep.h:232
ppcnbsd_sigtramp
static const struct tramp_frame ppcnbsd_sigtramp
Definition: ppc-nbsd-tdep.c:135
ppc_reg_offsets::xr_size
int xr_size
Definition: ppc-tdep.h:90
ppcnbsd_init_abi
static void ppcnbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: ppc-nbsd-tdep.c:173
TYPE_CODE
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1238
gdbarch_tdep::wordsize
int wordsize
Definition: ppc-tdep.h:216
GDB_OSABI_NETBSD
Definition: defs.h:519
tramp_frame_prepend_unwinder
void tramp_frame_prepend_unwinder(struct gdbarch *gdbarch, const struct tramp_frame *tramp_frame)
Definition: tramp-frame.c:146
gdbarch_tdep::ppc_xer_regnum
int ppc_xer_regnum
Definition: ppc-tdep.h:233
ppc_reg_offsets::r0_offset
int r0_offset
Definition: ppc-tdep.h:88
ppc_reg_offsets::pc_offset
int pc_offset
Definition: ppc-tdep.h:91
ppc_reg_offsets::ctr_offset
int ctr_offset
Definition: ppc-tdep.h:95
ppc_reg_offsets::cr_offset
int cr_offset
Definition: ppc-tdep.h:93
ppc_reg_offsets::lr_offset
int lr_offset
Definition: ppc-tdep.h:94
gdbtypes.h
ppc_reg_offsets::ps_offset
int ps_offset
Definition: ppc-tdep.h:92
regcache
Definition: regcache.h:232
gdbarch_info
Definition: gdbarch.h:1626
set_gdbarch_return_value
void set_gdbarch_return_value(struct gdbarch *gdbarch, gdbarch_return_value_ftype return_value)
Definition: gdbarch.c:2738
gdbarch_pc_regnum
int gdbarch_pc_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2163
regset.h
TYPE_LENGTH
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1235
tramp_frame
Definition: tramp-frame.h:46
set_gdbarch_iterate_over_regset_sections
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3647
_initialize_ppcnbsd_tdep
void _initialize_ppcnbsd_tdep(void)
Definition: ppc-nbsd-tdep.c:192
ppc_supply_gregset
void ppc_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
Definition: rs6000-tdep.c:511
ppc_num_gprs
Definition: ppc-tdep.h:283
get_frame_arch
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691