OSDN Git Service

2011-08-05 Yannick Moy <moy@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-vxworks.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-2010, 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 3,  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.                                     --
18 --                                                                          --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception,   --
21 -- version 3.1, as published by the Free Software Foundation.               --
22 --                                                                          --
23 -- You should have received a copy of the GNU General Public License and    --
24 -- a copy of the GCC Runtime Library Exception along with this program;     --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
26 -- <http://www.gnu.org/licenses/>.                                          --
27 --                                                                          --
28 -- GNARL was developed by the GNARL team at Florida State University.       --
29 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
30 --                                                                          --
31 ------------------------------------------------------------------------------
32
33 --  This is the VxWorks version of this package
34
35 --  This package encapsulates all direct interfaces to OS services
36 --  that are needed by the tasking run-time (libgnarl).
37
38 --  PLEASE DO NOT add any with-clauses to this package or remove the pragma
39 --  Preelaborate. This package is designed to be a bottom-level (leaf) package.
40
41 with Interfaces.C;
42 with System.VxWorks;
43 with System.VxWorks.Ext;
44 with System.Multiprocessors;
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    --  Signals common to Vxworks 5.x and 6.x
87
88    SIGILL    : constant :=  4; --  illegal instruction (not reset when caught)
89    SIGABRT   : constant :=  6; --  used by abort, replace SIGIOT in the future
90    SIGFPE    : constant :=  8; --  floating point exception
91    SIGBUS    : constant := 10; --  bus error
92    SIGSEGV   : constant := 11; --  segmentation violation
93
94    --  Signals specific to VxWorks 6.x
95
96    SIGHUP    : constant :=  1; --  hangup
97    SIGINT    : constant :=  2; --  interrupt
98    SIGQUIT   : constant :=  3; --  quit
99    SIGTRAP   : constant :=  5; --  trace trap (not reset when caught)
100    SIGEMT    : constant :=  7; --  EMT instruction
101    SIGKILL   : constant :=  9; --  kill
102    SIGFMT    : constant := 12; --  STACK FORMAT ERROR (not posix)
103    SIGPIPE   : constant := 13; --  write on a pipe with no one to read it
104    SIGALRM   : constant := 14; --  alarm clock
105    SIGTERM   : constant := 15; --  software termination signal from kill
106    SIGCNCL   : constant := 16; --  pthreads cancellation signal
107    SIGSTOP   : constant := 17; --  sendable stop signal not from tty
108    SIGTSTP   : constant := 18; --  stop signal from tty
109    SIGCONT   : constant := 19; --  continue a stopped process
110    SIGCHLD   : constant := 20; --  to parent on child stop or exit
111    SIGTTIN   : constant := 21; --  to readers pgrp upon background tty read
112    SIGTTOU   : constant := 22; --  like TTIN for output
113
114    SIGRES1   : constant := 23; --  reserved signal number (Not POSIX)
115    SIGRES2   : constant := 24; --  reserved signal number (Not POSIX)
116    SIGRES3   : constant := 25; --  reserved signal number (Not POSIX)
117    SIGRES4   : constant := 26; --  reserved signal number (Not POSIX)
118    SIGRES5   : constant := 27; --  reserved signal number (Not POSIX)
119    SIGRES6   : constant := 28; --  reserved signal number (Not POSIX)
120    SIGRES7   : constant := 29; --  reserved signal number (Not POSIX)
121
122    SIGUSR1   : constant := 30; --  user defined signal 1
123    SIGUSR2   : constant := 31; --  user defined signal 2
124
125    SIGPOLL   : constant := 32; --  pollable event
126    SIGPROF   : constant := 33; --  profiling timer expired
127    SIGSYS    : constant := 34; --  bad system call
128    SIGURG    : constant := 35; --  high bandwidth data is available at socket
129    SIGVTALRM : constant := 36; --  virtual timer expired
130    SIGXCPU   : constant := 37; --  CPU time limit exceeded
131    SIGXFSZ   : constant := 38; --  file size time limit exceeded
132
133    SIGEVTS   : constant := 39; --  signal event thread send
134    SIGEVTD   : constant := 40; --  signal event thread delete
135
136    SIGRTMIN  : constant := 48; --  Realtime signal min
137    SIGRTMAX  : constant := 63; --  Realtime signal max
138
139    -----------------------------------
140    -- Signal processing definitions --
141    -----------------------------------
142
143    --  The how in sigprocmask()
144
145    SIG_BLOCK   : constant := 1;
146    SIG_UNBLOCK : constant := 2;
147    SIG_SETMASK : constant := 3;
148
149    --  The sa_flags in struct sigaction
150
151    SA_SIGINFO : constant := 16#0002#;
152    SA_ONSTACK : constant := 16#0004#;
153
154    SIG_DFL : constant := 0;
155    SIG_IGN : constant := 1;
156
157    type sigset_t is private;
158
159    type struct_sigaction is record
160       sa_handler : System.Address;
161       sa_mask    : sigset_t;
162       sa_flags   : int;
163    end record;
164    pragma Convention (C, struct_sigaction);
165    type struct_sigaction_ptr is access all struct_sigaction;
166
167    function sigaddset (set : access sigset_t; sig : Signal) return int;
168    pragma Import (C, sigaddset, "sigaddset");
169
170    function sigdelset (set : access sigset_t; sig : Signal) return int;
171    pragma Import (C, sigdelset, "sigdelset");
172
173    function sigfillset (set : access sigset_t) return int;
174    pragma Import (C, sigfillset, "sigfillset");
175
176    function sigismember (set : access sigset_t; sig : Signal) return int;
177    pragma Import (C, sigismember, "sigismember");
178
179    function sigemptyset (set : access sigset_t) return int;
180    pragma Import (C, sigemptyset, "sigemptyset");
181
182    function sigaction
183      (sig  : Signal;
184       act  : struct_sigaction_ptr;
185       oact : struct_sigaction_ptr) return int;
186    pragma Import (C, sigaction, "sigaction");
187
188    type isr_address is access procedure (sig : int);
189    pragma Convention (C, isr_address);
190
191    function c_signal (sig : Signal; handler : isr_address) return isr_address;
192    pragma Import (C, c_signal, "signal");
193
194    function sigwait (set : access sigset_t; sig : access Signal) return int;
195    pragma Inline (sigwait);
196
197    function pthread_sigmask
198      (how  : int;
199       set  : access sigset_t;
200       oset : access sigset_t) return int;
201    pragma Import (C, pthread_sigmask, "sigprocmask");
202
203    subtype t_id is System.VxWorks.Ext.t_id;
204    subtype Thread_Id is t_id;
205
206    function kill (pid : t_id; sig : Signal) return int;
207    pragma Inline (kill);
208
209    function getpid return t_id renames System.VxWorks.Ext.getpid;
210
211    function Task_Stop (tid : t_id) return int
212      renames System.VxWorks.Ext.Task_Stop;
213    --  If we are in the kernel space, stop the task whose t_id is
214    --  given in parameter in such a way that it can be examined by the
215    --  debugger. This typically maps to taskSuspend on VxWorks 5 and
216    --  to taskStop on VxWorks 6.
217
218    function Task_Cont (tid : t_id) return int
219      renames System.VxWorks.Ext.Task_Cont;
220    --  If we are in the kernel space, continue the task whose t_id is
221    --  given in parameter if it has been stopped previously to be examined
222    --  by the debugger (e.g. by taskStop). It typically maps to taskResume
223    --  on VxWorks 5 and to taskCont on VxWorks 6.
224
225    function Int_Lock return int renames System.VxWorks.Ext.Int_Lock;
226    --  If we are in the kernel space, lock interrupts. It typically maps to
227    --  intLock.
228
229    function Int_Unlock return int renames System.VxWorks.Ext.Int_Unlock;
230    --  If we are in the kernel space, unlock interrupts. It typically maps to
231    --  intUnlock.
232
233    ----------
234    -- Time --
235    ----------
236
237    type time_t is new unsigned_long;
238
239    type timespec is record
240       ts_sec  : time_t;
241       ts_nsec : long;
242    end record;
243    pragma Convention (C, timespec);
244
245    type clockid_t is private;
246
247    CLOCK_REALTIME : constant clockid_t;   --  System wide realtime clock
248
249    function To_Duration (TS : timespec) return Duration;
250    pragma Inline (To_Duration);
251
252    function To_Timespec (D : Duration) return timespec;
253    pragma Inline (To_Timespec);
254
255    function To_Clock_Ticks (D : Duration) return int;
256    --  Convert a duration value (in seconds) into clock ticks
257
258    function clock_gettime
259      (clock_id : clockid_t; tp : access timespec) return int;
260    pragma Import (C, clock_gettime, "clock_gettime");
261
262    ----------------------
263    -- Utility Routines --
264    ----------------------
265
266    function To_VxWorks_Priority (Priority : int) return int;
267    pragma Inline (To_VxWorks_Priority);
268    --  Convenience routine to convert between VxWorks priority and Ada priority
269
270    --------------------------
271    -- VxWorks specific API --
272    --------------------------
273
274    subtype STATUS is int;
275    --  Equivalent of the C type STATUS
276
277    OK    : constant STATUS := 0;
278    ERROR : constant STATUS := Interfaces.C.int (-1);
279
280    function taskIdVerify (tid : t_id)  return STATUS;
281    pragma Import (C, taskIdVerify, "taskIdVerify");
282
283    function taskIdSelf return t_id;
284    pragma Import (C, taskIdSelf, "taskIdSelf");
285
286    function taskOptionsGet (tid : t_id; pOptions : access int) return int;
287    pragma Import (C, taskOptionsGet, "taskOptionsGet");
288
289    function taskSuspend (tid : t_id) return int;
290    pragma Import (C, taskSuspend, "taskSuspend");
291
292    function taskResume (tid : t_id) return int;
293    pragma Import (C, taskResume, "taskResume");
294
295    function taskIsSuspended (tid : t_id) return int;
296    pragma Import (C, taskIsSuspended, "taskIsSuspended");
297
298    function taskDelay (ticks : int) return int;
299    procedure taskDelay (ticks : int);
300    pragma Import (C, taskDelay, "taskDelay");
301
302    function sysClkRateGet return int;
303    pragma Import (C, sysClkRateGet, "sysClkRateGet");
304
305    --  VxWorks 5.x specific functions
306    --  Must not be called from run-time for versions that do not support
307    --  taskVarLib: eg VxWorks 6 RTPs
308
309    function taskVarAdd
310      (tid : t_id; pVar : access System.Address) return int;
311    pragma Import (C, taskVarAdd, "taskVarAdd");
312
313    function taskVarDelete
314      (tid : t_id; pVar : access System.Address) return int;
315    pragma Import (C, taskVarDelete, "taskVarDelete");
316
317    function taskVarSet
318      (tid   : t_id;
319       pVar  : access System.Address;
320       value : System.Address) return int;
321    pragma Import (C, taskVarSet, "taskVarSet");
322
323    function taskVarGet
324      (tid  : t_id;
325       pVar : access System.Address) return int;
326    pragma Import (C, taskVarGet, "taskVarGet");
327
328    --  VxWorks 6.x specific functions
329    --  Can only be called from the VxWorks 6 run-time libary that supports
330    --  tlsLib, and not by the VxWorks 6.6 SMP library
331
332    function tlsKeyCreate return int;
333    pragma Import (C, tlsKeyCreate, "tlsKeyCreate");
334
335    function tlsValueGet (key : int) return System.Address;
336    pragma Import (C, tlsValueGet, "tlsValueGet");
337
338    function tlsValueSet (key : int; value : System.Address) return STATUS;
339    pragma Import (C, tlsValueSet, "tlsValueSet");
340
341    --  Option flags for taskSpawn
342
343    VX_UNBREAKABLE    : constant := 16#0002#;
344    VX_FP_PRIVATE_ENV : constant := 16#0080#;
345    VX_NO_STACK_FILL  : constant := 16#0100#;
346
347    function taskSpawn
348      (name          : System.Address;  --  Pointer to task name
349       priority      : int;
350       options       : int;
351       stacksize     : size_t;
352       start_routine : System.Address;
353       arg1          : System.Address;
354       arg2          : int := 0;
355       arg3          : int := 0;
356       arg4          : int := 0;
357       arg5          : int := 0;
358       arg6          : int := 0;
359       arg7          : int := 0;
360       arg8          : int := 0;
361       arg9          : int := 0;
362       arg10         : int := 0) return t_id;
363    pragma Import (C, taskSpawn, "taskSpawn");
364
365    procedure taskDelete (tid : t_id);
366    pragma Import (C, taskDelete, "taskDelete");
367
368    function Set_Time_Slice (ticks : int) return int
369      renames System.VxWorks.Ext.Set_Time_Slice;
370    --  Calls kernelTimeSlice under VxWorks 5.x, VxWorks 653, or in VxWorks 6
371    --  kernel apps. Returns ERROR for RTPs, VxWorks 5 /CERT
372
373    function taskPriorityGet (tid : t_id; pPriority : access int) return int;
374    pragma Import (C, taskPriorityGet, "taskPriorityGet");
375
376    function taskPrioritySet (tid : t_id; newPriority : int) return int;
377    pragma Import (C, taskPrioritySet, "taskPrioritySet");
378
379    --  Semaphore creation flags
380
381    SEM_Q_FIFO         : constant := 0;
382    SEM_Q_PRIORITY     : constant := 1;
383    SEM_DELETE_SAFE    : constant := 4;  -- only valid for binary semaphore
384    SEM_INVERSION_SAFE : constant := 8;  -- only valid for binary semaphore
385
386    --  Semaphore initial state flags
387
388    SEM_EMPTY : constant := 0;
389    SEM_FULL  : constant := 1;
390
391    --  Semaphore take (semTake) time constants
392
393    WAIT_FOREVER : constant := -1;
394    NO_WAIT      : constant := 0;
395
396    --  Error codes (errno). The lower level 16 bits are the error code, with
397    --  the upper 16 bits representing the module number in which the error
398    --  occurred. By convention, the module number is 0 for UNIX errors. VxWorks
399    --  reserves module numbers 1-500, with the remaining module numbers being
400    --  available for user applications.
401
402    M_objLib                 : constant := 61 * 2**16;
403    --  semTake() failure with ticks = NO_WAIT
404    S_objLib_OBJ_UNAVAILABLE : constant := M_objLib + 2;
405    --  semTake() timeout with ticks > NO_WAIT
406    S_objLib_OBJ_TIMEOUT     : constant := M_objLib + 4;
407
408    subtype SEM_ID is System.VxWorks.Ext.SEM_ID;
409    --  typedef struct semaphore *SEM_ID;
410
411    --  We use two different kinds of VxWorks semaphores: mutex and binary
412    --  semaphores. A null ID is returned when a semaphore cannot be created.
413
414    function semBCreate (options : int; initial_state : int) return SEM_ID;
415    pragma Import (C, semBCreate, "semBCreate");
416    --  Create a binary semaphore. Return ID, or 0 if memory could not
417    --  be allocated.
418
419    function semMCreate (options : int) return SEM_ID;
420    pragma Import (C, semMCreate, "semMCreate");
421
422    function semDelete (Sem : SEM_ID) return int
423      renames System.VxWorks.Ext.semDelete;
424    --  Delete a semaphore
425
426    function semGive (Sem : SEM_ID) return int;
427    pragma Import (C, semGive, "semGive");
428
429    function semTake (Sem : SEM_ID; timeout : int) return int;
430    pragma Import (C, semTake, "semTake");
431    --  Attempt to take binary semaphore.  Error is returned if operation
432    --  times out
433
434    function semFlush (SemID : SEM_ID) return STATUS;
435    pragma Import (C, semFlush, "semFlush");
436    --  Release all threads blocked on the semaphore
437
438    ------------------------------------------------------------
439    --   Binary Semaphore Wrapper to Support interrupt Tasks  --
440    ------------------------------------------------------------
441
442    type Binary_Semaphore_Id is new Long_Integer;
443
444    function Binary_Semaphore_Create return Binary_Semaphore_Id;
445    pragma Inline (Binary_Semaphore_Create);
446
447    function Binary_Semaphore_Delete (ID : Binary_Semaphore_Id) return int;
448    pragma Inline (Binary_Semaphore_Delete);
449
450    function Binary_Semaphore_Obtain (ID : Binary_Semaphore_Id) return int;
451    pragma Inline (Binary_Semaphore_Obtain);
452
453    function Binary_Semaphore_Release (ID : Binary_Semaphore_Id) return int;
454    pragma Inline (Binary_Semaphore_Release);
455
456    function Binary_Semaphore_Flush (ID : Binary_Semaphore_Id) return int;
457    pragma Inline (Binary_Semaphore_Flush);
458
459    ------------------------------------------------------------
460    -- Hardware Interrupt Wrappers to Support Interrupt Tasks --
461    ------------------------------------------------------------
462
463    type Interrupt_Handler is access procedure (parameter : System.Address);
464    pragma Convention (C, Interrupt_Handler);
465
466    type Interrupt_Vector is new System.Address;
467
468    function Interrupt_Connect
469      (Vector    : Interrupt_Vector;
470       Handler   : Interrupt_Handler;
471       Parameter : System.Address := System.Null_Address) return int;
472    pragma Inline (Interrupt_Connect);
473    --  Use this to set up an user handler. The routine installs a user
474    --  handler which is invoked after the OS has saved enough context for a
475    --  high-level language routine to be safely invoked.
476
477    function Interrupt_Context return int;
478    pragma Inline (Interrupt_Context);
479    --  Return 1 if executing in an interrupt context; return 0 if executing in
480    --  a task context.
481
482    function Interrupt_Number_To_Vector (intNum : int) return Interrupt_Vector;
483    pragma Inline (Interrupt_Number_To_Vector);
484    --  Convert a logical interrupt number to the hardware interrupt vector
485    --  number used to connect the interrupt.
486
487    --------------------------------
488    -- Processor Affinity for SMP --
489    --------------------------------
490
491    function taskCpuAffinitySet (tid : t_id; CPU : int) return int
492      renames System.VxWorks.Ext.taskCpuAffinitySet;
493    --  For SMP run-times the affinity to CPU.
494    --  For uniprocessor systems return ERROR status.
495
496    ---------------------
497    -- Multiprocessors --
498    ---------------------
499
500    function Current_CPU return Multiprocessors.CPU;
501    --  Return the id of the current CPU
502
503 private
504    type pid_t is new int;
505
506    ERROR_PID : constant pid_t := -1;
507
508    type clockid_t is new int;
509    CLOCK_REALTIME : constant clockid_t := 0;
510
511    type sigset_t is new System.VxWorks.Ext.sigset_t;
512 end System.OS_Interface;