#include #include #include #include "dllist.h" #include "kt.h" #include "simulator.h" #include "scheduler.h" Dllist readyq; extern char *Argv[]; struct PCB_struct *Current_pcb; int Idle; void *InitUserProcess(void *arg) { int registers[NumTotalRegs]; int i; struct PCB_struct *pcb; char *fname; char **argv; int *user_argv; argv = (char **)arg; fname = argv[0]; /* * begin initial setup for user state */ bzero(main_memory, MemorySize); if (load_user_program(fname) < 0) { fprintf(stderr,"Can't load program.\n"); exit(1); } /* * allocate a pcb for the first process */ pcb = (struct PCB_struct *)malloc(sizeof(struct PCB_struct)); if(pcb == NULL) { exit(1); } for (i=0; i < NumTotalRegs; i++) pcb->registers[i] = 0; /* set up the program counters and the stack register */ pcb->registers[PCReg] = 0; pcb->registers[NextPCReg] = 4; /* need to back off from top of memory */ /* 12 for stack frame */ pcb->registers[StackReg] = MemorySize - 12; /* * use zero as mem_base in first lab */ // InitUserArgs(registers,argv,0); user_argv = MoveArgsToStack(pcb->registers,argv,0); InitCRuntime(user_argv,pcb->registers,argv,0); /* end user setup */ /* * put it at the end of the readyq */ dll_append(readyq,new_jval_v((void *)pcb)); kt_exit(NULL); return(NULL); } void ScheduleProcess() { printf("scheduler called\n"); // scheduler code goes here return; } void SysCallReturn(struct PCB_struct *pcb, int return_val) { printf("SysCallReturn called\n"); // syscallreturn code goes here kt_exit(NULL); }