GDB (xrefs)

/tmp/gdb-8.1/gdb/aarch64-fbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for FreeBSD/aarch64.
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 "gdbarch.h"
23 #include "fbsd-tdep.h"
24 #include "aarch64-tdep.h"
25 #include "aarch64-fbsd-tdep.h"
26 #include "osabi.h"
27 #include "solib-svr4.h"
28 #include "target.h"
29 #include "tramp-frame.h"
30 #include "trad-frame.h"
31
32 /* In a signal frame, sp points to a 'struct sigframe' which is
33 defined as:
34
35 struct sigframe {
36 siginfo_t sf_si;
37 ucontext_t sf_uc;
38 };
39
40 ucontext_t is defined as:
41
42 struct __ucontext {
43 sigset_t uc_sigmask;
44 mcontext_t uc_mcontext;
45 ...
46 };
47
48 The mcontext_t contains the general purpose register set followed
49 by the floating point register set. The floating point register
50 set is only valid if the _MC_FP_VALID flag is set in mc_flags. */
51
52 #define AARCH64_MCONTEXT_REG_SIZE 8
53 #define AARCH64_MCONTEXT_FPREG_SIZE 16
54 #define AARCH64_SIGFRAME_UCONTEXT_OFFSET 80
55 #define AARCH64_UCONTEXT_MCONTEXT_OFFSET 16
56 #define AARCH64_MCONTEXT_FPREGS_OFFSET 272
57 #define AARCH64_MCONTEXT_FLAGS_OFFSET 800
58 #define AARCH64_MCONTEXT_FLAG_FP_VALID 0x1
59
60 /* Implement the "init" method of struct tramp_frame. */
61
62 static void
63 aarch64_fbsd_sigframe_init (const struct tramp_frame *self,
64 struct frame_info *this_frame,
65 struct trad_frame_cache *this_cache,
66 CORE_ADDR func)
67 {
68 struct gdbarch *gdbarch = get_frame_arch (this_frame);
69 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
70 CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
71 CORE_ADDR mcontext_addr =
72 sp
73 + AARCH64_SIGFRAME_UCONTEXT_OFFSET
74 + AARCH64_UCONTEXT_MCONTEXT_OFFSET;
75 gdb_byte buf[4];
76 int i;
77
78 for (i = 0; i < 30; i++)
79 {
80 trad_frame_set_reg_addr (this_cache,
81 AARCH64_X0_REGNUM + i,
82 mcontext_addr + i * AARCH64_MCONTEXT_REG_SIZE);
83 }
84 trad_frame_set_reg_addr (this_cache, AARCH64_LR_REGNUM,
85 mcontext_addr + 30 * AARCH64_MCONTEXT_REG_SIZE);
86 trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM,
87 mcontext_addr + 31 * AARCH64_MCONTEXT_REG_SIZE);
88 trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM,
89 mcontext_addr + 32 * AARCH64_MCONTEXT_REG_SIZE);
90 trad_frame_set_reg_addr (this_cache, AARCH64_CPSR_REGNUM,
91 mcontext_addr + 33 * AARCH64_MCONTEXT_REG_SIZE);
92
93 if (target_read_memory (mcontext_addr + AARCH64_MCONTEXT_FLAGS_OFFSET, buf,
94 4) == 0
95 && (extract_unsigned_integer (buf, 4, byte_order)
96 & AARCH64_MCONTEXT_FLAG_FP_VALID))
97 {
98 for (i = 0; i < 32; i++)
99 {
100 trad_frame_set_reg_addr (this_cache, AARCH64_V0_REGNUM + i,
101 mcontext_addr
102 + AARCH64_MCONTEXT_FPREGS_OFFSET
103 + i * AARCH64_MCONTEXT_FPREG_SIZE);
104 }
105 trad_frame_set_reg_addr (this_cache, AARCH64_FPSR_REGNUM,
106 mcontext_addr + AARCH64_MCONTEXT_FPREGS_OFFSET
107 + 32 * AARCH64_MCONTEXT_FPREG_SIZE);
108 trad_frame_set_reg_addr (this_cache, AARCH64_FPCR_REGNUM,
109 mcontext_addr + AARCH64_MCONTEXT_FPREGS_OFFSET
110 + 32 * AARCH64_MCONTEXT_FPREG_SIZE + 4);
111 }
112
113 trad_frame_set_id (this_cache, frame_id_build (sp, func));
114 }
115
116 static const struct tramp_frame aarch64_fbsd_sigframe =
117 {
118 SIGTRAMP_FRAME,
119 4,
120 {
121 {0x910003e0, -1}, /* mov x0, sp */
122 {0x91014000, -1}, /* add x0, x0, #SF_UC */
123 {0xd2803428, -1}, /* mov x8, #SYS_sigreturn */
124 {0xd4000001, -1}, /* svc 0x0 */
125 {TRAMP_SENTINEL_INSN, -1}
126 },
127 aarch64_fbsd_sigframe_init
128 };
129
130 /* Register maps. */
131
132 static const struct regcache_map_entry aarch64_fbsd_gregmap[] =
133 {
134 { 30, AARCH64_X0_REGNUM, 8 }, /* x0 ... x29 */
135 { 1, AARCH64_LR_REGNUM, 8 },
136 { 1, AARCH64_SP_REGNUM, 8 },
137 { 1, AARCH64_PC_REGNUM, 8 },
138 { 1, AARCH64_CPSR_REGNUM, 4 },
139 { 0 }
140 };
141
142 static const struct regcache_map_entry aarch64_fbsd_fpregmap[] =
143 {
144 { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */
145 { 1, AARCH64_FPSR_REGNUM, 4 },
146 { 1, AARCH64_FPCR_REGNUM, 4 },
147 { 0 }
148 };
149
150 /* Register set definitions. */
151
152 const struct regset aarch64_fbsd_gregset =
153 {
154 aarch64_fbsd_gregmap,
155 regcache_supply_regset, regcache_collect_regset
156 };
157
158 const struct regset aarch64_fbsd_fpregset =
159 {
160 aarch64_fbsd_fpregmap,
161 regcache_supply_regset, regcache_collect_regset
162 };
163
164 /* Implement the "regset_from_core_section" gdbarch method. */
165
166 static void
167 aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
168 iterate_over_regset_sections_cb *cb,
169 void *cb_data,
170 const struct regcache *regcache)
171 {
172 cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, &aarch64_fbsd_gregset,
173 NULL, cb_data);
174 cb (".reg2", AARCH64_FBSD_SIZEOF_FPREGSET, &aarch64_fbsd_fpregset,
175 NULL, cb_data);
176 }
177
178 /* Implement the 'init_osabi' method of struct gdb_osabi_handler. */
179
180 static void
181 aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
182 {
183 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
184
185 /* Generic FreeBSD support. */
186 fbsd_init_abi (info, gdbarch);
187
188 set_solib_svr4_fetch_link_map_offsets (gdbarch,
189 svr4_lp64_fetch_link_map_offsets);
190
191 tramp_frame_prepend_unwinder (gdbarch, &aarch64_fbsd_sigframe);
192
193 /* Enable longjmp. */
194 tdep->jb_pc = 13;
195
196 set_gdbarch_iterate_over_regset_sections
197 (gdbarch, aarch64_fbsd_iterate_over_regset_sections);
198 }
199
200 void
201 _initialize_aarch64_fbsd_tdep (void)
202 {
203 gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_FREEBSD,
204 aarch64_fbsd_init_abi);
205 }
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
frame_id_build
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:624
AARCH64_FPSR_REGNUM
Definition: aarch64.h:38
aarch64_fbsd_sigframe
static const struct tramp_frame aarch64_fbsd_sigframe
Definition: aarch64-fbsd-tdep.c:116
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
TRAMP_SENTINEL_INSN
#define TRAMP_SENTINEL_INSN
Definition: tramp-frame.h:44
svr4_lp64_fetch_link_map_offsets
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3214
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
AARCH64_FPCR_REGNUM
Definition: aarch64.h:39
AARCH64_FBSD_SIZEOF_FPREGSET
#define AARCH64_FBSD_SIZEOF_FPREGSET
Definition: aarch64-fbsd-tdep.h:30
AARCH64_CPSR_REGNUM
Definition: aarch64.h:35
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
aarch64_fbsd_gregmap
static const struct regcache_map_entry aarch64_fbsd_gregmap[]
Definition: aarch64-fbsd-tdep.c:132
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
SIGTRAMP_FRAME
Definition: frame.h:255
aarch64_fbsd_init_abi
static void aarch64_fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: aarch64-fbsd-tdep.c:181
frame_info
Definition: frame.c:85
AARCH64_SP_REGNUM
Definition: aarch64.h:33
aarch64_fbsd_fpregmap
static const struct regcache_map_entry aarch64_fbsd_fpregmap[]
Definition: aarch64-fbsd-tdep.c:142
_initialize_aarch64_fbsd_tdep
void _initialize_aarch64_fbsd_tdep(void)
Definition: aarch64-fbsd-tdep.c:201
defs.h
aarch64-tdep.h
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
AARCH64_MCONTEXT_FPREGS_OFFSET
#define AARCH64_MCONTEXT_FPREGS_OFFSET
Definition: aarch64-fbsd-tdep.c:56
regset
Definition: regset.h:34
GDB_OSABI_FREEBSD
Definition: defs.h:518
AARCH64_PC_REGNUM
Definition: aarch64.h:34
trad-frame.h
solib-svr4.h
extract_unsigned_integer
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:577
osabi.h
AARCH64_MCONTEXT_FPREG_SIZE
#define AARCH64_MCONTEXT_FPREG_SIZE
Definition: aarch64-fbsd-tdep.c:53
trad_frame_cache
Definition: trad-frame.c:27
gdbarch.h
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
AARCH64_SIGFRAME_UCONTEXT_OFFSET
#define AARCH64_SIGFRAME_UCONTEXT_OFFSET
Definition: aarch64-fbsd-tdep.c:54
get_frame_register_unsigned
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1308
AARCH64_MCONTEXT_REG_SIZE
#define AARCH64_MCONTEXT_REG_SIZE
Definition: aarch64-fbsd-tdep.c:52
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
aarch64_fbsd_fpregset
const struct regset aarch64_fbsd_fpregset
Definition: aarch64-fbsd-tdep.c:158
aarch64_fbsd_sigframe_init
static void aarch64_fbsd_sigframe_init(const struct tramp_frame *self, struct frame_info *this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
Definition: aarch64-fbsd-tdep.c:63
tramp-frame.h
aarch64_fbsd_gregset
const struct regset aarch64_fbsd_gregset
Definition: aarch64-fbsd-tdep.c:152
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
AARCH64_FBSD_SIZEOF_GREGSET
#define AARCH64_FBSD_SIZEOF_GREGSET
Definition: aarch64-fbsd-tdep.h:25
target_read_memory
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1370
AARCH64_V0_REGNUM
Definition: aarch64.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
target.h
aarch64_fbsd_iterate_over_regset_sections
static void aarch64_fbsd_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
Definition: aarch64-fbsd-tdep.c:167
AARCH64_MCONTEXT_FLAG_FP_VALID
#define AARCH64_MCONTEXT_FLAG_FP_VALID
Definition: aarch64-fbsd-tdep.c:58
AARCH64_LR_REGNUM
Definition: aarch64.h:32
regcache
Definition: regcache.h:232
gdbarch_info
Definition: gdbarch.h:1626
AARCH64_MCONTEXT_FLAGS_OFFSET
#define AARCH64_MCONTEXT_FLAGS_OFFSET
Definition: aarch64-fbsd-tdep.c:57
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
gdbarch::byte_order
enum bfd_endian byte_order
Definition: gdbarch.c:137
aarch64-fbsd-tdep.h
get_frame_arch
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
AARCH64_X0_REGNUM
Definition: aarch64.h:30
regcache_map_entry
Definition: regcache.h:157
AARCH64_UCONTEXT_MCONTEXT_OFFSET
#define AARCH64_UCONTEXT_MCONTEXT_OFFSET
Definition: aarch64-fbsd-tdep.c:55