1 /* Target-dependent code for GNU/Linux on OpenRISC processors.
2 Copyright (C) 2018-2019 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/>. */
20 #include "or1k-tdep.h"
22 #include "glibc-tdep.h"
23 #include "linux-tdep.h"
24 #include "solib-svr4.h"
26 #include "tramp-frame.h"
27 #include "trad-frame.h"
29 /* Define the general register mapping. The kernel puts the PC at offset 0,
30 gdb puts it at offset 32. Register x0 is always 0 and can be ignored.
31 Registers x1 to x31 are in the same place. */
33 static const struct regcache_map_entry or1k_linux_gregmap[] =
35 { 32, OR1K_ZERO_REGNUM, 4 }, /* r0 to r31 */
36 { 1, OR1K_NPC_REGNUM, 4 },
40 /* Define the general register regset. */
42 static const struct regset or1k_linux_gregset =
44 or1k_linux_gregmap, regcache_supply_regset, regcache_collect_regset
47 /* Define hook for core file support. */
50 or1k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
51 iterate_over_regset_sections_cb *cb,
53 const struct regcache *regcache)
55 cb (".reg", (33 * 4), (33 * 4), &or1k_linux_gregset, NULL, cb_data);
58 /* Signal trampoline support. */
60 static void or1k_linux_sigframe_init (const struct tramp_frame *self,
61 struct frame_info *this_frame,
62 struct trad_frame_cache *this_cache,
65 #define OR1K_RT_SIGRETURN 139
67 #define OR1K_INST_L_ORI_R11_R0_IMM 0xa9600000
68 #define OR1K_INST_L_SYS_1 0x20000001
69 #define OR1K_INST_L_NOP 0x15000000
71 static const struct tramp_frame or1k_linux_sigframe = {
75 { OR1K_INST_L_ORI_R11_R0_IMM | OR1K_RT_SIGRETURN, ULONGEST_MAX },
76 { OR1K_INST_L_SYS_1, ULONGEST_MAX },
77 { OR1K_INST_L_NOP, ULONGEST_MAX },
78 { TRAMP_SENTINEL_INSN }
80 or1k_linux_sigframe_init,
84 /* Runtime signal frames look like this:
88 unsigned char retcode[16];
92 unsigned long uc_flags; - 4
93 struct ucontext *uc_link; - 4
94 stack_t uc_stack; - 4 * 3
95 struct sigcontext uc_mcontext;
100 struct user_regs_struct regs;
101 unsigned long oldmask;
104 struct user_regs_struct {
105 unsigned long gpr[32];
110 #define SIGFRAME_SIGINFO_SIZE 128
111 #define UCONTEXT_MCONTEXT_OFFSET 20
114 or1k_linux_sigframe_init (const struct tramp_frame *self,
115 struct frame_info *this_frame,
116 struct trad_frame_cache *this_cache,
119 CORE_ADDR frame_sp = get_frame_sp (this_frame);
120 CORE_ADDR mcontext_base;
123 mcontext_base = frame_sp + SIGFRAME_SIGINFO_SIZE + UCONTEXT_MCONTEXT_OFFSET;
125 /* Handle the general registers 0-31 followed by the PC. */
126 regs_base = mcontext_base;
127 for (int i = 0; i < 32; i++)
128 trad_frame_set_reg_addr (this_cache, OR1K_ZERO_REGNUM + i,
129 regs_base + (i * 4));
130 trad_frame_set_reg_addr (this_cache, OR1K_NPC_REGNUM, regs_base + (32 * 4));
131 trad_frame_set_reg_addr (this_cache, OR1K_SR_REGNUM, regs_base + (33 * 4));
133 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
134 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
137 /* Initialize OpenRISC Linux ABI info. */
140 or1k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
142 linux_init_abi (info, gdbarch);
144 set_solib_svr4_fetch_link_map_offsets (gdbarch,
145 svr4_ilp32_fetch_link_map_offsets);
147 /* GNU/Linux uses SVR4-style shared libraries. */
148 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
150 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
151 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
153 /* Enable TLS support. */
154 set_gdbarch_fetch_tls_load_module_address (gdbarch,
155 svr4_fetch_objfile_link_map);
157 set_gdbarch_iterate_over_regset_sections
158 (gdbarch, or1k_linux_iterate_over_regset_sections);
160 tramp_frame_prepend_unwinder (gdbarch, &or1k_linux_sigframe);
163 /* Initialize OpenRISC Linux target support. */
166 _initialize_or1k_linux_tdep (void)
168 gdbarch_register_osabi (bfd_arch_or1k, 0, GDB_OSABI_LINUX,
169 or1k_linux_init_abi);