Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / ada / 5zosinte.adb
blob920dc1da270209e4ec37f3ae326844c9d6199ad1
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . O S _ I N T E R F A C E --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1997-2002 Free Software Foundation --
11 -- --
12 -- GNARL 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. GNARL 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 GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
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. --
29 -- --
30 -- GNARL was developed by the GNARL team at Florida State University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This is the VxWorks version.
37 -- This package encapsulates all direct interfaces to OS services
38 -- that are needed by children of System.
40 pragma Polling (Off);
41 -- Turn off polling, we do not want ATC polling to take place during
42 -- tasking operations. It causes infinite loops and other problems.
44 package body System.OS_Interface is
46 use type Interfaces.C.int;
48 Low_Priority : constant := 255;
49 -- VxWorks native (default) lowest scheduling priority.
51 -------------
52 -- sigwait --
53 -------------
55 function sigwait
56 (set : access sigset_t;
57 sig : access Signal) return int
59 Result : int;
61 function sigwaitinfo
62 (set : access sigset_t; sigvalue : System.Address) return int;
63 pragma Import (C, sigwaitinfo, "sigwaitinfo");
65 begin
66 Result := sigwaitinfo (set, System.Null_Address);
68 if Result /= -1 then
69 sig.all := Signal (Result);
70 return 0;
71 else
72 sig.all := 0;
73 return errno;
74 end if;
75 end sigwait;
77 -----------------
78 -- To_Duration --
79 -----------------
81 function To_Duration (TS : timespec) return Duration is
82 begin
83 return Duration (TS.ts_sec) + Duration (TS.ts_nsec) / 10#1#E9;
84 end To_Duration;
86 -----------------
87 -- To_Timespec --
88 -----------------
90 function To_Timespec (D : Duration) return timespec is
91 S : time_t;
92 F : Duration;
93 begin
94 S := time_t (Long_Long_Integer (D));
95 F := D - Duration (S);
97 -- If F has negative value due to a round-up, adjust for positive F
98 -- value.
99 if F < 0.0 then
100 S := S - 1;
101 F := F + 1.0;
102 end if;
104 return timespec' (ts_sec => S,
105 ts_nsec => long (Long_Long_Integer (F * 10#1#E9)));
106 end To_Timespec;
108 -------------------------
109 -- To_VxWorks_Priority --
110 -------------------------
112 function To_VxWorks_Priority (Priority : in int) return int is
113 begin
114 return Low_Priority - Priority;
115 end To_VxWorks_Priority;
117 --------------------
118 -- To_Clock_Ticks --
119 --------------------
121 -- ??? - For now, we'll always get the system clock rate
122 -- since it is allowed to be changed during run-time in
123 -- VxWorks. A better method would be to provide an operation
124 -- to set it that so we can always know its value.
126 -- Another thing we should probably allow for is a resultant
127 -- tick count greater than int'Last. This should probably
128 -- be a procedure with two output parameters, one in the
129 -- range 0 .. int'Last, and another representing the overflow
130 -- count.
132 function To_Clock_Ticks (D : Duration) return int is
133 Ticks : Long_Long_Integer;
134 Rate_Duration : Duration;
135 Ticks_Duration : Duration;
137 begin
138 if D < 0.0 then
139 return -1;
140 end if;
142 -- Ensure that the duration can be converted to ticks
143 -- at the current clock tick rate without overflowing.
145 Rate_Duration := Duration (sysClkRateGet);
147 if D > (Duration'Last / Rate_Duration) then
148 Ticks := Long_Long_Integer (int'Last);
149 else
150 Ticks_Duration := D * Rate_Duration;
151 Ticks := Long_Long_Integer (Ticks_Duration);
153 if Ticks_Duration > Duration (Ticks) then
154 Ticks := Ticks + 1;
155 end if;
157 if Ticks > Long_Long_Integer (int'Last) then
158 Ticks := Long_Long_Integer (int'Last);
159 end if;
160 end if;
162 return int (Ticks);
163 end To_Clock_Ticks;
165 end System.OS_Interface;