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