OSDN Git Service

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