OSDN Git Service

optimize
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-vxworks.ads
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 --                                   S p e c                                --
8 --                                                                          --
9 --             Copyright (C) 1991-1994, Florida State University            --
10 --             Copyright (C) 1995-2004, Free Software Foundation, Inc.      --
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 ------------------------------------------------------------------------------
34
35 --  This is the VxWorks version of this package
36
37 --  This package encapsulates all direct interfaces to OS services
38 --  that are needed by children of System.
39
40 --  PLEASE DO NOT add any with-clauses to this package or remove the pragma
41 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
42
43 with Interfaces.C;
44 with System.VxWorks;
45
46 package System.OS_Interface is
47    pragma Preelaborate;
48
49    subtype int         is Interfaces.C.int;
50    subtype short       is Short_Integer;
51    type long           is new Long_Integer;
52    type unsigned_long  is mod 2 ** long'Size;
53    type size_t         is mod 2 ** Standard'Address_Size;
54
55    -----------
56    -- Errno --
57    -----------
58
59    function errno return int;
60    pragma Import (C, errno, "errnoGet");
61
62    EINTR     : constant := 4;
63    EAGAIN    : constant := 35;
64    ENOMEM    : constant := 12;
65    EINVAL    : constant := 22;
66    ETIMEDOUT : constant := 60;
67
68    FUNC_ERR  : constant := -1;
69
70    ----------------------------
71    -- Signals and Interrupts --
72    ----------------------------
73
74    NSIG : constant := 32;
75    --  Number of signals on the target OS
76    type Signal is new int range 0 .. Interfaces.C."-" (NSIG, 1);
77
78    Max_HW_Interrupt : constant := System.VxWorks.Num_HW_Interrupts - 1;
79    type HW_Interrupt is new int range 0 .. Max_HW_Interrupt;
80
81    Max_Interrupt : constant := Max_HW_Interrupt;
82
83    SIGILL  : constant :=  4; --  illegal instruction (not reset)
84    SIGABRT : constant :=  6; --  used by abort, replace SIGIOT in the future
85    SIGFPE  : constant :=  8; --  floating point exception
86    SIGBUS  : constant := 10; --  bus error
87    SIGSEGV : constant := 11; --  segmentation violation
88
89    -----------------------------------
90    -- Signal processing definitions --
91    -----------------------------------
92
93    --  The how in sigprocmask().
94    SIG_BLOCK   : constant := 1;
95    SIG_UNBLOCK : constant := 2;
96    SIG_SETMASK : constant := 3;
97
98    --  The sa_flags in struct sigaction.
99    SA_SIGINFO   : constant := 16#0002#;
100    SA_ONSTACK   : constant := 16#0004#;
101
102    SIG_DFL : constant := 0;
103    SIG_IGN : constant := 1;
104
105    type sigset_t is private;
106
107    type struct_sigaction is record
108       sa_handler : System.Address;
109       sa_mask    : sigset_t;
110       sa_flags   : int;
111    end record;
112    pragma Convention (C, struct_sigaction);
113    type struct_sigaction_ptr is access all struct_sigaction;
114
115    function sigaddset (set : access sigset_t; sig : Signal) return int;
116    pragma Import (C, sigaddset, "sigaddset");
117
118    function sigdelset (set : access sigset_t; sig : Signal) return int;
119    pragma Import (C, sigdelset, "sigdelset");
120
121    function sigfillset (set : access sigset_t) return int;
122    pragma Import (C, sigfillset, "sigfillset");
123
124    function sigismember (set : access sigset_t; sig : Signal) return int;
125    pragma Import (C, sigismember, "sigismember");
126
127    function sigemptyset (set : access sigset_t) return int;
128    pragma Import (C, sigemptyset, "sigemptyset");
129
130    function sigaction
131      (sig  : Signal;
132       act  : struct_sigaction_ptr;
133       oact : struct_sigaction_ptr) return int;
134    pragma Import (C, sigaction, "sigaction");
135
136    type isr_address is access procedure (sig : int);
137
138    function c_signal (sig : Signal; handler : isr_address) return isr_address;
139    pragma Import (C, c_signal, "signal");
140
141    function sigwait (set : access sigset_t; sig : access Signal) return int;
142    pragma Inline (sigwait);
143
144    type sigset_t_ptr is access all sigset_t;
145
146    function pthread_sigmask
147      (how  : int;
148       set  : sigset_t_ptr;
149       oset : sigset_t_ptr) return int;
150    pragma Import (C, pthread_sigmask, "sigprocmask");
151
152    type t_id is new long;
153    subtype Thread_Id is t_id;
154
155    function kill (pid : t_id; sig : Signal) return int;
156    pragma Import (C, kill, "kill");
157
158    --  VxWorks doesn't have getpid; taskIdSelf is the equivalent
159    --  routine.
160    function getpid return t_id;
161    pragma Import (C, getpid, "taskIdSelf");
162
163    ----------
164    -- Time --
165    ----------
166
167    type time_t is new unsigned_long;
168
169    type timespec is record
170       ts_sec  : time_t;
171       ts_nsec : long;
172    end record;
173    pragma Convention (C, timespec);
174
175    type clockid_t is private;
176
177    CLOCK_REALTIME : constant clockid_t;   --  System wide realtime clock
178
179    function To_Duration (TS : timespec) return Duration;
180    pragma Inline (To_Duration);
181
182    function To_Timespec (D : Duration) return timespec;
183    pragma Inline (To_Timespec);
184
185    function To_Clock_Ticks (D : Duration) return int;
186    --  Convert a duration value (in seconds) into clock ticks.
187
188    function clock_gettime
189      (clock_id : clockid_t; tp : access timespec) return int;
190    pragma Import (C, clock_gettime, "clock_gettime");
191
192    type ULONG is new unsigned_long;
193
194    procedure tickSet (ticks : ULONG);
195    pragma Import (C, tickSet, "tickSet");
196
197    function tickGet return ULONG;
198    pragma Import (C, tickGet, "tickGet");
199
200    ----------------------
201    -- Utility Routines --
202    ----------------------
203
204    function To_VxWorks_Priority (Priority : in int) return int;
205    pragma Inline (To_VxWorks_Priority);
206    --  Convenience routine to convert between VxWorks priority and Ada priority
207
208    --------------------------
209    -- VxWorks specific API --
210    --------------------------
211
212    subtype STATUS is int;
213    --  Equivalent of the C type STATUS
214
215    OK    : constant STATUS := 0;
216    ERROR : constant STATUS := Interfaces.C.int (-1);
217
218    function taskIdVerify (tid : t_id)  return STATUS;
219    pragma Import (C, taskIdVerify, "taskIdVerify");
220
221    function taskIdSelf return t_id;
222    pragma Import (C, taskIdSelf, "taskIdSelf");
223
224    function taskSuspend (tid : t_id) return int;
225    pragma Import (C, taskSuspend, "taskSuspend");
226
227    function taskResume (tid : t_id) return int;
228    pragma Import (C, taskResume, "taskResume");
229
230    function taskIsSuspended (tid : t_id) return int;
231    pragma Import (C, taskIsSuspended, "taskIsSuspended");
232
233    function taskVarAdd
234      (tid : t_id; pVar : access System.Address) return int;
235    pragma Import (C, taskVarAdd, "taskVarAdd");
236
237    function taskVarDelete
238      (tid : t_id; pVar : access System.Address) return int;
239    pragma Import (C, taskVarDelete, "taskVarDelete");
240
241    function taskVarSet
242      (tid   : t_id;
243       pVar  : access System.Address;
244       value : System.Address) return int;
245    pragma Import (C, taskVarSet, "taskVarSet");
246
247    function taskVarGet
248      (tid  : t_id;
249       pVar : access System.Address) return int;
250    pragma Import (C, taskVarGet, "taskVarGet");
251
252    function taskDelay (ticks : int) return int;
253    procedure taskDelay (ticks : int);
254    pragma Import (C, taskDelay, "taskDelay");
255
256    function sysClkRateGet return int;
257    pragma Import (C, sysClkRateGet, "sysClkRateGet");
258
259    --  Option flags for taskSpawn
260
261    VX_UNBREAKABLE    : constant := 16#0002#;
262    VX_FP_TASK        : constant := 16#0008#;
263    VX_FP_PRIVATE_ENV : constant := 16#0080#;
264    VX_NO_STACK_FILL  : constant := 16#0100#;
265
266    function taskSpawn
267      (name          : System.Address;  --  Pointer to task name
268       priority      : int;
269       options       : int;
270       stacksize     : size_t;
271       start_routine : System.Address;
272       arg1          : System.Address;
273       arg2          : int := 0;
274       arg3          : int := 0;
275       arg4          : int := 0;
276       arg5          : int := 0;
277       arg6          : int := 0;
278       arg7          : int := 0;
279       arg8          : int := 0;
280       arg9          : int := 0;
281       arg10         : int := 0) return t_id;
282    pragma Import (C, taskSpawn, "taskSpawn");
283
284    procedure taskDelete (tid : t_id);
285    pragma Import (C, taskDelete, "taskDelete");
286
287    function kernelTimeSlice (ticks : int) return int;
288    pragma Import (C, kernelTimeSlice, "kernelTimeSlice");
289
290    function taskPrioritySet
291      (tid : t_id; newPriority : int) return int;
292    pragma Import (C, taskPrioritySet, "taskPrioritySet");
293
294    --  Semaphore creation flags.
295
296    SEM_Q_FIFO         : constant := 0;
297    SEM_Q_PRIORITY     : constant := 1;
298    SEM_DELETE_SAFE    : constant := 4;  -- only valid for binary semaphore
299    SEM_INVERSION_SAFE : constant := 8;  -- only valid for binary semaphore
300
301    --  Semaphore initial state flags
302
303    SEM_EMPTY : constant := 0;
304    SEM_FULL  : constant := 1;
305
306    --  Semaphore take (semTake) time constants.
307
308    WAIT_FOREVER : constant := -1;
309    NO_WAIT      : constant := 0;
310
311    --  Error codes (errno).  The lower level 16 bits are the
312    --  error code, with the upper 16 bits representing the
313    --  module number in which the error occurred.  By convention,
314    --  the module number is 0 for UNIX errors.  VxWorks reserves
315    --  module numbers 1-500, with the remaining module numbers
316    --  being available for user applications.
317
318    M_objLib                 : constant := 61 * 2**16;
319    --  semTake() failure with ticks = NO_WAIT
320    S_objLib_OBJ_UNAVAILABLE : constant := M_objLib + 2;
321    --  semTake() timeout with ticks > NO_WAIT
322    S_objLib_OBJ_TIMEOUT     : constant := M_objLib + 4;
323
324    type SEM_ID is new System.Address;
325    --  typedef struct semaphore *SEM_ID;
326
327    --  We use two different kinds of VxWorks semaphores: mutex
328    --  and binary semaphores.  A null ID is returned when
329    --  a semaphore cannot be created.
330
331    function semBCreate (options : int; initial_state : int) return SEM_ID;
332    --  Create a binary semaphore. Return ID, or 0 if memory could not
333    --  be allocated.
334    pragma Import (C, semBCreate, "semBCreate");
335
336    function semMCreate (options : int) return SEM_ID;
337    pragma Import (C, semMCreate, "semMCreate");
338
339    function semDelete (Sem : SEM_ID) return int;
340    --  Delete a semaphore
341    pragma Import (C, semDelete, "semDelete");
342
343    function semGive (Sem : SEM_ID) return int;
344    pragma Import (C, semGive, "semGive");
345
346    function semTake (Sem : SEM_ID; timeout : int) return int;
347    --  Attempt to take binary semaphore.  Error is returned if operation
348    --  times out
349    pragma Import (C, semTake, "semTake");
350
351    function semFlush (SemID : SEM_ID) return STATUS;
352    --  Release all threads blocked on the semaphore
353    pragma Import (C, semFlush, "semFlush");
354
355    function taskLock return int;
356    pragma Import (C, taskLock, "taskLock");
357
358    function taskUnlock return int;
359    pragma Import (C, taskUnlock, "taskUnlock");
360
361 private
362    type sigset_t is new long;
363
364    type pid_t is new int;
365
366    ERROR_PID : constant pid_t := -1;
367
368    type clockid_t is new int;
369    CLOCK_REALTIME : constant clockid_t := 0;
370
371 end System.OS_Interface;