1 /* Target-dependent code for GNU/Linux on OpenRISC processors.
2 Copyright (C) 2018-2022 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"
30 #include "features/or1k-linux.c"
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 popupated from linux.
35 Register r0 is always 0 and can be ignored. */
37 static const struct regcache_map_entry or1k_linux_gregmap
[] =
39 { 32, OR1K_ZERO_REGNUM
, 4 }, /* r0 to r31 */
40 { 1, OR1K_NPC_REGNUM
, 4 },
44 /* Define the general register regset. */
46 static const struct regset or1k_linux_gregset
=
48 or1k_linux_gregmap
, regcache_supply_regset
, regcache_collect_regset
51 /* Define hook for core file support. */
54 or1k_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
55 iterate_over_regset_sections_cb
*cb
,
57 const struct regcache
*regcache
)
59 cb (".reg", (33 * 4), (33 * 4), &or1k_linux_gregset
, NULL
, cb_data
);
62 /* Signal trampoline support. */
64 static void or1k_linux_sigframe_init (const struct tramp_frame
*self
,
65 struct frame_info
*this_frame
,
66 struct trad_frame_cache
*this_cache
,
69 #define OR1K_RT_SIGRETURN 139
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
75 static const struct tramp_frame or1k_linux_sigframe
= {
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
}
84 or1k_linux_sigframe_init
,
88 /* Runtime signal frames look like this:
92 unsigned char retcode[16];
96 unsigned long uc_flags; - 4
97 struct ucontext *uc_link; - 4
98 stack_t uc_stack; - 4 * 3
99 struct sigcontext uc_mcontext;
104 struct user_regs_struct regs;
105 unsigned long oldmask;
108 struct user_regs_struct {
109 unsigned long gpr[32];
114 #define SIGFRAME_SIGINFO_SIZE 128
115 #define UCONTEXT_MCONTEXT_OFFSET 20
118 or1k_linux_sigframe_init (const struct tramp_frame
*self
,
119 struct frame_info
*this_frame
,
120 struct trad_frame_cache
*this_cache
,
123 CORE_ADDR frame_sp
= get_frame_sp (this_frame
);
124 CORE_ADDR mcontext_base
;
127 mcontext_base
= frame_sp
+ SIGFRAME_SIGINFO_SIZE
+ UCONTEXT_MCONTEXT_OFFSET
;
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));
137 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
138 trad_frame_set_id (this_cache
, frame_id_build (frame_sp
, func
));
141 /* Initialize OpenRISC Linux ABI info. */
144 or1k_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
146 linux_init_abi (info
, gdbarch
, 0);
148 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
149 linux_ilp32_fetch_link_map_offsets
);
151 /* GNU/Linux uses SVR4-style shared libraries. */
152 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
154 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
155 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
157 set_gdbarch_software_single_step (gdbarch
, or1k_software_single_step
);
159 /* Enable TLS support. */
160 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
161 svr4_fetch_objfile_link_map
);
163 set_gdbarch_iterate_over_regset_sections
164 (gdbarch
, or1k_linux_iterate_over_regset_sections
);
166 tramp_frame_prepend_unwinder (gdbarch
, &or1k_linux_sigframe
);
169 /* Initialize OpenRISC Linux target support. */
171 void _initialize_or1k_linux_tdep ();
173 _initialize_or1k_linux_tdep ()
175 gdbarch_register_osabi (bfd_arch_or1k
, 0, GDB_OSABI_LINUX
,
176 or1k_linux_init_abi
);
178 /* Initialize the standard target descriptions. */
179 initialize_tdesc_or1k_linux ();