User guide

104 CHAPTER 4. THE COMMAND LANGUAGE
It always starts execution at the start of the function irqrtn wit h Cintcode register
ST set to 3 to indicate that an interrupt is being servi c ed . The interrupt sevice routine
may return control to the interrupted task or it may enter the scheduler if another task
desrves to gain control .
Before creating the resident tasks, startroot initialises a few more rootnode fields.
These are rtn tcblist and rtn crntask both set to zero since there are currently no
Cintpos tasks, rtn
blklist set to the start of the memory block list used by getvec
and freevec, rtn
clkintson se t to FALSE to globally disable interrupts, rtn clwkq
set to zero representing an empty list of packets for the clock device, and rtn
info set
to a c l ear e d table of 50 element s.
The resident tasks are now created using suitable calls of createtask. Each time
createtask is called it allocates a task control block (TCB) giving it the next available
task id entifier and updating the appropriate entry in tasktab to point to it. Such tasks
are initially gi ven a state of #b1100 indicating that they are DEAD, not HELD and
have no packets in the work queue. The first task to be created is a special one called
Idle whose body is in cin/syscin/idle and although createtask will have chosen
identifier one for it, this must be replaced by zero and it entry in tasktab removed.
It is given a startup packet and an initial state of #b1101 indicating it is DEAD, not
HELD but has a packet and so can be given control by the scheduler when it is run.
Six more resident tasks are now created, all have state #b1100. They are the root
command language interpreter that initially waits for commands from the keyboard,
and interactive debugging task, the console handler providing communication between
the keyboard and tasks, the file handler providing access t o disk files, the mailbox
handler that provides a mechani s m that lets t ask s send and rece i ve short mess ages via
named mailboxes and the TCP handler providing TCP/IP communication.
Just after Cintpos starts up t he status command will output the following.
Task 1: Root_Cli running CLI Loaded command: status
Task 2: Debug_Task waiting DEBUG
Task 3: Console_Handler waiting COHAND
Task 4: File_Handler waiting FH0
Task 5: MBX_Handler waiting MBXHAND
Task 6: TCP_Handler waiting TCPHAND
Once the kernel structure and all the r es i de nt tasks have been set up, the system
can be started by entering the scheduler which is a function called srchwk defined in
sysb/klib.b. It take one argument which is a pointer to the highest priority TCB
that could possibly run. It searches through the chain of TCBs that are linked in
decreasing priority order looking at only the status field of each. This field is sufficient
to tell whether the corresponding task can run or not. It has 4 bits IWHP. The I bit is
a 1 if the task has been interrupted inwhich case its Cintcode registers will be packed
elsewhere in the TCB. The W bit is a 1 if the task is suspended in taskwait waiting
for a packet to arrive from anot her task oer a device. The H bit is 1 if the task is in
HOLD state indicating that it cannot run even if it otherwise would be ready to do
so, and the P bit is a 1 if the tasks’s work queue is not empty. A task cannot be both
interrupted and waiting for a packet and the setting of both the I and W bits have
a special meaning, namely that the task is in DEAD state having no runtime st ack