source: buchla-68k/orig/MT/MTINIT.C@ e15f784

Last change on this file since e15f784 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 3.0 KB
Line 
1/*
2 =============================================================================
3 mtinit.c -- Multi-Tasker -- initialization, etc.
4 Version 31 -- 1988-04-15 -- D.N. Lynx Crowe
5 (c) Copyright 1988 -- D.N. Lynx Crowe
6 =============================================================================
7*/
8
9#include "stddefs.h"
10#include "biosdefs.h"
11#include "mtdefs.h"
12#include "debug.h"
13
14extern short _MT_Swp(); /* swapper TRAP handler -- swap */
15extern short _MT_Nxt(); /* swapper TRAP handler -- next */
16extern short setipl(); /* set processor IPL function */
17
18extern TCB *MT_TCBs; /* TCB chain pointer */
19extern TCB *MT_CurP; /* current TCB pointer */
20extern TCB *MT_RdyQ; /* ready queue pointer */
21extern TCB _MTptcb[2]; /* private TCBs */
22
23extern unsigned MT_IDct; /* next available task ID */
24
25extern unsigned *_MT_Vc1; /* old swapper TRAP vector 1 */
26extern unsigned *_MT_Vc2; /* old swapper TRAP vector 2 */
27
28long _MT_Stk[48]; /* a stack for _MT_Nil() */
29
30TCB _MT_TCB; /* dummy TCB for shutdown */
31
32/*
33
34*/
35
36/*
37 =============================================================================
38 _MT_Nil() -- the NIL task (must always be present on the ready queue)
39 =============================================================================
40*/
41
42_MT_Nil()
43{
44 register short i, j;
45
46 while (TRUE) {
47
48 setipl(2); /* make sure we're interruptable */
49
50 for (i = 0; i < 10; i++)
51 ++j;
52
53 DB_CMNT("_MT_Nil");
54 MTSwap();
55 }
56}
57
58/*
59 =============================================================================
60 MTInit() -- initialize the mutitasker and setup the task 0 default TCB
61 =============================================================================
62*/
63
64MTInit()
65{
66 register short i, oldipl;
67 register TCB *tcp;
68
69 DB_ENTR("MTInit");
70 oldipl = setipl(7); /* DISABLE INTERRUPTS */
71
72 MT_TCBs = &_MTptcb[1]; /* setup the TCB chain pointer */
73 MT_RdyQ = &_MTptcb[0]; /* task 0 is on the ready queue */
74
75 memsetw(&_MTptcb[0], 0, sizeof (TCB) / 2); /* clear task 0 TCB */
76 memsetw(&_MTptcb[1], 0, sizeof (TCB) / 2); /* clear task 1 TCB */
77
78 _MTptcb[0].flags = MTF_OCC | MTF_RDY; /* set task 0 ready ... */
79 _MTptcb[0].slice = -1L; /* ... not time-sliced */
80 _MTptcb[0].pc = _MT_Nil; /* ... NIL task */
81 _MTptcb[0].sp = &_MT_Stk[48]; /* ... set stack space */
82 _MTptcb[0].reg[15] = &_MT_Stk[48]; /* ... and a7 */
83 _MTptcb[0].sr = MT_NilSR; /* ... set sr */
84
85 MT_CurP = &_MTptcb[1]; /* task 1 is the current task */
86
87 _MTptcb[1].fwd = &_MTptcb[0]; /* point at next TCB */
88 _MTptcb[1].flags = MTF_OCC | MTF_RUN; /* set task 1 running ... */
89 _MTptcb[1].pri = MT_DfPri; /* ... default priority */
90 _MTptcb[1].slice = -1L; /* ... not time-sliced */
91 _MTptcb[1].tid = 1; /* ... set task ID */
92
93 MT_IDct = 2; /* next task ID = 2 */
94
95 _MT_Vc1 = BIOS(B_SETV, 40, _MT_Swp); /* set swapper TRAP vector 1 */
96 _MT_Vc2 = BIOS(B_SETV, 41, _MT_Nxt); /* set swapper TRAP vector 2 */
97
98 setipl(oldipl); /* RESTORE INTERRUPTS */
99 DB_EXIT("MTInit");
100}
101
Note: See TracBrowser for help on using the repository browser.