diff options
author | pbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-09-13 12:48:33 +0000 |
---|---|---|
committer | pbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-09-13 12:48:33 +0000 |
commit | 7e5fc0c4013728ba367150879c8705f5e3beb05f (patch) | |
tree | 919ab69e4bf163c2220a80d2baee8cd54fe40723 /libgcc/config/c6x | |
parent | 73cd2c42217339beb8c2a3da896f2daac37963d7 (diff) | |
download | gcc-7e5fc0c4013728ba367150879c8705f5e3beb05f.tar.gz |
2011-09-13 Paul Brook <paul@codesourcery.com>
gcc/
* config/arm/arm.h (ASM_PREFERRED_EH_DATA_FORMAT): Define.
(ARM_TARGET2_DWARF_FORMAT): Provide default definition.
* config/arm/linux-eabi.h (ARM_TARGET2_DWARF_FORMAT): Define.
* config/arm/symbian.h (ARM_TARGET2_DWARF_FORMAT): Define.
* config/arm/uclinux-eabi.h(ARM_TARGET2_DWARF_FORMAT): Define.
* config/arm/t-bpabi (EXTRA_HEADERS): Add unwind-arm-common.h.
* config/arm/t-symbian (EXTRA_HEADERS): Add unwind-arm-common.h.
* config/c6x/c6x.c (c6x_output_file_unwind): Don't rely on dwarf2 code
enabling unwind tables.
(c6x_debug_unwind_info): New function.
(TARGET_ARM_EABI_UNWINDER): Define.
(TARGET_DEBUG_UNWIND_INFO): Define.
* config/c6x/c6x.h (DWARF_FRAME_RETURN_COLUMN): Define.
(TARGET_EXTRA_CFI_SECTION): Remove.
* config/c6x/t-c6x-elf (EXTRA_HEADERS): Set.
* ginclude/unwind-arm-common.h: New file.
libgcc/
* config.host (tic6x-*-*): Add c6x/t-c6x-elf. Set unwind_header.
* unwind-c.c (PERSONALITY_FUNCTION): Use UNWIND_POINTER_REG.
* unwind-arm-common.inc: New file.
* config/arm/unwind-arm.c: Use unwind-arm-common.inc.
* config/arm/unwind-arm.h: Use unwind-arm-common.h.
(_GLIBCXX_OVERRIDE_TTYPE_ENCODING): Define.
* config/c6x/libunwind.S: New file.
* config/c6x/pr-support.c: New file.
* config/c6x/unwind-c6x.c: New file.
* config/c6x/unwind-c6x.h: New file.
* config/c6x/t-c6x-elf: New file.
libstdc++-v3/
* libsupc++/eh_arm.cc (__cxa_end_cleanup): Add C6X implementation.
* libsupc++/eh_call.cc (__cxa_call_unexpected): Set rtti_base.
* libsupc++/eh_personality.cc (NO_SIZE_OF_ENCODED_VALUE): Remove
__ARM_EABI_UNWINDER__ check.
(parse_lsda_header): Check _GLIBCXX_OVERRIDE_TTYPE_ENCODING.
(get_ttype_entry): Use generic implementation on ARM EABI.
(check_exception_spec): Use _Unwind_decode_typeinfo_ptr and
UNWIND_STACK_REG.
(PERSONALITY_FUNCTION): Set ttype_base.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@178808 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgcc/config/c6x')
-rw-r--r-- | libgcc/config/c6x/libunwind.S | 133 | ||||
-rw-r--r-- | libgcc/config/c6x/pr-support.c | 534 | ||||
-rw-r--r-- | libgcc/config/c6x/t-c6x-elf | 4 | ||||
-rw-r--r-- | libgcc/config/c6x/unwind-c6x.c | 224 | ||||
-rw-r--r-- | libgcc/config/c6x/unwind-c6x.h | 71 |
5 files changed, 966 insertions, 0 deletions
diff --git a/libgcc/config/c6x/libunwind.S b/libgcc/config/c6x/libunwind.S new file mode 100644 index 00000000000..d37ea5730bf --- /dev/null +++ b/libgcc/config/c6x/libunwind.S @@ -0,0 +1,133 @@ +.text +.macro do_call fn +#ifdef _TMS320C6400_PLUS + callp .s2 (\fn), B3 +#elif defined(_TMS320C6400) + call .s2 (\fn) + addkpc .s2 9f, B3, 0 + nop 4 +9f: +#else + call .s2 (\fn) + mhkl .s2 9f, B3 + mhkh .s2 9f, B3 + nop 3 +9f: +#endif +.endm +.align 2 +.global restore_core_regs +.type restore_core_regs, STT_FUNC +restore_core_regs: + mv .s2x A4, B4 + ldw .d1t1 *+A4[0], A0 + || ldw .d2t2 *++B4[16], B0 + ldw .d1t1 *+A4[1], A1 + || ldw .d2t2 *+B4[1], B1 + ldw .d1t1 *+A4[2], A2 + || ldw .d2t2 *+B4[2], B2 + ldw .d1t1 *+A4[3], A3 + || ldw .d2t2 *+B4[3], B3 + ;; Base registers are loaded later + ldw .d1t1 *+A4[5], A5 + || ldw .d2t2 *+B4[5], B5 + ldw .d1t1 *+A4[6], A6 + || ldw .d2t2 *+B4[6], B6 + ldw .d1t1 *+A4[7], A7 + || ldw .d2t2 *+B4[7], B7 + ldw .d1t1 *+A4[8], A8 + || ldw .d2t2 *+B4[8], B8 + ldw .d1t1 *+A4[9], A9 + || ldw .d2t2 *+B4[9], B9 + ;; load PC into B10 so that it is ready for the branch + ldw .d2t2 *+B4[16], B10 + ldw .d1t1 *+A4[11], A11 + || ldw .d2t2 *+B4[11], B11 + ldw .d1t1 *+A4[12], A12 + || ldw .d2t2 *+B4[12], B12 + ldw .d1t1 *+A4[13], A13 + || ldw .d2t2 *+B4[13], B13 + ldw .d1t1 *+A4[14], A14 + || ldw .d2t2 *+B4[14], B14 + ;; Loads have 4 delay slots. Take advantage of this to restore the + ;; scratch registers and stack pointer before the base registers + ;; disappear. We also need to make sure no interrupts occur, + ;; so put the whole thing in the delay slots of a dummy branch + ;; We can not move the ret earlier as that would cause it to occur + ;; before the last load completes + b .s1 (1f) + ldw .d1t1 *+A4[4], A4 + || ldw .d2t2 *+B4[4], B4 + ldw .d1t1 *+A4[15], A15 + || ldw .d2t2 *+B4[15], B15 + ret .s2 B10 + ldw .d1t1 *+A4[10], A10 + || ldw .d2t2 *+B4[10], B10 + nop 1 +1: + nop 3 +.size restore_core_regs, . - restore_core_regs + +.macro UNWIND_WRAPPER name argreg argside +.global \name +.type \name, STT_FUNC +\name: + # Create saved register state: flags,A0-A15,B0-B15,PC = 136 bytes. + # Plus 4 (rounded to 8) for saving return. + addk .s2 -144, B15 + stw .d2t1 A0, *+B15[2] + stw .d2t1 A1, *+B15[3] + stw .d2t1 A2, *+B15[4] + stw .d2t1 A3, *+B15[5] + stw .d2t1 A4, *+B15[6] + stw .d2t1 A5, *+B15[7] + stw .d2t1 A6, *+B15[8] + stw .d2t1 A7, *+B15[9] + stw .d2t1 A8, *+B15[10] + stw .d2t1 A9, *+B15[11] + stw .d2t1 A10, *+B15[12] + stw .d2t1 A11, *+B15[13] + stw .d2t1 A12, *+B15[14] + stw .d2t1 A13, *+B15[15] + stw .d2t1 A14, *+B15[16] + stw .d2t1 A15, *+B15[17] + mv .s1x B15, A0 + addk .s1 144, A0 + stw .d2t2 B0, *+B15[18] + stw .d2t2 B1, *+B15[19] + stw .d2t2 B2, *+B15[20] + stw .d2t2 B3, *+B15[21] + stw .d2t2 B4, *+B15[22] + stw .d2t2 B5, *+B15[23] + stw .d2t2 B6, *+B15[24] + stw .d2t2 B7, *+B15[25] + stw .d2t2 B8, *+B15[26] + stw .d2t2 B9, *+B15[27] + stw .d2t2 B10, *+B15[28] + stw .d2t2 B11, *+B15[29] + stw .d2t2 B12, *+B15[30] + stw .d2t2 B13, *+B15[31] + stw .d2t2 B14, *+B15[32] + stw .d2t1 A0, *+B15[33] + stw .d2t1 A0, *+B15[34] + # Zero demand saved flags + mvk .s1 0, A0 + stw .d2t1 A0, *+B15[1] + # Save return address, setup additional argument and call fucntion + stw .d2t2 B3, *+B15[35] + add .d\argside B15, 4, \argreg + do_call __gnu\name + # Restore stack and return + ldw .d2t2 *+B15[35], B3 + addk .s2 144, B15 + nop 3 + ret .s2 B3 + nop 5 +.size \name, . - \name +.endm + +UNWIND_WRAPPER _Unwind_RaiseException B4 2 +UNWIND_WRAPPER _Unwind_Resume B4 2 +UNWIND_WRAPPER _Unwind_Resume_or_Rethrow B4 2 +UNWIND_WRAPPER _Unwind_ForcedUnwind B6 2 +UNWIND_WRAPPER _Unwind_Backtrace A6 1x diff --git a/libgcc/config/c6x/pr-support.c b/libgcc/config/c6x/pr-support.c new file mode 100644 index 00000000000..6375013cb66 --- /dev/null +++ b/libgcc/config/c6x/pr-support.c @@ -0,0 +1,534 @@ +/* C6X ABI compliant unwinding routines + Copyright (C) 2011 Free Software Foundation, Inc. + + 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/>. */ + +#include "unwind.h" + +/* We add a prototype for abort here to avoid creating a dependency on + target headers. */ +extern void abort (void); + +typedef struct _ZSt9type_info type_info; /* This names C++ type_info type */ + +/* Misc constants. */ +#define R_A0 0 +#define R_A1 1 +#define R_A2 2 +#define R_A3 3 +#define R_A4 4 +#define R_A5 5 +#define R_A6 6 +#define R_A7 7 +#define R_A8 8 +#define R_A9 9 +#define R_A10 10 +#define R_A11 11 +#define R_A12 12 +#define R_A13 13 +#define R_A14 14 +#define R_A15 15 +#define R_B0 16 +#define R_B1 17 +#define R_B2 18 +#define R_B3 19 +#define R_B4 20 +#define R_B5 21 +#define R_B6 22 +#define R_B7 23 +#define R_B8 24 +#define R_B9 25 +#define R_B10 26 +#define R_B11 27 +#define R_B12 28 +#define R_B13 29 +#define R_B14 30 +#define R_B15 31 + +#define R_SP R_B15 +#define R_PC 33 + +#define uint32_highbit (((_uw) 1) << 31) + +void __attribute__((weak)) __cxa_call_unexpected(_Unwind_Control_Block *ucbp); + +/* Unwind descriptors. */ + +typedef struct +{ + _uw16 length; + _uw16 offset; +} EHT16; + +typedef struct +{ + _uw length; + _uw offset; +} EHT32; + +/* Calculate the address encoded by a 31-bit self-relative offset at address + P. Copy of routine in unwind-arm.c. */ + +static inline _uw +selfrel_offset31 (const _uw *p) +{ + _uw offset; + + offset = *p; + /* Sign extend to 32 bits. */ + if (offset & (1 << 30)) + offset |= 1u << 31; + + return offset + (_uw) p; +} + + +/* Personality routine helper functions. */ + +#define CODE_FINISH (0xe7) + +/* Return the next byte of unwinding information, or CODE_FINISH if there is + no data remaining. */ +static inline _uw8 +next_unwind_byte (__gnu_unwind_state * uws) +{ + _uw8 b; + + if (uws->bytes_left == 0) + { + /* Load another word */ + if (uws->words_left == 0) + return CODE_FINISH; /* Nothing left. */ + uws->words_left--; + uws->data = *(uws->next++); + uws->bytes_left = 3; + } + else + uws->bytes_left--; + + /* Extract the most significant byte. */ + b = (uws->data >> 24) & 0xff; + uws->data <<= 8; + return b; +} + +static void +unwind_restore_pair (_Unwind_Context * context, int reg, _uw *ptr) +{ +#ifdef _BIG_ENDIAN + _Unwind_VRS_Set (context, _UVRSC_CORE, reg, _UVRSD_UINT32, ptr + 1); + _Unwind_VRS_Set (context, _UVRSC_CORE, reg + 1, _UVRSD_UINT32, ptr); +#else + _Unwind_VRS_Set (context, _UVRSC_CORE, reg, _UVRSD_UINT32, ptr); + _Unwind_VRS_Set (context, _UVRSC_CORE, reg + 1, _UVRSD_UINT32, ptr + 1); +#endif +} + +static const int +unwind_frame_regs[13] = +{ + R_A15, R_B15, R_B14, R_B13, R_B12, R_B11, R_B10, R_B3, + R_A14, R_A13, R_A12, R_A11, R_A10 +}; + +static void +pop_compact_frame (_Unwind_Context * context, _uw mask, _uw *ptr, int inc_sp) +{ + int size; + _uw test; + int i; + int regno; + int regno2; + int nregs; + + size = 0; + nregs = __builtin_popcount (mask); + for (i = 0; i < 13; i++) + { + test = 1 << i; + if ((mask & test) == 0) + continue; + + regno = unwind_frame_regs[12 - i]; + /* The last slot is a sigle word, so cannot store a register pair. */ + if (nregs > 2) + regno2 = unwind_frame_regs[13 - i]; + else + regno2 = 0xff; + + if ((mask & (test << 1)) != 0 && regno2 == regno + 1 && (regno & 1) == 0) + { + i++; + nregs--; + } + + nregs--; + size += 2; + } + + if (!inc_sp) + ptr -= size; + + /* SP points just past the end of the stack. */ + ptr += 2; + nregs = __builtin_popcount (mask); + for (i = 0; i < 13; i++) + { + test = 1 << i; + if ((mask & test) == 0) + continue; + + regno = unwind_frame_regs[12 - i]; + if (nregs > 2) + regno2 = unwind_frame_regs[13 - i]; + else + regno2 = 0xff; + + if ((mask & (test << 1)) != 0 && regno2 == regno + 1 && (regno & 1) == 0) + { + /* Register pair. */ + unwind_restore_pair (context, regno, ptr); + i++; + nregs--; + } + else + { + /* Single register with padding. */ + _Unwind_VRS_Set (context, _UVRSC_CORE, regno, _UVRSD_UINT32, ptr); + } + + nregs--; + ptr += 2; + } + + ptr -= 2; + if ((mask & (1 << 11)) == 0) + _Unwind_VRS_Set (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &ptr); +} + +static void +pop_frame (_Unwind_Context * context, _uw mask, _uw *ptr, int inc_sp) +{ + int i; + int regno; + int nregs; + + nregs = __builtin_popcount (mask); + + if (!inc_sp) + ptr -= nregs; + else if (nregs & 1) + ptr++; + + ptr++; + for (i = 0; i < 13; i++) + { + if ((mask & (1 << i)) == 0) + continue; + regno = unwind_frame_regs[12 - i]; + if (i < 12 && unwind_frame_regs[13 - i] == (regno + 1) + && (mask & (1 << (i + 1))) != 0 + && (((_uw)ptr) & 4) == 0 + && (regno & 1) == 0) + { + unwind_restore_pair (context, regno, ptr); + i++; + ptr += 2; + } + else + { + _Unwind_VRS_Set (context, _UVRSC_CORE, regno, _UVRSD_UINT32, + ptr); + ptr++; + } + } + + ptr--; + if ((mask & (1 << 11)) == 0) + _Unwind_VRS_Set (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &ptr); +} + +/* Unwind a 24-bit encoded frame. */ +_Unwind_Reason_Code +__gnu_unwind_24bit (_Unwind_Context * context, _uw data, int compact) +{ + _uw offset; + _uw mask; + _uw *ptr; + _uw tmp; + + mask = (data >> 4) & 0x1fff; + + offset = (data >> 17) & 0x7f; + if (offset == 0x7f) + _Unwind_VRS_Get (context, _UVRSC_CORE, R_A15, _UVRSD_UINT32, &ptr); + else + { + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &ptr); + ptr += offset * 2; + } + + + if (compact) + pop_compact_frame (context, mask, ptr, offset != 0x7f); + else + pop_frame (context, mask, ptr, offset != 0x7f); + + _Unwind_VRS_Get (context, _UVRSC_CORE, unwind_frame_regs[data & 0xf], + _UVRSD_UINT32, &tmp); + _Unwind_VRS_Set (context, _UVRSC_CORE, R_PC, _UVRSD_UINT32, &tmp); + + return _URC_OK; +} + +static void +unwind_pop_rts (_Unwind_Context * context) +{ + _uw *ptr; + + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &ptr); +#ifdef _BIG_ENDIAN + _Unwind_VRS_Set (context, _UVRSC_CORE, R_B3, _UVRSD_UINT32, ptr + 1); +#else + _Unwind_VRS_Set (context, _UVRSC_CORE, R_B3, _UVRSD_UINT32, ptr + 2); +#endif + ptr += 3; + unwind_restore_pair (context, R_A10, ptr); + ptr += 2; + unwind_restore_pair (context, R_B10, ptr); + ptr += 2; + unwind_restore_pair (context, R_A12, ptr); + ptr += 2; + unwind_restore_pair (context, R_B12, ptr); + ptr += 2; + unwind_restore_pair (context, R_A14, ptr); + ptr += 2; + _Unwind_VRS_Set (context, _UVRSC_CORE, R_B14, _UVRSD_UINT32, ptr); + _Unwind_VRS_Set (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &ptr); + /* PC will be set by implicit RETURN opcode. */ +} + +/* Execute the unwinding instructions described by UWS. */ +_Unwind_Reason_Code +__gnu_unwind_execute (_Unwind_Context * context, __gnu_unwind_state * uws) +{ + _uw op; + int inc_sp; + _uw reg; + _uw *ptr; + + inc_sp = 1; + for (;;) + { + op = next_unwind_byte (uws); + if (op == CODE_FINISH) + { + /* Drop out of the loop. */ + break; + } + if ((op & 0xc0) == 0) + { + /* sp += (imm6 << 3) + 8. */ + _uw offset; + + offset = ((op & 0x3f) << 3) + 8; + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, ®); + reg += offset; + _Unwind_VRS_Set (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, ®); + continue; + } + + if (op == 0xd2) + { + /* vsp = vsp + 0x204 + (uleb128 << 2). */ + int shift; + + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, ®); + op = next_unwind_byte (uws); + shift = 3; + while (op & 0x80) + { + reg += ((op & 0x7f) << shift); + shift += 7; + op = next_unwind_byte (uws); + } + reg += ((op & 0x7f) << shift) + 0x408; + _Unwind_VRS_Set (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, ®); + continue; + } + + if ((op & 0xe0) == 0x80) + { + /* POP bitmask */ + _uw mask = ((op & 0x1f) << 8) | next_unwind_byte (uws); + + if (mask == 0) + { + /* CANTUNWIND */ + return _URC_FAILURE; + } + + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &ptr); + pop_frame (context, mask, ptr, inc_sp); + continue; + } + + if ((op & 0xe0) == 0xa0) + { + /* POP bitmask (compact) */ + _uw mask = ((op & 0x1f) << 8) | next_unwind_byte (uws); + + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &ptr); + pop_compact_frame (context, mask, ptr, inc_sp); + continue; + } + + if ((op & 0xf0) == 0xc0) + { + /* POP registers */ + int nregs = op & 0xf; + + _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &ptr); + while (nregs > 0) + { + op = next_unwind_byte (uws); + if ((op >> 4) != 0xf) + { + reg = unwind_frame_regs[op >> 4]; + _Unwind_VRS_Set (context, _UVRSC_CORE, reg, _UVRSD_UINT32, + ptr); + nregs--; + } + ptr--; + if ((op & 0xf) != 0xf) + { + reg = unwind_frame_regs[op & 0xf]; + _Unwind_VRS_Set (context, _UVRSC_CORE, reg, _UVRSD_UINT32, + ptr); + nregs--; + } + ptr--; + } + + continue; + } + + if (op == 0xd0) + { + /* MV FP, SP */ + inc_sp = 0; + _Unwind_VRS_Get (context, _UVRSC_CORE, R_A15, _UVRSD_UINT32, ®); + _Unwind_VRS_Set (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, ®); + continue; + } + + if (op == 0xd1) + { + /* __cx6abi_pop_rts */ + unwind_pop_rts (context); + break; + } + + if ((op & 0xf0) == 0xe0) + { + /* B3 = reg. RETURN case alreadh handled above. */ + int regno = unwind_frame_regs[op & 0xf]; + + _Unwind_VRS_Get (context, _UVRSC_CORE, regno, _UVRSD_UINT32, ®); + _Unwind_VRS_Set (context, _UVRSC_CORE, R_B3, _UVRSD_UINT32, ®); + continue; + } + + /* Reserved. */ + return _URC_FAILURE; + } + + /* Implicit RETURN. */ + _Unwind_VRS_Get (context, _UVRSC_CORE, R_B3, _UVRSD_UINT32, ®); + _Unwind_VRS_Set (context, _UVRSC_CORE, R_PC, _UVRSD_UINT32, ®); + return _URC_OK; +} + + +/* Execute the unwinding instructions associated with a frame. UCBP and + CONTEXT are the current exception object and virtual CPU state + respectively. */ + +_Unwind_Reason_Code +__gnu_unwind_frame (_Unwind_Control_Block * ucbp, _Unwind_Context * context) +{ + _uw *ptr; + __gnu_unwind_state uws; + + ptr = (_uw *) ucbp->pr_cache.ehtp; + /* Skip over the personality routine address. */ + ptr++; + /* Setup the unwinder state. */ + uws.data = (*ptr) << 8; + uws.next = ptr + 1; + uws.bytes_left = 3; + uws.words_left = ((*ptr) >> 24) & 0xff; + + return __gnu_unwind_execute (context, &uws); +} + +/* Data segment base pointer corresponding to the function catching + the exception. */ + +_Unwind_Ptr +_Unwind_GetDataRelBase (_Unwind_Context *context) +{ + return _Unwind_GetGR (context, R_B14); +} + +/* This should never be used. */ + +_Unwind_Ptr +_Unwind_GetTextRelBase (_Unwind_Context *context __attribute__ ((unused))) +{ + abort (); +} + +/* Only used by gcc personality routines, so can rely on a value they hid + there earlier. */ +_Unwind_Ptr +_Unwind_GetRegionStart (_Unwind_Context *context) +{ + _Unwind_Control_Block *ucbp; + + ucbp = (_Unwind_Control_Block *) _Unwind_GetGR (context, UNWIND_POINTER_REG); + return (_Unwind_Ptr) ucbp->pr_cache.fnstart; +} + +void * +_Unwind_GetLanguageSpecificData (_Unwind_Context *context) +{ + _Unwind_Control_Block *ucbp; + _uw *ptr; + + ucbp = (_Unwind_Control_Block *) _Unwind_GetGR (context, UNWIND_POINTER_REG); + ptr = (_uw *) ucbp->pr_cache.ehtp; + /* Skip the personality routine address. */ + ptr++; + /* Skip the unwind opcodes. */ + ptr += (((*ptr) >> 24) & 0xff) + 1; + + return ptr; +} diff --git a/libgcc/config/c6x/t-c6x-elf b/libgcc/config/c6x/t-c6x-elf new file mode 100644 index 00000000000..445de9b3224 --- /dev/null +++ b/libgcc/config/c6x/t-c6x-elf @@ -0,0 +1,4 @@ +LIB2ADDEH = $(srcdir)/config/c6x/unwind-c6x.c \ + $(srcdir)/config/c6x/libunwind.S \ + $(srcdir)/config/c6x/pr-support.c $(srcdir)/unwind-c.c + diff --git a/libgcc/config/c6x/unwind-c6x.c b/libgcc/config/c6x/unwind-c6x.c new file mode 100644 index 00000000000..da2f79ba4e1 --- /dev/null +++ b/libgcc/config/c6x/unwind-c6x.c @@ -0,0 +1,224 @@ +/* C6X EABI compliant unwinding routines. + Copyright (C) 2011 Free Software Foundation, Inc. + + 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/>. */ + +#include "unwind.h" + +/* Misc constants. */ +#define NUM_SAVED_REGS 32 +#define R_B0 16 +#define R_B3 (R_B0 + 3) +#define R_B15 (R_B0 + 15) +#define R_SP R_B15 +#define R_LR R_B3 +#define R_PC 33 + +#define VRS_PC(vrs) ((vrs)->core.pc) +#define VRS_SP(vrs) ((vrs)->core.reg[R_SP]) +#define VRS_RETURN(vrs) ((vrs)->core.reg[R_B3]) + +struct core_regs +{ + _uw reg[NUM_SAVED_REGS]; + _uw pc; +}; + +typedef struct +{ + /* The first fields must be the same as a phase2_vrs. */ + _uw demand_save_flags; /* Currently always zero. */ + struct core_regs core; + _uw prev_sp; /* Only valid during forced unwinding. */ +} phase1_vrs; + +/* This must match the structure created by the assembly wrappers. */ +typedef struct +{ + _uw demand_save_flags; + struct core_regs core; +} phase2_vrs; + +/* Coprocessor register state manipulation functions. */ + +/* Restore coprocessor state after phase1 unwinding. */ +static void +restore_non_core_regs (phase1_vrs * vrs __attribute__((unused))) +{ +} + +#include "unwind-arm-common.inc" + +/* ABI defined personality routines. */ +extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr0 (_Unwind_State, + _Unwind_Control_Block *, _Unwind_Context *);// __attribute__((weak)); +extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr1 (_Unwind_State, + _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak)); +extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr2 (_Unwind_State, + _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak)); +extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr3 (_Unwind_State, + _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak)); +extern _Unwind_Reason_Code __c6xabi_unwind_cpp_pr4 (_Unwind_State, + _Unwind_Control_Block *, _Unwind_Context *) __attribute__((weak)); + +/* ABI defined routine to store a virtual register to memory. */ + +_Unwind_VRS_Result _Unwind_VRS_Get (_Unwind_Context *context, + _Unwind_VRS_RegClass regclass, + _uw regno, + _Unwind_VRS_DataRepresentation representation, + void *valuep) +{ + phase1_vrs *vrs = (phase1_vrs *) context; + + switch (regclass) + { + case _UVRSC_CORE: + if (representation != _UVRSD_UINT32) + return _UVRSR_FAILED; + if (regno == R_PC) + { + *(_uw *) valuep = vrs->core.pc; + return _UVRSR_OK; + } + if (regno >= NUM_SAVED_REGS) + return _UVRSR_FAILED; + *(_uw *) valuep = vrs->core.reg[regno]; + return _UVRSR_OK; + + default: + return _UVRSR_FAILED; + } +} + + +/* ABI defined function to load a virtual register from memory. */ + +_Unwind_VRS_Result _Unwind_VRS_Set (_Unwind_Context *context, + _Unwind_VRS_RegClass regclass, + _uw regno, + _Unwind_VRS_DataRepresentation representation, + void *valuep) +{ + phase1_vrs *vrs = (phase1_vrs *) context; + + switch (regclass) + { + case _UVRSC_CORE: + if (representation != _UVRSD_UINT32) + return _UVRSR_FAILED; + if (regno == R_PC) + { + vrs->core.pc = *(_uw *) valuep; + return _UVRSR_OK; + } + if (regno >= NUM_SAVED_REGS) + return _UVRSR_FAILED; + + vrs->core.reg[regno] = *(_uw *) valuep; + return _UVRSR_OK; + + default: + return _UVRSR_FAILED; + } +} + + +/* Core unwinding functions. */ + +/* Calculate the address encoded by a 31-bit self-relative offset at address + P. */ +static inline _uw +selfrel_offset31 (const _uw *p) +{ + _uw offset; + + offset = *p << 1; + return offset + (_uw) p; +} + + +static _uw +__gnu_unwind_get_pr_addr (int idx) +{ + switch (idx) + { + case 0: + return (_uw) &__c6xabi_unwind_cpp_pr0; + + case 1: + return (_uw) &__c6xabi_unwind_cpp_pr1; + + case 2: + return (_uw) &__c6xabi_unwind_cpp_pr2; + + case 3: + return (_uw) &__c6xabi_unwind_cpp_pr3; + + case 4: + return (_uw) &__c6xabi_unwind_cpp_pr4; + + default: + return 0; + } +} + + +/* ABI defined personality routine entry points. */ + +_Unwind_Reason_Code +__c6xabi_unwind_cpp_pr0 (_Unwind_State state, + _Unwind_Control_Block *ucbp, + _Unwind_Context *context) +{ + return __gnu_unwind_pr_common (state, ucbp, context, 0); +} + +_Unwind_Reason_Code +__c6xabi_unwind_cpp_pr1 (_Unwind_State state, + _Unwind_Control_Block *ucbp, + _Unwind_Context *context) +{ + return __gnu_unwind_pr_common (state, ucbp, context, 1); +} + +_Unwind_Reason_Code +__c6xabi_unwind_cpp_pr2 (_Unwind_State state, + _Unwind_Control_Block *ucbp, + _Unwind_Context *context) +{ + return __gnu_unwind_pr_common (state, ucbp, context, 2); +} + +_Unwind_Reason_Code +__c6xabi_unwind_cpp_pr3 (_Unwind_State state, + _Unwind_Control_Block *ucbp, + _Unwind_Context *context) +{ + return __gnu_unwind_pr_common (state, ucbp, context, 3); +} + +_Unwind_Reason_Code +__c6xabi_unwind_cpp_pr4 (_Unwind_State state, + _Unwind_Control_Block *ucbp, + _Unwind_Context *context) +{ + return __gnu_unwind_pr_common (state, ucbp, context, 4); +} diff --git a/libgcc/config/c6x/unwind-c6x.h b/libgcc/config/c6x/unwind-c6x.h new file mode 100644 index 00000000000..3d6c73e7f9b --- /dev/null +++ b/libgcc/config/c6x/unwind-c6x.h @@ -0,0 +1,71 @@ +/* Header file for the C6X EABI unwinder + Copyright (C) 2011 + Free Software Foundation, Inc. + + 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/>. */ + +/* Language-independent unwinder header public defines. This contains both + ABI defined objects, and GNU support routines. */ + +#ifndef UNWIND_C6X_H +#define UNWIND_C6X_H + +/* Not really the ARM EABI, but pretty close. */ +#include "unwind-arm-common.h" + +#define UNWIND_STACK_REG 31 +/* Use A0 as a scratch register within the personality routine. */ +#define UNWIND_POINTER_REG 0 + +#ifdef __cplusplus +extern "C" { +#endif + _Unwind_Reason_Code __gnu_unwind_24bit (_Unwind_Context *, _uw, int); + + /* Decode an EH table reference to a typeinfo object. */ + static inline _Unwind_Word + _Unwind_decode_typeinfo_ptr (_Unwind_Ptr base, _Unwind_Word ptr) + { + _Unwind_Word tmp; + + tmp = *(_Unwind_Word *) ptr; + /* Zero values are always NULL. */ + if (!tmp) + return 0; + + /* SB-relative indirect. Propagate the bottom 2 bits, which can + contain referenceness information in gnu unwinding tables. */ + tmp += base; + tmp = *(_Unwind_Word *) (tmp & ~(_Unwind_Word)3) | (tmp & 3); + return tmp; + } + +#define _Unwind_GetIP(context) \ + (_Unwind_GetGR (context, 33)) + + +#define _Unwind_SetIP(context, val) \ + _Unwind_SetGR (context, 33, val) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* defined UNWIND_ARM_H */ |