1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- SYSTEM.MACHINE_STATE_OPERATIONS --
8 -- (Version for Alpha/VMS) --
10 -- Copyright (C) 2001-2007, AdaCore --
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, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, USA. --
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. --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
35 -- This version of System.Machine_State_Operations is for use on
36 -- Alpha systems running VMS.
39 with System
.Aux_DEC
; use System
.Aux_DEC
;
40 with Ada
.Unchecked_Conversion
;
42 package body System
.Machine_State_Operations
is
44 subtype Cond_Value_Type
is Unsigned_Longword
;
46 -- Record layouts copied from Starlet
48 type ICB_Fflags_Bits_Type
is record
49 Exception_Frame
: Boolean;
51 Bottom_Of_Stack
: Boolean;
53 Filler_1
: Unsigned_20
;
56 for ICB_Fflags_Bits_Type
use record
57 Exception_Frame
at 0 range 0 .. 0;
58 Ast_Frame
at 0 range 1 .. 1;
59 Bottom_Of_Stack
at 0 range 2 .. 2;
60 Base_Frame
at 0 range 3 .. 3;
61 Filler_1
at 0 range 4 .. 23;
63 for ICB_Fflags_Bits_Type
'Size use 24;
65 type ICB_Hdr_Quad_Type
is record
66 Context_Length
: Unsigned_Longword
;
67 Fflags_Bits
: ICB_Fflags_Bits_Type
;
68 Block_Version
: Unsigned_Byte
;
71 for ICB_Hdr_Quad_Type
use record
72 Context_Length
at 0 range 0 .. 31;
73 Fflags_Bits
at 4 range 0 .. 23;
74 Block_Version
at 7 range 0 .. 7;
76 for ICB_Hdr_Quad_Type
'Size use 64;
78 type Invo_Context_Blk_Type
is record
80 Hdr_Quad
: ICB_Hdr_Quad_Type
;
81 -- The first quadword contains:
82 -- o The length of the structure in bytes (a longword field)
83 -- o The frame flags (a 3 byte field of bits)
84 -- o The version number (a 1 byte field)
86 Procedure_Descriptor
: Unsigned_Quadword
;
87 -- The address of the procedure descriptor for the procedure
89 Program_Counter
: Integer_64
;
90 -- The current PC of a given procedure invocation
92 Processor_Status
: Integer_64
;
93 -- The current PS of a given procedure invocation
95 Ireg
: Unsigned_Quadword_Array
(0 .. 30);
96 Freg
: Unsigned_Quadword_Array
(0 .. 30);
97 -- The register contents areas. 31 for scalars, 31 for float
99 System_Defined
: Unsigned_Quadword_Array
(0 .. 1);
100 -- The following is an "internal" area that's reserved for use by
101 -- the operating system. It's size may vary over time.
103 -- Chfctx_Addr : Unsigned_Quadword;
104 -- Defined as a comment since it overlaps other fields
106 Filler_1
: String (1 .. 0);
110 for Invo_Context_Blk_Type
use record
111 Hdr_Quad
at 0 range 0 .. 63;
112 Procedure_Descriptor
at 8 range 0 .. 63;
113 Program_Counter
at 16 range 0 .. 63;
114 Processor_Status
at 24 range 0 .. 63;
115 Ireg
at 32 range 0 .. 1983;
116 Freg
at 280 range 0 .. 1983;
117 System_Defined
at 528 range 0 .. 127;
119 -- Component representation spec(s) below are defined as
120 -- comments since they overlap other fields
122 -- Chfctx_Addr at 528 range 0 .. 63;
124 Filler_1
at 544 range 0 .. -1;
126 for Invo_Context_Blk_Type
'Size use 4352;
128 subtype Invo_Handle_Type
is Unsigned_Longword
;
130 type Invo_Handle_Access_Type
is access all Invo_Handle_Type
;
132 function Fetch
is new Fetch_From_Address
(Code_Loc
);
134 function To_Invo_Handle_Access
is new Ada
.Unchecked_Conversion
135 (Machine_State
, Invo_Handle_Access_Type
);
137 function To_Machine_State
is new Ada
.Unchecked_Conversion
138 (System
.Address
, Machine_State
);
140 ----------------------------
141 -- Allocate_Machine_State --
142 ----------------------------
144 function Allocate_Machine_State
return Machine_State
is
146 return To_Machine_State
147 (Memory
.Alloc
(Invo_Handle_Type
'Max_Size_In_Storage_Elements));
148 end Allocate_Machine_State
;
154 function Fetch_Code
(Loc
: Code_Loc
) return Code_Loc
is
156 -- The starting address is in the second longword pointed to by Loc
158 return Fetch
(System
.Aux_DEC
."+" (Loc
, 8));
161 ------------------------
162 -- Free_Machine_State --
163 ------------------------
165 procedure Free_Machine_State
(M
: in out Machine_State
) is
167 Memory
.Free
(Address
(M
));
168 M
:= Machine_State
(Null_Address
);
169 end Free_Machine_State
;
175 function Get_Code_Loc
(M
: Machine_State
) return Code_Loc
is
176 procedure Get_Invo_Context
(
177 Result
: out Unsigned_Longword
; -- return value
178 Invo_Handle
: Invo_Handle_Type
;
179 Invo_Context
: out Invo_Context_Blk_Type
);
181 pragma Interface
(External
, Get_Invo_Context
);
183 pragma Import_Valued_Procedure
(Get_Invo_Context
, "LIB$GET_INVO_CONTEXT",
184 (Unsigned_Longword
, Invo_Handle_Type
, Invo_Context_Blk_Type
),
185 (Value
, Value
, Reference
));
187 Asm_Call_Size
: constant := 4;
189 -- asm instruction takes 4 bytes. So we must remove this amount.
191 ICB
: Invo_Context_Blk_Type
;
192 Status
: Cond_Value_Type
;
195 Get_Invo_Context
(Status
, To_Invo_Handle_Access
(M
).all, ICB
);
197 if (Status
and 1) /= 1 then
198 return Code_Loc
(System
.Null_Address
);
201 return Code_Loc
(ICB
.Program_Counter
- Asm_Call_Size
);
204 --------------------------
205 -- Machine_State_Length --
206 --------------------------
208 function Machine_State_Length
209 return System
.Storage_Elements
.Storage_Offset
211 use System
.Storage_Elements
;
214 return Invo_Handle_Type
'Size / 8;
215 end Machine_State_Length
;
221 procedure Pop_Frame
(M
: Machine_State
) is
222 procedure Get_Prev_Invo_Handle
(
223 Result
: out Invo_Handle_Type
; -- return value
224 ICB
: Invo_Handle_Type
);
226 pragma Interface
(External
, Get_Prev_Invo_Handle
);
228 pragma Import_Valued_Procedure
229 (Get_Prev_Invo_Handle
, "LIB$GET_PREV_INVO_HANDLE",
230 (Invo_Handle_Type
, Invo_Handle_Type
),
233 Prev_Handle
: aliased Invo_Handle_Type
;
236 Get_Prev_Invo_Handle
(Prev_Handle
, To_Invo_Handle_Access
(M
).all);
237 To_Invo_Handle_Access
(M
).all := Prev_Handle
;
240 -----------------------
241 -- Set_Machine_State --
242 -----------------------
244 procedure Set_Machine_State
(M
: Machine_State
) is
246 procedure Get_Curr_Invo_Context
247 (Invo_Context
: out Invo_Context_Blk_Type
);
249 pragma Interface
(External
, Get_Curr_Invo_Context
);
251 pragma Import_Valued_Procedure
252 (Get_Curr_Invo_Context
, "LIB$GET_CURR_INVO_CONTEXT",
253 (Invo_Context_Blk_Type
),
256 procedure Get_Invo_Handle
(
257 Result
: out Invo_Handle_Type
; -- return value
258 Invo_Context
: Invo_Context_Blk_Type
);
260 pragma Interface
(External
, Get_Invo_Handle
);
262 pragma Import_Valued_Procedure
(Get_Invo_Handle
, "LIB$GET_INVO_HANDLE",
263 (Invo_Handle_Type
, Invo_Context_Blk_Type
),
266 ICB
: Invo_Context_Blk_Type
;
267 Invo_Handle
: aliased Invo_Handle_Type
;
270 Get_Curr_Invo_Context
(ICB
);
271 Get_Invo_Handle
(Invo_Handle
, ICB
);
272 To_Invo_Handle_Access
(M
).all := Invo_Handle
;
273 Pop_Frame
(M
, System
.Null_Address
);
274 end Set_Machine_State
;
276 end System
.Machine_State_Operations
;