GDB (xrefs)

/tmp/gdb-8.1/gdb/arm-fbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for FreeBSD/arm.
2
3 Copyright (C) 2017-2018 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 3 of the License, or
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21
22 #include "elf/common.h"
23 #include "arm-tdep.h"
24 #include "arm-fbsd-tdep.h"
25 #include "auxv.h"
26 #include "fbsd-tdep.h"
27 #include "gdbcore.h"
28 #include "osabi.h"
29 #include "solib-svr4.h"
30 #include "trad-frame.h"
31 #include "tramp-frame.h"
32
33 /* In a signal frame, sp points to a 'struct sigframe' which is
34 defined as:
35
36 struct sigframe {
37 siginfo_t sf_si;
38 ucontext_t sf_uc;
39 mcontext_vfp_t sf_vfp;
40 };
41
42 ucontext_t is defined as:
43
44 struct __ucontext {
45 sigset_t uc_sigmask;
46 mcontext_t uc_mcontext;
47 ...
48 };
49
50 mcontext_t is defined as:
51
52 struct {
53 unsigned int __gregs[17];
54 size_t mc_vfp_size;
55 void *mc_vfp_ptr;
56 ...
57 };
58
59 mcontext_vfp_t is defined as:
60
61 struct {
62 uint64_t mcv_reg[32];
63 uint32_t mcv_fpscr;
64 };
65
66 If the VFP state is valid, then mc_vfp_ptr will point to sf_vfp in
67 the sigframe, otherwise it is NULL. There is no non-VFP floating
68 point register state saved in the signal frame. */
69
70 #define ARM_MCONTEXT_REG_SIZE 4
71 #define ARM_MCONTEXT_VFP_REG_SIZE 8
72 #define ARM_SIGFRAME_UCONTEXT_OFFSET 64
73 #define ARM_UCONTEXT_MCONTEXT_OFFSET 16
74 #define ARM_MCONTEXT_VFP_PTR_OFFSET 72
75
76 /* Implement the "init" method of struct tramp_frame. */
77
78 static void
79 arm_fbsd_sigframe_init (const struct tramp_frame *self,
80 struct frame_info *this_frame,
81 struct trad_frame_cache *this_cache,
82 CORE_ADDR func)
83 {
84 struct gdbarch *gdbarch = get_frame_arch (this_frame);
85 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
86 CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
87 CORE_ADDR mcontext_addr = (sp
88 + ARM_SIGFRAME_UCONTEXT_OFFSET
89 + ARM_UCONTEXT_MCONTEXT_OFFSET);
90 ULONGEST mcontext_vfp_addr;
91
92 for (int i = 0; i < 16; i++)
93 {
94 trad_frame_set_reg_addr (this_cache,
95 ARM_A1_REGNUM + i,
96 mcontext_addr + i * ARM_MCONTEXT_REG_SIZE);
97 }
98 trad_frame_set_reg_addr (this_cache, ARM_PS_REGNUM,
99 mcontext_addr + 16 * ARM_MCONTEXT_REG_SIZE);
100
101 if (safe_read_memory_unsigned_integer (mcontext_addr
102 + ARM_MCONTEXT_VFP_PTR_OFFSET, 4,
103 byte_order,
104 &mcontext_vfp_addr)
105 && mcontext_vfp_addr != 0)
106 {
107 for (int i = 0; i < 32; i++)
108 {
109 trad_frame_set_reg_addr (this_cache, ARM_D0_REGNUM + i,
110 mcontext_vfp_addr
111 + i * ARM_MCONTEXT_VFP_REG_SIZE);
112 }
113 trad_frame_set_reg_addr (this_cache, ARM_FPSCR_REGNUM,
114 mcontext_vfp_addr
115 + 32 * ARM_MCONTEXT_VFP_REG_SIZE);
116 }
117
118 trad_frame_set_id (this_cache, frame_id_build (sp, func));
119 }
120
121 static const struct tramp_frame arm_fbsd_sigframe =
122 {
123 SIGTRAMP_FRAME,
124 4,
125 {
126 {0xe1a0000d, -1}, /* mov r0, sp */
127 {0xe2800040, -1}, /* add r0, r0, #SIGF_UC */
128 {0xe59f700c, -1}, /* ldr r7, [pc, #12] */
129 {0xef0001a1, -1}, /* swi SYS_sigreturn */
130 {TRAMP_SENTINEL_INSN, -1}
131 },
132 arm_fbsd_sigframe_init
133 };
134
135 /* Register maps. */
136
137 static const struct regcache_map_entry arm_fbsd_gregmap[] =
138 {
139 { 13, ARM_A1_REGNUM, 4 }, /* r0 ... r12 */
140 { 1, ARM_SP_REGNUM, 4 },
141 { 1, ARM_LR_REGNUM, 4 },
142 { 1, ARM_PC_REGNUM, 4 },
143 { 1, ARM_PS_REGNUM, 4 },
144 { 0 }
145 };
146
147 static const struct regcache_map_entry arm_fbsd_vfpregmap[] =
148 {
149 { 32, ARM_D0_REGNUM, 8 }, /* d0 ... d31 */
150 { 1, ARM_FPSCR_REGNUM, 4 },
151 { 0 }
152 };
153
154 /* Register set definitions. */
155
156 const struct regset arm_fbsd_gregset =
157 {
158 arm_fbsd_gregmap,
159 regcache_supply_regset, regcache_collect_regset
160 };
161
162 const struct regset arm_fbsd_vfpregset =
163 {
164 arm_fbsd_vfpregmap,
165 regcache_supply_regset, regcache_collect_regset
166 };
167
168 /* Implement the "regset_from_core_section" gdbarch method. */
169
170 static void
171 arm_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
172 iterate_over_regset_sections_cb *cb,
173 void *cb_data,
174 const struct regcache *regcache)
175 {
176 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
177
178 cb (".reg", ARM_FBSD_SIZEOF_GREGSET, &arm_fbsd_gregset, NULL, cb_data);
179
180 /* While FreeBSD/arm cores do contain a NT_FPREGSET / ".reg2"
181 register set, it is not populated with register values by the
182 kernel but just contains all zeroes. */
183 if (tdep->vfp_register_count > 0)
184 cb (".reg-arm-vfp", ARM_FBSD_SIZEOF_VFPREGSET, &arm_fbsd_vfpregset,
185 "VFP floating-point", cb_data);
186 }
187
188 /* Lookup a target description from a target's AT_HWCAP auxiliary
189 vector. */
190
191 const struct target_desc *
192 arm_fbsd_read_description_auxv (struct target_ops *target)
193 {
194 CORE_ADDR arm_hwcap = 0;
195
196 if (target_auxv_search (target, AT_FREEBSD_HWCAP, &arm_hwcap) != 1)
197 return NULL;
198
199 if (arm_hwcap & HWCAP_VFP)
200 {
201 if (arm_hwcap & HWCAP_NEON)
202 return tdesc_arm_with_neon;
203 else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPD32))
204 == (HWCAP_VFPv3 | HWCAP_VFPD32))
205 return tdesc_arm_with_vfpv3;
206 else
207 return tdesc_arm_with_vfpv2;
208 }
209
210 return NULL;
211 }
212
213 /* Implement the "core_read_description" gdbarch method. */
214
215 static const struct target_desc *
216 arm_fbsd_core_read_description (struct gdbarch *gdbarch,
217 struct target_ops *target,
218 bfd *abfd)
219 {
220 return arm_fbsd_read_description_auxv (target);
221 }
222
223 /* Implement the 'init_osabi' method of struct gdb_osabi_handler. */
224
225 static void
226 arm_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
227 {
228 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
229
230 /* Generic FreeBSD support. */
231 fbsd_init_abi (info, gdbarch);
232
233 if (tdep->fp_model == ARM_FLOAT_AUTO)
234 tdep->fp_model = ARM_FLOAT_SOFT_VFP;
235
236 tramp_frame_prepend_unwinder (gdbarch, &arm_fbsd_sigframe);
237
238 set_solib_svr4_fetch_link_map_offsets
239 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
240
241 tdep->jb_pc = 24;
242 tdep->jb_elt_size = 4;
243
244 set_gdbarch_iterate_over_regset_sections
245 (gdbarch, arm_fbsd_iterate_over_regset_sections);
246 set_gdbarch_core_read_description (gdbarch, arm_fbsd_core_read_description);
247
248 /* Single stepping. */
249 set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
250 }
251
252 void
253 _initialize_arm_fbsd_tdep (void)
254 {
255 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_FREEBSD,
256 arm_fbsd_init_abi);
257 }
gdbarch
Definition: gdbarch.c:127
fbsd-tdep.h
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
arm-fbsd-tdep.h
frame_id_build
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:624
arm_fbsd_gregmap
static const struct regcache_map_entry arm_fbsd_gregmap[]
Definition: arm-fbsd-tdep.c:137
arm_fbsd_vfpregmap
static const struct regcache_map_entry arm_fbsd_vfpregmap[]
Definition: arm-fbsd-tdep.c:147
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
ARM_D0_REGNUM
Definition: arm.h:46
TRAMP_SENTINEL_INSN
#define TRAMP_SENTINEL_INSN
Definition: tramp-frame.h:44
safe_read_memory_unsigned_integer
int safe_read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order, ULONGEST *return_value)
Definition: corefile.c:302
arm_fbsd_core_read_description
static const struct target_desc * arm_fbsd_core_read_description(struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd)
Definition: arm-fbsd-tdep.c:216
func
void(* func)(char *)
Definition: remote-fileio.c:1104
tdesc_arm_with_vfpv2
struct target_desc * tdesc_arm_with_vfpv2
Definition: arm-with-vfpv2.c:8
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
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
gdbarch_tdep::fp_model
enum arm_float_model fp_model
Definition: arm-tdep.h:101
HWCAP_VFPD32
#define HWCAP_VFPD32
Definition: arm-fbsd-tdep.h:37
gdbarch_tdep
Definition: aarch64-tdep.h:55
regcache_supply_regset
void regcache_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition: regcache.c:1192
tdesc_arm_with_neon
struct target_desc * tdesc_arm_with_neon
Definition: arm-with-neon.c:8
auxv.h
SIGTRAMP_FRAME
Definition: frame.h:255
frame_info
Definition: frame.c:85
ARM_MCONTEXT_REG_SIZE
#define ARM_MCONTEXT_REG_SIZE
Definition: arm-fbsd-tdep.c:70
svr4_ilp32_fetch_link_map_offsets
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3183
ARM_UCONTEXT_MCONTEXT_OFFSET
#define ARM_UCONTEXT_MCONTEXT_OFFSET
Definition: arm-fbsd-tdep.c:73
arm_fbsd_sigframe_init
static void arm_fbsd_sigframe_init(const struct tramp_frame *self, struct frame_info *this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
Definition: arm-fbsd-tdep.c:79
ARM_FBSD_SIZEOF_VFPREGSET
#define ARM_FBSD_SIZEOF_VFPREGSET
Definition: arm-fbsd-tdep.h:28
defs.h
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
regset
Definition: regset.h:34
arm_fbsd_sigframe
static const struct tramp_frame arm_fbsd_sigframe
Definition: arm-fbsd-tdep.c:121
GDB_OSABI_FREEBSD
Definition: defs.h:518
arm_fbsd_gregset
const struct regset arm_fbsd_gregset
Definition: arm-fbsd-tdep.c:156
arm-tdep.h
trad-frame.h
target_ops
Definition: target.h:412
arm_fbsd_read_description_auxv
const struct target_desc * arm_fbsd_read_description_auxv(struct target_ops *target)
Definition: arm-fbsd-tdep.c:192
solib-svr4.h
osabi.h
trad_frame_cache
Definition: trad-frame.c:27
target_auxv_search
int target_auxv_search(struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
Definition: auxv.c:375
gdbarch_byte_order
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
gdbarch_tdep::jb_pc
int jb_pc
Definition: aarch64-tdep.h:62
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
regcache_collect_regset
void regcache_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *buf, size_t size)
Definition: regcache.c:1211
fbsd_init_abi
void fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: fbsd-tdep.c:516
ARM_MCONTEXT_VFP_REG_SIZE
#define ARM_MCONTEXT_VFP_REG_SIZE
Definition: arm-fbsd-tdep.c:71
ARM_FLOAT_SOFT_VFP
Definition: arm-tdep.h:72
arm_fbsd_init_abi
static void arm_fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: arm-fbsd-tdep.c:226
HWCAP_NEON
#define HWCAP_NEON
Definition: arm-fbsd-tdep.h:35
ARM_A1_REGNUM
Definition: arm.h:25
ARM_FPSCR_REGNUM
Definition: arm.h:48
ARM_LR_REGNUM
Definition: arm.h:30
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
gdbarch_tdep::jb_elt_size
size_t jb_elt_size
Definition: aarch64-tdep.h:65
_initialize_arm_fbsd_tdep
void _initialize_arm_fbsd_tdep(void)
Definition: arm-fbsd-tdep.c:253
arm_fbsd_iterate_over_regset_sections
static void arm_fbsd_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
Definition: arm-fbsd-tdep.c:171
tramp-frame.h
set_gdbarch_software_single_step
void set_gdbarch_software_single_step(struct gdbarch *gdbarch, gdbarch_software_single_step_ftype software_single_step)
Definition: gdbarch.c:3258
gdbcore.h
ARM_FLOAT_AUTO
Definition: arm-tdep.h:69
target_desc
Definition: target-descriptions.c:591
ARM_MCONTEXT_VFP_PTR_OFFSET
#define ARM_MCONTEXT_VFP_PTR_OFFSET
Definition: arm-fbsd-tdep.c:74
ARM_PS_REGNUM
Definition: arm.h:36
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::vfp_register_count
int vfp_register_count
Definition: arm-tdep.h:107
ARM_SP_REGNUM
Definition: arm.h:29
ULONGEST
unsigned long long ULONGEST
Definition: common-types.h:53
regcache
Definition: regcache.h:232
gdbarch_info
Definition: gdbarch.h:1626
arm_software_single_step
std::vector< CORE_ADDR > arm_software_single_step(struct regcache *regcache)
Definition: arm-tdep.c:6251
HWCAP_VFP
#define HWCAP_VFP
Definition: arm-fbsd-tdep.h:34
tramp_frame
Definition: tramp-frame.h:46
arm_fbsd_vfpregset
const struct regset arm_fbsd_vfpregset
Definition: arm-fbsd-tdep.c:162
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
HWCAP_VFPv3
#define HWCAP_VFPv3
Definition: arm-fbsd-tdep.h:36
gdbarch::byte_order
enum bfd_endian byte_order
Definition: gdbarch.c:137
ARM_PC_REGNUM
Definition: arm.h:31
tdesc_arm_with_vfpv3
struct target_desc * tdesc_arm_with_vfpv3
Definition: arm-with-vfpv3.c:8
set_gdbarch_core_read_description
void set_gdbarch_core_read_description(struct gdbarch *gdbarch, gdbarch_core_read_description_ftype core_read_description)
Definition: gdbarch.c:4072
get_frame_arch
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
regcache_map_entry
Definition: regcache.h:157
ARM_SIGFRAME_UCONTEXT_OFFSET
#define ARM_SIGFRAME_UCONTEXT_OFFSET
Definition: arm-fbsd-tdep.c:72
ARM_FBSD_SIZEOF_GREGSET
#define ARM_FBSD_SIZEOF_GREGSET
Definition: arm-fbsd-tdep.h:24