1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . A U X _ D E C --
9 -- Copyright (C) 1996-2002 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 ------------------------------------------------------------------------------
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 with Unchecked_Conversion
;
42 package System
.Aux_DEC
is
43 pragma Elaborate_Body
(Aux_DEC
);
45 type Integer_8
is range -2 ** (8 - 1) .. +2 ** (8 - 1) - 1;
46 for Integer_8
'Size use 8;
48 type Integer_16
is range -2 ** (16 - 1) .. +2 ** (16 - 1) - 1;
49 for Integer_16
'Size use 16;
51 type Integer_32
is range -2 ** (32 - 1) .. +2 ** (32 - 1) - 1;
52 for Integer_32
'Size use 32;
54 type Integer_64
is range -2 ** (64 - 1) .. +2 ** (64 - 1) - 1;
55 for Integer_64
'Size use 64;
57 type Largest_Integer
is range Min_Int
.. Max_Int
;
59 type AST_Handler
is limited private;
61 No_AST_Handler
: constant AST_Handler
;
64 (Type_Class_Enumeration
,
66 Type_Class_Fixed_Point
,
67 Type_Class_Floating_Point
,
71 Type_Class_Task
, -- also in Ada 95 protected
74 function "not" (Left
: Largest_Integer
) return Largest_Integer
;
75 function "and" (Left
, Right
: Largest_Integer
) return Largest_Integer
;
76 function "or" (Left
, Right
: Largest_Integer
) return Largest_Integer
;
77 function "xor" (Left
, Right
: Largest_Integer
) return Largest_Integer
;
79 Address_Zero
: constant Address
;
80 No_Addr
: constant Address
;
81 Address_Size
: constant := Standard
'Address_Size;
83 function "+" (Left
: Address
; Right
: Integer) return Address
;
84 function "+" (Left
: Integer; Right
: Address
) return Address
;
85 function "-" (Left
: Address
; Right
: Address
) return Integer;
86 function "-" (Left
: Address
; Right
: Integer) return Address
;
89 type Target
is private;
90 function Fetch_From_Address
(A
: Address
) return Target
;
93 type Target
is private;
94 procedure Assign_To_Address
(A
: Address
; T
: Target
);
96 -- Floating point type declarations for VAX floating point data types
98 pragma Warnings
(Off
);
100 type F_Float
is digits 6;
101 pragma Float_Representation
(VAX_Float
, F_Float
);
103 type D_Float
is digits 9;
104 pragma Float_Representation
(Vax_Float
, D_Float
);
106 type G_Float
is digits 15;
107 pragma Float_Representation
(Vax_Float
, G_Float
);
109 -- Floating point type declarations for IEEE floating point data types
111 type IEEE_Single_Float
is digits 6;
112 pragma Float_Representation
(IEEE_Float
, IEEE_Single_Float
);
114 type IEEE_Double_Float
is digits 15;
115 pragma Float_Representation
(IEEE_Float
, IEEE_Double_Float
);
117 pragma Warnings
(On
);
119 Non_Ada_Error
: exception;
121 -- Hardware-oriented types and functions
123 type Bit_Array
is array (Integer range <>) of Boolean;
124 pragma Pack
(Bit_Array
);
126 subtype Bit_Array_8
is Bit_Array
(0 .. 7);
127 subtype Bit_Array_16
is Bit_Array
(0 .. 15);
128 subtype Bit_Array_32
is Bit_Array
(0 .. 31);
129 subtype Bit_Array_64
is Bit_Array
(0 .. 63);
131 type Unsigned_Byte
is range 0 .. 255;
132 for Unsigned_Byte
'Size use 8;
134 function "not" (Left
: Unsigned_Byte
) return Unsigned_Byte
;
135 function "and" (Left
, Right
: Unsigned_Byte
) return Unsigned_Byte
;
136 function "or" (Left
, Right
: Unsigned_Byte
) return Unsigned_Byte
;
137 function "xor" (Left
, Right
: Unsigned_Byte
) return Unsigned_Byte
;
139 function To_Unsigned_Byte
(X
: Bit_Array_8
) return Unsigned_Byte
;
140 function To_Bit_Array_8
(X
: Unsigned_Byte
) return Bit_Array_8
;
142 type Unsigned_Byte_Array
is array (Integer range <>) of Unsigned_Byte
;
144 type Unsigned_Word
is range 0 .. 65535;
145 for Unsigned_Word
'Size use 16;
147 function "not" (Left
: Unsigned_Word
) return Unsigned_Word
;
148 function "and" (Left
, Right
: Unsigned_Word
) return Unsigned_Word
;
149 function "or" (Left
, Right
: Unsigned_Word
) return Unsigned_Word
;
150 function "xor" (Left
, Right
: Unsigned_Word
) return Unsigned_Word
;
152 function To_Unsigned_Word
(X
: Bit_Array_16
) return Unsigned_Word
;
153 function To_Bit_Array_16
(X
: Unsigned_Word
) return Bit_Array_16
;
155 type Unsigned_Word_Array
is array (Integer range <>) of Unsigned_Word
;
157 type Unsigned_Longword
is range -2_147_483_648
.. 2_147_483_647
;
158 for Unsigned_Longword
'Size use 32;
160 function "not" (Left
: Unsigned_Longword
) return Unsigned_Longword
;
161 function "and" (Left
, Right
: Unsigned_Longword
) return Unsigned_Longword
;
162 function "or" (Left
, Right
: Unsigned_Longword
) return Unsigned_Longword
;
163 function "xor" (Left
, Right
: Unsigned_Longword
) return Unsigned_Longword
;
165 function To_Unsigned_Longword
(X
: Bit_Array_32
) return Unsigned_Longword
;
166 function To_Bit_Array_32
(X
: Unsigned_Longword
) return Bit_Array_32
;
168 type Unsigned_Longword_Array
is
169 array (Integer range <>) of Unsigned_Longword
;
171 type Unsigned_32
is range 0 .. 4_294_967_295
;
172 for Unsigned_32
'Size use 32;
174 function "not" (Left
: Unsigned_32
) return Unsigned_32
;
175 function "and" (Left
, Right
: Unsigned_32
) return Unsigned_32
;
176 function "or" (Left
, Right
: Unsigned_32
) return Unsigned_32
;
177 function "xor" (Left
, Right
: Unsigned_32
) return Unsigned_32
;
179 function To_Unsigned_32
(X
: Bit_Array_32
) return Unsigned_32
;
180 function To_Bit_Array_32
(X
: Unsigned_32
) return Bit_Array_32
;
182 type Unsigned_Quadword
is record
183 L0
: Unsigned_Longword
;
184 L1
: Unsigned_Longword
;
187 for Unsigned_Quadword
'Size use 64;
188 for Unsigned_Quadword
'Alignment use
189 Integer'Min (8, Standard
'Maximum_Alignment);
191 function "not" (Left
: Unsigned_Quadword
) return Unsigned_Quadword
;
192 function "and" (Left
, Right
: Unsigned_Quadword
) return Unsigned_Quadword
;
193 function "or" (Left
, Right
: Unsigned_Quadword
) return Unsigned_Quadword
;
194 function "xor" (Left
, Right
: Unsigned_Quadword
) return Unsigned_Quadword
;
196 function To_Unsigned_Quadword
(X
: Bit_Array_64
) return Unsigned_Quadword
;
197 function To_Bit_Array_64
(X
: Unsigned_Quadword
) return Bit_Array_64
;
199 type Unsigned_Quadword_Array
is
200 array (Integer range <>) of Unsigned_Quadword
;
202 function To_Address
(X
: Integer) return Address
;
203 pragma Pure_Function
(To_Address
);
205 function To_Address_Long
(X
: Unsigned_Longword
) return Address
;
206 pragma Pure_Function
(To_Address_Long
);
208 function To_Integer
(X
: Address
) return Integer;
210 function To_Unsigned_Longword
(X
: Address
) return Unsigned_Longword
;
211 function To_Unsigned_Longword
(X
: AST_Handler
) return Unsigned_Longword
;
213 -- Conventional names for static subtypes of type UNSIGNED_LONGWORD
215 subtype Unsigned_1
is Unsigned_Longword
range 0 .. 2** 1-1;
216 subtype Unsigned_2
is Unsigned_Longword
range 0 .. 2** 2-1;
217 subtype Unsigned_3
is Unsigned_Longword
range 0 .. 2** 3-1;
218 subtype Unsigned_4
is Unsigned_Longword
range 0 .. 2** 4-1;
219 subtype Unsigned_5
is Unsigned_Longword
range 0 .. 2** 5-1;
220 subtype Unsigned_6
is Unsigned_Longword
range 0 .. 2** 6-1;
221 subtype Unsigned_7
is Unsigned_Longword
range 0 .. 2** 7-1;
222 subtype Unsigned_8
is Unsigned_Longword
range 0 .. 2** 8-1;
223 subtype Unsigned_9
is Unsigned_Longword
range 0 .. 2** 9-1;
224 subtype Unsigned_10
is Unsigned_Longword
range 0 .. 2**10-1;
225 subtype Unsigned_11
is Unsigned_Longword
range 0 .. 2**11-1;
226 subtype Unsigned_12
is Unsigned_Longword
range 0 .. 2**12-1;
227 subtype Unsigned_13
is Unsigned_Longword
range 0 .. 2**13-1;
228 subtype Unsigned_14
is Unsigned_Longword
range 0 .. 2**14-1;
229 subtype Unsigned_15
is Unsigned_Longword
range 0 .. 2**15-1;
230 subtype Unsigned_16
is Unsigned_Longword
range 0 .. 2**16-1;
231 subtype Unsigned_17
is Unsigned_Longword
range 0 .. 2**17-1;
232 subtype Unsigned_18
is Unsigned_Longword
range 0 .. 2**18-1;
233 subtype Unsigned_19
is Unsigned_Longword
range 0 .. 2**19-1;
234 subtype Unsigned_20
is Unsigned_Longword
range 0 .. 2**20-1;
235 subtype Unsigned_21
is Unsigned_Longword
range 0 .. 2**21-1;
236 subtype Unsigned_22
is Unsigned_Longword
range 0 .. 2**22-1;
237 subtype Unsigned_23
is Unsigned_Longword
range 0 .. 2**23-1;
238 subtype Unsigned_24
is Unsigned_Longword
range 0 .. 2**24-1;
239 subtype Unsigned_25
is Unsigned_Longword
range 0 .. 2**25-1;
240 subtype Unsigned_26
is Unsigned_Longword
range 0 .. 2**26-1;
241 subtype Unsigned_27
is Unsigned_Longword
range 0 .. 2**27-1;
242 subtype Unsigned_28
is Unsigned_Longword
range 0 .. 2**28-1;
243 subtype Unsigned_29
is Unsigned_Longword
range 0 .. 2**29-1;
244 subtype Unsigned_30
is Unsigned_Longword
range 0 .. 2**30-1;
245 subtype Unsigned_31
is Unsigned_Longword
range 0 .. 2**31-1;
247 -- Function for obtaining global symbol values
249 function Import_Value
(Symbol
: String) return Unsigned_Longword
;
250 function Import_Address
(Symbol
: String) return Address
;
251 function Import_Largest_Value
(Symbol
: String) return Largest_Integer
;
253 pragma Import
(Intrinsic
, Import_Value
);
254 pragma Import
(Intrinsic
, Import_Address
);
255 pragma Import
(Intrinsic
, Import_Largest_Value
);
257 -- For the following declarations, note that the declaration without
258 -- a Retry_Count parameter means to retry infinitely. A value of zero
259 -- for the Retry_Count parameter means do not retry.
261 -- Interlocked-instruction procedures
263 procedure Clear_Interlocked
264 (Bit
: in out Boolean;
265 Old_Value
: out Boolean);
267 procedure Set_Interlocked
268 (Bit
: in out Boolean;
269 Old_Value
: out Boolean);
271 type Aligned_Word
is record
272 Value
: Short_Integer;
275 for Aligned_Word
'Alignment use
276 Integer'Min (2, Standard
'Maximum_Alignment);
278 procedure Clear_Interlocked
279 (Bit
: in out Boolean;
280 Old_Value
: out Boolean;
281 Retry_Count
: in Natural;
282 Success_Flag
: out Boolean);
284 procedure Set_Interlocked
285 (Bit
: in out Boolean;
286 Old_Value
: out Boolean;
287 Retry_Count
: in Natural;
288 Success_Flag
: out Boolean);
290 procedure Add_Interlocked
291 (Addend
: in Short_Integer;
292 Augend
: in out Aligned_Word
;
295 type Aligned_Integer
is record
299 for Aligned_Integer
'Alignment use
300 Integer'Min (4, Standard
'Maximum_Alignment);
302 type Aligned_Long_Integer
is record
303 Value
: Long_Integer;
306 for Aligned_Long_Integer
'Alignment use
307 Integer'Min (8, Standard
'Maximum_Alignment);
309 -- For the following declarations, note that the declaration without
310 -- a Retry_Count parameter mean to retry infinitely. A value of zero
311 -- for the Retry_Count means do not retry.
314 (To
: in out Aligned_Integer
;
315 Amount
: in Integer);
318 (To
: in out Aligned_Integer
;
320 Retry_Count
: in Natural;
321 Old_Value
: out Integer;
322 Success_Flag
: out Boolean);
325 (To
: in out Aligned_Long_Integer
;
326 Amount
: in Long_Integer);
329 (To
: in out Aligned_Long_Integer
;
330 Amount
: in Long_Integer;
331 Retry_Count
: in Natural;
332 Old_Value
: out Long_Integer;
333 Success_Flag
: out Boolean);
336 (To
: in out Aligned_Integer
;
340 (To
: in out Aligned_Integer
;
342 Retry_Count
: in Natural;
343 Old_Value
: out Integer;
344 Success_Flag
: out Boolean);
347 (To
: in out Aligned_Long_Integer
;
348 From
: in Long_Integer);
351 (To
: in out Aligned_Long_Integer
;
352 From
: in Long_Integer;
353 Retry_Count
: in Natural;
354 Old_Value
: out Long_Integer;
355 Success_Flag
: out Boolean);
358 (To
: in out Aligned_Integer
;
362 (To
: in out Aligned_Integer
;
364 Retry_Count
: in Natural;
365 Old_Value
: out Integer;
366 Success_Flag
: out Boolean);
369 (To
: in out Aligned_Long_Integer
;
370 From
: in Long_Integer);
373 (To
: in out Aligned_Long_Integer
;
374 From
: in Long_Integer;
375 Retry_Count
: in Natural;
376 Old_Value
: out Long_Integer;
377 Success_Flag
: out Boolean);
380 (Fail_No_Lock
, OK_Not_First
, OK_First
);
387 type Remq_Status
is (
402 Status
: out Insq_Status
);
405 (Header
: in Address
;
407 Status
: out Remq_Status
);
412 Status
: out Insq_Status
);
415 (Header
: in Address
;
417 Status
: out Remq_Status
);
421 Address_Zero
: constant Address
:= Null_Address
;
422 No_Addr
: constant Address
:= Null_Address
;
424 -- An AST_Handler value is from a typing point of view simply a pointer
425 -- to a procedure taking a single 64bit parameter. However, this
426 -- is a bit misleading, because the data that this pointer references is
427 -- highly stylized. See body of System.AST_Handling for full details.
429 type AST_Handler
is access procedure (Param
: Long_Integer);
430 No_AST_Handler
: constant AST_Handler
:= null;
432 -- Other operators have incorrect profiles. It would be nice to make
433 -- them intrinsic, since the backend can handle them, but the front
434 -- end is not prepared to deal with them, so at least inline them.
436 pragma Inline_Always
("+");
437 pragma Inline_Always
("-");
438 pragma Inline_Always
("not");
439 pragma Inline_Always
("and");
440 pragma Inline_Always
("or");
441 pragma Inline_Always
("xor");
443 -- Other inlined subprograms
445 pragma Inline_Always
(Fetch_From_Address
);
446 pragma Inline_Always
(Assign_To_Address
);
448 -- Synchronization related subprograms. These are declared to have
449 -- convention C so that the critical parameters are passed by reference.
450 -- Without this, the parameters are passed by copy, creating load/store
451 -- race conditions. We also inline them, since this seems more in the
452 -- spirit of the original (hardware instrinsic) routines.
454 pragma Convention
(C
, Clear_Interlocked
);
455 pragma Inline_Always
(Clear_Interlocked
);
457 pragma Convention
(C
, Set_Interlocked
);
458 pragma Inline_Always
(Set_Interlocked
);
460 pragma Convention
(C
, Add_Interlocked
);
461 pragma Inline_Always
(Add_Interlocked
);
463 pragma Convention
(C
, Add_Atomic
);
464 pragma Inline_Always
(Add_Atomic
);
466 pragma Convention
(C
, And_Atomic
);
467 pragma Inline_Always
(And_Atomic
);
469 pragma Convention
(C
, Or_Atomic
);
470 pragma Inline_Always
(Or_Atomic
);
472 -- Provide proper unchecked conversion definitions for transfer
473 -- functions. Note that we need this level of indirection because
474 -- the formal parameter name is X and not Source (and this is indeed
475 -- detectable by a program)
477 function To_Unsigned_Byte_A
is new
478 Unchecked_Conversion
(Bit_Array_8
, Unsigned_Byte
);
480 function To_Unsigned_Byte
(X
: Bit_Array_8
) return Unsigned_Byte
481 renames To_Unsigned_Byte_A
;
483 function To_Bit_Array_8_A
is new
484 Unchecked_Conversion
(Unsigned_Byte
, Bit_Array_8
);
486 function To_Bit_Array_8
(X
: Unsigned_Byte
) return Bit_Array_8
487 renames To_Bit_Array_8_A
;
489 function To_Unsigned_Word_A
is new
490 Unchecked_Conversion
(Bit_Array_16
, Unsigned_Word
);
492 function To_Unsigned_Word
(X
: Bit_Array_16
) return Unsigned_Word
493 renames To_Unsigned_Word_A
;
495 function To_Bit_Array_16_A
is new
496 Unchecked_Conversion
(Unsigned_Word
, Bit_Array_16
);
498 function To_Bit_Array_16
(X
: Unsigned_Word
) return Bit_Array_16
499 renames To_Bit_Array_16_A
;
501 function To_Unsigned_Longword_A
is new
502 Unchecked_Conversion
(Bit_Array_32
, Unsigned_Longword
);
504 function To_Unsigned_Longword
(X
: Bit_Array_32
) return Unsigned_Longword
505 renames To_Unsigned_Longword_A
;
507 function To_Bit_Array_32_A
is new
508 Unchecked_Conversion
(Unsigned_Longword
, Bit_Array_32
);
510 function To_Bit_Array_32
(X
: Unsigned_Longword
) return Bit_Array_32
511 renames To_Bit_Array_32_A
;
513 function To_Unsigned_32_A
is new
514 Unchecked_Conversion
(Bit_Array_32
, Unsigned_32
);
516 function To_Unsigned_32
(X
: Bit_Array_32
) return Unsigned_32
517 renames To_Unsigned_32_A
;
519 function To_Bit_Array_32_A
is new
520 Unchecked_Conversion
(Unsigned_32
, Bit_Array_32
);
522 function To_Bit_Array_32
(X
: Unsigned_32
) return Bit_Array_32
523 renames To_Bit_Array_32_A
;
525 function To_Unsigned_Quadword_A
is new
526 Unchecked_Conversion
(Bit_Array_64
, Unsigned_Quadword
);
528 function To_Unsigned_Quadword
(X
: Bit_Array_64
) return Unsigned_Quadword
529 renames To_Unsigned_Quadword_A
;
531 function To_Bit_Array_64_A
is new
532 Unchecked_Conversion
(Unsigned_Quadword
, Bit_Array_64
);
534 function To_Bit_Array_64
(X
: Unsigned_Quadword
) return Bit_Array_64
535 renames To_Bit_Array_64_A
;
537 pragma Warnings
(Off
);
538 -- Turn warnings off. This is needed for systems with 64-bit integers,
539 -- where some of these operations are of dubious meaning, but we do not
540 -- want warnings when we compile on such systems.
542 function To_Address_A
is new
543 Unchecked_Conversion
(Integer, Address
);
544 pragma Pure_Function
(To_Address_A
);
546 function To_Address
(X
: Integer) return Address
547 renames To_Address_A
;
548 pragma Pure_Function
(To_Address
);
550 function To_Address_Long_A
is new
551 Unchecked_Conversion
(Unsigned_Longword
, Address
);
552 pragma Pure_Function
(To_Address_Long_A
);
554 function To_Address_Long
(X
: Unsigned_Longword
) return Address
555 renames To_Address_Long_A
;
556 pragma Pure_Function
(To_Address_Long
);
558 function To_Integer_A
is new
559 Unchecked_Conversion
(Address
, Integer);
561 function To_Integer
(X
: Address
) return Integer
562 renames To_Integer_A
;
564 function To_Unsigned_Longword_A
is new
565 Unchecked_Conversion
(Address
, Unsigned_Longword
);
567 function To_Unsigned_Longword
(X
: Address
) return Unsigned_Longword
568 renames To_Unsigned_Longword_A
;
570 function To_Unsigned_Longword_A
is new
571 Unchecked_Conversion
(AST_Handler
, Unsigned_Longword
);
573 function To_Unsigned_Longword
(X
: AST_Handler
) return Unsigned_Longword
574 renames To_Unsigned_Longword_A
;
576 pragma Warnings
(On
);