source: buchla-68k/orig/MT/MTRUN.C

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

Imported original source code.

  • Property mode set to 100755
File size: 2.9 KB
Line 
1/*
2 =============================================================================
3 mtrun.c -- Multi-Tasker -- task initialization, etc.
4 Version 8 -- 1988-04-12 -- 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 termination function */
16
17extern struct _mt_def *_MT_; /* Multi-Tasker structure pointer */
18
19/*
20
21*/
22
23/*
24 =============================================================================
25 MTRun() -- initialize and start a task
26
27 SUCCESS TCB created and placed on ready queue
28 FAILURE no TCB available for task
29 =============================================================================
30*/
31
32short
33MTRun(tid, pri, stat, slice, pstack, func, par)
34unsigned tid;
35register unsigned pri;
36unsigned stat;
37long slice, pstack;
38short (*func)();
39long par;
40{
41 register short oldipl;
42 register TCB *rcur, *rprv, *tcp;
43
44 DB_ENTR("MTRun");
45
46 if ((struct _mt_def *)NIL EQ _MT_)
47 _MT_ = (struct _mt_def *)XBIOS(X_MTDEFS);
48
49 tcp = _MT_->mtp->TCBs; /* point at the first TCB */
50 oldipl = setipl(7); /* DISABLE INTERRUPTS */
51
52 while (tcp) { /* search for a free TCB */
53
54 if (NOT (tcp->flags & MTF_OCC)) {
55
56 /* setup the TCB */
57
58 tcp->tos = pstack; /* put top of stack in TCB */
59
60 pstack -= 4L; /* adjust stack pointer */
61 *(long *)pstack = par; /* store task parameter */
62
63 pstack -= 4L; /* adjust stack pointer */
64 *(long *)pstack = MTExit; /* store return address */
65
66 tcp->flags = MTF_OCC; /* flags = TCB occupied */
67 tcp->tid = tid; /* ID */
68 tcp->pri = pri; /* priority */
69 tcp->slice = slice; /* time slice */
70 tcp->sp = pstack; /* stack pointer */
71 tcp->reg[15] = pstack; /* a7 */
72 tcp->pc = func; /* program counter */
73 tcp->sr = stat; /* status register */
74/*
75
76*/
77 rcur = (TCB *)&_MT_->mtp->RdyQ; /* point at the head of the queue */
78
79 while (TRUE) {
80
81 rprv = rcur; /* previous TCB = current TCB */
82 rcur = rprv->next; /* current TCB = next TCB */
83
84 if (rcur EQ (TCB *)NIL) /* enqueue here if next was NIL */
85 break;
86
87 if (pri > rcur->pri) /* enqueue here if priority is greater */
88 break;
89 }
90
91 rprv->next = tcp; /* set next of previous TCB to new TCB */
92 tcp->next = rcur; /* set next of new TCB to old next */
93 tcp->flags |= MTF_RDY; /* set the ready flag in the new TCB */
94
95 setipl(oldipl); /* RESTORE INTERUPTS */
96 DB_EXIT("MTRun - SUCCESS");
97 return(SUCCESS); /* return -- SUCCESS */
98 }
99
100 tcp = tcp->fwd; /* look at next TCB */
101 }
102
103 setipl(oldipl); /* RESTORE INTERRUPTS */
104 DB_EXIT("MTRun - FAILURE");
105 return(FAILURE); /* return -- FAILURE */
106}
107
Note: See TracBrowser for help on using the repository browser.