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"
30 /* Define the general register mapping. The kernel puts the PC at offset 0,
31 gdb puts it at offset 32. Register x0 is always 0 and can be ignored.
32 Registers x1 to x31 are in the same place. */
34 static const struct regcache_map_entry or1k_linux_gregmap
[] =
36 { 32, OR1K_ZERO_REGNUM
, 4 }, /* r0 to r31 */
37 { 1, OR1K_NPC_REGNUM
, 4 },
41 /* Define the general register regset. */
43 static const struct regset or1k_linux_gregset
=
45 or1k_linux_gregmap
, regcache_supply_regset
, regcache_collect_regset
48 /* Define hook for core file support. */
51 or1k_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
52 iterate_over_regset_sections_cb
*cb
,
54 const struct regcache
*regcache
)
56 cb (".reg", (33 * 4), (33 * 4), &or1k_linux_gregset
, NULL
, cb_data
);
59 /* Signal trampoline support. */
61 static void or1k_linux_sigframe_init (const struct tramp_frame
*self
,
62 struct frame_info
*this_frame
,
63 struct trad_frame_cache
*this_cache
,
66 #define OR1K_RT_SIGRETURN 139
68 #define OR1K_INST_L_ORI_R11_R0_IMM 0xa9600000
69 #define OR1K_INST_L_SYS_1 0x20000001
70 #define OR1K_INST_L_NOP 0x15000000
72 static const struct tramp_frame or1k_linux_sigframe
= {
76 { OR1K_INST_L_ORI_R11_R0_IMM
| OR1K_RT_SIGRETURN
, ULONGEST_MAX
},
77 { OR1K_INST_L_SYS_1
, ULONGEST_MAX
},
78 { OR1K_INST_L_NOP
, ULONGEST_MAX
},
79 { TRAMP_SENTINEL_INSN
}
81 or1k_linux_sigframe_init
,
85 /* Runtime signal frames look like this:
89 unsigned char retcode[16];
93 unsigned long uc_flags; - 4
94 struct ucontext *uc_link; - 4
95 stack_t uc_stack; - 4 * 3
96 struct sigcontext uc_mcontext;
101 struct user_regs_struct regs;
102 unsigned long oldmask;
105 struct user_regs_struct {
106 unsigned long gpr[32];
111 #define SIGFRAME_SIGINFO_SIZE 128
112 #define UCONTEXT_MCONTEXT_OFFSET 20
115 or1k_linux_sigframe_init (const struct tramp_frame
*self
,
116 struct frame_info
*this_frame
,
117 struct trad_frame_cache
*this_cache
,
120 CORE_ADDR frame_sp
= get_frame_sp (this_frame
);
121 CORE_ADDR mcontext_base
;
124 mcontext_base
= frame_sp
+ SIGFRAME_SIGINFO_SIZE
+ UCONTEXT_MCONTEXT_OFFSET
;
126 /* Handle the general registers 0-31 followed by the PC. */
127 regs_base
= mcontext_base
;
128 for (int i
= 0; i
< 32; i
++)
129 trad_frame_set_reg_addr (this_cache
, OR1K_ZERO_REGNUM
+ i
,
130 regs_base
+ (i
* 4));
131 trad_frame_set_reg_addr (this_cache
, OR1K_NPC_REGNUM
, regs_base
+ (32 * 4));
132 trad_frame_set_reg_addr (this_cache
, OR1K_SR_REGNUM
, regs_base
+ (33 * 4));
134 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
135 trad_frame_set_id (this_cache
, frame_id_build (frame_sp
, func
));
138 /* Initialize OpenRISC Linux ABI info. */
141 or1k_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
143 linux_init_abi (info
, gdbarch
);
145 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
146 svr4_ilp32_fetch_link_map_offsets
);
148 /* GNU/Linux uses SVR4-style shared libraries. */
149 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
151 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
152 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
154 /* Enable TLS support. */
155 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
156 svr4_fetch_objfile_link_map
);
158 set_gdbarch_iterate_over_regset_sections
159 (gdbarch
, or1k_linux_iterate_over_regset_sections
);
161 tramp_frame_prepend_unwinder (gdbarch
, &or1k_linux_sigframe
);
164 /* Initialize OpenRISC Linux target support. */
167 _initialize_or1k_linux_tdep (void)
169 gdbarch_register_osabi (bfd_arch_or1k
, 0, GDB_OSABI_LINUX
,
170 or1k_linux_init_abi
);