/* *****

        Operative System for MIPS Written by Filip Ekberg at the Blekinge Institute Of Technology
        Contact: Filip@SmartIT.se

*** */

#include <iregdef.h>
#include <idtcpu.h>
        .text
        .globl  Scheduler
/* *************************************************************************
        Operative System Scheduler
                This instruction set will handle the Operative System Processor Threads
                The main point is that all processes can run until they are finished!

************************************************************************** */
.data
AmountOfProcesses:      .word 0
ProcessesInQue:         .word 0
ActiveProcess:          .word 0        // Have the adress for the Active Process here
NextProcessInQue:       .word 0       // The next adress for the upcomming Process

LNK = 0
PID = LNK + 4
TIMESLICE = PID + 4
PRIORITY = TIMESLICE + 4
SLEEP = PRIORITY + 4
REGISTERY = SLEEP + 4
PC = REGISTERY + 160
SIZE = PC + 4

ADDR=0
PCB_ADDR=ADDR + 4

Blocked:	.space 10 * 8
Ready:		.space 10 * 8

Process: PCB:   .word PCS
PCS:            .space  SIZE * 10

.text

TraverseReady:
			// Look if PCB_ADDR is null, then jump back to scheduler or whatever
			j TraverseReady

Scheduler:
			
			j Scheduler

CreateNewProcess:	// -- START PROCESS CREATION -- //
			la t7, Process
			lw t0, 0(t7)

			add t1, SIZE, t0
			sw t1, 0(t7)		

			sw a0, PID(t0)
			sw a1, PRIORITY(t0)
			sw a2, SLEEP(t0)
			sw a3, PC(t0)

			move v0, t0
			
			// Save Process to external Memmory, t0 might be used elsewhere
			// -- END OF PROCESS CREATINON -- //
			
			

