TD3:II.1 First working version of ForkExec
But need to implement Process exit...
This commit is contained in:
parent
f7eca8c6ac
commit
07853cbcd3
8 changed files with 61 additions and 4 deletions
|
@ -36,7 +36,7 @@
|
||||||
// the disk sector size, for
|
// the disk sector size, for
|
||||||
// simplicity
|
// simplicity
|
||||||
|
|
||||||
#define NumPhysPages 64 // Increase this as necessary!
|
#define NumPhysPages 128 // Increase this as necessary!
|
||||||
#define MemorySize (NumPhysPages * PageSize)
|
#define MemorySize (NumPhysPages * PageSize)
|
||||||
#define TLBSize 4 // if there is a TLB, make it small
|
#define TLBSize 4 // if there is a TLB, make it small
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,15 @@ ThreadExit:
|
||||||
syscall
|
syscall
|
||||||
j $31
|
j $31
|
||||||
.end ThreadExit
|
.end ThreadExit
|
||||||
|
|
||||||
|
|
||||||
|
.globl ForkExec
|
||||||
|
.ent ForkExec
|
||||||
|
ForkExec:
|
||||||
|
addiu $2,$0,SC_ForkExec
|
||||||
|
syscall
|
||||||
|
j $31
|
||||||
|
.end ForkExec
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* dummy function to keep gcc happy */
|
/* dummy function to keep gcc happy */
|
||||||
|
|
Binary file not shown.
|
@ -34,7 +34,7 @@ extern Timer *timer; // the hardware alarm clock
|
||||||
extern Machine *machine; // user program memory and registers
|
extern Machine *machine; // user program memory and registers
|
||||||
|
|
||||||
#ifdef CHANGED
|
#ifdef CHANGED
|
||||||
#define MAX_STRING_SIZE 8
|
#define MAX_STRING_SIZE 64
|
||||||
#include "consoledriver.h"
|
#include "consoledriver.h"
|
||||||
extern ConsoleDriver *consoledriver; // add console driver
|
extern ConsoleDriver *consoledriver; // add console driver
|
||||||
#include "pageprovider.h"
|
#include "pageprovider.h"
|
||||||
|
|
|
@ -226,6 +226,14 @@ ExceptionHandler (ExceptionType which)
|
||||||
do_ThreadExit();
|
do_ThreadExit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SC_ForkExec:
|
||||||
|
{
|
||||||
|
int s = machine->ReadRegister(4);
|
||||||
|
char * command = new char[MAX_STRING_SIZE];
|
||||||
|
int size = copyStringFromMachine(s, command, MAX_STRING_SIZE);
|
||||||
|
do_ForkExec(command);
|
||||||
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#define SC_GetInt 16
|
#define SC_GetInt 16
|
||||||
#define SC_ThreadCreate 17
|
#define SC_ThreadCreate 17
|
||||||
#define SC_ThreadExit 18
|
#define SC_ThreadExit 18
|
||||||
|
#define SC_ForkExec 19
|
||||||
#endif
|
#endif
|
||||||
#ifdef IN_USER_MODE
|
#ifdef IN_USER_MODE
|
||||||
|
|
||||||
|
@ -148,6 +149,7 @@ void PutInt(int n);
|
||||||
void GetInt( int * n);
|
void GetInt( int * n);
|
||||||
int ThreadCreate(void f(void * args), void * args);
|
int ThreadCreate(void f(void * args), void * args);
|
||||||
void ThreadExit(void);
|
void ThreadExit(void);
|
||||||
|
int ForkExec ( const char * s);
|
||||||
|
|
||||||
#endif // CHANGED
|
#endif // CHANGED
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,46 @@ void do_ThreadExit(){
|
||||||
if ( currentThread->space->threads == 0 ){
|
if ( currentThread->space->threads == 0 ){
|
||||||
// No threads remains, desallocate addrspace
|
// No threads remains, desallocate addrspace
|
||||||
delete currentThread->space;
|
delete currentThread->space;
|
||||||
Exit(0);
|
currentThread->space = NULL;
|
||||||
}
|
}
|
||||||
currentThread->Finish();
|
currentThread->Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StartUserProc( void * args ){
|
||||||
|
currentThread->space->InitRegisters();
|
||||||
|
currentThread->space->RestoreState();
|
||||||
|
machine->DumpMem("memory.svg");
|
||||||
|
machine->Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_ForkExec( const char * c){
|
||||||
|
DEBUG('x', "Enter ForkExec\n");
|
||||||
|
AddrSpace * space;
|
||||||
|
Thread * fork;
|
||||||
|
OpenFile * file;
|
||||||
|
|
||||||
|
file = fileSystem->Open(c);
|
||||||
|
|
||||||
|
if (file == NULL) {
|
||||||
|
printf("Unable to open file %s\n", file);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
space = new AddrSpace(file);
|
||||||
|
}catch(const std::bad_alloc& e) {
|
||||||
|
printf("==> BAD ALLOC ERROR: no empty space\n");
|
||||||
|
delete space;
|
||||||
|
ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
fork = new Thread("forkThread");
|
||||||
|
fork->space = space;
|
||||||
|
fork->Start(StartUserProc, NULL);
|
||||||
|
|
||||||
|
delete file;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,4 +11,5 @@ typedef struct {
|
||||||
|
|
||||||
extern int do_ThreadCreate(int f, int arg);
|
extern int do_ThreadCreate(int f, int arg);
|
||||||
extern void do_ThreadExit();
|
extern void do_ThreadExit();
|
||||||
|
extern int do_ForkExec( const char * s);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue