60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#ifdef CHANGED
|
|
#include "copyright.h"
|
|
#include "system.h"
|
|
#include "userthread.h"
|
|
#include "syscall.h"
|
|
#include "addrspace.h"
|
|
|
|
|
|
static void StartUserThread( void * args ){
|
|
|
|
DEBUG('x', "Enter StartUserThread function\n");
|
|
// retrieve function and arguments
|
|
// create a ThreadArgs_t struct and cast args content into it
|
|
// because we only have a void in our function definition
|
|
ThreadArgs_t * cpy_args;
|
|
cpy_args = (ThreadArgs_t *) args;
|
|
int stack_addr = currentThread->space->AllocateUserStack();
|
|
|
|
// init register
|
|
for (int i = 0; i < NumTotalRegs; i++ ) {
|
|
machine->WriteRegister(i, 0);
|
|
}
|
|
|
|
// init Program counter and Next Program Counter registers
|
|
machine->WriteRegister(PCReg, cpy_args->f);
|
|
machine->WriteRegister (NextPCReg, machine->ReadRegister(PCReg) + 4);
|
|
DEBUG('x',"PCReg: 0x%x, NextPCReg: 0x%x\n", cpy_args->f, cpy_args->f + 4);
|
|
|
|
// init register 4: arguments
|
|
machine->WriteRegister(4, cpy_args->arg);
|
|
DEBUG('x',"Register 4: 0x%x\n", cpy_args->arg);
|
|
|
|
// init stack
|
|
machine->WriteRegister(StackReg, stack_addr);
|
|
DEBUG('x',"StackRegister: 0x%x\n", stack_addr);
|
|
|
|
// run our thread
|
|
machine->Run();
|
|
}
|
|
|
|
int do_ThreadCreate(int f, int arg){
|
|
|
|
DEBUG('x',"Enter do_ThreadCreate function\n");
|
|
|
|
// Initialize our structure we'll pass to StartUserThread
|
|
ThreadArgs_t * args = (ThreadArgs_t *) malloc(sizeof(ThreadArgs_t));
|
|
args->f = f;
|
|
args->arg = arg;
|
|
|
|
// create a new Thread and start it
|
|
Thread * newThread = new Thread("new thread");
|
|
newThread->space = currentThread->space;
|
|
newThread->Start(StartUserThread, args);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void do_ThreadExit(){
|
|
}
|
|
#endif
|