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-2019, 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-- Declaration of the machine exception and some associated facilities. The 33-- machine exception is the object that is propagated by low level routines 34-- and that contains the Ada exception occurrence. 35 36-- This is the version using the ARM EHABI mechanism 37 38with Ada.Unchecked_Conversion; 39with Ada.Exceptions; 40 41package System.Exceptions.Machine is 42 pragma Preelaborate; 43 44 ------------------------------------------------ 45 -- Entities to interface with the GCC runtime -- 46 ------------------------------------------------ 47 48 -- Return codes from GCC runtime functions used to propagate an exception 49 50 type Unwind_Reason_Code is 51 (URC_OK, 52 URC_FOREIGN_EXCEPTION_CAUGHT, 53 URC_Unused2, 54 URC_Unused3, 55 URC_Unused4, 56 URC_Unused5, 57 URC_HANDLER_FOUND, 58 URC_INSTALL_CONTEXT, 59 URC_CONTINUE_UNWIND, 60 URC_FAILURE); 61 pragma Convention (C, Unwind_Reason_Code); 62 63 pragma Unreferenced 64 (URC_OK, 65 URC_FOREIGN_EXCEPTION_CAUGHT, 66 URC_Unused2, 67 URC_Unused3, 68 URC_Unused4, 69 URC_Unused5, 70 URC_HANDLER_FOUND, 71 URC_INSTALL_CONTEXT, 72 URC_CONTINUE_UNWIND, 73 URC_FAILURE); 74 75 -- ARM Unwinding State 76 77 type uint32_t is mod 2**32; 78 pragma Convention (C, uint32_t); 79 80 type uint32_t_array is array (Natural range <>) of uint32_t; 81 pragma Convention (C, uint32_t_array); 82 83 type Unwind_State is new uint32_t; 84 pragma Convention (C, Unwind_State); 85 86 US_VIRTUAL_UNWIND_FRAME : constant Unwind_State := 0; 87 US_UNWIND_FRAME_STARTING : constant Unwind_State := 1; 88 US_UNWIND_FRAME_RESUME : constant Unwind_State := 2; 89 90 pragma Unreferenced 91 (US_VIRTUAL_UNWIND_FRAME, 92 US_UNWIND_FRAME_STARTING, 93 US_UNWIND_FRAME_RESUME); 94 95 -- Mandatory common header for any exception object handled by the 96 -- GCC unwinding runtime. 97 98 type Exception_Class is array (0 .. 7) of Character; 99 100 GNAT_Exception_Class : constant Exception_Class := "GNU-Ada" & ASCII.NUL; 101 -- "GNU-Ada\0" 102 103 type Unwinder_Cache_Type is record 104 Reserved1 : uint32_t; 105 Reserved2 : uint32_t; 106 Reserved3 : uint32_t; 107 Reserved4 : uint32_t; 108 Reserved5 : uint32_t; 109 end record; 110 111 type Barrier_Cache_Type is record 112 Sp : uint32_t; 113 Bitpattern : uint32_t_array (0 .. 4); 114 end record; 115 116 type Cleanup_Cache_Type is record 117 Bitpattern : uint32_t_array (0 .. 3); 118 end record; 119 120 type Pr_Cache_Type is record 121 Fnstart : uint32_t; 122 Ehtp : System.Address; 123 Additional : uint32_t; 124 Reserved1 : uint32_t; 125 end record; 126 127 type Unwind_Control_Block is record 128 Class : Exception_Class; 129 Cleanup : System.Address; 130 131 -- Caches 132 Unwinder_Cache : Unwinder_Cache_Type; 133 Barrier_Cache : Barrier_Cache_Type; 134 Cleanup_Cache : Cleanup_Cache_Type; 135 Pr_Cache : Pr_Cache_Type; 136 end record; 137 pragma Convention (C, Unwind_Control_Block); 138 for Unwind_Control_Block'Alignment use 8; 139 -- Map the GCC struct used for exception handling 140 141 type Unwind_Control_Block_Access is access all Unwind_Control_Block; 142 subtype GCC_Exception_Access is Unwind_Control_Block_Access; 143 -- Pointer to a UCB 144 145 procedure Unwind_DeleteException 146 (Ucbp : not null Unwind_Control_Block_Access); 147 pragma Import (C, Unwind_DeleteException, "_Unwind_DeleteException"); 148 -- Procedure to free any GCC exception 149 150 -------------------------------------------------------------- 151 -- GNAT Specific Entities To Deal With The GCC EH Circuitry -- 152 -------------------------------------------------------------- 153 154 -- A GNAT exception object to be dealt with by the personality routine 155 -- called by the GCC unwinding runtime. 156 157 type GNAT_GCC_Exception is record 158 Header : Unwind_Control_Block; 159 -- ABI Exception header first 160 161 Occurrence : aliased Ada.Exceptions.Exception_Occurrence; 162 -- The Ada occurrence 163 end record; 164 165 pragma Convention (C, GNAT_GCC_Exception); 166 167 type GNAT_GCC_Exception_Access is access all GNAT_GCC_Exception; 168 169 function To_GCC_Exception is new 170 Ada.Unchecked_Conversion (System.Address, GCC_Exception_Access); 171 172 function To_GNAT_GCC_Exception is new 173 Ada.Unchecked_Conversion 174 (GCC_Exception_Access, GNAT_GCC_Exception_Access); 175 176 function New_Occurrence return GNAT_GCC_Exception_Access; 177 -- Allocate and initialize a machine occurrence 178 179end System.Exceptions.Machine; 180