OSDN Git Service

2007-09-26 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-vxworks6.ads
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 --                                   S p e c                                --
8 --                                                                          --
9 --            Copyright (C) 1991-1994, Florida State University             --
10 --          Copyright (C) 1995-2007, 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,  51  Franklin  Street,  Fifth  Floor, --
21 -- Boston, MA 02110-1301, 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 6.x 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 unsigned_int       is mod 2 ** int'Size;
52    type long               is new Long_Integer;
53    type unsigned_long      is mod 2 ** long'Size;
54    type long_long          is new Long_Long_Integer;
55    type unsigned_long_long is mod 2 ** long_long'Size;
56    type size_t             is mod 2 ** Standard'Address_Size;
57
58    -----------
59    -- Errno --
60    -----------
61
62    function errno return int;
63    pragma Import (C, errno, "errnoGet");
64
65    EINTR     : constant := 4;
66    EAGAIN    : constant := 35;
67    ENOMEM    : constant := 12;
68    EINVAL    : constant := 22;
69    ETIMEDOUT : constant := 60;
70
71    FUNC_ERR  : constant := -1;
72
73    ----------------------------
74    -- Signals and Interrupts --
75    ----------------------------
76
77    NSIG : constant := 64;
78    --  Number of signals on the target OS
79    type Signal is new int range 0 .. Interfaces.C."-" (NSIG, 1);
80
81    Max_HW_Interrupt : constant := System.VxWorks.Num_HW_Interrupts - 1;
82    type HW_Interrupt is new int range 0 .. Max_HW_Interrupt;
83
84    Max_Interrupt : constant := Max_HW_Interrupt;
85
86    SIGHUP    : constant :=  1; --  hangup
87    SIGINT    : constant :=  2; --  interrupt
88    SIGQUIT   : constant :=  3; --  quit
89    SIGILL    : constant :=  4; --  illegal instruction (not reset when caught)
90    SIGTRAP   : constant :=  5; --  trace trap (not reset when caught)
91    SIGABRT   : constant :=  6; --  used by abort, replace SIGIOT in the future
92    SIGEMT    : constant :=  7; --  EMT instruction
93    SIGFPE    : constant :=  8; --  floating point exception
94    SIGKILL   : constant :=  9; --  kill
95    SIGBUS    : constant := 10; --  bus error
96    SIGSEGV   : constant := 11; --  segmentation violation
97    SIGFMT    : constant := 12; --  STACK FORMAT ERROR (not posix)
98    SIGPIPE   : constant := 13; --  write on a pipe with no one to read it
99    SIGALRM   : constant := 14; --  alarm clock
100    SIGTERM   : constant := 15; --  software termination signal from kill
101    SIGCNCL   : constant := 16; --  pthreads cancellation signal
102    SIGSTOP   : constant := 17; --  sendable stop signal not from tty
103    SIGTSTP   : constant := 18; --  stop signal from tty
104    SIGCONT   : constant := 19; --  continue a stopped process
105    SIGCHLD   : constant := 20; --  to parent on child stop or exit
106    SIGTTIN   : constant := 21; --  to readers pgrp upon background tty read
107    SIGTTOU   : constant := 22; --  like TTIN for output
108
109    SIGRES1   : constant := 23; --  reserved signal number (Not POSIX)
110    SIGRES2   : constant := 24; --  reserved signal number (Not POSIX)
111    SIGRES3   : constant := 25; --  reserved signal number (Not POSIX)
112    SIGRES4   : constant := 26; --  reserved signal number (Not POSIX)
113    SIGRES5   : constant := 27; --  reserved signal number (Not POSIX)
114    SIGRES6   : constant := 28; --  reserved signal number (Not POSIX)
115    SIGRES7   : constant := 29; --  reserved signal number (Not POSIX)
116
117    SIGUSR1   : constant := 30; --  user defined signal 1
118    SIGUSR2   : constant := 31; --  user defined signal 2
119
120    SIGPOLL   : constant := 32; --  pollable event
121    SIGPROF   : constant := 33; --  profiling timer expired
122    SIGSYS    : constant := 34; --  bad system call
123    SIGURG    : constant := 35; --  high bandwidth data is available at socket
124    SIGVTALRM : constant := 36; --  virtual timer expired
125    SIGXCPU   : constant := 37; --  CPU time limit exceeded
126    SIGXFSZ   : constant := 38; --  file size time limit exceeded
127
128    SIGEVTS   : constant := 39; --  signal event thread send
129    SIGEVTD   : constant := 40; --  signal event thread delete
130
131    SIGRTMIN  : constant := 48; --  Realtime signal min
132    SIGRTMAX  : constant := 63; --  Realtime signal max
133
134    -----------------------------------
135    -- Signal processing definitions --
136    -----------------------------------
137
138    --  The how in sigprocmask().
139    SIG_BLOCK   : constant := 1;
140    SIG_UNBLOCK : constant := 2;
141    SIG_SETMASK : constant := 3;
142
143    --  The sa_flags in struct sigaction.
144    SA_SIGINFO   : constant := 16#0002#;
145    SA_ONSTACK   : constant := 16#0004#;
146
147    SIG_DFL : constant := 0;
148    SIG_IGN : constant := 1;
149
150    type sigset_t is private;
151
152    type struct_sigaction is record
153       sa_handler : System.Address;
154       sa_mask    : sigset_t;
155       sa_flags   : int;
156    end record;
157    pragma Convention (C, struct_sigaction);
158    type struct_sigaction_ptr is access all struct_sigaction;
159
160    function sigaddset (set : access sigset_t; sig : Signal) return int;
161    pragma Import (C, sigaddset, "sigaddset");
162
163    function sigdelset (set : access sigset_t; sig : Signal) return int;
164    pragma Import (C, sigdelset, "sigdelset");
165
166    function sigfillset (set : access sigset_t) return int;
167    pragma Import (C, sigfillset, "sigfillset");
168
169    function sigismember (set : access sigset_t; sig : Signal) return int;
170    pragma Import (C, sigismember, "sigismember");
171
172    function sigemptyset (set : access sigset_t) return int;
173    pragma Import (C, sigemptyset, "sigemptyset");
174
175    function sigaction
176      (sig  : Signal;
177       act  : struct_sigaction_ptr;
178       oact : struct_sigaction_ptr) return int;
179    pragma Import (C, sigaction, "sigaction");
180
181    type isr_address is access procedure (sig : int);
182
183    function c_signal (sig : Signal; handler : isr_address) return isr_address;
184    pragma Import (C, c_signal, "signal");
185
186    function sigwait (set : access sigset_t; sig : access Signal) return int;
187    pragma Inline (sigwait);
188
189    function pthread_sigmask
190      (how  : int;
191       set  : access sigset_t;
192       oset : access sigset_t) return int;
193    pragma Import (C, pthread_sigmask, "sigprocmask");
194
195    type t_id is new long;
196    subtype Thread_Id is t_id;
197
198    function kill (pid : t_id; sig : Signal) return int;
199    pragma Inline (kill);
200
201    function getpid return t_id;
202    pragma Inline (getpid);
203
204    function Task_Stop (tid : t_id) return int;
205    pragma Inline (Task_Stop);
206    --  If we are in the kernel space, continue the task whose t_id is
207    --  given in parameter if it has been stopped previously to be examined
208    --  by the debugger (e.g. by taskStop). It typically maps to taskResume
209    --  on VxWorks 5 and to taskCont on VxWorks 6.
210
211    function Task_Cont (tid : t_id) return int;
212    pragma Inline (Task_Cont);
213    --  If we are in the kernel space, lock interrupts. It typically maps to
214    --  intLock.
215
216    function Int_Lock return int;
217    pragma Inline (Int_Lock);
218    --  If we are in the kernel space, lock interrupts. It typically maps to
219    --  intLock.
220
221    function Int_Unlock return int;
222    pragma Inline (Int_Unlock);
223    --  If we are in the kernel space, unlock interrupts. It typically maps to
224    --  intUnlock.
225
226    ----------
227    -- Time --
228    ----------
229
230    type time_t is new unsigned_long;
231
232    type timespec is record
233       ts_sec  : time_t;
234       ts_nsec : long;
235    end record;
236    pragma Convention (C, timespec);
237
238    type clockid_t is private;
239
240    CLOCK_REALTIME : constant clockid_t;   --  System wide realtime clock
241
242    function To_Duration (TS : timespec) return Duration;
243    pragma Inline (To_Duration);
244
245    function To_Timespec (D : Duration) return timespec;
246    pragma Inline (To_Timespec);
247
248    function To_Clock_Ticks (D : Duration) return int;
249    --  Convert a duration value (in seconds) into clock ticks
250
251    function clock_gettime
252      (clock_id : clockid_t; tp : access timespec) return int;
253    pragma Import (C, clock_gettime, "clock_gettime");
254
255    type ULONG is new unsigned_long;
256
257    procedure tickSet (ticks : ULONG);
258    pragma Import (C, tickSet, "tickSet");
259
260    function tickGet return ULONG;
261    pragma Import (C, tickGet, "tickGet");
262
263    ----------------------
264    -- Utility Routines --
265    ----------------------
266
267    function To_VxWorks_Priority (Priority : int) return int;
268    pragma Inline (To_VxWorks_Priority);
269    --  Convenience routine to convert between VxWorks priority and Ada priority
270
271    --------------------------
272    -- VxWorks specific API --
273    --------------------------
274
275    subtype STATUS is int;
276    --  Equivalent of the C type STATUS
277
278    OK    : constant STATUS := 0;
279    ERROR : constant STATUS := Interfaces.C.int (-1);
280
281    function taskIdVerify (tid : t_id)  return STATUS;
282    pragma Import (C, taskIdVerify, "taskIdVerify");
283
284    function taskIdSelf return t_id;
285    pragma Import (C, taskIdSelf, "taskIdSelf");
286
287    function taskOptionsGet (tid : t_id; pOptions : access int) return int;
288    pragma Import (C, taskOptionsGet, "taskOptionsGet");
289
290    function taskSuspend (tid : t_id) return int;
291    pragma Import (C, taskSuspend, "taskSuspend");
292
293    function taskResume (tid : t_id) return int;
294    pragma Import (C, taskResume, "taskResume");
295
296    function taskIsSuspended (tid : t_id) return int;
297    pragma Import (C, taskIsSuspended, "taskIsSuspended");
298
299    function taskDelay (ticks : int) return int;
300    procedure taskDelay (ticks : int);
301    pragma Import (C, taskDelay, "taskDelay");
302
303    function sysClkRateGet return int;
304    pragma Import (C, sysClkRateGet, "sysClkRateGet");
305
306    --  VxWorks 5.x specific functions
307
308    function taskVarAdd
309      (tid : t_id; pVar : access System.Address) return int;
310    pragma Import (C, taskVarAdd, "taskVarAdd");
311
312    function taskVarDelete
313      (tid : t_id; pVar : access System.Address) return int;
314    pragma Import (C, taskVarDelete, "taskVarDelete");
315
316    function taskVarSet
317      (tid   : t_id;
318       pVar  : access System.Address;
319       value : System.Address) return int;
320    pragma Import (C, taskVarSet, "taskVarSet");
321
322    function taskVarGet
323      (tid  : t_id;
324       pVar : access System.Address) return int;
325    pragma Import (C, taskVarGet, "taskVarGet");
326
327    --  VxWorks 6.x specific functions
328
329    function tlsKeyCreate return int;
330    pragma Import (C, tlsKeyCreate, "tlsKeyCreate");
331
332    function tlsValueGet (key : int) return System.Address;
333    pragma Import (C, tlsValueGet, "tlsValueGet");
334
335    function tlsValueSet (key : int; value : System.Address) return STATUS;
336    pragma Import (C, tlsValueSet, "tlsValueSet");
337
338    --  Option flags for taskSpawn
339
340    VX_UNBREAKABLE    : constant := 16#0002#;
341    VX_FP_PRIVATE_ENV : constant := 16#0080#;
342    VX_NO_STACK_FILL  : constant := 16#0100#;
343
344    function taskSpawn
345      (name          : System.Address;  --  Pointer to task name
346       priority      : int;
347       options       : int;
348       stacksize     : size_t;
349       start_routine : System.Address;
350       arg1          : System.Address;
351       arg2          : int := 0;
352       arg3          : int := 0;
353       arg4          : int := 0;
354       arg5          : int := 0;
355       arg6          : int := 0;
356       arg7          : int := 0;
357       arg8          : int := 0;
358       arg9          : int := 0;
359       arg10         : int := 0) return t_id;
360    pragma Import (C, taskSpawn, "taskSpawn");
361
362    procedure taskDelete (tid : t_id);
363    pragma Import (C, taskDelete, "taskDelete");
364
365    function Set_Time_Slice (ticks : int) return int;
366    pragma Inline (Set_Time_Slice);
367    --  Calls kernelTimeSlice under VxWorks 5.x
368    --  Do nothing under VxWorks 6.x
369
370    function taskPriorityGet (tid : t_id; pPriority : access int) return int;
371    pragma Import (C, taskPriorityGet, "taskPriorityGet");
372
373    function taskPrioritySet (tid : t_id; newPriority : int) return int;
374    pragma Import (C, taskPrioritySet, "taskPrioritySet");
375
376    --  Semaphore creation flags
377
378    SEM_Q_FIFO         : constant := 0;
379    SEM_Q_PRIORITY     : constant := 1;
380    SEM_DELETE_SAFE    : constant := 4;  -- only valid for binary semaphore
381    SEM_INVERSION_SAFE : constant := 8;  -- only valid for binary semaphore
382
383    --  Semaphore initial state flags
384
385    SEM_EMPTY : constant := 0;
386    SEM_FULL  : constant := 1;
387
388    --  Semaphore take (semTake) time constants
389
390    WAIT_FOREVER : constant := -1;
391    NO_WAIT      : constant := 0;
392
393    --  Error codes (errno). The lower level 16 bits are the error code, with
394    --  the upper 16 bits representing the module number in which the error
395    --  occurred. By convention, the module number is 0 for UNIX errors. VxWorks
396    --  reserves module numbers 1-500, with the remaining module numbers being
397    --  available for user applications.
398
399    M_objLib                 : constant := 61 * 2**16;
400    --  semTake() failure with ticks = NO_WAIT
401    S_objLib_OBJ_UNAVAILABLE : constant := M_objLib + 2;
402    --  semTake() timeout with ticks > NO_WAIT
403    S_objLib_OBJ_TIMEOUT     : constant := M_objLib + 4;
404
405    type SEM_ID is new System.Address;
406    --  typedef struct semaphore *SEM_ID;
407
408    --  We use two different kinds of VxWorks semaphores: mutex and binary
409    --  semaphores. A null ID is returned when a semaphore cannot be created.
410
411    function semBCreate (options : int; initial_state : int) return SEM_ID;
412    pragma Import (C, semBCreate, "semBCreate");
413    --  Create a binary semaphore. Return ID, or 0 if memory could not
414    --  be allocated.
415
416    function semMCreate (options : int) return SEM_ID;
417    pragma Import (C, semMCreate, "semMCreate");
418
419    function semDelete (Sem : SEM_ID) return int;
420    pragma Import (C, semDelete, "semDelete");
421    --  Delete a semaphore
422
423    function semGive (Sem : SEM_ID) return int;
424    pragma Import (C, semGive, "semGive");
425
426    function semTake (Sem : SEM_ID; timeout : int) return int;
427    pragma Import (C, semTake, "semTake");
428    --  Attempt to take binary semaphore.  Error is returned if operation
429    --  times out
430
431    function semFlush (SemID : SEM_ID) return STATUS;
432    pragma Import (C, semFlush, "semFlush");
433    --  Release all threads blocked on the semaphore
434
435 private
436    type sigset_t is new unsigned_long_long;
437
438    type pid_t is new int;
439
440    ERROR_PID : constant pid_t := -1;
441
442    type clockid_t is new int;
443    CLOCK_REALTIME : constant clockid_t := 0;
444
445 end System.OS_Interface;