[multiple changes]
[gcc.git] / gcc / ada / s-excmac-arm.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . E X C E P T I O N S . M A C H I N E --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2013, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- This is the version using the ARM EHABI mechanism
33
34 with Ada.Unchecked_Conversion;
35 with Ada.Exceptions;
36
37 package System.Exceptions.Machine is
38 pragma Preelaborate;
39
40 ------------------------------------------------
41 -- Entities to interface with the GCC runtime --
42 ------------------------------------------------
43
44 -- Return codes from GCC runtime functions used to propagate an exception
45
46 type Unwind_Reason_Code is
47 (URC_OK,
48 URC_FOREIGN_EXCEPTION_CAUGHT,
49 URC_Unused2,
50 URC_Unused3,
51 URC_Unused4,
52 URC_Unused5,
53 URC_HANDLER_FOUND,
54 URC_INSTALL_CONTEXT,
55 URC_CONTINUE_UNWIND,
56 URC_FAILURE);
57
58 pragma Unreferenced
59 (URC_OK,
60 URC_FOREIGN_EXCEPTION_CAUGHT,
61 URC_Unused2,
62 URC_Unused3,
63 URC_Unused4,
64 URC_Unused5,
65 URC_HANDLER_FOUND,
66 URC_INSTALL_CONTEXT,
67 URC_CONTINUE_UNWIND,
68 URC_FAILURE);
69
70 pragma Convention (C, Unwind_Reason_Code);
71 subtype Unwind_Action is Unwind_Reason_Code;
72 -- Phase identifiers
73
74 type uint32_t is mod 2**32;
75 pragma Convention (C, uint32_t);
76
77 type uint32_t_array is array (Natural range <>) of uint32_t;
78 pragma Convention (C, uint32_t_array);
79
80 type Unwind_State is new uint32_t;
81 pragma Convention (C, Unwind_State);
82
83 US_VIRTUAL_UNWIND_FRAME : constant Unwind_State := 0;
84 US_UNWIND_FRAME_STARTING : constant Unwind_State := 1;
85 US_UNWIND_FRAME_RESUME : constant Unwind_State := 2;
86
87 pragma Unreferenced
88 (US_VIRTUAL_UNWIND_FRAME,
89 US_UNWIND_FRAME_STARTING,
90 US_UNWIND_FRAME_RESUME);
91
92 -- Mandatory common header for any exception object handled by the
93 -- GCC unwinding runtime.
94
95 type Exception_Class is array (0 .. 7) of Character;
96
97 GNAT_Exception_Class : constant Exception_Class := "GNU-Ada" & ASCII.NUL;
98 -- "GNU-Ada\0"
99
100 type Unwinder_Cache_Type is record
101 Reserved1 : uint32_t;
102 Reserved2 : uint32_t;
103 Reserved3 : uint32_t;
104 Reserved4 : uint32_t;
105 Reserved5 : uint32_t;
106 end record;
107
108 type Barrier_Cache_Type is record
109 Sp : uint32_t;
110 Bitpattern : uint32_t_array (0 .. 4);
111 end record;
112
113 type Cleanup_Cache_Type is record
114 Bitpattern : uint32_t_array (0 .. 3);
115 end record;
116
117 type Pr_Cache_Type is record
118 Fnstart : uint32_t;
119 Ehtp : System.Address;
120 Additional : uint32_t;
121 Reserved1 : uint32_t;
122 end record;
123
124 type Unwind_Control_Block is record
125 Class : Exception_Class;
126 Cleanup : System.Address;
127
128 -- Caches
129 Unwinder_Cache : Unwinder_Cache_Type;
130 Barrier_Cache : Barrier_Cache_Type;
131 Cleanup_Cache : Cleanup_Cache_Type;
132 Pr_Cache : Pr_Cache_Type;
133 end record;
134 pragma Convention (C, Unwind_Control_Block);
135 for Unwind_Control_Block'Alignment use 8;
136 -- Map the GCC struct used for exception handling
137
138 type Unwind_Control_Block_Access is access all Unwind_Control_Block;
139 subtype GCC_Exception_Access is Unwind_Control_Block_Access;
140 -- Pointer to a UCB
141
142 procedure Unwind_DeleteException
143 (Ucbp : not null Unwind_Control_Block_Access);
144 pragma Import (C, Unwind_DeleteException, "_Unwind_DeleteException");
145 -- Procedure to free any GCC exception
146
147 --------------------------------------------------------------
148 -- GNAT Specific Entities To Deal With The GCC EH Circuitry --
149 --------------------------------------------------------------
150
151 -- A GNAT exception object to be dealt with by the personality routine
152 -- called by the GCC unwinding runtime.
153
154 type GNAT_GCC_Exception is record
155 Header : Unwind_Control_Block;
156 -- ABI Exception header first
157
158 Occurrence : aliased Ada.Exceptions.Exception_Occurrence;
159 -- The Ada occurrence
160 end record;
161
162 pragma Convention (C, GNAT_GCC_Exception);
163
164 type GNAT_GCC_Exception_Access is access all GNAT_GCC_Exception;
165
166 function To_GCC_Exception is new
167 Ada.Unchecked_Conversion (System.Address, GCC_Exception_Access);
168
169 function To_GNAT_GCC_Exception is new
170 Ada.Unchecked_Conversion
171 (GCC_Exception_Access, GNAT_GCC_Exception_Access);
172
173 function New_Occurrence return GNAT_GCC_Exception_Access is
174 (new GNAT_GCC_Exception'
175 (Header => (Class => GNAT_Exception_Class,
176 Unwinder_Cache => (Reserved1 => 0,
177 others => <>),
178 others => <>),
179 Occurrence => <>));
180 -- Allocate and initialize a machine occurrence
181 end System.Exceptions.Machine;