-- $Source: /commtar/monoBANK/RTS/tsksupp.dat,v $ -- $Revision: 1.4 $ -- $Date: 86/09/03 09:00:52 $ -- $Author: fitch $ ------------------------------------------------------------------ with System; with RTS_TGT_Clock; with RTS_Lock_Package; with RTS_TGT_Tasking_Types; package RTS_TaskingSupport is --| Types/Globals used for Ada Tasking RTS NullPriority : constant := System.Priority'POS(System.Priority'First)-1; --| Use priority below legal priority to represent uninitialized prio Num_System_Priorities : constant := 16; --| Provide for 16 extra system-reserved high priorities HighPriority : constant := System.Priority'POS(System.Priority'Last) + Num_System_Priorities; --| Allow for extra priorities for Interrupt-level priorities subtype DelayType is Standard.Duration; subtype TaskCount is Integer; subtype PriorityNumber is Integer range NullPriority .. HighPriority; Tasking_Internal_Error : exception; ------------------------------------------------------------- Max_Entries : constant := 200; --| Maximum number of entries supported subtype IndexType is Integer range 0 .. Max_Entries; --| Includes family indices, entry indices. subtype EntryCount is IndexType range 0 .. IndexType'last; subtype EntryIndex is IndexType range 1 .. IndexType'last; --| Index of a task entry. --| --| Each task (type) has a known number of entries or --| entry families, except for tasks with no entry. Entry --| indices start at 1. Simple entries are numbered first, --| followed by entry family members. The entry index is a --| temporary created by the compiler which also computes --| the offset for each family member. type TCB(Number_Of_Entries : EntryCount); type TCBHandle is access TCB; ---------------------------------------------------------------------- type Task_Status is ( --| Values for tcb_status. --| The meanings of the task_status --| must hold anytime tasking is not locked. --| Note that Runnable/Running may be the --| status even after the task has been aborted --| or has completed, because the task is --| performing cleanup activities. --| The Wakeup_Action is used to determine --| whether the task is Abnormal/Completed --| (see below). Unactivated, --| Created & elaborated; on activation list. Runnable, --| On a Runnable queue, as determined by --| its priority; --| no entries open; not on entry queue; not --| on delay queue. Running, --| Running on some processor, as determined --| by Current_TCB for that processor; --| no entries open; not on entry queue; not --| on delay queue. --| For a short period at the start of --| a rendezvous, both an acceptor and --| a caller have status = Running. Task_Wait, --| Waiting for dependents --| to terminate; tm_nonterm > 0. Terminated, --| Terminated; all dependents terminated; --| no longer running; stack space released. Delayed, --| Waiting for delay to expire; on delay queue. ActivatorWaiting, --| Waiting for activation of subtasks; --| al_count > 0. CallerWaiting, --| Normal entry call; on entry queue. CallerDelayed, --| Timed entry call; on delay and entry queue; --| tcb_expired = FALSE. CallerInRendezvous, --| Caller in rendezvous. AcceptorWaiting, --| At ACCEPT, awaiting a caller; entries open. AcceptorDelayed, --| SELECTIVE WAIT with delay; on delay queue; --| entries open. AcceptorTerminable, --| SELECTIVE WAIT with terminate; entries open. Unknown --| Status being changed (RTS locked only). ); -------------------------------------------------------------------- type Wakeup_Action is ( --| Actions you can take when a task wakes up --| as recorded in tcb_wakeup Normal, --| Continue executing normally. Raise_Exception, --| Raise an exception given by tcb_exceptinfo --| when you wakeup. Raise_Tasking_Error, --| Raise Tasking Error because acceptor --| no longer callable. Abnormal_Termination,--| You were aborted while you were asleep --| so terminate yourself at next wakeup. Continue_Termination --| Task has completed, continue waiting --| on dependents until all terminated. ); subtype Uncallable is Wakeup_Action range Abnormal_Termination .. Continue_Termination; --| A task is uncallable if its wakeup action indicates --| it has been aborted or has completed. type Termination_Status is ( --| Termination status; may induce OS --| dependent action at task cleanup; --| recorded in tcb_term_status. Not_Yet_Terminated, --| Initial value Terminated_Normally, --| Task terminated of its own free will. Terminated_In_Select, --| Task terminated as part of selective --| wait with terminate alternative. Never_Activated, --| Task terminated without activating. Unhandled_Exception, --| Task terminated due to unhandled --| exception. Aborted --| Task terminated by abort of task or --| its parent. ); type TaskMasterRecord; --| A queue of dependent tasks. --| --| All dependent subtasks of a master (subprogram, task, --| block, or library package) are kept on a dependency list --| for that master. The tasking package uses this list to --| determine when tasks can be terminated, whether a block --| can be exited, and which subtasks are affected by an --| ABORT statement. type TaskMasterHandle is access TaskMasterRecord; ---------------------------------------------------------------- type ActivationList; --| A queue of tasks to activate. --| --| Tasks being activated are linked onto both the --| dependency list and an activation list. Several allocators --| may exist for dependents of a single master, givning rise --| to several activation lists. type ActivationListHandle is access ActivationList; ---------------------------------------------------------------------- type RendezvousSaveArea; --| The Rendezvous Save Area is where we save information needed --| for after a rendezvous finishes (and which is available when --| the rendezvous begins). This includes the current eps' frame --| pointer for nested accepts and a rendezvous save area, if you --| are aborted inside a nested accept construct. type RendezvousSaveAreaPtr is access RendezvousSaveArea; ---------------------------------------------------------------------- -- Exception information ---------------------------------------------------------------------- subtype ExceptionInfo is System.Address; --| Exceptions are represented by the address of a descriptor ------------------------------------------------------------------ -- Queue of TCB's ------------------------------------------------------------------ ---------------------------------------------------------------------- type TaskQueueType is record --| Queue of tcb's. tq_count: TaskCount := 0; --| Number of tasks in queue. tq_first: TCBHandle; --| First task on list. tq_last: TCBHandle; --| Last task on list. end record; type PerEntryInfo is record --| Info kept for each entry of a task pei_queue : TaskQueueType; --| Queue of waiting entry callers pei_open : Boolean := FALSE; --| True implies acceptor is waiting for callers pei_accept_case : Integer := 0; --| Identifies which accept body is to be executed --| by the EPS for the rendezvous. --| Only relevant if there are multiple accept bodies --| for the same entry (family). end record; type BitVector is array (EntryIndex range <>) of Boolean; --| Per entry information for selective wait info records type TaskEntryArray is array (EntryIndex range <>) of PerEntryInfo; --| Array of caller queues, one per entry, holding --| run-time information for each entry of a task. ------------------------------------------------------------------ -- List of dependent tasks ------------------------------------------------------------------ type TaskMasterRecord is record --| List of dependent tasks. tm_id: Integer; --| Identifier of task master. tm_complete_on_wait: Boolean := False; --| When true, indicates that --| enclosing task is complete --| when this master is awaited. tm_nonterm: TaskCount := 1; --| Number of nonterminable --| dependents. --| This includes one for --| the master itself until --| it does a task wait or --| becomes terminable. --| This is incremented when --| a dependent is first --| activated. tm_dependents: TaskQueueType; --| Queue of master's dependents. --| Tasks created by their --| master (always true unless --| created by an allocator) --| are added when created. --| Others are added when first --| activated. tm_enclosing_master: TaskMasterHandle; --| Ptr to enclosing master. tm_enclosing_task: TCBHandle; --| Ptr to enclosing task. tm_enclosing_rsa: RendezvousSaveAreaPtr; --| RSA (if any) enclosing TM. --| Must not abort rendezvous --| until having waited for --| inner TaskMaster's, to avoid --| clobbering stack. end record; -------------------------------------------------------------------- -- Activation list -------------------------------------------------------------------- type ActivationList is record --| List for activating tasks. al_id: Integer; --| Identifier of Activation list al_tasks: TaskQueueType; --| The list of tasks to be --| activated. al_count: TaskCount:= 0; --| Count of tasks still --| activating. al_success: Boolean:= TRUE;--| True if all activations --| succeeded. al_activator: TCBhandle; --| Task initiating the --| activations. end record; --------------------------------------------------------------------- -- RendezvousSaveArea --------------------------------------------------------------------- type Double_Word_Record is record --| Type used for MVS ECB's, to guarantee that an aligned full-word --| will be available. Assembly code will pick aligned part. first_word: Integer := 0; second_word: Integer := 0; end record; type RendezvousSaveArea is record --| Temporary save area during --| a rendezvous. rsa_id: Integer; --| Id of RSA. rsa_ecb: Double_Word_Record; --| The MVS target --| uses this ECB to wait --| on when the caller --| processor waits for --| the acceptor to --| finish. rsa_caller: TCBhandle; --| Caller of rendezvous rsa_current_frame: System.Address; --| pointer to the EPS --| frame. rsa_static_link: System.Address; --| save the old value --| of the static link --| so it can be restored --| when leaving a --| rendezvous rsa_acceptor_priority: PriorityNumber; --| Acceptor's priority, --| which may get changed --| during the rendezvous rsa_acceptor_state: RTS_TGT_Tasking_Types.Task_State_Info; --| Acceptor's state --| information. rsa_rsaptr: RendezvousSaveAreaPtr; --| Save the rsa of the --| enclosing eps, for --| use in aborting --| of nested rendezvous' end record; ---------------------------------------------------------------------- -- Task Control Block -- -- comprising state, context, link and entry information. ------------------------------------------------------------------ type Elab_Bit_Array is array(1..1) of Boolean; type Elab_Bit_Ptr is access Elab_Bit_Array; --| Types used for accessing elaboration bits; --| must use access to constrained array to guarantee --| proper packing (always one SU for elaboration "bit"). type TCB(Number_Of_Entries : EntryCount) is record --| Info describing one task. --- Task Identification --- tcb_id : Integer:= 1; --| Numerical ID of TCB, for --| debugging only. tcb_the_real_one : TCBHandle; --| Pointer to the real --| TCB. This one may be --| a copy on the secondary --| stack. tcb_uda: System.Address; --| Address of task body code tcb_staticlink: System.Address; --| Static link for task body tcb_elab_bit: Elab_Bit_Ptr; --| Pointer to elab-bit for task body --- State Information --- tcb_status: Task_Status := Unactivated; --| task state tcb_priority: PriorityNumber := 0; --| Priority of the task. tcb_wakeup : Wakeup_Action := Normal; --| checked when a task --| wakes up to decide --| what action to take . --| Task is not callable --| if tcb_wakeup in Uncallable. tcb_exceptinfo : ExceptionInfo; --| exception to raise on --| wakeup. tcb_term_status : Termination_Status := Not_Yet_Terminated; --| How task terminated. tcb_wakeup_time: RTS_TGT_Clock.TGT_Time_Type; --| Time to be re-awoken if --| delayed tcb_expired: Boolean := FALSE; --| if the timed/conditional --| entry call expired. --- Links on Queues and Lists --- tcb_innermost_submaster: TaskMasterHandle; --| Master executing in this --| task. tcb_master: TaskMasterHandle; --| Master of this task. --| dep_prev/next used for links tcb_activator: ActivationListHandle; --| Pointer to activation list --| for this task. --| cur_prev/next used for links --| Set to null after notifying --| activator of successful --| activation. tcb_del_prev: TCBHandle; --| Prev on delay queue. tcb_del_next: TCBHandle; --| Next on delay queue. tcb_dep_prev: TCBHandle; --| Prev on dependency list. tcb_dep_next: TCBHandle; --| Next on dependency list. tcb_cur_prev: TCBHandle; --| Prev, current queue. tcb_cur_next: TCBHandle; --| Next, current queue (i.e., --| entry caller queue or --| runnable queue). tcb_called_task: TCBHandle; --| The head of the entry tcb_entry_index: IndexType := 0; --| queue, if that is what --| cur_prev/next is on, null --| otherwise. tcb_lock_chain: RTS_Lock_Package.Lock_Chain_Type; --| chain in the semaphore queue. --- Entry Information --- tcb_entry: TaskEntryArray(1 .. Number_Of_Entries); --| Info for each entry. --- Processor and Stack state information --- tcb_state_info : RTS_TGT_Tasking_Types.Task_State_Info; --| Saved stack/frame pointers tcb_processor_info : RTS_TGT_Tasking_Types.Processor_Info; --| Saved processor information, e.g. pointer to global area tcb_state_inited : Boolean := False; --| True means state_info has been allocated/initialized tcb_frame_ptr : System.Address; --| This is a pointer to --| the frame ptr for the --| base frame of the task tcb_rsaptr : RendezvousSaveAreaPtr := null; --| Used to perform the abort --| statement when an --| acceptor inside a --| rendezvous. --| Null means not nested in --| a rendezvous. tcb_caller_rsa : RendezvousSaveAreaPtr; --| RSA if caller-in-rendezvous. --| Used for MVS tasking. end record; -------------------------------------------------------------------- -- EntryCallDescriptor -------------------------------------------------------------------- type EntryCallDescriptor is record --| Descriptor of an entry call --| with discriminant for distinction of --| timed/conditional vs. simple calls, --| pointed to by static link for call. --| Static link is replaced by --| Start_Rendezvous with pointer to --| appropriate enclosing frame. ecd_id: Integer; --| identifies the entry call descrip. ecd_called: TCBhandle; --| Called task. ecd_entry: EntryIndex; --| Entry index of entry called ecd_delay: DelayType;--| delay before canceling call. ecd_is_timed: Boolean := FALSE; --| is the entry call a --| timed or conditional entry call. end record; type CallHandle is access EntryCallDescriptor; --| Static link for task entries -------------------------------------------------------------------- type SelectKind is ( simple_select, select_with_else, select_with_delay, select_with_terminate ) ; --| Different types of select wait (see LRM 9.7.1) -------------------------------------------------------------------- -- Information for Selective Wait statement -------------------------------------------------------------------- type SelectInfo(Number_Of_Entries : EntryCount) --| Record used for selective wait statement --?stt? Would be ideal if si_kind could be a discriminant, --?stt? but it makes calculating the size more difficult for STO is record si_kind: SelectKind; --| Kind of selective wait si_id: Integer; si_open: BitVector (1 .. Number_Of_Entries); --| Set of open entries, one bit --| for entry; TRUE if the entry --| has an open accept alternative. si_open_accept: Boolean := False; --| true for a select statement with --| open accept statements si_terminate_open: Boolean := FALSE; --| Select has terminate alternative? si_delay_open: Boolean := FALSE; --| True if any delay is open. si_mindelay: DelayType := DelayType'LAST; --| Minimum delay encountered so far. end record; Verbose_Debug : Boolean := FALSE; DelayQueue: TaskQueueType; THE_UDA : Integer; THE_STATIC_LINK : Integer; THE_TCB : TCBHandle; THE_MAIN_PROGRAM : TCBHandle; THE_DEFAULT_MASTER : TaskMasterHandle; ------------------------------------------------------------ -- The following variables are used by the compiler -- to lookup the size of the various data types in the -- compiler. Any change to these names should be accompanied -- by a change to the storage phase of the compiler. -- An enumeration in the Run_Time_System_Calls package has -- to correspond with the names given here!!!!!! ------------------------------------------------------------ RTS_TCB_DEF : TCB(0); --| Has minimal TCB size RTS_TM_DEF : TaskMasterRecord; RTS_AL_DEF : ActivationList; RTS_SI_DEF : SelectInfo(0); --| Has minimal SI size RTS_RSA_DEF : RendezvousSaveArea; RTS_ECD_DEF : EntryCallDescriptor; RTS_Per_TCB_Entry_Def : TaskEntryArray(1..1); --| Incremental TCB size RTS_Per_SI_Entry_Def : BitVector(1..1); --| Incremental SI size -- end RTS_TaskingSupport; -- $Cprt start$ -- -- Copyright (C) 1988 by Intermetrics, Inc. -- -- This material may be used duplicated or disclosed by or for the -- U.S. Government pursuant to the copyright license under DAR clause -- 7-104.9(a) (May 1981). -- -- This project was spnsored by the STARS Foundation -- Naval Research Laboratory, Washington DC -- -- $Cprt end$