OSDN Git Service

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