Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / ada / s-mastop.ads
blob20efa01903d054009ba191611c69e75375b3c740
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- SYSTEM.MACHINE_STATE_OPERATIONS --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1999-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 -- --
33 ------------------------------------------------------------------------------
35 pragma Polling (Off);
36 -- We must turn polling off for this unit, because otherwise we get
37 -- elaboration circularities with System.Exception_Tables.
39 with System.Storage_Elements;
40 with System.Exceptions;
42 package System.Machine_State_Operations is
44 subtype Code_Loc is System.Address;
45 -- Code location used in building exception tables and for call
46 -- addresses when propagating an exception (also traceback table)
47 -- Values of this type are created by using Label'Address or
48 -- extracted from machine states using Get_Code_Loc.
50 type Machine_State is new System.Address;
51 -- The table based exception handling approach (see a-except.adb) isolates
52 -- the target dependent aspects using an abstract data type interface
53 -- to the type Machine_State, which is represented as a System.Address
54 -- value (presumably implemented as a pointer to an appropriate record
55 -- structure).
57 function Machine_State_Length return System.Storage_Elements.Storage_Offset;
58 -- Function to determine the length of the Storage_Array needed to hold
59 -- a machine state. The machine state will always be maximally aligned.
60 -- The value returned is a constant that will be used to allocate space
61 -- for a machine state value.
63 function Allocate_Machine_State return Machine_State;
64 -- Allocate the required space for a Machine_State
66 procedure Free_Machine_State (M : in out Machine_State);
67 -- Free the dynamic memory taken by Machine_State
69 -- The initial value of type Machine_State is created by the low level
70 -- routine that actually raises an exception using the special builtin
71 -- _builtin_machine_state. This value will typically encode the value
72 -- of the program counter, and relevant registers. The following
73 -- operations are defined on Machine_State values:
75 function Get_Code_Loc (M : Machine_State) return Code_Loc;
76 -- This function extracts the program counter value from a machine
77 -- state, which the caller uses for searching the exception tables,
78 -- and also for recording entries in the traceback table. The call
79 -- returns a value of Null_Loc if the machine state represents the
80 -- outer level, or some other frame for which no information can be
81 -- provided.
83 procedure Pop_Frame
84 (M : Machine_State;
85 Info : System.Exceptions.Subprogram_Info_Type);
86 -- This procedure pops the machine state M so that it represents the
87 -- call point, as though the current subprogram had returned. It
88 -- changes only the value referenced by M, and does not affect
89 -- the current stack environment.
91 -- The Info parameter represents information generated by the backend
92 -- (see description of Subprogram_Info node in sinfo.ads). This
93 -- information is stored as static data during compilation. The
94 -- caller then passes this information to Pop_Frame, which will
95 -- use it to determine what must be changed in the machine state
96 -- (e.g. which save-over-call registers must be restored, and from
97 -- where on the stack frame they must be restored).
99 -- A value of No_Info for Info means either that the backend provided
100 -- no information for current frame, or that the current frame is an
101 -- other language frame for which no information exists, or that this
102 -- is an outer level subprogram. In any case, Pop_Frame sets the code
103 -- location to Null_Address when it pops past such a frame, and this
104 -- is taken as an indication that the exception is unhandled.
106 -- Note: at the current time, Info, if present is always a copy of
107 -- the entry point of the procedure, as found by searching the
108 -- subprogram table. For the case where a procedure is indeed in
109 -- the table (either it is an Ada procedure, or a foreign procedure
110 -- which is registered using pragma Propagate_Exceptions), then the
111 -- entry point information will indeed be correct. It may well be
112 -- possible for Pop_Frame to avoid using the Info parameter (for
113 -- example if it consults auxiliary Dwarf tables to do its job).
114 -- This is desirable if it can be done, because it means that it
115 -- will work fine to propagate exceptions through unregistered
116 -- foreign procedures. What will happen is that the search in the
117 -- Ada subprogram table will find a junk entry. Even if this junk
118 -- entry has an exception table, none of them will apply to the
119 -- current location, so they will be ignored, and then Pop_Frame
120 -- will be called to pop the frame. The Info parameter for this
121 -- call will be junk, but if it is not used that does not matter.
122 -- Note that the address recorded in the traceback table is of
123 -- the exception location, so the traceback will be correct even
124 -- in this case.
126 procedure Enter_Handler
127 (M : Machine_State;
128 Handler : System.Exceptions.Handler_Loc);
129 -- When Propagate_Handler locates an applicable exception handler, it
130 -- calls Enter_Handler, passing it two parameters. The first is the
131 -- machine state that corresponds to what is required for entry to
132 -- the handler, as computed by repeated Pop_Frame calls to reach the
133 -- handler to be entered. The second is the code location for the
134 -- handler itself which is the address of the label at the start of
135 -- the handler code.
137 -- Note: The machine state M is likely stored on the part of the
138 -- stack that will be popped by the call, so care must be taken
139 -- not to pop the stack until the Machine_State is entirely read.
140 -- The value passed as Handler was obtained from elaboration of
141 -- an N_Handler_Loc node by the backend.
143 function Fetch_Code (Loc : Code_Loc) return Code_Loc;
144 -- Some architectures (notably VMS) use a descriptor to describe
145 -- a subprogram address. This function computes the actual starting
146 -- address of the code from Loc.
147 -- Do not add pragma Inline, see 9116-002.
148 -- ??? This function will go away when 'Code_Address is fixed on VMS.
150 procedure Set_Machine_State (M : Machine_State);
151 -- This routine sets M from the current machine state. It is called
152 -- when an exception is initially signalled to initialize the state.
154 procedure Set_Signal_Machine_State
155 (M : Machine_State;
156 Context : System.Address);
157 -- This routine sets M from the machine state that corresponds to the
158 -- point in the code where a signal was raised. The parameter Context
159 -- is a pointer to a structure created by the operating system when a
160 -- signal is raised, and made available to the signal handler. The
161 -- format of this context block, and the manner in which it is made
162 -- available to the handler, are implementation dependent.
164 end System.Machine_State_Operations;