| 1 |
/* DWARF2 EH unwinding support for OpenRISC Linux. |
| 2 |
Copyright (C) 2018-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC 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, or (at your option) |
| 9 |
any later version. |
| 10 |
|
| 11 |
GCC 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 |
Under Section 7 of GPL version 3, you are granted additional |
| 17 |
permissions described in the GCC Runtime Library Exception, version |
| 18 |
3.1, as published by the Free Software Foundation. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License and |
| 21 |
a copy of the GCC Runtime Library Exception along with this program; |
| 22 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 23 |
<http://www.gnu.org/licenses/>. */ |
| 24 |
|
| 25 |
#ifndef inhibit_libc |
| 26 |
/* Do code reading to identify a signal frame, and set the frame |
| 27 |
state data appropriately. See unwind-dw2.c for the structs. */ |
| 28 |
|
| 29 |
#include <signal.h> |
| 30 |
#include <sys/ucontext.h> |
| 31 |
|
| 32 |
#define MD_FALLBACK_FRAME_STATE_FOR or1k_fallback_frame_state |
| 33 |
|
| 34 |
static _Unwind_Reason_Code |
| 35 |
or1k_fallback_frame_state (struct _Unwind_Context *context, |
| 36 |
_Unwind_FrameState *fs) |
| 37 |
{ |
| 38 |
unsigned int *pc = context->ra; |
| 39 |
struct rt_sigframe { |
| 40 |
siginfo_t info; |
| 41 |
ucontext_t uc; |
| 42 |
} *rt; |
| 43 |
struct sigcontext *sc; |
| 44 |
long new_cfa; |
| 45 |
int i; |
| 46 |
|
| 47 |
if (pc[0] != 0xa960008b /* l.ori r11, r0, NR_rt_sigreturn */ |
| 48 |
|| pc[1] != 0x20000001) /* l.sys 1 */ |
| 49 |
return _URC_END_OF_STACK; |
| 50 |
if (context->cfa == 0) |
| 51 |
return _URC_END_OF_STACK; |
| 52 |
|
| 53 |
rt = context->cfa; |
| 54 |
sc = (struct sigcontext *) &rt->uc.uc_mcontext; |
| 55 |
|
| 56 |
new_cfa = sc->regs.gpr[1]; |
| 57 |
fs->regs.cfa_how = CFA_REG_OFFSET; |
| 58 |
fs->regs.cfa_reg = 1; |
| 59 |
fs->regs.cfa_offset = new_cfa - (long) context->cfa; |
| 60 |
for (i = 2; i < 32; ++i) |
| 61 |
{ |
| 62 |
fs->regs.how[i] = REG_SAVED_OFFSET; |
| 63 |
fs->regs.reg[i].loc.offset = (long) &sc->regs.gpr[i] - new_cfa; |
| 64 |
} |
| 65 |
fs->regs.how[32] = REG_SAVED_OFFSET; |
| 66 |
fs->regs.reg[32].loc.offset = (long)&sc->regs.pc - new_cfa; |
| 67 |
fs->retaddr_column = 32; |
| 68 |
fs->signal_frame = 1; |
| 69 |
|
| 70 |
return _URC_NO_REASON; |
| 71 |
} |
| 72 |
|
| 73 |
#define MD_FROB_UPDATE_CONTEXT or1k_frob_update_context |
| 74 |
|
| 75 |
/* Fix up for signal handlers that don't have S flag set. */ |
| 76 |
|
| 77 |
static void |
| 78 |
or1k_frob_update_context (struct _Unwind_Context *context, |
| 79 |
_Unwind_FrameState *fs ATTRIBUTE_UNUSED) |
| 80 |
{ |
| 81 |
unsigned int *pc = context->ra; |
| 82 |
|
| 83 |
if (pc[0] == 0xa960008b /* l.ori r11, r0, NR_rt_sigreturn */ |
| 84 |
&& pc[1] == 0x20000001) /* l.sys 1 */ |
| 85 |
_Unwind_SetSignalFrame (context, 1); |
| 86 |
} |
| 87 |
#endif |