1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- SYSTEM.MACHINE_STATE_OPERATIONS --
8 -- (Version for Alpha/VMS) --
12 -- Copyright (C) 2001 Ada Core Technologies, Inc. --
14 -- GNAT is free software; you can redistribute it and/or modify it under --
15 -- terms of the GNU General Public License as published by the Free Soft- --
16 -- ware Foundation; either version 2, or (at your option) any later ver- --
17 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
18 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
19 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
20 -- for more details. You should have received a copy of the GNU General --
21 -- Public License distributed with GNAT; see file COPYING. If not, write --
22 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
23 -- MA 02111-1307, USA. --
25 -- As a special exception, if other files instantiate generics from this --
26 -- unit, or you link this unit with other files to produce an executable, --
27 -- this unit does not by itself cause the resulting executable to be --
28 -- covered by the GNU General Public License. This exception does not --
29 -- however invalidate any other reasons why the executable file might be --
30 -- covered by the GNU Public License. --
32 -- GNAT was originally developed by the GNAT team at New York University. --
33 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
37 -- This version of System.Machine_State_Operations is for use on
38 -- Alpha systems running VMS.
41 with System
.Aux_DEC
; use System
.Aux_DEC
;
42 with Unchecked_Conversion
;
44 package body System
.Machine_State_Operations
is
46 use System
.Exceptions
;
47 subtype Cond_Value_Type
is Unsigned_Longword
;
49 -- Record layouts copied from Starlet.
51 type ICB_Fflags_Bits_Type
is record
52 Exception_Frame
: Boolean;
54 Bottom_Of_Stack
: Boolean;
56 Filler_1
: Unsigned_20
;
59 for ICB_Fflags_Bits_Type
use record
60 Exception_Frame
at 0 range 0 .. 0;
61 Ast_Frame
at 0 range 1 .. 1;
62 Bottom_Of_Stack
at 0 range 2 .. 2;
63 Base_Frame
at 0 range 3 .. 3;
64 Filler_1
at 0 range 4 .. 23;
66 for ICB_Fflags_Bits_Type
'Size use 24;
68 ICB_Fflags_Bits_Type_Init
: constant ICB_Fflags_Bits_Type
:=
69 (ExceptIon_Frame
=> False,
71 Bottom_Of_STACK
=> False,
75 type ICB_Hdr_Quad_Type
is record
76 Context_Length
: Unsigned_Longword
;
77 Fflags_Bits
: ICB_Fflags_Bits_Type
;
78 Block_Version
: Unsigned_Byte
;
81 for ICB_Hdr_Quad_Type
use record
82 Context_Length
at 0 range 0 .. 31;
83 Fflags_Bits
at 4 range 0 .. 23;
84 Block_Version
at 7 range 0 .. 7;
86 for ICB_Hdr_Quad_Type
'Size use 64;
88 ICB_Hdr_Quad_Type_Init
: constant ICB_Hdr_Quad_Type
:=
90 Fflags_Bits
=> ICB_Fflags_Bits_Type_Init
,
93 type Invo_Context_Blk_Type
is record
95 -- The first quadword contains:
96 -- o The length of the structure in bytes (a longword field)
97 -- o The frame flags (a 3 byte field of bits)
98 -- o The version number (a 1 byte field)
100 Hdr_Quad
: ICB_Hdr_Quad_Type
;
102 -- The address of the procedure descriptor for the procedure.
104 Procedure_Descriptor
: Unsigned_Quadword
;
106 -- The current PC of a given procedure invocation.
108 Program_Counter
: Integer_64
;
110 -- The current PS of a given procedure invocation.
112 Processor_Status
: Integer_64
;
114 -- The register contents areas. 31 for scalars, 31 for float.
116 Ireg
: Unsigned_Quadword_Array
(0 .. 30);
117 Freg
: Unsigned_Quadword_Array
(0 .. 30);
119 -- The following is an "internal" area that's reserved for use by
120 -- the operating system. It's size may vary over time.
122 System_Defined
: Unsigned_Quadword_Array
(0 .. 1);
124 ----Component(s) below are defined as comments since they
125 ----overlap other fields
127 ----Chfctx_Addr : Unsigned_Quadword;
130 -- Align to octaword.
132 Filler_1
: String (1 .. 0);
135 for Invo_Context_Blk_Type
use record
136 Hdr_Quad
at 0 range 0 .. 63;
137 Procedure_Descriptor
at 8 range 0 .. 63;
138 Program_Counter
at 16 range 0 .. 63;
139 Processor_Status
at 24 range 0 .. 63;
140 Ireg
at 32 range 0 .. 1983;
141 Freg
at 280 range 0 .. 1983;
142 System_Defined
at 528 range 0 .. 127;
144 ----Component representation spec(s) below are defined as
145 ----comments since they overlap other fields
147 ----Chfctx_Addr at 528 range 0 .. 63;
149 Filler_1
at 544 range 0 .. -1;
151 for Invo_Context_Blk_Type
'Size use 4352;
153 Invo_Context_Blk_Type_Init
: constant Invo_Context_Blk_Type
:=
154 (Hdr_Quad
=> ICB_Hdr_Quad_Type_Init
,
155 Procedure_Descriptor
=> (0, 0),
156 Program_Counter
=> 0,
157 Processor_Status
=> 0,
158 Ireg
=> (others => (0, 0)),
159 Freg
=> (others => (0, 0)),
160 System_Defined
=> (others => (0, 0)),
161 Filler_1
=> (others => ASCII
.NUL
));
163 subtype Invo_Handle_Type
is Unsigned_Longword
;
165 type Invo_Handle_Access_Type
is access all Invo_Handle_Type
;
167 function Fetch
is new Fetch_From_Address
(Code_Loc
);
169 function To_Invo_Handle_Access
is new Unchecked_Conversion
170 (Machine_State
, Invo_Handle_Access_Type
);
172 function To_Machine_State
is new Unchecked_Conversion
173 (System
.Address
, Machine_State
);
175 function To_Code_Loc
is new Unchecked_Conversion
176 (Unsigned_Longword
, Code_Loc
);
178 ----------------------------
179 -- Allocate_Machine_State --
180 ----------------------------
182 function Allocate_Machine_State
return Machine_State
is
184 return To_Machine_State
185 (Memory
.Alloc
(Invo_Handle_Type
'Max_Size_In_Storage_Elements));
186 end Allocate_Machine_State
;
192 procedure Enter_Handler
(M
: Machine_State
; Handler
: Handler_Loc
) is
193 procedure Get_Invo_Context
(
194 Result
: out Unsigned_Longword
; -- return value
195 Invo_Handle
: in Invo_Handle_Type
;
196 Invo_Context
: out Invo_Context_Blk_Type
);
198 pragma Interface
(External
, Get_Invo_Context
);
200 pragma Import_Valued_Procedure
(Get_Invo_Context
, "LIB$GET_INVO_CONTEXT",
201 (Unsigned_Longword
, Invo_Handle_Type
, Invo_Context_Blk_Type
),
202 (Value
, Value
, Reference
));
204 ICB
: Invo_Context_Blk_Type
;
206 procedure Goto_Unwind
(
207 Status
: out Cond_Value_Type
; -- return value
208 Target_Invo
: in Address
:= Address_Zero
;
209 Target_PC
: in Address
:= Address_Zero
;
210 New_R0
: in Unsigned_Quadword
211 := Unsigned_Quadword
'Null_Parameter;
212 New_R1
: in Unsigned_Quadword
213 := Unsigned_Quadword
'Null_Parameter);
215 pragma Interface
(External
, Goto_Unwind
);
217 pragma Import_Valued_Procedure
218 (Goto_Unwind
, "SYS$GOTO_UNWIND",
219 (Cond_Value_Type
, Address
, Address
,
220 Unsigned_Quadword
, Unsigned_Quadword
),
221 (Value
, Reference
, Reference
,
222 Reference
, Reference
));
224 Status
: Cond_Value_Type
;
227 Get_Invo_Context
(Status
, To_Invo_Handle_Access
(M
).all, ICB
);
229 (Status
, System
.Address
(To_Invo_Handle_Access
(M
).all), Handler
);
236 function Fetch_Code
(Loc
: Code_Loc
) return Code_Loc
is
238 -- The starting address is in the second longword pointed to by Loc.
239 return Fetch
(System
.Aux_DEC
."+" (Loc
, 8));
242 ------------------------
243 -- Free_Machine_State --
244 ------------------------
246 procedure Free_Machine_State
(M
: in out Machine_State
) is
247 procedure Gnat_Free
(M
: in Invo_Handle_Access_Type
);
248 pragma Import
(C
, Gnat_Free
, "__gnat_free");
251 Gnat_Free
(To_Invo_Handle_Access
(M
));
252 M
:= Machine_State
(Null_Address
);
253 end Free_Machine_State
;
259 function Get_Code_Loc
(M
: Machine_State
) return Code_Loc
is
260 procedure Get_Invo_Context
(
261 Result
: out Unsigned_Longword
; -- return value
262 Invo_Handle
: in Invo_Handle_Type
;
263 Invo_Context
: out Invo_Context_Blk_Type
);
265 pragma Interface
(External
, Get_Invo_Context
);
267 pragma Import_Valued_Procedure
(Get_Invo_Context
, "LIB$GET_INVO_CONTEXT",
268 (Unsigned_Longword
, Invo_Handle_Type
, Invo_Context_Blk_Type
),
269 (Value
, Value
, Reference
));
271 Asm_Call_Size
: constant := 4;
273 -- asm instruction takes 4 bytes. So we must remove this amount.
275 ICB
: Invo_Context_Blk_Type
;
276 Status
: Cond_Value_Type
;
279 Get_Invo_Context
(Status
, To_Invo_Handle_Access
(M
).all, ICB
);
280 if (Status
and 1) /= 1 then
281 return Code_Loc
(System
.Null_Address
);
283 return Code_Loc
(ICB
.Program_Counter
- Asm_Call_Size
);
286 --------------------------
287 -- Machine_State_Length --
288 --------------------------
290 function Machine_State_Length
291 return System
.Storage_Elements
.Storage_Offset
293 use System
.Storage_Elements
;
296 return Invo_Handle_Type
'Size / 8;
297 end Machine_State_Length
;
305 Info
: Subprogram_Info_Type
)
308 procedure Get_Prev_Invo_Handle
(
309 Result
: out Invo_Handle_Type
; -- return value
310 ICB
: in Invo_Handle_Type
);
312 pragma Interface
(External
, Get_Prev_Invo_Handle
);
314 pragma Import_Valued_Procedure
315 (Get_Prev_Invo_Handle
, "LIB$GET_PREV_INVO_HANDLE",
316 (Invo_Handle_Type
, Invo_Handle_Type
),
319 Prev_Handle
: aliased Invo_Handle_Type
;
322 Get_Prev_Invo_Handle
(Prev_Handle
, To_Invo_Handle_Access
(M
).all);
323 To_Invo_Handle_Access
(M
).all := Prev_Handle
;
326 -----------------------
327 -- Set_Machine_State --
328 -----------------------
330 procedure Set_Machine_State
(M
: Machine_State
) is
332 procedure Get_Curr_Invo_Context
333 (Invo_Context
: out Invo_Context_Blk_Type
);
335 pragma Interface
(External
, Get_Curr_Invo_Context
);
337 pragma Import_Valued_Procedure
338 (Get_Curr_Invo_Context
, "LIB$GET_CURR_INVO_CONTEXT",
339 (Invo_Context_Blk_Type
),
342 procedure Get_Invo_Handle
(
343 Result
: out Invo_Handle_Type
; -- return value
344 Invo_Context
: in Invo_Context_Blk_Type
);
346 pragma Interface
(External
, Get_Invo_Handle
);
348 pragma Import_Valued_Procedure
(Get_Invo_Handle
, "LIB$GET_INVO_HANDLE",
349 (Invo_Handle_Type
, Invo_Context_Blk_Type
),
352 ICB
: Invo_Context_Blk_Type
;
353 Invo_Handle
: aliased Invo_Handle_Type
;
356 Get_Curr_Invo_Context
(ICB
);
357 Get_Invo_Handle
(Invo_Handle
, ICB
);
358 To_Invo_Handle_Access
(M
).all := Invo_Handle
;
359 Pop_Frame
(M
, System
.Null_Address
);
360 end Set_Machine_State
;
362 ------------------------------
363 -- Set_Signal_Machine_State --
364 ------------------------------
366 procedure Set_Signal_Machine_State
368 Context
: System
.Address
) is
371 end Set_Signal_Machine_State
;
373 end System
.Machine_State_Operations
;