OSDN Git Service

Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-vxworks.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                  GNAT 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 --         Copyright (C) 1997-2009, Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNARL 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 3,  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.                                     --
17 --                                                                          --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception,   --
20 -- version 3.1, as published by the Free Software Foundation.               --
21 --                                                                          --
22 -- You should have received a copy of the GNU General Public License and    --
23 -- a copy of the GCC Runtime Library Exception along with this program;     --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25 -- <http://www.gnu.org/licenses/>.                                          --
26 --                                                                          --
27 -- GNARL was developed by the GNARL team at Florida State University.       --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
29 --                                                                          --
30 ------------------------------------------------------------------------------
31
32 --  This is the VxWorks version
33
34 --  This package encapsulates all direct interfaces to OS services that are
35 --  needed by children of System.
36
37 pragma Polling (Off);
38 --  Turn off polling, we do not want ATC polling to take place during tasking
39 --  operations. It causes infinite loops and other problems.
40
41 package body System.OS_Interface is
42
43    use type Interfaces.C.int;
44
45    Low_Priority : constant := 255;
46    --  VxWorks native (default) lowest scheduling priority
47
48    ----------
49    -- kill --
50    ----------
51
52    function kill (pid : t_id; sig : Signal) return int is
53    begin
54       return System.VxWorks.Ext.kill (pid, int (sig));
55    end kill;
56
57    -------------
58    -- sigwait --
59    -------------
60
61    function sigwait
62      (set : access sigset_t;
63       sig : access Signal) return int
64    is
65       Result : int;
66
67       function sigwaitinfo
68         (set : access sigset_t; sigvalue : System.Address) return int;
69       pragma Import (C, sigwaitinfo, "sigwaitinfo");
70
71    begin
72       Result := sigwaitinfo (set, System.Null_Address);
73
74       if Result /= -1 then
75          sig.all := Signal (Result);
76          return 0;
77       else
78          sig.all := 0;
79          return errno;
80       end if;
81    end sigwait;
82
83    -----------------
84    -- To_Duration --
85    -----------------
86
87    function To_Duration (TS : timespec) return Duration is
88    begin
89       return Duration (TS.ts_sec) + Duration (TS.ts_nsec) / 10#1#E9;
90    end To_Duration;
91
92    -----------------
93    -- To_Timespec --
94    -----------------
95
96    function To_Timespec (D : Duration) return timespec is
97       S : time_t;
98       F : Duration;
99
100    begin
101       S := time_t (Long_Long_Integer (D));
102       F := D - Duration (S);
103
104       --  If F is negative due to a round-up, adjust for positive F value
105
106       if F < 0.0 then
107          S := S - 1;
108          F := F + 1.0;
109       end if;
110
111       return timespec'(ts_sec  => S,
112                        ts_nsec => long (Long_Long_Integer (F * 10#1#E9)));
113    end To_Timespec;
114
115    -------------------------
116    -- To_VxWorks_Priority --
117    -------------------------
118
119    function To_VxWorks_Priority (Priority : int) return int is
120    begin
121       return Low_Priority - Priority;
122    end To_VxWorks_Priority;
123
124    --------------------
125    -- To_Clock_Ticks --
126    --------------------
127
128    --  ??? - For now, we'll always get the system clock rate since it is
129    --  allowed to be changed during run-time in VxWorks. A better method would
130    --  be to provide an operation to set it that so we can always know its
131    --  value.
132
133    --  Another thing we should probably allow for is a resultant tick count
134    --  greater than int'Last. This should probably be a procedure with two
135    --  output parameters, one in the range 0 .. int'Last, and another
136    --  representing the overflow count.
137
138    function To_Clock_Ticks (D : Duration) return int is
139       Ticks          : Long_Long_Integer;
140       Rate_Duration  : Duration;
141       Ticks_Duration : Duration;
142
143    begin
144       if D < 0.0 then
145          return -1;
146       end if;
147
148       --  Ensure that the duration can be converted to ticks
149       --  at the current clock tick rate without overflowing.
150
151       Rate_Duration := Duration (sysClkRateGet);
152
153       if D > (Duration'Last / Rate_Duration) then
154          Ticks := Long_Long_Integer (int'Last);
155       else
156          Ticks_Duration := D * Rate_Duration;
157          Ticks := Long_Long_Integer (Ticks_Duration);
158
159          if Ticks_Duration > Duration (Ticks) then
160             Ticks := Ticks + 1;
161          end if;
162
163          if Ticks > Long_Long_Integer (int'Last) then
164             Ticks := Long_Long_Integer (int'Last);
165          end if;
166       end if;
167
168       return int (Ticks);
169    end To_Clock_Ticks;
170
171    -----------------------------
172    -- Binary_Semaphore_Create --
173    -----------------------------
174
175    function Binary_Semaphore_Create return Binary_Semaphore_Id is
176    begin
177       return Binary_Semaphore_Id (semBCreate (SEM_Q_FIFO, SEM_EMPTY));
178    end Binary_Semaphore_Create;
179
180    -----------------------------
181    -- Binary_Semaphore_Delete --
182    -----------------------------
183
184    function Binary_Semaphore_Delete (ID : Binary_Semaphore_Id) return int is
185    begin
186       return semDelete (SEM_ID (ID));
187    end Binary_Semaphore_Delete;
188
189    -----------------------------
190    -- Binary_Semaphore_Obtain --
191    -----------------------------
192
193    function Binary_Semaphore_Obtain (ID : Binary_Semaphore_Id) return int is
194    begin
195       return semTake (SEM_ID (ID), WAIT_FOREVER);
196    end Binary_Semaphore_Obtain;
197
198    ------------------------------
199    -- Binary_Semaphore_Release --
200    ------------------------------
201
202    function Binary_Semaphore_Release (ID : Binary_Semaphore_Id) return int is
203    begin
204       return semGive (SEM_ID (ID));
205    end Binary_Semaphore_Release;
206
207    ----------------------------
208    -- Binary_Semaphore_Flush --
209    ----------------------------
210
211    function Binary_Semaphore_Flush (ID : Binary_Semaphore_Id) return int is
212    begin
213       return semFlush (SEM_ID (ID));
214    end Binary_Semaphore_Flush;
215
216    -----------------------
217    -- Interrupt_Connect --
218    -----------------------
219
220    function Interrupt_Connect
221      (Vector    : Interrupt_Vector;
222       Handler   : Interrupt_Handler;
223       Parameter : System.Address := System.Null_Address) return int
224    is
225       pragma Unreferenced (Vector, Handler, Parameter);
226    begin
227       return 0;
228    end Interrupt_Connect;
229
230    --------------------------------
231    -- Interrupt_Number_To_Vector --
232    --------------------------------
233
234    function Interrupt_Number_To_Vector
235      (intNum : int) return Interrupt_Vector is
236    begin
237       return Interrupt_Vector (intNum);
238    end Interrupt_Number_To_Vector;
239
240 end System.OS_Interface;