1 /* Target-dependent code for GNU/Linux on OpenRISC processors. 2 Copyright (C) 2018-2019 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 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. */ 32 33 static const struct regcache_map_entry or1k_linux_gregmap[] = 34 { 35 { 32, OR1K_ZERO_REGNUM, 4 }, /* r0 to r31 */ 36 { 1, OR1K_NPC_REGNUM, 4 }, 37 { 0 } 38 }; 39 40 /* Define the general register regset. */ 41 42 static const struct regset or1k_linux_gregset = 43 { 44 or1k_linux_gregmap, regcache_supply_regset, regcache_collect_regset 45 }; 46 47 /* Define hook for core file support. */ 48 49 static void 50 or1k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, 51 iterate_over_regset_sections_cb *cb, 52 void *cb_data, 53 const struct regcache *regcache) 54 { 55 cb (".reg", (33 * 4), (33 * 4), &or1k_linux_gregset, NULL, cb_data); 56 } 57 58 /* Signal trampoline support. */ 59 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, 63 CORE_ADDR func); 64 65 #define OR1K_RT_SIGRETURN 139 66 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 70 71 static const struct tramp_frame or1k_linux_sigframe = { 72 SIGTRAMP_FRAME, 73 4, 74 { 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 } 79 }, 80 or1k_linux_sigframe_init, 81 NULL 82 }; 83 84 /* Runtime signal frames look like this: 85 struct rt_sigframe { 86 struct siginfo info; 87 struct ucontext uc; 88 unsigned char retcode[16]; 89 }; 90 91 struct ucontext { 92 unsigned long uc_flags; - 4 93 struct ucontext *uc_link; - 4 94 stack_t uc_stack; - 4 * 3 95 struct sigcontext uc_mcontext; 96 sigset_t uc_sigmask; 97 }; 98 99 struct sigcontext { 100 struct user_regs_struct regs; 101 unsigned long oldmask; 102 }; 103 104 struct user_regs_struct { 105 unsigned long gpr[32]; 106 unsigned long pc; 107 unsigned long sr; 108 }; */ 109 110 #define SIGFRAME_SIGINFO_SIZE 128 111 #define UCONTEXT_MCONTEXT_OFFSET 20 112 113 static void 114 or1k_linux_sigframe_init (const struct tramp_frame *self, 115 struct frame_info *this_frame, 116 struct trad_frame_cache *this_cache, 117 CORE_ADDR func) 118 { 119 CORE_ADDR frame_sp = get_frame_sp (this_frame); 120 CORE_ADDR mcontext_base; 121 CORE_ADDR regs_base; 122 123 mcontext_base = frame_sp + SIGFRAME_SIGINFO_SIZE + UCONTEXT_MCONTEXT_OFFSET; 124 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)); 132 133 /* Choice of the bottom of the sigframe is somewhat arbitrary. */ 134 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func)); 135 } 136 137 /* Initialize OpenRISC Linux ABI info. */ 138 139 static void 140 or1k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 141 { 142 linux_init_abi (info, gdbarch); 143 144 set_solib_svr4_fetch_link_map_offsets (gdbarch, 145 svr4_ilp32_fetch_link_map_offsets); 146 147 /* GNU/Linux uses SVR4-style shared libraries. */ 148 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); 149 150 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */ 151 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); 152 153 /* Enable TLS support. */ 154 set_gdbarch_fetch_tls_load_module_address (gdbarch, 155 svr4_fetch_objfile_link_map); 156 157 set_gdbarch_iterate_over_regset_sections 158 (gdbarch, or1k_linux_iterate_over_regset_sections); 159 160 tramp_frame_prepend_unwinder (gdbarch, &or1k_linux_sigframe); 161 } 162 163 /* Initialize OpenRISC Linux target support. */ 164 165 void 166 _initialize_or1k_linux_tdep (void) 167 { 168 gdbarch_register_osabi (bfd_arch_or1k, 0, GDB_OSABI_LINUX, 169 or1k_linux_init_abi); 170 } 171