1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . A U X _ D E C --
9 -- Copyright (C) 1996-2007, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 ------------------------------------------------------------------------------
34 -- This package contains definitions that are designed to be compatible
35 -- with the extra definitions in package System for DEC Ada implementations.
37 -- These definitions can be used directly by withing this package, or merged
38 -- with System using pragma Extend_System (Aux_DEC)
40 -- This is the VMS 64 bit version
42 with Ada
.Unchecked_Conversion
;
44 package System
.Aux_DEC
is
47 type Short_Integer_Address
is
48 range -2 ** (32 - 1) .. +2 ** (32 - 1) - 1;
49 -- Integer literals cannot appear naked in an address context, as a
50 -- result the bounds of Short_Address cannot be given simply as 2^32 etc.
52 subtype Short_Address
is Address
53 range Address
(Short_Integer_Address
'First) ..
54 Address
(Short_Integer_Address
'Last);
55 for Short_Address
'Object_Size use 32;
56 -- This subtype allows addresses to be converted from 64 bits to 32 bits
57 -- with an appropriate range check. Note that since this is a subtype of
58 -- type System.Address, the same limitations apply to this subtype. Namely
59 -- there are no visible arithmetic operations, and integer literals are
62 Short_Memory_Size
: constant := 2 ** 32;
63 -- Defined for convenience of porting
65 type Integer_8
is range -2 ** (8 - 1) .. +2 ** (8 - 1) - 1;
66 for Integer_8
'Size use 8;
68 type Integer_16
is range -2 ** (16 - 1) .. +2 ** (16 - 1) - 1;
69 for Integer_16
'Size use 16;
71 type Integer_32
is range -2 ** (32 - 1) .. +2 ** (32 - 1) - 1;
72 for Integer_32
'Size use 32;
74 type Integer_64
is range -2 ** (64 - 1) .. +2 ** (64 - 1) - 1;
75 for Integer_64
'Size use 64;
77 type Largest_Integer
is range Min_Int
.. Max_Int
;
79 type AST_Handler
is private;
81 No_AST_Handler
: constant AST_Handler
;
84 (Type_Class_Enumeration
,
86 Type_Class_Fixed_Point
,
87 Type_Class_Floating_Point
,
91 Type_Class_Task
, -- also in Ada 95 protected
94 function "not" (Left
: Largest_Integer
) return Largest_Integer
;
95 function "and" (Left
, Right
: Largest_Integer
) return Largest_Integer
;
96 function "or" (Left
, Right
: Largest_Integer
) return Largest_Integer
;
97 function "xor" (Left
, Right
: Largest_Integer
) return Largest_Integer
;
99 Address_Zero
: constant Address
;
100 No_Addr
: constant Address
;
101 Address_Size
: constant := Standard
'Address_Size;
103 function "+" (Left
: Address
; Right
: Integer) return Address
;
104 function "+" (Left
: Integer; Right
: Address
) return Address
;
105 function "-" (Left
: Address
; Right
: Address
) return Integer;
106 function "-" (Left
: Address
; Right
: Integer) return Address
;
109 type Target
is private;
110 function Fetch_From_Address
(A
: Address
) return Target
;
113 type Target
is private;
114 procedure Assign_To_Address
(A
: Address
; T
: Target
);
116 -- Floating point type declarations for VAX floating point data types
118 pragma Warnings
(Off
);
120 type F_Float
is digits 6;
121 pragma Float_Representation
(VAX_Float
, F_Float
);
123 type D_Float
is digits 9;
124 pragma Float_Representation
(Vax_Float
, D_Float
);
126 type G_Float
is digits 15;
127 pragma Float_Representation
(Vax_Float
, G_Float
);
129 -- Floating point type declarations for IEEE floating point data types
131 type IEEE_Single_Float
is digits 6;
132 pragma Float_Representation
(IEEE_Float
, IEEE_Single_Float
);
134 type IEEE_Double_Float
is digits 15;
135 pragma Float_Representation
(IEEE_Float
, IEEE_Double_Float
);
137 pragma Warnings
(On
);
139 Non_Ada_Error
: exception;
141 -- Hardware-oriented types and functions
143 type Bit_Array
is array (Integer range <>) of Boolean;
144 pragma Pack
(Bit_Array
);
146 subtype Bit_Array_8
is Bit_Array
(0 .. 7);
147 subtype Bit_Array_16
is Bit_Array
(0 .. 15);
148 subtype Bit_Array_32
is Bit_Array
(0 .. 31);
149 subtype Bit_Array_64
is Bit_Array
(0 .. 63);
151 type Unsigned_Byte
is range 0 .. 255;
152 for Unsigned_Byte
'Size use 8;
154 function "not" (Left
: Unsigned_Byte
) return Unsigned_Byte
;
155 function "and" (Left
, Right
: Unsigned_Byte
) return Unsigned_Byte
;
156 function "or" (Left
, Right
: Unsigned_Byte
) return Unsigned_Byte
;
157 function "xor" (Left
, Right
: Unsigned_Byte
) return Unsigned_Byte
;
159 function To_Unsigned_Byte
(X
: Bit_Array_8
) return Unsigned_Byte
;
160 function To_Bit_Array_8
(X
: Unsigned_Byte
) return Bit_Array_8
;
162 type Unsigned_Byte_Array
is array (Integer range <>) of Unsigned_Byte
;
164 type Unsigned_Word
is range 0 .. 65535;
165 for Unsigned_Word
'Size use 16;
167 function "not" (Left
: Unsigned_Word
) return Unsigned_Word
;
168 function "and" (Left
, Right
: Unsigned_Word
) return Unsigned_Word
;
169 function "or" (Left
, Right
: Unsigned_Word
) return Unsigned_Word
;
170 function "xor" (Left
, Right
: Unsigned_Word
) return Unsigned_Word
;
172 function To_Unsigned_Word
(X
: Bit_Array_16
) return Unsigned_Word
;
173 function To_Bit_Array_16
(X
: Unsigned_Word
) return Bit_Array_16
;
175 type Unsigned_Word_Array
is array (Integer range <>) of Unsigned_Word
;
177 type Unsigned_Longword
is range -2_147_483_648
.. 2_147_483_647
;
178 for Unsigned_Longword
'Size use 32;
180 function "not" (Left
: Unsigned_Longword
) return Unsigned_Longword
;
181 function "and" (Left
, Right
: Unsigned_Longword
) return Unsigned_Longword
;
182 function "or" (Left
, Right
: Unsigned_Longword
) return Unsigned_Longword
;
183 function "xor" (Left
, Right
: Unsigned_Longword
) return Unsigned_Longword
;
185 function To_Unsigned_Longword
(X
: Bit_Array_32
) return Unsigned_Longword
;
186 function To_Bit_Array_32
(X
: Unsigned_Longword
) return Bit_Array_32
;
188 type Unsigned_Longword_Array
is
189 array (Integer range <>) of Unsigned_Longword
;
191 type Unsigned_32
is range 0 .. 4_294_967_295
;
192 for Unsigned_32
'Size use 32;
194 function "not" (Left
: Unsigned_32
) return Unsigned_32
;
195 function "and" (Left
, Right
: Unsigned_32
) return Unsigned_32
;
196 function "or" (Left
, Right
: Unsigned_32
) return Unsigned_32
;
197 function "xor" (Left
, Right
: Unsigned_32
) return Unsigned_32
;
199 function To_Unsigned_32
(X
: Bit_Array_32
) return Unsigned_32
;
200 function To_Bit_Array_32
(X
: Unsigned_32
) return Bit_Array_32
;
202 type Unsigned_Quadword
is record
203 L0
: Unsigned_Longword
;
204 L1
: Unsigned_Longword
;
207 for Unsigned_Quadword
'Size use 64;
208 for Unsigned_Quadword
'Alignment use
209 Integer'Min (8, Standard
'Maximum_Alignment);
211 function "not" (Left
: Unsigned_Quadword
) return Unsigned_Quadword
;
212 function "and" (Left
, Right
: Unsigned_Quadword
) return Unsigned_Quadword
;
213 function "or" (Left
, Right
: Unsigned_Quadword
) return Unsigned_Quadword
;
214 function "xor" (Left
, Right
: Unsigned_Quadword
) return Unsigned_Quadword
;
216 function To_Unsigned_Quadword
(X
: Bit_Array_64
) return Unsigned_Quadword
;
217 function To_Bit_Array_64
(X
: Unsigned_Quadword
) return Bit_Array_64
;
219 type Unsigned_Quadword_Array
is
220 array (Integer range <>) of Unsigned_Quadword
;
222 function To_Address
(X
: Integer) return Address
;
223 pragma Pure_Function
(To_Address
);
225 function To_Address_Long
(X
: Unsigned_Longword
) return Address
;
226 pragma Pure_Function
(To_Address_Long
);
228 function To_Integer
(X
: Address
) return Integer;
230 function To_Unsigned_Longword
(X
: Address
) return Unsigned_Longword
;
231 function To_Unsigned_Longword
(X
: AST_Handler
) return Unsigned_Longword
;
233 -- Conventional names for static subtypes of type UNSIGNED_LONGWORD
235 subtype Unsigned_1
is Unsigned_Longword
range 0 .. 2** 1-1;
236 subtype Unsigned_2
is Unsigned_Longword
range 0 .. 2** 2-1;
237 subtype Unsigned_3
is Unsigned_Longword
range 0 .. 2** 3-1;
238 subtype Unsigned_4
is Unsigned_Longword
range 0 .. 2** 4-1;
239 subtype Unsigned_5
is Unsigned_Longword
range 0 .. 2** 5-1;
240 subtype Unsigned_6
is Unsigned_Longword
range 0 .. 2** 6-1;
241 subtype Unsigned_7
is Unsigned_Longword
range 0 .. 2** 7-1;
242 subtype Unsigned_8
is Unsigned_Longword
range 0 .. 2** 8-1;
243 subtype Unsigned_9
is Unsigned_Longword
range 0 .. 2** 9-1;
244 subtype Unsigned_10
is Unsigned_Longword
range 0 .. 2**10-1;
245 subtype Unsigned_11
is Unsigned_Longword
range 0 .. 2**11-1;
246 subtype Unsigned_12
is Unsigned_Longword
range 0 .. 2**12-1;
247 subtype Unsigned_13
is Unsigned_Longword
range 0 .. 2**13-1;
248 subtype Unsigned_14
is Unsigned_Longword
range 0 .. 2**14-1;
249 subtype Unsigned_15
is Unsigned_Longword
range 0 .. 2**15-1;
250 subtype Unsigned_16
is Unsigned_Longword
range 0 .. 2**16-1;
251 subtype Unsigned_17
is Unsigned_Longword
range 0 .. 2**17-1;
252 subtype Unsigned_18
is Unsigned_Longword
range 0 .. 2**18-1;
253 subtype Unsigned_19
is Unsigned_Longword
range 0 .. 2**19-1;
254 subtype Unsigned_20
is Unsigned_Longword
range 0 .. 2**20-1;
255 subtype Unsigned_21
is Unsigned_Longword
range 0 .. 2**21-1;
256 subtype Unsigned_22
is Unsigned_Longword
range 0 .. 2**22-1;
257 subtype Unsigned_23
is Unsigned_Longword
range 0 .. 2**23-1;
258 subtype Unsigned_24
is Unsigned_Longword
range 0 .. 2**24-1;
259 subtype Unsigned_25
is Unsigned_Longword
range 0 .. 2**25-1;
260 subtype Unsigned_26
is Unsigned_Longword
range 0 .. 2**26-1;
261 subtype Unsigned_27
is Unsigned_Longword
range 0 .. 2**27-1;
262 subtype Unsigned_28
is Unsigned_Longword
range 0 .. 2**28-1;
263 subtype Unsigned_29
is Unsigned_Longword
range 0 .. 2**29-1;
264 subtype Unsigned_30
is Unsigned_Longword
range 0 .. 2**30-1;
265 subtype Unsigned_31
is Unsigned_Longword
range 0 .. 2**31-1;
267 -- Function for obtaining global symbol values
269 function Import_Value
(Symbol
: String) return Unsigned_Longword
;
270 function Import_Address
(Symbol
: String) return Address
;
271 function Import_Largest_Value
(Symbol
: String) return Largest_Integer
;
273 pragma Import
(Intrinsic
, Import_Value
);
274 pragma Import
(Intrinsic
, Import_Address
);
275 pragma Import
(Intrinsic
, Import_Largest_Value
);
277 -- For the following declarations, note that the declaration without
278 -- a Retry_Count parameter means to retry infinitely. A value of zero
279 -- for the Retry_Count parameter means do not retry.
281 -- Interlocked-instruction procedures
283 procedure Clear_Interlocked
284 (Bit
: in out Boolean;
285 Old_Value
: out Boolean);
287 procedure Set_Interlocked
288 (Bit
: in out Boolean;
289 Old_Value
: out Boolean);
291 type Aligned_Word
is record
292 Value
: Short_Integer;
295 for Aligned_Word
'Alignment use
296 Integer'Min (2, Standard
'Maximum_Alignment);
298 procedure Clear_Interlocked
299 (Bit
: in out Boolean;
300 Old_Value
: out Boolean;
301 Retry_Count
: Natural;
302 Success_Flag
: out Boolean);
304 procedure Set_Interlocked
305 (Bit
: in out Boolean;
306 Old_Value
: out Boolean;
307 Retry_Count
: Natural;
308 Success_Flag
: out Boolean);
310 procedure Add_Interlocked
311 (Addend
: Short_Integer;
312 Augend
: in out Aligned_Word
;
315 type Aligned_Integer
is record
319 for Aligned_Integer
'Alignment use
320 Integer'Min (4, Standard
'Maximum_Alignment);
322 type Aligned_Long_Integer
is record
323 Value
: Long_Integer;
326 for Aligned_Long_Integer
'Alignment use
327 Integer'Min (8, Standard
'Maximum_Alignment);
329 -- For the following declarations, note that the declaration without
330 -- a Retry_Count parameter mean to retry infinitely. A value of zero
331 -- for the Retry_Count means do not retry.
334 (To
: in out Aligned_Integer
;
338 (To
: in out Aligned_Integer
;
340 Retry_Count
: Natural;
341 Old_Value
: out Integer;
342 Success_Flag
: out Boolean);
345 (To
: in out Aligned_Long_Integer
;
346 Amount
: Long_Integer);
349 (To
: in out Aligned_Long_Integer
;
350 Amount
: Long_Integer;
351 Retry_Count
: Natural;
352 Old_Value
: out Long_Integer;
353 Success_Flag
: out Boolean);
356 (To
: in out Aligned_Integer
;
360 (To
: in out Aligned_Integer
;
362 Retry_Count
: Natural;
363 Old_Value
: out Integer;
364 Success_Flag
: out Boolean);
367 (To
: in out Aligned_Long_Integer
;
368 From
: Long_Integer);
371 (To
: in out Aligned_Long_Integer
;
373 Retry_Count
: Natural;
374 Old_Value
: out Long_Integer;
375 Success_Flag
: out Boolean);
378 (To
: in out Aligned_Integer
;
382 (To
: in out Aligned_Integer
;
384 Retry_Count
: Natural;
385 Old_Value
: out Integer;
386 Success_Flag
: out Boolean);
389 (To
: in out Aligned_Long_Integer
;
390 From
: Long_Integer);
393 (To
: in out Aligned_Long_Integer
;
395 Retry_Count
: Natural;
396 Old_Value
: out Long_Integer;
397 Success_Flag
: out Boolean);
400 (Fail_No_Lock
, OK_Not_First
, OK_First
);
407 type Remq_Status
is (
422 Status
: out Insq_Status
);
427 Status
: out Remq_Status
);
432 Status
: out Insq_Status
);
437 Status
: out Remq_Status
);
441 Address_Zero
: constant Address
:= Null_Address
;
442 No_Addr
: constant Address
:= Null_Address
;
444 -- An AST_Handler value is from a typing point of view simply a pointer
445 -- to a procedure taking a single 64bit parameter. However, this
446 -- is a bit misleading, because the data that this pointer references is
447 -- highly stylized. See body of System.AST_Handling for full details.
449 type AST_Handler
is access procedure (Param
: Long_Integer);
450 No_AST_Handler
: constant AST_Handler
:= null;
452 -- Other operators have incorrect profiles. It would be nice to make
453 -- them intrinsic, since the backend can handle them, but the front
454 -- end is not prepared to deal with them, so at least inline them.
456 pragma Inline_Always
("+");
457 pragma Inline_Always
("-");
458 pragma Inline_Always
("not");
459 pragma Inline_Always
("and");
460 pragma Inline_Always
("or");
461 pragma Inline_Always
("xor");
463 -- Other inlined subprograms
465 pragma Inline_Always
(Fetch_From_Address
);
466 pragma Inline_Always
(Assign_To_Address
);
468 -- Synchronization related subprograms. These are declared to have
469 -- convention C so that the critical parameters are passed by reference.
470 -- Without this, the parameters are passed by copy, creating load/store
471 -- race conditions. We also inline them, since this seems more in the
472 -- spirit of the original (hardware intrinsic) routines.
474 pragma Convention
(C
, Clear_Interlocked
);
475 pragma Inline_Always
(Clear_Interlocked
);
477 pragma Convention
(C
, Set_Interlocked
);
478 pragma Inline_Always
(Set_Interlocked
);
480 pragma Convention
(C
, Add_Interlocked
);
481 pragma Inline_Always
(Add_Interlocked
);
483 pragma Convention
(C
, Add_Atomic
);
484 pragma Inline_Always
(Add_Atomic
);
486 pragma Convention
(C
, And_Atomic
);
487 pragma Inline_Always
(And_Atomic
);
489 pragma Convention
(C
, Or_Atomic
);
490 pragma Inline_Always
(Or_Atomic
);
492 -- Provide proper unchecked conversion definitions for transfer
493 -- functions. Note that we need this level of indirection because
494 -- the formal parameter name is X and not Source (and this is indeed
495 -- detectable by a program)
497 function To_Unsigned_Byte_A
is new
498 Ada
.Unchecked_Conversion
(Bit_Array_8
, Unsigned_Byte
);
500 function To_Unsigned_Byte
(X
: Bit_Array_8
) return Unsigned_Byte
501 renames To_Unsigned_Byte_A
;
503 function To_Bit_Array_8_A
is new
504 Ada
.Unchecked_Conversion
(Unsigned_Byte
, Bit_Array_8
);
506 function To_Bit_Array_8
(X
: Unsigned_Byte
) return Bit_Array_8
507 renames To_Bit_Array_8_A
;
509 function To_Unsigned_Word_A
is new
510 Ada
.Unchecked_Conversion
(Bit_Array_16
, Unsigned_Word
);
512 function To_Unsigned_Word
(X
: Bit_Array_16
) return Unsigned_Word
513 renames To_Unsigned_Word_A
;
515 function To_Bit_Array_16_A
is new
516 Ada
.Unchecked_Conversion
(Unsigned_Word
, Bit_Array_16
);
518 function To_Bit_Array_16
(X
: Unsigned_Word
) return Bit_Array_16
519 renames To_Bit_Array_16_A
;
521 function To_Unsigned_Longword_A
is new
522 Ada
.Unchecked_Conversion
(Bit_Array_32
, Unsigned_Longword
);
524 function To_Unsigned_Longword
(X
: Bit_Array_32
) return Unsigned_Longword
525 renames To_Unsigned_Longword_A
;
527 function To_Bit_Array_32_A
is new
528 Ada
.Unchecked_Conversion
(Unsigned_Longword
, Bit_Array_32
);
530 function To_Bit_Array_32
(X
: Unsigned_Longword
) return Bit_Array_32
531 renames To_Bit_Array_32_A
;
533 function To_Unsigned_32_A
is new
534 Ada
.Unchecked_Conversion
(Bit_Array_32
, Unsigned_32
);
536 function To_Unsigned_32
(X
: Bit_Array_32
) return Unsigned_32
537 renames To_Unsigned_32_A
;
539 function To_Bit_Array_32_A
is new
540 Ada
.Unchecked_Conversion
(Unsigned_32
, Bit_Array_32
);
542 function To_Bit_Array_32
(X
: Unsigned_32
) return Bit_Array_32
543 renames To_Bit_Array_32_A
;
545 function To_Unsigned_Quadword_A
is new
546 Ada
.Unchecked_Conversion
(Bit_Array_64
, Unsigned_Quadword
);
548 function To_Unsigned_Quadword
(X
: Bit_Array_64
) return Unsigned_Quadword
549 renames To_Unsigned_Quadword_A
;
551 function To_Bit_Array_64_A
is new
552 Ada
.Unchecked_Conversion
(Unsigned_Quadword
, Bit_Array_64
);
554 function To_Bit_Array_64
(X
: Unsigned_Quadword
) return Bit_Array_64
555 renames To_Bit_Array_64_A
;
557 pragma Warnings
(Off
);
558 -- Turn warnings off. This is needed for systems with 64-bit integers,
559 -- where some of these operations are of dubious meaning, but we do not
560 -- want warnings when we compile on such systems.
562 function To_Address_A
is new
563 Ada
.Unchecked_Conversion
(Integer, Address
);
564 pragma Pure_Function
(To_Address_A
);
566 function To_Address
(X
: Integer) return Address
567 renames To_Address_A
;
568 pragma Pure_Function
(To_Address
);
570 function To_Address_Long_A
is new
571 Ada
.Unchecked_Conversion
(Unsigned_Longword
, Address
);
572 pragma Pure_Function
(To_Address_Long_A
);
574 function To_Address_Long
(X
: Unsigned_Longword
) return Address
575 renames To_Address_Long_A
;
576 pragma Pure_Function
(To_Address_Long
);
578 function To_Integer_A
is new
579 Ada
.Unchecked_Conversion
(Address
, Integer);
581 function To_Integer
(X
: Address
) return Integer
582 renames To_Integer_A
;
584 function To_Unsigned_Longword_A
is new
585 Ada
.Unchecked_Conversion
(Address
, Unsigned_Longword
);
587 function To_Unsigned_Longword
(X
: Address
) return Unsigned_Longword
588 renames To_Unsigned_Longword_A
;
590 function To_Unsigned_Longword_A
is new
591 Ada
.Unchecked_Conversion
(AST_Handler
, Unsigned_Longword
);
593 function To_Unsigned_Longword
(X
: AST_Handler
) return Unsigned_Longword
594 renames To_Unsigned_Longword_A
;
596 pragma Warnings
(On
);