2013-12-31 08:05:35 +01:00
|
|
|
/* DWARF2 EH unwinding support for Nios II Linux.
|
2016-01-04 15:30:50 +01:00
|
|
|
Copyright (C) 2008-2016 Free Software Foundation, Inc.
|
2013-12-31 08:05:35 +01:00
|
|
|
|
|
|
|
This file is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
This file is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#ifndef inhibit_libc
|
|
|
|
|
|
|
|
/* Do code reading to identify a signal frame, and set the frame
|
|
|
|
state data appropriately. See unwind-dw2.c for the structs.
|
|
|
|
The corresponding bits in the Linux kernel are in
|
|
|
|
arch/nios2/kernel/signal.c. */
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <asm/unistd.h>
|
|
|
|
|
|
|
|
/* Exactly the same layout as the kernel structures, unique names. */
|
|
|
|
struct nios2_mcontext {
|
|
|
|
int version;
|
|
|
|
int gregs[32];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nios2_ucontext {
|
|
|
|
unsigned long uc_flags;
|
|
|
|
struct ucontext *uc_link;
|
|
|
|
stack_t uc_stack;
|
|
|
|
struct nios2_mcontext uc_mcontext;
|
|
|
|
sigset_t uc_sigmask; /* mask last for extensibility */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MD_FALLBACK_FRAME_STATE_FOR nios2_fallback_frame_state
|
|
|
|
|
|
|
|
static _Unwind_Reason_Code
|
|
|
|
nios2_fallback_frame_state (struct _Unwind_Context *context,
|
|
|
|
_Unwind_FrameState *fs)
|
|
|
|
{
|
|
|
|
u_int32_t *pc = (u_int32_t *) context->ra;
|
|
|
|
_Unwind_Ptr new_cfa;
|
|
|
|
|
|
|
|
/* The expected sequence of instructions is:
|
|
|
|
movi r2,(rt_sigreturn)
|
|
|
|
trap
|
|
|
|
Check for the trap first. */
|
|
|
|
if (pc[1] != 0x003b683a)
|
|
|
|
return _URC_END_OF_STACK;
|
|
|
|
|
|
|
|
#define NIOS2_REG(NUM,NAME) \
|
|
|
|
(fs->regs.reg[NUM].how = REG_SAVED_OFFSET, \
|
|
|
|
fs->regs.reg[NUM].loc.offset = (_Unwind_Ptr)&(regs->NAME) - new_cfa)
|
|
|
|
|
|
|
|
if (pc[0] == (0x00800004 | (__NR_rt_sigreturn << 6)))
|
|
|
|
{
|
|
|
|
struct rt_sigframe {
|
|
|
|
siginfo_t info;
|
|
|
|
struct nios2_ucontext uc;
|
2015-01-20 15:49:51 +01:00
|
|
|
} *rt_ = context->cfa;
|
2013-12-31 08:05:35 +01:00
|
|
|
struct nios2_mcontext *regs = &rt_->uc.uc_mcontext;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* MCONTEXT_VERSION is defined to 2 in the kernel. */
|
|
|
|
if (regs->version != 2)
|
|
|
|
return _URC_END_OF_STACK;
|
|
|
|
|
|
|
|
/* The CFA is the user's incoming stack pointer value. */
|
|
|
|
new_cfa = (_Unwind_Ptr)regs->gregs[28];
|
|
|
|
fs->regs.cfa_how = CFA_REG_OFFSET;
|
Use -fbuilding-libgcc for more target macros used in libgcc.
gcc/c-family:
* c-cppbuiltin.c (c_cpp_builtins): Also define
__LIBGCC_EH_TABLES_CAN_BE_READ_ONLY__,
__LIBGCC_EH_FRAME_SECTION_NAME__, __LIBGCC_JCR_SECTION_NAME__,
__LIBGCC_CTORS_SECTION_ASM_OP__, __LIBGCC_DTORS_SECTION_ASM_OP__,
__LIBGCC_TEXT_SECTION_ASM_OP__, __LIBGCC_INIT_SECTION_ASM_OP__,
__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__,
__LIBGCC_STACK_GROWS_DOWNWARD__,
__LIBGCC_DONT_USE_BUILTIN_SETJMP__,
__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__,
__LIBGCC_DWARF_FRAME_REGISTERS__,
__LIBGCC_EH_RETURN_STACKADJ_RTX__, __LIBGCC_JMP_BUF_SIZE__,
__LIBGCC_STACK_POINTER_REGNUM__ and
__LIBGCC_VTABLE_USES_DESCRIPTORS__ for -fbuilding-libgcc.
(builtin_define_with_value): Handle backslash-escaping in string
macro values.
libgcc:
* Makefile.in (CRTSTUFF_CFLAGS): Add -fbuilding-libgcc.
* config/aarch64/linux-unwind.h (STACK_POINTER_REGNUM): Change all
uses to __LIBGCC_STACK_POINTER_REGNUM__.
(DWARF_ALT_FRAME_RETURN_COLUMN): Change all uses to
__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__.
* config/alpha/vms-unwind.h (DWARF_ALT_FRAME_RETURN_COLUMN):
Change use to __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__.
* config/cr16/unwind-cr16.c (STACK_GROWS_DOWNWARD): Change all
uses to __LIBGCC_STACK_GROWS_DOWNWARD__.
(DWARF_FRAME_REGISTERS): Change all uses to
__LIBGCC_DWARF_FRAME_REGISTERS__.
(EH_RETURN_STACKADJ_RTX): Change all uses to
__LIBGCC_EH_RETURN_STACKADJ_RTX__.
* config/cr16/unwind-dw2.h (DWARF_FRAME_REGISTERS): Change use to
__LIBGCC_DWARF_FRAME_REGISTERS__. Remove conditional definition.
* config/i386/cygming-crtbegin.c (EH_FRAME_SECTION_NAME): Change
use to __LIBGCC_EH_FRAME_SECTION_NAME__.
(JCR_SECTION_NAME): Change use to __LIBGCC_JCR_SECTION_NAME__.
* config/i386/cygming-crtend.c (EH_FRAME_SECTION_NAME): Change use
to __LIBGCC_EH_FRAME_SECTION_NAME__.
(JCR_SECTION_NAME): Change use to __LIBGCC_JCR_SECTION_NAME__
* config/mips/linux-unwind.h (STACK_POINTER_REGNUM): Change use to
__LIBGCC_STACK_POINTER_REGNUM__.
(DWARF_ALT_FRAME_RETURN_COLUMN): Change all uses to
__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__.
* config/nios2/linux-unwind.h (STACK_POINTER_REGNUM): Change use
to __LIBGCC_STACK_POINTER_REGNUM__.
* config/pa/hpux-unwind.h (DWARF_ALT_FRAME_RETURN_COLUMN): Change
all uses to __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__.
* config/pa/linux-unwind.h (DWARF_ALT_FRAME_RETURN_COLUMN): Change
all uses to __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__.
* config/rs6000/aix-unwind.h (DWARF_ALT_FRAME_RETURN_COLUMN):
Change all uses to __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__.
(STACK_POINTER_REGNUM): Change all uses to
__LIBGCC_STACK_POINTER_REGNUM__.
* config/rs6000/darwin-fallback.c (STACK_POINTER_REGNUM): Change
use to __LIBGCC_STACK_POINTER_REGNUM__.
* config/rs6000/linux-unwind.h (STACK_POINTER_REGNUM): Change all
uses to __LIBGCC_STACK_POINTER_REGNUM__.
* config/sparc/linux-unwind.h (DWARF_FRAME_REGISTERS): Change use
to __LIBGCC_DWARF_FRAME_REGISTERS__.
* config/sparc/sol2-unwind.h (DWARF_FRAME_REGISTERS): Change use
to __LIBGCC_DWARF_FRAME_REGISTERS__.
* config/tilepro/linux-unwind.h (STACK_POINTER_REGNUM): Change use
to __LIBGCC_STACK_POINTER_REGNUM__.
* config/xtensa/unwind-dw2-xtensa.h (DWARF_FRAME_REGISTERS):
Remove conditional definition.
* crtstuff.c (TEXT_SECTION_ASM_OP): Change all uses to
__LIBGCC_TEXT_SECTION_ASM_OP__.
(EH_FRAME_SECTION_NAME): Change all uses to
__LIBGCC_EH_FRAME_SECTION_NAME__.
(EH_TABLES_CAN_BE_READ_ONLY): Change all uses to
__LIBGCC_EH_TABLES_CAN_BE_READ_ONLY__.
(CTORS_SECTION_ASM_OP): Change all uses to
__LIBGCC_CTORS_SECTION_ASM_OP__.
(DTORS_SECTION_ASM_OP): Change all uses to
__LIBGCC_DTORS_SECTION_ASM_OP__.
(JCR_SECTION_NAME): Change all uses to
__LIBGCC_JCR_SECTION_NAME__.
(INIT_SECTION_ASM_OP): Change all uses to
__LIBGCC_INIT_SECTION_ASM_OP__.
(INIT_ARRAY_SECTION_ASM_OP): Change all uses to
__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__.
* generic-morestack.c (STACK_GROWS_DOWNWARD): Change all uses to
__LIBGCC_STACK_GROWS_DOWNWARD__.
* libgcc2.c (INIT_SECTION_ASM_OP): Change all uses to
__LIBGCC_INIT_SECTION_ASM_OP__.
(INIT_ARRAY_SECTION_ASM_OP): Change all uses to
__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__.
(EH_FRAME_SECTION_NAME): Change all uses to
__LIBGCC_EH_FRAME_SECTION_NAME__.
* libgcov-profiler.c (VTABLE_USES_DESCRIPTORS): Remove conditional
definitions. Change all uses to
__LIBGCC_VTABLE_USES_DESCRIPTORS__.
* unwind-dw2.c (STACK_GROWS_DOWNWARD): Change all uses to
__LIBGCC_STACK_GROWS_DOWNWARD__.
(DWARF_FRAME_REGISTERS): Change all uses to
__LIBGCC_DWARF_FRAME_REGISTERS__.
(EH_RETURN_STACKADJ_RTX): Change all uses to
__LIBGCC_EH_RETURN_STACKADJ_RTX__.
* unwind-dw2.h (DWARF_FRAME_REGISTERS): Remove conditional
definition. Change use to __LIBGCC_DWARF_FRAME_REGISTERS__.
* unwind-sjlj.c (DONT_USE_BUILTIN_SETJMP): Change all uses to
__LIBGCC_DONT_USE_BUILTIN_SETJMP__.
(JMP_BUF_SIZE): Change use to __LIBGCC_JMP_BUF_SIZE__.
From-SVN: r214954
2014-09-05 14:03:46 +02:00
|
|
|
fs->regs.cfa_reg = __LIBGCC_STACK_POINTER_REGNUM__;
|
2013-12-31 08:05:35 +01:00
|
|
|
fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa;
|
|
|
|
|
|
|
|
/* The sequential registers. */
|
|
|
|
for (i = 1; i < 24; i++)
|
|
|
|
NIOS2_REG (i, gregs[i-1]);
|
|
|
|
|
|
|
|
/* The random registers. The kernel stores these in a funny order
|
|
|
|
in the gregs array. */
|
|
|
|
NIOS2_REG (RA_REGNO, gregs[23]);
|
|
|
|
NIOS2_REG (FP_REGNO, gregs[24]);
|
|
|
|
NIOS2_REG (GP_REGNO, gregs[25]);
|
|
|
|
NIOS2_REG (EA_REGNO, gregs[27]);
|
|
|
|
|
|
|
|
fs->retaddr_column = EA_REGNO;
|
|
|
|
fs->signal_frame = 1;
|
|
|
|
|
|
|
|
return _URC_NO_REASON;
|
|
|
|
}
|
|
|
|
#undef NIOS2_REG
|
|
|
|
return _URC_END_OF_STACK;
|
|
|
|
}
|
|
|
|
#endif
|