* doc/install.texi (*-*-aix): Update explanation of XLC bootstrap.
[official-gcc.git] / gcc / ada / s-osinte-rtems.ads
blobe1b0261d6d15a8cf071be0ce911dabb5c3e91847
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-2009 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 private;
181 CLOCK_REALTIME : constant clockid_t;
183 function clock_gettime
184 (clock_id : clockid_t;
185 tp : access timespec) return int;
186 pragma Import (C, clock_gettime, "clock_gettime");
188 function To_Duration (TS : timespec) return Duration;
189 pragma Inline (To_Duration);
191 function To_Timespec (D : Duration) return timespec;
192 pragma Inline (To_Timespec);
194 type struct_timeval is private;
196 function To_Duration (TV : struct_timeval) return Duration;
197 pragma Inline (To_Duration);
199 function To_Timeval (D : Duration) return struct_timeval;
200 pragma Inline (To_Timeval);
202 -------------------------
203 -- Priority Scheduling --
204 -------------------------
206 SCHED_FIFO : constant := 1;
207 SCHED_RR : constant := 2;
208 SCHED_OTHER : constant := 0;
210 function To_Target_Priority
211 (Prio : System.Any_Priority) return Interfaces.C.int;
212 -- Maps System.Any_Priority to a POSIX priority
214 -------------
215 -- Process --
216 -------------
218 type pid_t is private;
220 function kill (pid : pid_t; sig : Signal) return int;
221 pragma Import (C, kill, "kill");
223 function getpid return pid_t;
224 pragma Import (C, getpid, "getpid");
226 ---------
227 -- LWP --
228 ---------
230 function lwp_self return System.Address;
231 -- lwp_self does not exist on this thread library, revert to pthread_self
232 -- which is the closest approximation (with getpid). This function is
233 -- needed to share 7staprop.adb across POSIX-like targets.
234 pragma Import (C, lwp_self, "pthread_self");
236 -------------
237 -- Threads --
238 -------------
240 type Thread_Body is access
241 function (arg : System.Address) return System.Address;
242 pragma Convention (C, Thread_Body);
244 type pthread_t is private;
245 subtype Thread_Id is pthread_t;
247 type pthread_mutex_t is limited private;
248 type pthread_cond_t is limited private;
249 type pthread_attr_t is limited private;
250 type pthread_mutexattr_t is limited private;
251 type pthread_condattr_t is limited private;
252 type pthread_key_t is private;
254 No_Key : constant pthread_key_t;
256 PTHREAD_CREATE_DETACHED : constant := 0;
258 PTHREAD_SCOPE_PROCESS : constant := 0;
259 PTHREAD_SCOPE_SYSTEM : constant := 1;
261 -----------
262 -- Stack --
263 -----------
265 type stack_t is record
266 ss_sp : System.Address;
267 ss_flags : int;
268 ss_size : size_t;
269 end record;
270 pragma Convention (C, stack_t);
272 function sigaltstack
273 (ss : not null access stack_t;
274 oss : access stack_t) return int;
276 Alternate_Stack : aliased System.Address;
277 -- This is a dummy definition, never used (Alternate_Stack_Size is null)
279 Alternate_Stack_Size : constant := 0;
280 -- No alternate signal stack is used on this platform
282 Stack_Base_Available : constant Boolean := False;
283 -- Indicates whether the stack base is available on this target.
284 -- This allows us to share s-osinte.adb between all the FSU/RTEMS
285 -- run time.
286 -- Note that this value can only be true if pthread_t has a complete
287 -- definition that corresponds exactly to the C header files.
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.
294 -- These two functions are only needed to share s-taprop.adb with
295 -- FSU threads.
297 function Get_Page_Size return size_t;
298 function Get_Page_Size return Address;
299 -- returns the size of a page, or 0 if this is not relevant on this
300 -- target (which is the case for RTEMS)
302 PROT_ON : constant := 0;
303 PROT_OFF : constant := 0;
305 function mprotect (addr : Address; len : size_t; prot : int) return int;
306 pragma Import (C, mprotect);
308 -----------------------------------------
309 -- Nonstandard Thread Initialization --
310 -----------------------------------------
312 procedure pthread_init;
313 -- FSU_THREADS requires pthread_init, which is nonstandard
314 -- and this should be invoked during the elaboration of s-taprop.adb
316 -- RTEMS does not require this so we provide an empty Ada body.
318 -------------------------
319 -- POSIX.1c Section 3 --
320 -------------------------
322 function sigwait
323 (set : access sigset_t;
324 sig : access Signal) return int;
325 pragma Import (C, sigwait, "sigwait");
327 function pthread_kill
328 (thread : pthread_t;
329 sig : Signal) return int;
330 pragma Import (C, pthread_kill, "pthread_kill");
332 function pthread_sigmask
333 (how : int;
334 set : access sigset_t;
335 oset : access sigset_t) return int;
336 pragma Import (C, pthread_sigmask, "pthread_sigmask");
338 ----------------------------
339 -- POSIX.1c Section 11 --
340 ----------------------------
342 function pthread_mutexattr_init
343 (attr : access pthread_mutexattr_t) return int;
344 pragma Import (C, pthread_mutexattr_init, "pthread_mutexattr_init");
346 function pthread_mutexattr_destroy
347 (attr : access pthread_mutexattr_t) return int;
348 pragma Import (C, pthread_mutexattr_destroy, "pthread_mutexattr_destroy");
350 function pthread_mutex_init
351 (mutex : access pthread_mutex_t;
352 attr : access pthread_mutexattr_t) return int;
353 pragma Import (C, pthread_mutex_init, "pthread_mutex_init");
355 function pthread_mutex_destroy (mutex : access pthread_mutex_t) return int;
356 pragma Import (C, pthread_mutex_destroy, "pthread_mutex_destroy");
358 function pthread_mutex_lock (mutex : access pthread_mutex_t) return int;
359 pragma Import (C, pthread_mutex_lock, "pthread_mutex_lock");
361 function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
362 pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
364 function pthread_condattr_init
365 (attr : access pthread_condattr_t) return int;
366 pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
368 function pthread_condattr_destroy
369 (attr : access pthread_condattr_t) return int;
370 pragma Import (C, pthread_condattr_destroy, "pthread_condattr_destroy");
372 function pthread_cond_init
373 (cond : access pthread_cond_t;
374 attr : access pthread_condattr_t) return int;
375 pragma Import (C, pthread_cond_init, "pthread_cond_init");
377 function pthread_cond_destroy (cond : access pthread_cond_t) return int;
378 pragma Import (C, pthread_cond_destroy, "pthread_cond_destroy");
380 function pthread_cond_signal (cond : access pthread_cond_t) return int;
381 pragma Import (C, pthread_cond_signal, "pthread_cond_signal");
383 function pthread_cond_wait
384 (cond : access pthread_cond_t;
385 mutex : access pthread_mutex_t) return int;
386 pragma Import (C, pthread_cond_wait, "pthread_cond_wait");
388 function pthread_cond_timedwait
389 (cond : access pthread_cond_t;
390 mutex : access pthread_mutex_t;
391 abstime : access timespec) return int;
392 pragma Import (C, pthread_cond_timedwait, "pthread_cond_timedwait");
394 Relative_Timed_Wait : constant Boolean := False;
395 -- pthread_cond_timedwait requires an absolute delay time
397 --------------------------
398 -- POSIX.1c Section 13 --
399 --------------------------
401 PTHREAD_PRIO_NONE : constant := 0;
402 PTHREAD_PRIO_PROTECT : constant := 2;
403 PTHREAD_PRIO_INHERIT : constant := 1;
405 function pthread_mutexattr_setprotocol
406 (attr : access pthread_mutexattr_t;
407 protocol : int) return int;
408 pragma Import (C, pthread_mutexattr_setprotocol);
410 function pthread_mutexattr_setprioceiling
411 (attr : access pthread_mutexattr_t;
412 prioceiling : int) return int;
413 pragma Import
414 (C, pthread_mutexattr_setprioceiling,
415 "pthread_mutexattr_setprioceiling");
417 type struct_sched_param is record
418 sched_priority : int;
419 ss_low_priority : int;
420 ss_replenish_period : timespec;
421 ss_initial_budget : timespec;
422 end record;
423 pragma Convention (C, struct_sched_param);
425 function pthread_setschedparam
426 (thread : pthread_t;
427 policy : int;
428 param : access struct_sched_param) return int;
429 pragma Import (C, pthread_setschedparam, "pthread_setschedparam");
431 function pthread_attr_setscope
432 (attr : access pthread_attr_t;
433 contentionscope : int) return int;
434 pragma Import (C, pthread_attr_setscope, "pthread_attr_setscope");
436 function pthread_attr_setinheritsched
437 (attr : access pthread_attr_t;
438 inheritsched : int) return int;
439 pragma Import (C, pthread_attr_setinheritsched);
441 function pthread_attr_setschedpolicy
442 (attr : access pthread_attr_t;
443 policy : int) return int;
444 pragma Import (C, pthread_attr_setschedpolicy);
446 function pthread_attr_setschedparam
447 (attr : access pthread_attr_t;
448 sched_param : int) return int;
449 pragma Import (C, pthread_attr_setschedparam);
451 function sched_yield return int;
452 pragma Import (C, sched_yield, "sched_yield");
454 ---------------------------
455 -- P1003.1c - Section 16 --
456 ---------------------------
458 function pthread_attr_init (attributes : access pthread_attr_t) return int;
459 pragma Import (C, pthread_attr_init, "pthread_attr_init");
461 function pthread_attr_destroy
462 (attributes : access pthread_attr_t) return int;
463 pragma Import (C, pthread_attr_destroy, "pthread_attr_destroy");
465 function pthread_attr_setdetachstate
466 (attr : access pthread_attr_t;
467 detachstate : int) return int;
468 pragma Import (C, pthread_attr_setdetachstate);
470 function pthread_attr_setstacksize
471 (attr : access pthread_attr_t;
472 stacksize : size_t) return int;
473 pragma Import (C, pthread_attr_setstacksize, "pthread_attr_setstacksize");
475 function pthread_create
476 (thread : access pthread_t;
477 attributes : access pthread_attr_t;
478 start_routine : Thread_Body;
479 arg : System.Address) return int;
480 pragma Import (C, pthread_create, "pthread_create");
482 procedure pthread_exit (status : System.Address);
483 pragma Import (C, pthread_exit, "pthread_exit");
485 function pthread_self return pthread_t;
486 pragma Import (C, pthread_self, "pthread_self");
488 --------------------------
489 -- POSIX.1c Section 17 --
490 --------------------------
492 function pthread_setspecific
493 (key : pthread_key_t;
494 value : System.Address) return int;
495 pragma Import (C, pthread_setspecific, "pthread_setspecific");
497 function pthread_getspecific (key : pthread_key_t) return System.Address;
498 pragma Import (C, pthread_getspecific, "pthread_getspecific");
500 type destructor_pointer is access procedure (arg : System.Address);
501 pragma Convention (C, destructor_pointer);
503 function pthread_key_create
504 (key : access pthread_key_t;
505 destructor : destructor_pointer) return int;
506 pragma Import (C, pthread_key_create, "pthread_key_create");
508 ------------------------------------------------------------
509 -- Binary Semaphore Wrapper to Support Interrupt Tasks --
510 ------------------------------------------------------------
512 type Binary_Semaphore_Id is new rtems_id;
514 function Binary_Semaphore_Create return Binary_Semaphore_Id;
515 pragma Import (
517 Binary_Semaphore_Create,
518 "__gnat_binary_semaphore_create");
520 function Binary_Semaphore_Delete (ID : Binary_Semaphore_Id) return int;
521 pragma Import (
523 Binary_Semaphore_Delete,
524 "__gnat_binary_semaphore_delete");
526 function Binary_Semaphore_Obtain (ID : Binary_Semaphore_Id) return int;
527 pragma Import (
529 Binary_Semaphore_Obtain,
530 "__gnat_binary_semaphore_obtain");
532 function Binary_Semaphore_Release (ID : Binary_Semaphore_Id) return int;
533 pragma Import (
535 Binary_Semaphore_Release,
536 "__gnat_binary_semaphore_release");
538 function Binary_Semaphore_Flush (ID : Binary_Semaphore_Id) return int;
539 pragma Import (
541 Binary_Semaphore_Flush,
542 "__gnat_binary_semaphore_flush");
544 ------------------------------------------------------------
545 -- Hardware Interrupt Wrappers to Support Interrupt Tasks --
546 ------------------------------------------------------------
548 type Interrupt_Handler is access procedure (parameter : System.Address);
549 pragma Convention (C, Interrupt_Handler);
550 type Interrupt_Vector is new System.Address;
552 function Interrupt_Connect
553 (vector : Interrupt_Vector;
554 handler : Interrupt_Handler;
555 parameter : System.Address := System.Null_Address) return int;
556 pragma Import (C, Interrupt_Connect, "__gnat_interrupt_connect");
557 -- Use this to set up an user handler. The routine installs a
558 -- a user handler which is invoked after RTEMS has saved enough
559 -- context for a high-level language routine to be safely invoked.
561 function Interrupt_Vector_Get
562 (Vector : Interrupt_Vector) return Interrupt_Handler;
563 pragma Import (C, Interrupt_Vector_Get, "__gnat_interrupt_get");
564 -- Use this to get the existing handler for later restoral.
566 procedure Interrupt_Vector_Set
567 (Vector : Interrupt_Vector;
568 Handler : Interrupt_Handler);
569 pragma Import (C, Interrupt_Vector_Set, "__gnat_interrupt_set");
570 -- Use this to restore a handler obtained using Interrupt_Vector_Get.
572 function Interrupt_Number_To_Vector (intNum : int) return Interrupt_Vector;
573 -- Convert a logical interrupt number to the hardware interrupt vector
574 -- number used to connect the interrupt.
575 pragma Import (
577 Interrupt_Number_To_Vector,
578 "__gnat_interrupt_number_to_vector"
581 private
583 type sigset_t is new int;
585 type pid_t is new int;
587 type time_t is new long;
589 type timespec is record
590 tv_sec : time_t;
591 tv_nsec : long;
592 end record;
593 pragma Convention (C, timespec);
595 type clockid_t is new rtems_id;
596 CLOCK_REALTIME : constant clockid_t := 1;
598 type struct_timeval is record
599 tv_sec : int;
600 tv_usec : int;
601 end record;
602 pragma Convention (C, struct_timeval);
604 type pthread_attr_t is record
605 is_initialized : int;
606 stackaddr : System.Address;
607 stacksize : int;
608 contentionscope : int;
609 inheritsched : int;
610 schedpolicy : int;
611 schedparam : struct_sched_param;
612 cputime_clocked_allowed : int;
613 detatchstate : int;
614 end record;
615 pragma Convention (C, pthread_attr_t);
617 type pthread_condattr_t is record
618 flags : int;
619 process_shared : int;
620 end record;
621 pragma Convention (C, pthread_condattr_t);
623 type pthread_mutexattr_t is record
624 is_initialized : int;
625 process_shared : int;
626 prio_ceiling : int;
627 protocol : int;
628 recursive : int;
629 end record;
630 pragma Convention (C, pthread_mutexattr_t);
632 type pthread_t is new rtems_id;
634 type pthread_mutex_t is new rtems_id;
636 type pthread_cond_t is new rtems_id;
638 type pthread_key_t is new rtems_id;
640 No_Key : constant pthread_key_t := 0;
642 end System.OS_Interface;