1 // Exception handling and frame unwind runtime interface routines.
2 // Copyright (C) 2011-2020 Free Software Foundation, Inc.
3 
4 // GCC is free software; you can redistribute it and/or modify it under
5 // the terms of the GNU General Public License as published by the Free
6 // Software Foundation; either version 3, or (at your option) any later
7 // version.
8 
9 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
10 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 // for more details.
13 
14 // Under Section 7 of GPL version 3, you are granted additional
15 // permissions described in the GCC Runtime Library Exception, version
16 // 3.1, as published by the Free Software Foundation.
17 
18 // You should have received a copy of the GNU General Public License and
19 // a copy of the GCC Runtime Library Exception along with this program;
20 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21 // <http://www.gnu.org/licenses/>.
22 
23 // extern(C) interface for the ARM EABI unwinder library.
24 // This corresponds to unwind-arm.h
25 
26 module gcc.unwind.arm;
27 
28 import gcc.config;
29 
30 version (ARM):
31 static if (GNU_ARM_EABI_Unwinder):
32 
33 public import gcc.unwind.arm_common;
34 import gcc.unwind.pe;
35 
36 extern (C):
37 @nogc:
38 
39 enum int UNWIND_STACK_REG = 13;
40 // Use IP as a scratch register within the personality routine.
41 enum int UNWIND_POINTER_REG = 12;
42 
43 version (linux)
44     enum _TTYPE_ENCODING = (DW_EH_PE_pcrel | DW_EH_PE_indirect);
45 else version (NetBSD)
46     enum _TTYPE_ENCODING = (DW_EH_PE_pcrel | DW_EH_PE_indirect);
47 else version (FreeBSD)
48     enum _TTYPE_ENCODING = (DW_EH_PE_pcrel | DW_EH_PE_indirect);
49 else version (Symbian)
50     enum _TTYPE_ENCODING = (DW_EH_PE_absptr);
51 else version (uClinux)
52     enum _TTYPE_ENCODING = (DW_EH_PE_absptr);
53 else
54     enum _TTYPE_ENCODING = (DW_EH_PE_pcrel);
55 
56 // Return the address of the instruction, not the actual IP value.
_Unwind_GetIP(_Unwind_Context * context)57 _Unwind_Word _Unwind_GetIP(_Unwind_Context* context)
58 {
59     return _Unwind_GetGR(context, 15) & ~ cast(_Unwind_Word) 1;
60 }
61 
_Unwind_SetIP(_Unwind_Context * context,_Unwind_Word val)62 void _Unwind_SetIP(_Unwind_Context* context, _Unwind_Word val)
63 {
64     return _Unwind_SetGR(context, 15, val | (_Unwind_GetGR(context, 15) & 1));
65 }
66 
_Unwind_GetIPInfo(_Unwind_Context * context,int * ip_before_insn)67 _Unwind_Word _Unwind_GetIPInfo(_Unwind_Context* context, int* ip_before_insn)
68 {
69     *ip_before_insn = 0;
70     return _Unwind_GetIP(context);
71 }
72