Daily bump.
[gcc.git] / libgcc / config / loongarch / linux-unwind.h
blob4d31fbb9f5431477cb29b44f2c40b6af152bd952
1 /* DWARF2 EH unwinding support for LoongArch Linux.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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.
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/>. */
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. */
29 #include <signal.h>
30 #include <sys/syscall.h>
31 #include <sys/ucontext.h>
33 #define MD_FALLBACK_FRAME_STATE_FOR loongarch_fallback_frame_state
35 static _Unwind_Reason_Code
36 loongarch_fallback_frame_state (struct _Unwind_Context *context,
37 _Unwind_FrameState *fs)
39 u_int32_t *pc = (u_int32_t *) context->ra;
40 struct sigcontext *sc;
41 _Unwind_Ptr new_cfa;
42 int i;
44 /* 03822c0b li.d a7, 0x8b (sigreturn) */
45 /* 002b0000 syscall 0 */
46 if (pc[1] != 0x002b0000)
47 return _URC_END_OF_STACK;
48 if (pc[0] == 0x03822c0b)
50 struct rt_sigframe
52 siginfo_t info;
53 ucontext_t uc;
54 } *rt_ = context->cfa;
55 sc = (struct sigcontext *) (void *) &rt_->uc.uc_mcontext;
57 else
58 return _URC_END_OF_STACK;
60 new_cfa = (_Unwind_Ptr) sc;
61 fs->regs.cfa_how = CFA_REG_OFFSET;
62 fs->regs.cfa_reg = __LIBGCC_STACK_POINTER_REGNUM__;
63 fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa;
65 for (i = 0; i < 32; i++)
67 fs->regs.how[i] = REG_SAVED_OFFSET;
68 fs->regs.reg[i].loc.offset = (_Unwind_Ptr) & (sc->sc_regs[i]) - new_cfa;
71 fs->signal_frame = 1;
72 fs->regs.how[__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__]
73 = REG_SAVED_VAL_OFFSET;
74 fs->regs.reg[__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__].loc.offset
75 = (_Unwind_Ptr) (sc->sc_pc) - new_cfa;
76 fs->retaddr_column = __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__;
78 return _URC_NO_REASON;
80 #endif