1 | /*
|
---|
2 | =============================================================================
|
---|
3 | mtsett.c -- Multi-Tasker -- task initialization with a new TCB
|
---|
4 | Version 1 -- 1988-04-11 -- 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 |
|
---|
14 | extern short setipl(); /* set processor IPL function */
|
---|
15 | extern short MTExit(); /* task terminate function */
|
---|
16 |
|
---|
17 | extern struct _mtdef *_MT_; /* Multi-Tasker structure pointer */
|
---|
18 |
|
---|
19 | /* |
---|
20 |
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | =============================================================================
|
---|
25 | MTSetT() -- initialize a TCB
|
---|
26 | =============================================================================
|
---|
27 | */
|
---|
28 |
|
---|
29 | MTSetT(tcp, tid, pri, stat, slice, pstack, func, par)
|
---|
30 | register TCB *tcp;
|
---|
31 | unsigned tid;
|
---|
32 | register unsigned pri;
|
---|
33 | unsigned stat;
|
---|
34 | long slice, pstack;
|
---|
35 | short (*func)();
|
---|
36 | long par;
|
---|
37 | {
|
---|
38 | register short oldipl;
|
---|
39 | register TCB *rcur, *rprv;
|
---|
40 |
|
---|
41 | DB_ENTR("MTSetT");
|
---|
42 |
|
---|
43 | if ((struct _mt_def *)NIL EQ _MT_)
|
---|
44 | _MT_ = (struct _mt_def *)XBIOS(X_MTDEFS);
|
---|
45 |
|
---|
46 | oldipl = setipl(7); /* DISABLE INTERRUPTS */
|
---|
47 |
|
---|
48 | /* setup the TCB */
|
---|
49 |
|
---|
50 | tcp->tos = pstack; /* put top of stack in TCB */
|
---|
51 |
|
---|
52 | pstack -= 4L; /* adjust stack pointer */
|
---|
53 | *(long *)pstack = par; /* store task parameter */
|
---|
54 |
|
---|
55 | pstack -= 4L; /* adjust stack pointer */
|
---|
56 | *(long *)pstack = MTExit; /* store return address */
|
---|
57 |
|
---|
58 | tcp->flags = MTF_OCC; /* flags = TCB occupied */
|
---|
59 | tcp->tid = tid; /* ID */
|
---|
60 | tcp->pri = pri; /* priority */
|
---|
61 | tcp->slice = slice; /* time slice */
|
---|
62 | tcp->sp = pstack; /* stack pointer */
|
---|
63 | tcp->reg[15] = pstack; /* a7 */
|
---|
64 | tcp->pc = func; /* program counter */
|
---|
65 | tcp->sr = stat; /* status register */
|
---|
66 |
|
---|
67 | /* |
---|
68 |
|
---|
69 | */
|
---|
70 | /* queue the TCB */
|
---|
71 |
|
---|
72 | rcur = (TCB *)&_MT_->mtp->RdyQ; /* point at the head of the queue */
|
---|
73 |
|
---|
74 | while (TRUE) {
|
---|
75 |
|
---|
76 | rprv = rcur; /* previous TCB = current TCB */
|
---|
77 | rcur = rprv->next; /* current TCB = next TCB */
|
---|
78 |
|
---|
79 | if (rcur EQ (TCB *)NIL) /* enqueue here if next was NIL */
|
---|
80 | break;
|
---|
81 |
|
---|
82 | if (pri > rcur->pri) /* enqueue here if priority is greater */
|
---|
83 | break;
|
---|
84 | }
|
---|
85 |
|
---|
86 | rprv->next = tcp; /* set next of previous TCB to new TCB */
|
---|
87 | tcp->next = rcur; /* set next of new TCB to old next */
|
---|
88 | tcp->flags |= MTF_RDY; /* set the ready flag in the new TCB */
|
---|
89 |
|
---|
90 | tcp->fwd = _MT_->mtp->TCBs; /* add TCB to chain */
|
---|
91 | _MT_->mtp->TCBs = tcp; /* ... */
|
---|
92 |
|
---|
93 | setipl(oldipl); /* RESTORE INTERUPTS */
|
---|
94 | DB_EXIT("MTSetT");
|
---|
95 | }
|
---|