Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed bugs and output. seems to be working well

  • Loading branch information...
commit 75a8fcefbbfe2b1becacb429cb28f575c20811f1 1 parent fb5204c
@mettamara mettamara authored
View
21 test/Makefile
@@ -38,7 +38,7 @@ INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)
all: shell matmult sort halt halt2 cat cp mix_test mix_test1 mix_test2 ncat org\
- test1 ncp ncp2 test2 test3 test3_1 test3_2 test4 test4_1 test4_2
+ test1 ncp ncp2 test2 test3 test3_1 test3_2 test4 test4_1 test4_2 test5 test5_2 test5_1
start.o: start.s ../userprog/syscall.h
$(CPP) $(CPPFLAGS) start.c > strt.s
@@ -177,3 +177,22 @@ test4_2: test4_2.o start.o
$(LD) $(LDFLAGS) start.o test4_2.o -o test4_2.coff
../bin/coff2noff test4_2.coff test4_2
+test5.o: test5.c
+ $(CC) $(CFLAGS) -c test5.c
+test5: test5.o start.o
+ $(LD) $(LDFLAGS) start.o test5.o -o test5.coff
+ ../bin/coff2noff test5.coff test5
+
+test5_1.o: test5_1.c
+ $(CC) $(CFLAGS) -c test5_1.c
+test5_1: test5_1.o start.o
+ $(LD) $(LDFLAGS) start.o test5_1.o -o test5_1.coff
+ ../bin/coff2noff test5_1.coff test5_1
+
+test5_2.o: test5_2.c
+ $(CC) $(CFLAGS) -c test5_2.c
+test5_2: test5_2.o start.o
+ $(LD) $(LDFLAGS) start.o test5_2.o -o test5_2.coff
+ ../bin/coff2noff test5_2.coff test5_2
+
+
View
4 test/test5.c
@@ -6,7 +6,7 @@
void test5_1 () {
Write( "Test5 Fork(): This is test 5 after fork before Exec\n", 52, ConsoleOutput );
- Exec( "test5_1" );
+ Exec( "test/test5_1" );
}
int main()
@@ -17,7 +17,7 @@ int main()
Fork( test5_1);
Yield();
}
- for( i=0 ; i < 2 ; ++i ) Exec( "test5_2" );
+ for( i=0 ; i < 2 ; ++i ) Exec( "test/test5_2" );
Halt(0);
}
View
6 userprog/addrspace.cc
@@ -78,7 +78,7 @@ AddrSpace::AddrSpace(OpenFile *executable){
// to leave room for the stack
numPages = divRoundUp(size, PageSize);
size = numPages * PageSize;
-
+ if (numPages > memMgr->getFreePageCount()) printf("Unable to allocate a page\n");
ASSERT(numPages <= memMgr->getFreePageCount()); // check we're not trying
// to run anything too big --
// at least until we have
@@ -154,7 +154,9 @@ bool AddrSpace::CopyAddrSpace(AddrSpace* spaceDest){
// we need to duplicate all the pages into the new addrSpace
for (int i = 0; i < numPages; i++) {
int pageNum = memMgr->getPage();
- ASSERT( pageNum >= 0 );
+ if (pageNum < 0)
+ printf("Unable to allocate a page\n");
+ ASSERT( pageNum>= 0 );
spaceDest->pageTable[i].virtualPage = i;
spaceDest->pageTable[i].physicalPage = pageNum;
memcpy( machine->mainMemory + ( spaceDest->pageTable[i].physicalPage * PageSize ),
View
3  userprog/addrspace.h
@@ -35,10 +35,11 @@ class AddrSpace {
int ReadFile( int vAddr, OpenFile* file, int size, int fileAddr );
bool CopyAddrSpace(AddrSpace* spaceDest);
PCB* pcb;
+
+ unsigned int numPages; // Number of pages in the virtual
private:
TranslationEntry* pageTable; // Assume linear page table translation
// for now!
- unsigned int numPages; // Number of pages in the virtual
// address space
};
View
21 userprog/exception.cc
@@ -112,7 +112,7 @@ void myExit(int exitStatus){
int pid = currentThread->space->pcb->PID;
procMgr->setExitStatus( currentThread->space->pcb->PID, exitStatus );
- DEBUG('2', "Process %d exits with %d\n", pid , exitStatus); //TODO this is the parent PID #4
+ DEBUG('2', "Process %d exits with %d\n", pid , exitStatus);
delete currentThread->space;
currentThread->Finish();
@@ -124,7 +124,7 @@ void myExec( int vAddr ){
IntStatus oldLevel = interrupt->SetLevel(IntOff);
char* file = getString( vAddr );
OpenFile* executable = fileSystem->Open( file );
-
+
if( executable == NULL ){
DEBUG('t', "Unable to open file %s\n", file );
return;
@@ -133,20 +133,20 @@ void myExec( int vAddr ){
forkedThread = new Thread( "Exec Thread" );
AddrSpace* space = new AddrSpace( executable );
forkedThread->space = space;
- // in test3.c -- exec on test3_1
- // something is going wrong, space is getting the address 0x100
- // after the Yield for some reason!!
+
forkedThread->space->pcb->parentPID = currentThread->space->pcb->PID;
forkedThread->space->pcb->thread = forkedThread;
+ DEBUG('2', "Exec Program: %d loading %s\n", currentThread->space->pcb->PID , file); //TODO is this the right PID?
+
delete file;
delete executable; // close file
+
forkedThread->Fork( execBridge, 0 );
DEBUG('t', "EXEC, initiated by user program. %s myPID: %d parentPID:%d \n",
currentThread->getName(), currentThread->space->pcb->PID,
currentThread->space->pcb->parentPID );
- DEBUG('2', "Exec Program: %d loading %s\n", forkedThread->space->pcb->PID , file); //TODO is this the right PID?
machine->WriteRegister( 2, forkedThread->space->pcb->PID );
currentThread->Yield();
@@ -178,9 +178,11 @@ void myFork( int newPC ){
DEBUG('t', "FORK, initiated by user program %s. pid:%d parentPID:%d \n",
currentThread->getName(), currentThread->space->pcb->PID,
currentThread->space->pcb->parentPID );
+ DEBUG('2', "Process %d Fork: start at address 0x%x with %d pages memory\n", currentThread->space->pcb->PID, newPC, forkedThread->space->numPages);
forkedThread->Fork( forkBridge, newPC );
currentThread->Yield();
DEBUG('t',"returned from fork\n");
+
machine->WriteRegister(2, newPID);
interrupt->SetLevel(oldLevel);
}
@@ -242,12 +244,7 @@ int myRead( int vAddr, int size, OpenFileId fd ){
for( int i = 0; i < size; i++ ){
diskBuffer[i] = getchar();
}
- //Sample trimmed excess end line chars. is this needed?
- //char next = 'a';
- // Get rid of excess characters
- //while ((next != '\n')&&(next != EOF)) {
- // next = getchar();
- // }
+
putMemIntoVAddr( diskBuffer, vAddr, size );
machine->WriteRegister( 2, 1 );
}else{
View
4 userprog/processManager.cc
@@ -119,7 +119,9 @@ SysOpenFile* ProcessManager::createNewSysFile( OpenFile* openFile, char* fileNam
void ProcessManager::closeFile( int fd ){
fsLock[fd]->Acquire();
if(sysOpenFileTable==NULL || sysOpenFileTable[fd]==NULL){
- printf("Null pointer\n");
+ //TODO this is happening still....
+ DEBUG('t',"Null pointer\n");
+
return;
}
sysOpenFileTable[fd]->numUsers--;
Please sign in to comment.
Something went wrong with that request. Please try again.