gdb: remove interp_pre_command_loop
[binutils-gdb.git] / gdb / or1k-linux-tdep.c
1 /* Target-dependent code for GNU/Linux on OpenRISC processors.
2 Copyright (C) 2018-2023 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #include "defs.h"
20 #include "or1k-tdep.h"
21 #include "osabi.h"
22 #include "glibc-tdep.h"
23 #include "linux-tdep.h"
24 #include "solib-svr4.h"
25 #include "regset.h"
26 #include "tramp-frame.h"
27 #include "trad-frame.h"
28 #include "gdbarch.h"
29
30 #include "features/or1k-linux.c"
31
32 /* Define the general register mapping. The kernel and GDB put registers
33 r1 to r31 in the same place. The NPC register is stored at index 32 in
34 linux and 33 in GDB, in GDB 32 is for PPC which is not populated from linux.
35 Register r0 is always 0 and can be ignored. */
36
37 static const struct regcache_map_entry or1k_linux_gregmap[] =
38 {
39 { 32, OR1K_ZERO_REGNUM, 4 }, /* r0 to r31 */
40 { 1, OR1K_NPC_REGNUM, 4 },
41 { 0 }
42 };
43
44 /* Define the general register regset. */
45
46 static const struct regset or1k_linux_gregset =
47 {
48 or1k_linux_gregmap, regcache_supply_regset, regcache_collect_regset
49 };
50
51 /* Define hook for core file support. */
52
53 static void
54 or1k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
55 iterate_over_regset_sections_cb *cb,
56 void *cb_data,
57 const struct regcache *regcache)
58 {
59 cb (".reg", (33 * 4), (33 * 4), &or1k_linux_gregset, NULL, cb_data);
60 }
61
62 /* Signal trampoline support. */
63
64 static void or1k_linux_sigframe_init (const struct tramp_frame *self,
65 frame_info_ptr this_frame,
66 struct trad_frame_cache *this_cache,
67 CORE_ADDR func);
68
69 #define OR1K_RT_SIGRETURN 139
70
71 #define OR1K_INST_L_ORI_R11_R0_IMM 0xa9600000
72 #define OR1K_INST_L_SYS_1 0x20000001
73 #define OR1K_INST_L_NOP 0x15000000
74
75 static const struct tramp_frame or1k_linux_sigframe = {
76 SIGTRAMP_FRAME,
77 4,
78 {
79 { OR1K_INST_L_ORI_R11_R0_IMM | OR1K_RT_SIGRETURN, ULONGEST_MAX },
80 { OR1K_INST_L_SYS_1, ULONGEST_MAX },
81 { OR1K_INST_L_NOP, ULONGEST_MAX },
82 { TRAMP_SENTINEL_INSN }
83 },
84 or1k_linux_sigframe_init,
85 NULL
86 };
87
88 /* Runtime signal frames look like this:
89 struct rt_sigframe {
90 struct siginfo info;
91 struct ucontext uc;
92 unsigned char retcode[16];
93 };
94
95 struct ucontext {
96 unsigned long uc_flags; - 4
97 struct ucontext *uc_link; - 4
98 stack_t uc_stack; - 4 * 3
99 struct sigcontext uc_mcontext;
100 sigset_t uc_sigmask;
101 };
102
103 struct sigcontext {
104 struct user_regs_struct regs;
105 unsigned long oldmask;
106 };
107
108 struct user_regs_struct {
109 unsigned long gpr[32];
110 unsigned long pc;
111 unsigned long sr;
112 }; */
113
114 #define SIGFRAME_SIGINFO_SIZE 128
115 #define UCONTEXT_MCONTEXT_OFFSET 20
116
117 static void
118 or1k_linux_sigframe_init (const struct tramp_frame *self,
119 frame_info_ptr this_frame,
120 struct trad_frame_cache *this_cache,
121 CORE_ADDR func)
122 {
123 CORE_ADDR frame_sp = get_frame_sp (this_frame);
124 CORE_ADDR mcontext_base;
125 CORE_ADDR regs_base;
126
127 mcontext_base = frame_sp + SIGFRAME_SIGINFO_SIZE + UCONTEXT_MCONTEXT_OFFSET;
128
129 /* Handle the general registers 0-31 followed by the PC. */
130 regs_base = mcontext_base;
131 for (int i = 0; i < 32; i++)
132 trad_frame_set_reg_addr (this_cache, OR1K_ZERO_REGNUM + i,
133 regs_base + (i * 4));
134 trad_frame_set_reg_addr (this_cache, OR1K_NPC_REGNUM, regs_base + (32 * 4));
135 trad_frame_set_reg_addr (this_cache, OR1K_SR_REGNUM, regs_base + (33 * 4));
136
137 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
138 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
139 }
140
141 /* Initialize OpenRISC Linux ABI info. */
142
143 static void
144 or1k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
145 {
146 linux_init_abi (info, gdbarch, 0);
147
148 set_solib_svr4_fetch_link_map_offsets (gdbarch,
149 linux_ilp32_fetch_link_map_offsets);
150
151 /* GNU/Linux uses SVR4-style shared libraries. */
152 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
153
154 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
155 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
156
157 set_gdbarch_software_single_step (gdbarch, or1k_software_single_step);
158
159 /* Enable TLS support. */
160 set_gdbarch_fetch_tls_load_module_address (gdbarch,
161 svr4_fetch_objfile_link_map);
162
163 set_gdbarch_iterate_over_regset_sections
164 (gdbarch, or1k_linux_iterate_over_regset_sections);
165
166 tramp_frame_prepend_unwinder (gdbarch, &or1k_linux_sigframe);
167 }
168
169 /* Initialize OpenRISC Linux target support. */
170
171 void _initialize_or1k_linux_tdep ();
172 void
173 _initialize_or1k_linux_tdep ()
174 {
175 gdbarch_register_osabi (bfd_arch_or1k, 0, GDB_OSABI_LINUX,
176 or1k_linux_init_abi);
177
178 /* Initialize the standard target descriptions. */
179 initialize_tdesc_or1k_linux ();
180 }