Automatic date update in version.in
[binutils-gdb.git] / gdb / or1k-linux-tdep.c
blob00045a3382040938201187b083bfb698320536fc
1 /* Target-dependent code for GNU/Linux on OpenRISC processors.
2 Copyright (C) 2018-2024 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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/>. */
19 #include "or1k-tdep.h"
20 #include "osabi.h"
21 #include "glibc-tdep.h"
22 #include "linux-tdep.h"
23 #include "solib-svr4.h"
24 #include "regset.h"
25 #include "tramp-frame.h"
26 #include "trad-frame.h"
27 #include "gdbarch.h"
29 #include "features/or1k-linux.c"
31 /* Define the general register mapping. The kernel and GDB put registers
32 r1 to r31 in the same place. The NPC register is stored at index 32 in
33 linux and 33 in GDB, in GDB 32 is for PPC which is not populated from linux.
34 Register r0 is always 0 and can be ignored. */
36 static const struct regcache_map_entry or1k_linux_gregmap[] =
38 { 32, OR1K_ZERO_REGNUM, 4 }, /* r0 to r31 */
39 { 1, OR1K_NPC_REGNUM, 4 },
40 { 0 }
43 /* Define the general register regset. */
45 static const struct regset or1k_linux_gregset =
47 or1k_linux_gregmap, regcache_supply_regset, regcache_collect_regset
50 /* Define hook for core file support. */
52 static void
53 or1k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
54 iterate_over_regset_sections_cb *cb,
55 void *cb_data,
56 const struct regcache *regcache)
58 cb (".reg", (33 * 4), (33 * 4), &or1k_linux_gregset, NULL, cb_data);
61 /* Signal trampoline support. */
63 static void or1k_linux_sigframe_init (const struct tramp_frame *self,
64 const frame_info_ptr &this_frame,
65 struct trad_frame_cache *this_cache,
66 CORE_ADDR func);
68 #define OR1K_RT_SIGRETURN 139
70 #define OR1K_INST_L_ORI_R11_R0_IMM 0xa9600000
71 #define OR1K_INST_L_SYS_1 0x20000001
72 #define OR1K_INST_L_NOP 0x15000000
74 static const struct tramp_frame or1k_linux_sigframe = {
75 SIGTRAMP_FRAME,
78 { OR1K_INST_L_ORI_R11_R0_IMM | OR1K_RT_SIGRETURN, ULONGEST_MAX },
79 { OR1K_INST_L_SYS_1, ULONGEST_MAX },
80 { OR1K_INST_L_NOP, ULONGEST_MAX },
81 { TRAMP_SENTINEL_INSN }
83 or1k_linux_sigframe_init,
84 NULL
87 /* Runtime signal frames look like this:
88 struct rt_sigframe {
89 struct siginfo info;
90 struct ucontext uc;
91 unsigned char retcode[16];
94 struct ucontext {
95 unsigned long uc_flags; - 4
96 struct ucontext *uc_link; - 4
97 stack_t uc_stack; - 4 * 3
98 struct sigcontext uc_mcontext;
99 sigset_t uc_sigmask;
102 struct sigcontext {
103 struct user_regs_struct regs;
104 unsigned long oldmask;
107 struct user_regs_struct {
108 unsigned long gpr[32];
109 unsigned long pc;
110 unsigned long sr;
111 }; */
113 #define SIGFRAME_SIGINFO_SIZE 128
114 #define UCONTEXT_MCONTEXT_OFFSET 20
116 static void
117 or1k_linux_sigframe_init (const struct tramp_frame *self,
118 const frame_info_ptr &this_frame,
119 struct trad_frame_cache *this_cache,
120 CORE_ADDR func)
122 CORE_ADDR frame_sp = get_frame_sp (this_frame);
123 CORE_ADDR mcontext_base;
124 CORE_ADDR regs_base;
126 mcontext_base = frame_sp + SIGFRAME_SIGINFO_SIZE + UCONTEXT_MCONTEXT_OFFSET;
128 /* Handle the general registers 0-31 followed by the PC. */
129 regs_base = mcontext_base;
130 for (int i = 0; i < 32; i++)
131 trad_frame_set_reg_addr (this_cache, OR1K_ZERO_REGNUM + i,
132 regs_base + (i * 4));
133 trad_frame_set_reg_addr (this_cache, OR1K_NPC_REGNUM, regs_base + (32 * 4));
134 trad_frame_set_reg_addr (this_cache, OR1K_SR_REGNUM, regs_base + (33 * 4));
136 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
137 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
140 /* Initialize OpenRISC Linux ABI info. */
142 static void
143 or1k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
145 linux_init_abi (info, gdbarch, 0);
147 set_solib_svr4_fetch_link_map_offsets (gdbarch,
148 linux_ilp32_fetch_link_map_offsets);
150 /* GNU/Linux uses SVR4-style shared libraries. */
151 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
153 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
154 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
156 set_gdbarch_software_single_step (gdbarch, or1k_software_single_step);
158 /* Enable TLS support. */
159 set_gdbarch_fetch_tls_load_module_address (gdbarch,
160 svr4_fetch_objfile_link_map);
162 set_gdbarch_iterate_over_regset_sections
163 (gdbarch, or1k_linux_iterate_over_regset_sections);
165 tramp_frame_prepend_unwinder (gdbarch, &or1k_linux_sigframe);
168 /* Initialize OpenRISC Linux target support. */
170 void _initialize_or1k_linux_tdep ();
171 void
172 _initialize_or1k_linux_tdep ()
174 gdbarch_register_osabi (bfd_arch_or1k, 0, GDB_OSABI_LINUX,
175 or1k_linux_init_abi);
177 /* Initialize the standard target descriptions. */
178 initialize_tdesc_or1k_linux ();