GDB (xrefs)
Loading...
Searching...
No Matches
arm-netbsd-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for NetBSD/arm.
2
3 Copyright (C) 2002-2023 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#include "osabi.h"
22
23#include "arch/arm.h"
24#include "arm-netbsd-tdep.h"
25#include "netbsd-tdep.h"
26#include "arm-tdep.h"
27#include "regset.h"
28#include "solib-svr4.h"
29
30/* Description of the longjmp buffer. */
31#define ARM_NBSD_JB_PC 24
32#define ARM_NBSD_JB_ELEMENT_SIZE ARM_INT_REGISTER_SIZE
33
34/* For compatibility with previous implementations of GDB on arm/NetBSD,
35 override the default little-endian breakpoint. */
36static const gdb_byte arm_nbsd_arm_le_breakpoint[] = {0x11, 0x00, 0x00, 0xe6};
37static const gdb_byte arm_nbsd_arm_be_breakpoint[] = {0xe6, 0x00, 0x00, 0x11};
38static const gdb_byte arm_nbsd_thumb_le_breakpoint[] = {0xfe, 0xde};
39static const gdb_byte arm_nbsd_thumb_be_breakpoint[] = {0xde, 0xfe};
40
41/* This matches struct reg from NetBSD's sys/arch/arm/include/reg.h:
42 https://github.com/NetBSD/src/blob/7c13e6e6773bb171f4ed3ed53013e9d24b3c1eac/sys/arch/arm/include/reg.h#L39
43 */
45{
46 uint32_t reg[13];
47 uint32_t sp;
48 uint32_t lr;
49 uint32_t pc;
50 uint32_t cpsr;
51};
52
53void
55 int regnum, const void *gregs, size_t len)
56{
57 const arm_nbsd_reg *gregset = static_cast<const arm_nbsd_reg *>(gregs);
58 gdb_assert (len >= sizeof (arm_nbsd_reg));
59
60 /* Integer registers. */
61 for (int i = ARM_A1_REGNUM; i < ARM_SP_REGNUM; i++)
62 if (regnum == -1 || regnum == i)
63 regcache->raw_supply (i, (char *) &gregset->reg[i]);
64
65 if (regnum == -1 || regnum == ARM_SP_REGNUM)
66 regcache->raw_supply (ARM_SP_REGNUM, (char *) &gregset->sp);
67
68 if (regnum == -1 || regnum == ARM_LR_REGNUM)
69 regcache->raw_supply (ARM_LR_REGNUM, (char *) &gregset->lr);
70
71 if (regnum == -1 || regnum == ARM_PC_REGNUM)
72 {
73 CORE_ADDR r_pc = gdbarch_addr_bits_remove (regcache->arch (), gregset->pc);
74 regcache->raw_supply (ARM_PC_REGNUM, (char *) &r_pc);
75 }
76
77 if (regnum == -1 || regnum == ARM_PS_REGNUM)
78 {
79 if (arm_apcs_32)
80 regcache->raw_supply (ARM_PS_REGNUM, (char *) &gregset->cpsr);
81 else
82 regcache->raw_supply (ARM_PS_REGNUM, (char *) &gregset->pc);
83 }
84}
85
86static const struct regset arm_nbsd_regset = {
87 nullptr,
89 /* We don't need a collect function because we only use this reading registers
90 (via iterate_over_regset_sections and fetch_regs/fetch_register). */
91 nullptr,
92 0
93};
94
95static void
98 void *cb_data,
99 const struct regcache *regcache)
100{
101 cb (".reg", sizeof (arm_nbsd_reg), sizeof (arm_nbsd_reg), &arm_nbsd_regset,
102 NULL, cb_data);
103 /* cbiesinger/2020-02-12 -- as far as I can tell, ARM/NetBSD does
104 not write any floating point registers into the core file (tested
105 with NetBSD 9.1_RC1). When it does, this function will need to read them,
106 and the arm-netbsd gdbarch will need a core_read_description function
107 to return the right description for them. */
108}
109
110static void
112 struct gdbarch *gdbarch)
113{
114 arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
115
116 tdep->lowest_pc = 0x8000;
117 switch (info.byte_order)
118 {
119 case BFD_ENDIAN_LITTLE:
124 break;
125
126 case BFD_ENDIAN_BIG:
131 break;
132
133 default:
134 internal_error (_("arm_gdbarch_init: bad byte order for float format"));
135 }
136
137 tdep->jb_pc = ARM_NBSD_JB_PC;
139
142 /* Single stepping. */
144}
145
146static void
148 struct gdbarch *gdbarch)
149{
150 arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
151
153
154 nbsd_init_abi (info, gdbarch);
155
156 if (tdep->fp_model == ARM_FLOAT_AUTO)
157 tdep->fp_model = ARM_FLOAT_SOFT_VFP;
158
159 /* NetBSD ELF uses SVR4-style shared libraries. */
162}
163
165void
int regnum
static const gdb_byte arm_nbsd_thumb_le_breakpoint[]
static void arm_netbsd_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch)
#define ARM_NBSD_JB_ELEMENT_SIZE
static const gdb_byte arm_nbsd_arm_be_breakpoint[]
void arm_nbsd_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
static void arm_nbsd_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
static const gdb_byte arm_nbsd_arm_le_breakpoint[]
static const struct regset arm_nbsd_regset
#define ARM_NBSD_JB_PC
static const gdb_byte arm_nbsd_thumb_be_breakpoint[]
void _initialize_arm_netbsd_tdep()
static void arm_netbsd_elf_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
bool arm_apcs_32
Definition arm-tdep.c:598
std::vector< CORE_ADDR > arm_software_single_step(struct regcache *regcache)
Definition arm-tdep.c:7283
@ ARM_FLOAT_AUTO
Definition arm-tdep.h:64
@ ARM_FLOAT_SOFT_VFP
Definition arm-tdep.h:67
@ ARM_PC_REGNUM
Definition arm.h:46
@ ARM_LR_REGNUM
Definition arm.h:45
@ ARM_PS_REGNUM
Definition arm.h:52
@ ARM_A1_REGNUM
Definition arm.h:40
@ ARM_SP_REGNUM
Definition arm.h:44
gdbarch * arch() const
Definition regcache.c:231
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
void set_gdbarch_software_single_step(struct gdbarch *gdbarch, gdbarch_software_single_step_ftype *software_single_step)
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition gdbarch.c:3152
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections)
void iterate_over_regset_sections_cb(const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data)
Definition gdbarch.h:104
void nbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
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:146
@ GDB_OSABI_NETBSD
Definition osabi.h:34
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
const gdb_byte * thumb_breakpoint
Definition arm-tdep.h:146
size_t jb_elt_size
Definition arm-tdep.h:159
const gdb_byte * arm_breakpoint
Definition arm-tdep.h:144
int arm_breakpoint_size
Definition arm-tdep.h:145
CORE_ADDR lowest_pc
Definition arm-tdep.h:141
int thumb_breakpoint_size
Definition arm-tdep.h:147
uint32_t reg[13]