// nos-z nut operating system in Rz // model after nos2 in ecse\src 22 Aug 2011 // run two process (showTwoCount) 23 Aug 2011 // new Rz syntax and add monitor 28 Aug 2011 syscall(a) // anchor for compiler a = 0 new(n) // alloc n syscall(14,n) ei() syscall(20) di() syscall(21) getevent() return syscall(22) blockp() syscall(23) bootnos() syscall(24) // global activep // current active process psw // switchp sseg // stack segment pid // unique process id // event TIMEOUT, STOP, BLOCK // process descriptor // 0 next, 1 prev // 2 id, 3 value // 4 fp, 5 sp, 6 pc, 7 - // 8 inbox, 9 awaitbox, 10 msg // process state READY, RUNNING, WAIT, DEAD, SEND, RECEIVE init() TIMEOUT = 10 STOP = 13 BLOCK = 11 READY = 1 RUNNING = 2 WAIT = 3 DEAD = 4 SEND = 5 RECEIVE = 6 pid = 1 sseg = 1000 activep = 0 // process descriptor access function getNext(a) return a[0] getPrev(a) return a[1] setNext(a,v) a[0] = v setPrev(a,v) a[1] = v getId(p) return p[2] getValue(p) return p[3] setId(p,id) p[2] = id setValue(p, v) p[3] = v // ---- process list functions -------- // append a2 to the end of a1 appendDL(a1,a2) if(a1 == 0) setNext(a2,a2) // only one item setPrev(a2,a2) return a2 else b = getPrev(a1) setNext(a2,a1) setPrev(a1,a2) setNext(b,a2) setPrev(a2,b) return a1 deleteDL(b) if(getNext(b) == 0) return 0 // delete singleton else a = getPrev(b) c = getNext(b) setNext(a,c) setPrev(c,a) setNext(b,0) // make b singleton return c showp(a) // show pid,sseg,ip p = a while(p != 0) print(p[2]," ",p[4]," ",p[6],"\n") p = getNext(p) if(p == a) p = 0 print("\n") newp() // new process p = new(11) // new pdes setNext(p,0) setPrev(p,0) setValue(p,READY) p[4] = sseg p[5] = sseg + 1 p[6] = 0 sseg = sseg + 1000 p[7] = 0 p[8] = 0 return p // -------nos functions -------- run(ads) // return p p = newp() setId(p,pid) pid = pid + 1 p[6] = ads activep = appendDL(activep, p) return p switchp() // previlege process di() event = getevent() if(event == STOP) setValue(activep,DEAD) activep = deleteDL(activep) else // TIMEOUT, BLOCK setValue(activep,READY) activep = getNext(activep) // switch next ei() // -------- user program ------ count1() i = 10 while(i < 100) print(i," ") i = i + 2 count2() i = 3 while(i < 100) print(i," ") i = i + 2 // --- applications ---------- p1, p2 // user process main() init() psw = run(switchp()) activep = 0 // start user process p1 = run(count1()) p2 = run(count2()) bootnos() // end