OSDN Git Service

More improvements to sparc VIS vec_init code generation.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-osinte-lynxos-3.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                          GNAT RUN-TIME 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-2011, Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNAT 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.  GNAT 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 -- GNAT was originally developed  by the GNAT team at  New York University. --
29 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
30 --                                                                          --
31 ------------------------------------------------------------------------------
32
33 --  This is a LynxOS (Native) 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 Ada.Unchecked_Conversion;
42
43 with Interfaces.C;
44
45 package System.OS_Interface is
46    pragma Preelaborate;
47
48    pragma Linker_Options ("-mthreads");
49
50    subtype int            is Interfaces.C.int;
51    subtype char           is Interfaces.C.char;
52    subtype short          is Interfaces.C.short;
53    subtype long           is Interfaces.C.long;
54    subtype unsigned       is Interfaces.C.unsigned;
55    subtype unsigned_short is Interfaces.C.unsigned_short;
56    subtype unsigned_long  is Interfaces.C.unsigned_long;
57    subtype unsigned_char  is Interfaces.C.unsigned_char;
58    subtype plain_char     is Interfaces.C.plain_char;
59    subtype size_t         is Interfaces.C.size_t;
60
61    -----------
62    -- Errno --
63    -----------
64
65    function errno return int;
66    pragma Import (C, errno, "__get_errno");
67
68    EAGAIN    : constant := 11;
69    EINTR     : constant := 4;
70    EINVAL    : constant := 22;
71    ENOMEM    : constant := 12;
72    ETIMEDOUT : constant := 60;
73
74    -------------
75    -- Signals --
76    -------------
77
78    Max_Interrupt : constant := 63;
79    type Signal is new int range 0 .. Max_Interrupt;
80    for Signal'Size use int'Size;
81
82    SIGHUP      : constant := 1; --  hangup
83    SIGINT      : constant := 2; --  interrupt (rubout)
84    SIGQUIT     : constant := 3; --  quit (ASCD FS)
85    SIGILL      : constant := 4; --  illegal instruction (not reset)
86    SIGTRAP     : constant := 5; --  trace trap (not reset)
87    SIGBRK      : constant := 6; --  break
88    SIGIOT      : constant := 6; --  IOT instruction
89    SIGABRT     : constant := 6; --  used by abort, replace SIGIOT in the future
90    SIGCORE     : constant := 7; --  kill with core dump
91    SIGEMT      : constant := 7; --  EMT instruction
92    SIGFPE      : constant := 8; --  floating point exception
93    SIGKILL     : constant := 9; --  kill (cannot be caught or ignored)
94    SIGBUS      : constant := 10; --  bus error
95    SIGSEGV     : constant := 11; --  segmentation violation
96    SIGSYS      : constant := 12; --  bad argument to system call
97    SIGPIPE     : constant := 13; --  write on a pipe with no one to read it
98    SIGALRM     : constant := 14; --  alarm clock
99    SIGTERM     : constant := 15; --  software termination signal from kill
100    SIGURG      : constant := 16; --  urgent condition on IO channel
101    SIGSTOP     : constant := 17; --  stop (cannot be caught or ignored)
102    SIGTSTP     : constant := 18; --  user stop requested from tty
103    SIGCONT     : constant := 19; --  stopped process has been continued
104    SIGCLD      : constant := 20; --  alias for SIGCHLD
105    SIGCHLD     : constant := 20; --  child status change
106    SIGTTIN     : constant := 21; --  background tty read attempted
107    SIGTTOU     : constant := 22; --  background tty write attempted
108    SIGIO       : constant := 23; --  I/O possible (Solaris SIGPOLL alias)
109    SIGPOLL     : constant := 23; --  pollable event occurred
110    SIGXCPU     : constant := 24; --  CPU time limit exceeded
111    SIGXFSZ     : constant := 25; --  filesize limit exceeded
112    SIGVTALRM   : constant := 26; --  virtual timer expired
113    SIGPROF     : constant := 27; --  profiling timer expired
114    SIGWINCH    : constant := 28; --  window size change
115    SIGLOST     : constant := 29; --  SUN 4.1 compatibility
116    SIGUSR1     : constant := 30; --  user defined signal 1
117    SIGUSR2     : constant := 31; --  user defined signal 2
118    SIGPRIO     : constant := 32; --  sent to a process with its priority or
119                                  --  group is changed
120
121    SIGADAABORT : constant := SIGABRT;
122    --  Change this if you want to use another signal for task abort.
123    --  SIGTERM might be a good one.
124
125    type Signal_Set is array (Natural range <>) of Signal;
126
127    Unmasked    : constant Signal_Set :=
128      (SIGTRAP, SIGTTIN, SIGTTOU, SIGTSTP, SIGPROF);
129    Reserved    : constant Signal_Set := (SIGABRT, SIGKILL, SIGSTOP, SIGPRIO);
130
131    type sigset_t is private;
132
133    function sigaddset (set : access sigset_t; sig : Signal) return int;
134    pragma Import (C, sigaddset, "sigaddset");
135
136    function sigdelset (set : access sigset_t; sig : Signal) return int;
137    pragma Import (C, sigdelset, "sigdelset");
138
139    function sigfillset (set : access sigset_t) return int;
140    pragma Import (C, sigfillset, "sigfillset");
141
142    function sigismember (set : access sigset_t; sig : Signal) return int;
143    pragma Import (C, sigismember, "sigismember");
144
145    function sigemptyset (set : access sigset_t) return int;
146    pragma Import (C, sigemptyset, "sigemptyset");
147
148    type struct_sigaction is record
149       sa_handler : System.Address;
150       sa_mask    : sigset_t;
151       sa_flags   : int;
152    end record;
153    pragma Convention (C, struct_sigaction);
154    type struct_sigaction_ptr is access all struct_sigaction;
155
156    SA_SIGINFO  : constant := 16#80#;
157
158    SIG_BLOCK   : constant := 0;
159    SIG_UNBLOCK : constant := 1;
160    SIG_SETMASK : constant := 2;
161
162    SIG_DFL : constant := 0;
163    SIG_IGN : constant := 1;
164
165    function sigaction
166      (sig  : Signal;
167       act  : struct_sigaction_ptr;
168       oact : struct_sigaction_ptr) return int;
169    pragma Import (C, sigaction, "sigaction");
170
171    ----------
172    -- Time --
173    ----------
174
175    Time_Slice_Supported : constant Boolean := True;
176    --  Indicates whether time slicing is supported
177
178    type timespec is private;
179
180    type clockid_t is private;
181
182    CLOCK_REALTIME : constant clockid_t;
183
184    function clock_gettime
185      (clock_id : clockid_t;
186       tp       : access timespec) return int;
187    pragma Inline (clock_gettime);
188    --  LynxOS has non standard clock_gettime
189
190    function To_Duration (TS : timespec) return Duration;
191    pragma Inline (To_Duration);
192
193    function To_Timespec (D : Duration) return timespec;
194    pragma Inline (To_Timespec);
195
196    type struct_timezone is record
197       tz_minuteswest : int;
198       tz_dsttime     : int;
199    end record;
200    pragma Convention (C, struct_timezone);
201    type struct_timezone_ptr is access all struct_timezone;
202
203    -------------------------
204    -- Priority Scheduling --
205    -------------------------
206
207    SCHED_FIFO  : constant := 16#00200000#;
208    SCHED_RR    : constant := 16#00100000#;
209    SCHED_OTHER : constant := 16#00400000#;
210
211    function To_Target_Priority
212      (Prio : System.Any_Priority) return Interfaces.C.int;
213    --  Maps System.Any_Priority to a POSIX priority
214
215    -------------
216    -- Process --
217    -------------
218
219    type pid_t is private;
220
221    function kill (pid : pid_t; sig : Signal) return int;
222    pragma Import (C, kill, "kill");
223
224    function getpid return pid_t;
225    pragma Import (C, getpid, "getpid");
226
227    ---------
228    -- LWP --
229    ---------
230
231    function lwp_self return System.Address;
232    --  lwp_self does not exist on this thread library, revert to pthread_self
233    --  which is the closest approximation (with getpid). This function is
234    --  needed to share 7staprop.adb across POSIX-like targets.
235    pragma Import (C, lwp_self, "pthread_self");
236
237    -------------
238    -- Threads --
239    -------------
240
241    type Thread_Body is access
242      function (arg : System.Address) return System.Address;
243    pragma Convention (C, Thread_Body);
244
245    function Thread_Body_Access is new
246      Ada.Unchecked_Conversion (System.Address, Thread_Body);
247
248    type pthread_t           is private;
249    subtype Thread_Id        is pthread_t;
250
251    type pthread_mutex_t     is limited private;
252    type pthread_cond_t      is limited private;
253    type st_t                is limited private;
254    type pthread_attr_t      is limited private;
255    type pthread_mutexattr_t is limited private;
256    type pthread_condattr_t  is limited private;
257    type pthread_key_t       is private;
258
259    PTHREAD_CREATE_DETACHED : constant := 0;
260
261    PTHREAD_SCOPE_PROCESS : constant := 0;
262    PTHREAD_SCOPE_SYSTEM  : constant := 1;
263
264    -----------
265    -- Stack --
266    -----------
267
268    Alternate_Stack_Size : constant := 0;
269    --  No alternate signal stack is used on this platform
270
271    Stack_Base_Available : constant Boolean := False;
272    --  Indicates whether the stack base is available on this target
273
274    function Get_Stack_Base (thread : pthread_t) return Address;
275    pragma Inline (Get_Stack_Base);
276    --  returns the stack base of the specified thread.
277    --  Only call this function when Stack_Base_Available is True.
278
279    function Get_Page_Size return size_t;
280    function Get_Page_Size return Address;
281    pragma Import (C, Get_Page_Size, "getpagesize");
282    --  returns the size of a page, or 0 if this is not relevant on this
283    --  target
284
285    PROT_NONE  : constant := 0;
286    PROT_READ  : constant := 1;
287    PROT_WRITE : constant := 2;
288    PROT_EXEC  : constant := 4;
289    PROT_USER  : constant := 8;
290    PROT_ALL   : constant := PROT_READ + PROT_WRITE + PROT_EXEC + PROT_USER;
291
292    PROT_ON    : constant := PROT_READ;
293    PROT_OFF   : constant := PROT_ALL;
294
295    function mprotect (addr : Address; len : size_t; prot : int) return int;
296    pragma Import (C, mprotect);
297
298    -------------------------
299    -- POSIX.1c  Section 3 --
300    -------------------------
301
302    function sigwait
303      (set : access sigset_t;
304       sig : access Signal) return int;
305    pragma Inline (sigwait);
306    --  LynxOS has non standard sigwait
307
308    function pthread_kill (thread : pthread_t; sig : Signal) return int;
309    pragma Import (C, pthread_kill, "pthread_kill");
310
311    function pthread_sigmask
312      (how  : int;
313       set  : access sigset_t;
314       oset : access sigset_t) return int;
315    pragma Import (C, pthread_sigmask, "sigprocmask");
316
317    --------------------------
318    -- POSIX.1c  Section 11 --
319    --------------------------
320
321    function pthread_mutexattr_init
322      (attr : access pthread_mutexattr_t) return int;
323    pragma Inline (pthread_mutexattr_init);
324    --  LynxOS has a nonstandard pthread_mutexattr_init
325
326    function pthread_mutexattr_destroy
327      (attr : access pthread_mutexattr_t) return int;
328    pragma Inline (pthread_mutexattr_destroy);
329    --  Lynxos has a nonstandard pthread_mutexattr_destroy
330
331    function pthread_mutex_init
332      (mutex : access pthread_mutex_t;
333       attr  : access pthread_mutexattr_t) return int;
334    pragma Inline (pthread_mutex_init);
335    --  LynxOS has a nonstandard pthread_mutex_init
336
337    function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
338    pragma Inline (pthread_mutex_destroy);
339    --  LynxOS has a nonstandard pthread_mutex_destroy
340
341    function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
342    pragma Inline (pthread_mutex_lock);
343    --  LynxOS has a nonstandard pthread_mutex_lock
344
345    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
346    pragma Inline (pthread_mutex_unlock);
347    --  LynxOS has a nonstandard pthread_mutex_unlock
348
349    function pthread_condattr_init
350      (attr : access pthread_condattr_t) return int;
351    pragma Inline (pthread_condattr_init);
352    --  LynxOS has a nonstandard pthread_condattr_init
353
354    function pthread_condattr_destroy
355      (attr : access pthread_condattr_t) return int;
356    pragma Inline (pthread_condattr_destroy);
357    --  LynxOS has a nonstandard pthread_condattr_destroy
358
359    function pthread_cond_init
360      (cond : access pthread_cond_t;
361       attr : access pthread_condattr_t) return int;
362    pragma Inline (pthread_cond_init);
363    --  LynxOS has a non standard pthread_cond_init
364
365    function pthread_cond_destroy (cond : access pthread_cond_t) return int;
366    pragma Inline (pthread_cond_destroy);
367    --  LynxOS has a nonstandard pthread_cond_destroy
368
369    function pthread_cond_signal (cond : access pthread_cond_t) return int;
370    pragma Inline (pthread_cond_signal);
371    --  LynxOS has a nonstandard pthread_cond_signal
372
373    function pthread_cond_wait
374      (cond  : access pthread_cond_t;
375       mutex : access pthread_mutex_t) return int;
376    pragma Inline (pthread_cond_wait);
377    --  LynxOS has a nonstandard pthread_cond_wait
378
379    function pthread_cond_timedwait
380      (cond    : access pthread_cond_t;
381       mutex   : access pthread_mutex_t;
382       reltime : access timespec) return int;
383    pragma Inline (pthread_cond_timedwait);
384    --  LynxOS has a nonstandard pthread_cond_timedwait
385
386    Relative_Timed_Wait : constant Boolean := True;
387    --  pthread_cond_timedwait requires a relative delay time
388
389    --------------------------
390    -- POSIX.1c  Section 13 --
391    --------------------------
392
393    PTHREAD_PRIO_NONE    : constant := 0;
394    PTHREAD_PRIO_INHERIT : constant := 0;
395    PTHREAD_PRIO_PROTECT : constant := 0;
396
397    type struct_sched_param is record
398       sched_priority : int;  --  scheduling priority
399    end record;
400
401    function pthread_setschedparam
402      (thread : pthread_t;
403       policy : int;
404       param  : access struct_sched_param) return int;
405    pragma Inline (pthread_setschedparam);
406    --  LynxOS doesn't have pthread_setschedparam.
407    --  Instead, use pthread_setscheduler
408
409    function pthread_mutexattr_setprotocol
410      (attr     : access pthread_mutexattr_t;
411       protocol : int) return int;
412    pragma Inline (pthread_mutexattr_setprotocol);
413    --  LynxOS doesn't have pthread_mutexattr_setprotocol
414
415    function pthread_mutexattr_setprioceiling
416      (attr     : access pthread_mutexattr_t;
417       prioceiling : int) return int;
418    pragma Inline (pthread_mutexattr_setprioceiling);
419    --  LynxOS doesn't have pthread_mutexattr_setprioceiling
420
421    function pthread_attr_setscope
422      (attr            : access pthread_attr_t;
423       contentionscope : int) return int;
424    --  LynxOS doesn't have pthread_attr_setscope: all threads have system scope
425    pragma Inline (pthread_attr_setscope);
426
427    function pthread_attr_setschedpolicy
428      (attr   : access pthread_attr_t;
429       policy : int) return int;
430    pragma Import (C, pthread_attr_setschedpolicy, "pthread_attr_setsched");
431
432    function sched_yield return int;
433    --   pragma Import (C, sched_yield, "sched_yield");
434    pragma Inline (sched_yield);
435
436    ---------------------------
437    -- P1003.1c - Section 16 --
438    ---------------------------
439
440    function pthread_attr_init (attributes : access pthread_attr_t) return int;
441    pragma Import (C, pthread_attr_init, "pthread_attr_create");
442
443    function pthread_attr_destroy
444      (attributes : access pthread_attr_t) return int;
445    pragma Import (C, pthread_attr_destroy, "pthread_attr_delete");
446
447    function pthread_attr_setdetachstate
448      (attr        : access pthread_attr_t;
449       detachstate : int) return int;
450    pragma Inline (pthread_attr_setdetachstate);
451    --  LynxOS doesn't have pthread_attr_setdetachstate
452
453    function pthread_attr_setstacksize
454      (attr      : access pthread_attr_t;
455       stacksize : size_t) return int;
456    pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
457
458    function pthread_create
459      (thread        : access pthread_t;
460       attributes    : access pthread_attr_t;
461       start_routine : Thread_Body;
462       arg           : System.Address) return int;
463    pragma Inline (pthread_create);
464    --  LynxOS has a non standard pthread_create
465
466    function pthread_detach (thread : pthread_t) return int;
467    pragma Inline (pthread_detach);
468
469    procedure pthread_exit (status : System.Address);
470    pragma Import (C, pthread_exit, "pthread_exit");
471
472    function pthread_self return pthread_t;
473    pragma Import (C, pthread_self, "pthread_self");
474
475    --------------------------
476    -- POSIX.1c  Section 17 --
477    --------------------------
478
479    function pthread_setspecific
480      (key   : pthread_key_t;
481       value : System.Address) return int;
482    pragma Inline (pthread_setspecific);
483    --  LynxOS has a non standard pthread_setspecific
484
485    function pthread_getspecific (key : pthread_key_t) return System.Address;
486    pragma Inline (pthread_getspecific);
487    --  LynxOS has a non standard pthread_getspecific
488
489    type destructor_pointer is access procedure (arg : System.Address);
490    pragma Convention (C, destructor_pointer);
491
492    function pthread_key_create
493      (key        : access pthread_key_t;
494       destructor : destructor_pointer) return int;
495    pragma Inline (pthread_key_create);
496    --  LynxOS has a non standard pthread_keycreate
497
498    procedure pthread_init;
499    --  This is a dummy procedure to share some GNULLI files
500
501 private
502
503    type sigbit_array is array (1 .. 2) of long;
504    type sigset_t is record
505       sa_sigbits : sigbit_array;
506    end record;
507    pragma Convention (C_Pass_By_Copy, sigset_t);
508
509    type pid_t is new long;
510
511    type time_t is new long;
512
513    type timespec is record
514       tv_sec  : time_t;
515       tv_nsec : long;
516    end record;
517    pragma Convention (C, timespec);
518
519    type clockid_t is new unsigned_char;
520    CLOCK_REALTIME : constant clockid_t := 0;
521
522    type st_t is record
523       stksize      : int;
524       prio         : int;
525       inheritsched : int;
526       state        : int;
527       sched        : int;
528    end record;
529    pragma Convention (C, st_t);
530
531    type pthread_attr_t is record
532       st                 : st_t;
533       pthread_attr_scope : int;  --  ignored
534    end record;
535    pragma Convention (C, pthread_attr_t);
536
537    type pthread_condattr_t is new int;
538
539    type pthread_mutexattr_t is new int;
540
541    type tid_t is new short;
542    type pthread_t is new tid_t;
543
544    type synch_ptr is access all pthread_mutex_t;
545    type pthread_mutex_t is record
546       w_count   : int;
547       mut_owner : int;
548       id        : unsigned;
549       next      : synch_ptr;
550    end record;
551    pragma Convention (C, pthread_mutex_t);
552
553    type pthread_cond_t is new pthread_mutex_t;
554
555    type pthread_key_t is new int;
556
557 end System.OS_Interface;