source: buchla-68k/orig/MT/MTSETT.C@ 4b63bf3

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

Imported original source code.

  • Property mode set to 100755
File size: 2.5 KB
Line 
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
14extern short setipl(); /* set processor IPL function */
15extern short MTExit(); /* task terminate function */
16
17extern struct _mtdef *_MT_; /* Multi-Tasker structure pointer */
18
19/*
20
21*/
22
23/*
24 =============================================================================
25 MTSetT() -- initialize a TCB
26 =============================================================================
27*/
28
29MTSetT(tcp, tid, pri, stat, slice, pstack, func, par)
30register TCB *tcp;
31unsigned tid;
32register unsigned pri;
33unsigned stat;
34long slice, pstack;
35short (*func)();
36long 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}
Note: See TracBrowser for help on using the repository browser.