PR target/60039
[official-gcc.git] / gcc / ada / s-osinte-rtems.ads
blob8b9ae1297cdd3e3dfe6869a249abbbe6ee0e6fc9
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 -- Copyright (C) 1997-2011 Free Software Foundation, Inc. --
10 -- --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 -- The GNARL files that were developed for RTEMS are maintained by On-Line --
31 -- Applications Research Corporation (http://www.oarcorp.com) in coopera- --
32 -- tion with Ada Core Technologies Inc. and Florida State University. --
33 -- --
34 ------------------------------------------------------------------------------
36 -- This is the RTEMS version of this package.
38 -- RTEMS target names are of the form CPU-rtems.
39 -- This implementation is designed to work on ALL RTEMS targets.
40 -- The RTEMS implementation is primarily based upon the POSIX threads
41 -- API but there are also bindings to GNAT/RTEMS support routines
42 -- to insulate this code from C API specific details and, in some
43 -- cases, obtain target architecture and BSP specific information
44 -- that is unavailable at the time this package is built.
46 -- This package encapsulates all direct interfaces to OS services
47 -- that are needed by children of System.
49 -- PLEASE DO NOT add any with-clauses to this package
50 -- or remove the pragma Preelaborate.
51 -- It is designed to be a bottom-level (leaf) package.
53 with Interfaces.C;
54 package System.OS_Interface is
55 pragma Preelaborate;
57 -- This interface assumes that "unsigned" is a 32-bit entity. This
58 -- will correspond to RTEMS object ids.
60 subtype rtems_id is Interfaces.C.unsigned;
62 subtype int is Interfaces.C.int;
63 subtype short is Interfaces.C.short;
64 subtype long is Interfaces.C.long;
65 subtype unsigned is Interfaces.C.unsigned;
66 subtype unsigned_short is Interfaces.C.unsigned_short;
67 subtype unsigned_long is Interfaces.C.unsigned_long;
68 subtype unsigned_char is Interfaces.C.unsigned_char;
69 subtype plain_char is Interfaces.C.plain_char;
70 subtype size_t is Interfaces.C.size_t;
72 -----------
73 -- Errno --
74 -----------
76 function errno return int;
77 pragma Import (C, errno, "__get_errno");
79 EAGAIN : constant := 11;
80 EINTR : constant := 4;
81 EINVAL : constant := 22;
82 ENOMEM : constant := 12;
83 ETIMEDOUT : constant := 116;
85 -------------
86 -- Signals --
87 -------------
89 Num_HW_Interrupts : constant := 256;
91 Max_HW_Interrupt : constant := Num_HW_Interrupts - 1;
92 type HW_Interrupt is new int range 0 .. Max_HW_Interrupt;
94 Max_Interrupt : constant := Max_HW_Interrupt;
96 type Signal is new int range 0 .. Max_Interrupt;
98 SIGXCPU : constant := 0; -- XCPU
99 SIGHUP : constant := 1; -- hangup
100 SIGINT : constant := 2; -- interrupt (rubout)
101 SIGQUIT : constant := 3; -- quit (ASCD FS)
102 SIGILL : constant := 4; -- illegal instruction (not reset)
103 SIGTRAP : constant := 5; -- trace trap (not reset)
104 SIGIOT : constant := 6; -- IOT instruction
105 SIGABRT : constant := 6; -- used by abort, replace SIGIOT in the future
106 SIGEMT : constant := 7; -- EMT instruction
107 SIGFPE : constant := 8; -- floating point exception
108 SIGKILL : constant := 9; -- kill (cannot be caught or ignored)
109 SIGBUS : constant := 10; -- bus error
110 SIGSEGV : constant := 11; -- segmentation violation
111 SIGSYS : constant := 12; -- bad argument to system call
112 SIGPIPE : constant := 13; -- write on a pipe with no one to read it
113 SIGALRM : constant := 14; -- alarm clock
114 SIGTERM : constant := 15; -- software termination signal from kill
115 SIGUSR1 : constant := 16; -- user defined signal 1
116 SIGUSR2 : constant := 17; -- user defined signal 2
118 SIGADAABORT : constant := SIGABRT;
120 type Signal_Set is array (Natural range <>) of Signal;
122 Unmasked : constant Signal_Set := (SIGTRAP, SIGALRM, SIGEMT);
123 Reserved : constant Signal_Set := (1 .. 1 => SIGKILL);
125 type sigset_t is private;
127 function sigaddset (set : access sigset_t; sig : Signal) return int;
128 pragma Import (C, sigaddset, "sigaddset");
130 function sigdelset (set : access sigset_t; sig : Signal) return int;
131 pragma Import (C, sigdelset, "sigdelset");
133 function sigfillset (set : access sigset_t) return int;
134 pragma Import (C, sigfillset, "sigfillset");
136 function sigismember (set : access sigset_t; sig : Signal) return int;
137 pragma Import (C, sigismember, "sigismember");
139 function sigemptyset (set : access sigset_t) return int;
140 pragma Import (C, sigemptyset, "sigemptyset");
142 type struct_sigaction is record
143 sa_flags : int;
144 sa_mask : sigset_t;
145 sa_handler : System.Address;
146 end record;
147 pragma Convention (C, struct_sigaction);
148 type struct_sigaction_ptr is access all struct_sigaction;
150 SA_SIGINFO : constant := 16#02#;
152 SA_ONSTACK : constant := 16#00#;
153 -- SA_ONSTACK is not defined on RTEMS, but it is referred to in the POSIX
154 -- implementation of System.Interrupt_Management. Therefore we define a
155 -- dummy value of zero here so that setting this flag is a nop.
157 SIG_BLOCK : constant := 1;
158 SIG_UNBLOCK : constant := 2;
159 SIG_SETMASK : constant := 3;
161 SIG_DFL : constant := 0;
162 SIG_IGN : constant := 1;
164 function sigaction
165 (sig : Signal;
166 act : struct_sigaction_ptr;
167 oact : struct_sigaction_ptr) return int;
168 pragma Import (C, sigaction, "sigaction");
170 ----------
171 -- Time --
172 ----------
174 Time_Slice_Supported : constant Boolean := True;
175 -- Indicates whether time slicing is supported (i.e SCHED_RR is supported)
177 type timespec is private;
179 type clockid_t is new int;
181 CLOCK_REALTIME : constant clockid_t;
182 CLOCK_MONOTONIC : constant clockid_t;
184 function clock_gettime
185 (clock_id : clockid_t;
186 tp : access timespec) return int;
187 pragma Import (C, clock_gettime, "clock_gettime");
189 function To_Duration (TS : timespec) return Duration;
190 pragma Inline (To_Duration);
192 function To_Timespec (D : Duration) return timespec;
193 pragma Inline (To_Timespec);
195 -------------------------
196 -- Priority Scheduling --
197 -------------------------
199 SCHED_FIFO : constant := 1;
200 SCHED_RR : constant := 2;
201 SCHED_OTHER : constant := 0;
203 function To_Target_Priority
204 (Prio : System.Any_Priority) return Interfaces.C.int;
205 -- Maps System.Any_Priority to a POSIX priority
207 -------------
208 -- Process --
209 -------------
211 type pid_t is private;
213 function kill (pid : pid_t; sig : Signal) return int;
214 pragma Import (C, kill, "kill");
216 function getpid return pid_t;
217 pragma Import (C, getpid, "getpid");
219 ---------
220 -- LWP --
221 ---------
223 function lwp_self return System.Address;
224 -- lwp_self does not exist on this thread library, revert to pthread_self
225 -- which is the closest approximation (with getpid). This function is
226 -- needed to share 7staprop.adb across POSIX-like targets.
227 pragma Import (C, lwp_self, "pthread_self");
229 -------------
230 -- Threads --
231 -------------
233 type Thread_Body is access
234 function (arg : System.Address) return System.Address;
235 pragma Convention (C, Thread_Body);
237 type pthread_t is private;
238 subtype Thread_Id is pthread_t;
240 type pthread_mutex_t is limited private;
241 type pthread_rwlock_t is limited private;
242 type pthread_cond_t is limited private;
243 type pthread_attr_t is limited private;
244 type pthread_mutexattr_t is limited private;
245 type pthread_rwlockattr_t is limited private;
246 type pthread_condattr_t is limited private;
247 type pthread_key_t is private;
249 No_Key : constant pthread_key_t;
251 PTHREAD_CREATE_DETACHED : constant := 0;
253 PTHREAD_SCOPE_PROCESS : constant := 0;
254 PTHREAD_SCOPE_SYSTEM : constant := 1;
256 -----------
257 -- Stack --
258 -----------
260 type stack_t is record
261 ss_sp : System.Address;
262 ss_flags : int;
263 ss_size : size_t;
264 end record;
265 pragma Convention (C, stack_t);
267 function sigaltstack
268 (ss : not null access stack_t;
269 oss : access stack_t) return int;
271 Alternate_Stack : aliased System.Address;
272 -- This is a dummy definition, never used (Alternate_Stack_Size is null)
274 Alternate_Stack_Size : constant := 0;
275 -- No alternate signal stack is used on this platform
277 Stack_Base_Available : constant Boolean := False;
278 -- Indicates whether the stack base is available on this target.
279 -- This allows us to share s-osinte.adb between all the FSU/RTEMS
280 -- run time.
281 -- Note that this value can only be true if pthread_t has a complete
282 -- definition that corresponds exactly to the C header files.
284 function Get_Stack_Base (thread : pthread_t) return Address;
285 pragma Inline (Get_Stack_Base);
286 -- returns the stack base of the specified thread.
287 -- Only call this function when Stack_Base_Available is True.
289 -- These two functions are only needed to share s-taprop.adb with
290 -- FSU threads.
292 function Get_Page_Size return size_t;
293 function Get_Page_Size return Address;
294 pragma Import (C, Get_Page_Size, "getpagesize");
295 -- Returns the size of a page
297 PROT_ON : constant := 0;
298 PROT_OFF : constant := 0;
300 function mprotect (addr : Address; len : size_t; prot : int) return int;
301 pragma Import (C, mprotect);
303 -----------------------------------------
304 -- Nonstandard Thread Initialization --
305 -----------------------------------------
307 procedure pthread_init;
308 -- FSU_THREADS requires pthread_init, which is nonstandard
309 -- and this should be invoked during the elaboration of s-taprop.adb
311 -- RTEMS does not require this so we provide an empty Ada body.
313 -------------------------
314 -- POSIX.1c Section 3 --
315 -------------------------
317 function sigwait
318 (set : access sigset_t;
319 sig : access Signal) return int;
320 pragma Import (C, sigwait, "sigwait");
322 function pthread_kill
323 (thread : pthread_t;
324 sig : Signal) return int;
325 pragma Import (C, pthread_kill, "pthread_kill");
327 function pthread_sigmask
328 (how : int;
329 set : access sigset_t;
330 oset : access sigset_t) return int;
331 pragma Import (C, pthread_sigmask, "pthread_sigmask");
333 ----------------------------
334 -- POSIX.1c Section 11 --
335 ----------------------------
337 function pthread_mutexattr_init
338 (attr : access pthread_mutexattr_t) return int;
339 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
341 function pthread_mutexattr_destroy
342 (attr : access pthread_mutexattr_t) return int;
343 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
345 function pthread_mutex_init
346 (mutex : access pthread_mutex_t;
347 attr : access pthread_mutexattr_t) return int;
348 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
350 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
351 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
353 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
354 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
356 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
357 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
359 function pthread_rwlockattr_init
360 (attr : access pthread_rwlockattr_t) return int;
361 pragma Import (C, pthread_rwlockattr_init, "pthread_rwlockattr_init");
363 function pthread_rwlockattr_destroy
364 (attr : access pthread_rwlockattr_t) return int;
365 pragma Import (C, pthread_rwlockattr_destroy, "pthread_rwlockattr_destroy");
367 PTHREAD_RWLOCK_PREFER_READER_NP : constant := 0;
368 PTHREAD_RWLOCK_PREFER_WRITER_NP : constant := 1;
369 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP : constant := 2;
371 function pthread_rwlockattr_setkind_np
372 (attr : access pthread_rwlockattr_t;
373 pref : int) return int;
375 function pthread_rwlock_init
376 (mutex : access pthread_rwlock_t;
377 attr : access pthread_rwlockattr_t) return int;
378 pragma Import (C, pthread_rwlock_init, "pthread_rwlock_init");
380 function pthread_rwlock_destroy
381 (mutex : access pthread_rwlock_t) return int;
382 pragma Import (C, pthread_rwlock_destroy, "pthread_rwlock_destroy");
384 function pthread_rwlock_rdlock (mutex : access pthread_rwlock_t) return int;
385 pragma Import (C, pthread_rwlock_rdlock, "pthread_rwlock_rdlock");
387 function pthread_rwlock_wrlock (mutex : access pthread_rwlock_t) return int;
388 pragma Import (C, pthread_rwlock_wrlock, "pthread_rwlock_wrlock");
390 function pthread_rwlock_unlock (mutex : access pthread_rwlock_t) return int;
391 pragma Import (C, pthread_rwlock_unlock, "pthread_rwlock_unlock");
393 function pthread_condattr_init
394 (attr : access pthread_condattr_t) return int;
395 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
397 function pthread_condattr_destroy
398 (attr : access pthread_condattr_t) return int;
399 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
401 function pthread_cond_init
402 (cond : access pthread_cond_t;
403 attr : access pthread_condattr_t) return int;
404 pragma Import (C, pthread_cond_init, "pthread_cond_init");
406 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
407 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
409 function pthread_cond_signal (cond : access pthread_cond_t) return int;
410 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
412 function pthread_cond_wait
413 (cond : access pthread_cond_t;
414 mutex : access pthread_mutex_t) return int;
415 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
417 function pthread_cond_timedwait
418 (cond : access pthread_cond_t;
419 mutex : access pthread_mutex_t;
420 abstime : access timespec) return int;
421 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
423 Relative_Timed_Wait : constant Boolean := False;
424 -- pthread_cond_timedwait requires an absolute delay time
426 --------------------------
427 -- POSIX.1c Section 13 --
428 --------------------------
430 PTHREAD_PRIO_NONE : constant := 0;
431 PTHREAD_PRIO_PROTECT : constant := 2;
432 PTHREAD_PRIO_INHERIT : constant := 1;
434 function pthread_mutexattr_setprotocol
435 (attr : access pthread_mutexattr_t;
436 protocol : int) return int;
437 pragma Import (C, pthread_mutexattr_setprotocol);
439 function pthread_mutexattr_setprioceiling
440 (attr : access pthread_mutexattr_t;
441 prioceiling : int) return int;
442 pragma Import
443 (C, pthread_mutexattr_setprioceiling,
444 "pthread_mutexattr_setprioceiling");
446 type struct_sched_param is record
447 sched_priority : int;
448 ss_low_priority : int;
449 ss_replenish_period : timespec;
450 ss_initial_budget : timespec;
451 end record;
452 pragma Convention (C, struct_sched_param);
454 function pthread_setschedparam
455 (thread : pthread_t;
456 policy : int;
457 param : access struct_sched_param) return int;
458 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
460 function pthread_attr_setscope
461 (attr : access pthread_attr_t;
462 contentionscope : int) return int;
463 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
465 function pthread_attr_setinheritsched
466 (attr : access pthread_attr_t;
467 inheritsched : int) return int;
468 pragma Import (C, pthread_attr_setinheritsched);
470 function pthread_attr_setschedpolicy
471 (attr : access pthread_attr_t;
472 policy : int) return int;
473 pragma Import (C, pthread_attr_setschedpolicy);
475 function pthread_attr_setschedparam
476 (attr : access pthread_attr_t;
477 sched_param : int) return int;
478 pragma Import (C, pthread_attr_setschedparam);
480 function sched_yield return int;
481 pragma Import (C, sched_yield, "sched_yield");
483 ---------------------------
484 -- P1003.1c - Section 16 --
485 ---------------------------
487 function pthread_attr_init (attributes : access pthread_attr_t) return int;
488 pragma Import (C, pthread_attr_init, "pthread_attr_init");
490 function pthread_attr_destroy
491 (attributes : access pthread_attr_t) return int;
492 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
494 function pthread_attr_setdetachstate
495 (attr : access pthread_attr_t;
496 detachstate : int) return int;
497 pragma Import (C, pthread_attr_setdetachstate);
499 function pthread_attr_setstacksize
500 (attr : access pthread_attr_t;
501 stacksize : size_t) return int;
502 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
504 function pthread_create
505 (thread : access pthread_t;
506 attributes : access pthread_attr_t;
507 start_routine : Thread_Body;
508 arg : System.Address) return int;
509 pragma Import (C, pthread_create, "pthread_create");
511 procedure pthread_exit (status : System.Address);
512 pragma Import (C, pthread_exit, "pthread_exit");
514 function pthread_self return pthread_t;
515 pragma Import (C, pthread_self, "pthread_self");
517 --------------------------
518 -- POSIX.1c Section 17 --
519 --------------------------
521 function pthread_setspecific
522 (key : pthread_key_t;
523 value : System.Address) return int;
524 pragma Import (C, pthread_setspecific, "pthread_setspecific");
526 function pthread_getspecific (key : pthread_key_t) return System.Address;
527 pragma Import (C, pthread_getspecific, "pthread_getspecific");
529 type destructor_pointer is access procedure (arg : System.Address);
530 pragma Convention (C, destructor_pointer);
532 function pthread_key_create
533 (key : access pthread_key_t;
534 destructor : destructor_pointer) return int;
535 pragma Import (C, pthread_key_create, "pthread_key_create");
537 ------------------------------------------------------------
538 -- Binary Semaphore Wrapper to Support Interrupt Tasks --
539 ------------------------------------------------------------
541 type Binary_Semaphore_Id is new rtems_id;
543 function Binary_Semaphore_Create return Binary_Semaphore_Id;
544 pragma Import (
546 Binary_Semaphore_Create,
547 "__gnat_binary_semaphore_create");
549 function Binary_Semaphore_Delete (ID : Binary_Semaphore_Id) return int;
550 pragma Import (
552 Binary_Semaphore_Delete,
553 "__gnat_binary_semaphore_delete");
555 function Binary_Semaphore_Obtain (ID : Binary_Semaphore_Id) return int;
556 pragma Import (
558 Binary_Semaphore_Obtain,
559 "__gnat_binary_semaphore_obtain");
561 function Binary_Semaphore_Release (ID : Binary_Semaphore_Id) return int;
562 pragma Import (
564 Binary_Semaphore_Release,
565 "__gnat_binary_semaphore_release");
567 function Binary_Semaphore_Flush (ID : Binary_Semaphore_Id) return int;
568 pragma Import (
570 Binary_Semaphore_Flush,
571 "__gnat_binary_semaphore_flush");
573 ------------------------------------------------------------
574 -- Hardware Interrupt Wrappers to Support Interrupt Tasks --
575 ------------------------------------------------------------
577 type Interrupt_Handler is access procedure (parameter : System.Address);
578 pragma Convention (C, Interrupt_Handler);
579 type Interrupt_Vector is new System.Address;
581 function Interrupt_Connect
582 (vector : Interrupt_Vector;
583 handler : Interrupt_Handler;
584 parameter : System.Address := System.Null_Address) return int;
585 pragma Import (C, Interrupt_Connect, "__gnat_interrupt_connect");
586 -- Use this to set up an user handler. The routine installs a
587 -- a user handler which is invoked after RTEMS has saved enough
588 -- context for a high-level language routine to be safely invoked.
590 function Interrupt_Vector_Get
591 (Vector : Interrupt_Vector) return Interrupt_Handler;
592 pragma Import (C, Interrupt_Vector_Get, "__gnat_interrupt_get");
593 -- Use this to get the existing handler for later restoral.
595 procedure Interrupt_Vector_Set
596 (Vector : Interrupt_Vector;
597 Handler : Interrupt_Handler);
598 pragma Import (C, Interrupt_Vector_Set, "__gnat_interrupt_set");
599 -- Use this to restore a handler obtained using Interrupt_Vector_Get.
601 function Interrupt_Number_To_Vector (intNum : int) return Interrupt_Vector;
602 -- Convert a logical interrupt number to the hardware interrupt vector
603 -- number used to connect the interrupt.
604 pragma Import (
606 Interrupt_Number_To_Vector,
607 "__gnat_interrupt_number_to_vector"
610 private
612 type sigset_t is new int;
614 type pid_t is new int;
616 type time_t is new long;
618 type timespec is record
619 tv_sec : time_t;
620 tv_nsec : long;
621 end record;
622 pragma Convention (C, timespec);
624 CLOCK_REALTIME : constant clockid_t := 1;
625 CLOCK_MONOTONIC : constant clockid_t := 4;
627 type pthread_attr_t is record
628 is_initialized : int;
629 stackaddr : System.Address;
630 stacksize : int;
631 contentionscope : int;
632 inheritsched : int;
633 schedpolicy : int;
634 schedparam : struct_sched_param;
635 cputime_clocked_allowed : int;
636 detatchstate : int;
637 end record;
638 pragma Convention (C, pthread_attr_t);
640 type pthread_condattr_t is record
641 flags : int;
642 process_shared : int;
643 end record;
644 pragma Convention (C, pthread_condattr_t);
646 type pthread_mutexattr_t is record
647 is_initialized : int;
648 process_shared : int;
649 prio_ceiling : int;
650 protocol : int;
651 mutex_type : int;
652 recursive : int;
653 end record;
654 pragma Convention (C, pthread_mutexattr_t);
656 type pthread_rwlockattr_t is record
657 is_initialized : int;
658 process_shared : int;
659 end record;
660 pragma Convention (C, pthread_rwlockattr_t);
662 type pthread_t is new rtems_id;
664 type pthread_mutex_t is new rtems_id;
666 type pthread_rwlock_t is new rtems_id;
668 type pthread_cond_t is new rtems_id;
670 type pthread_key_t is new rtems_id;
672 No_Key : constant pthread_key_t := 0;
674 end System.OS_Interface;