diff --git a/src/bin/init/main.c b/src/bin/init/main.c index e6a74ed..06c0eb3 100755 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -42,12 +42,10 @@ exit(1); } printf("Initializing system.\n"); - if (!fork()) { - printf("Child\n"); - //exec("shell"); + if (!fork()) { + exec("shell"); + printf("Error Starting Shell\n"); while(1); } - printf("Parent\n"); - while(1); exit(1); } \ No newline at end of file diff --git a/src/bin/shell/main.c b/src/bin/shell/main.c index 7a4e3cb..0e3ab9a 100755 --- a/src/bin/shell/main.c +++ b/src/bin/shell/main.c @@ -33,7 +33,10 @@ int count=0,ch=0; while (1) { ch = fgetc(stdin); - if(ch == 10) break; + if(ch == 10) { + printf("\n"); + break; + } else if(ch == 8 && count > 0) count-=2; else if(ch == 0) count--; else buffer[count] = ch; @@ -48,18 +51,19 @@ int cPid = 0; tmp = &buffer; while (1) { - printf("\nUbixOS: "); + printf("UbixOS: "); gets(&buffer); if (0 == memcmp(buffer, "uname", 5)) - printf("\nUbixOS v0.01a " __DATE__" " __TIME__ " \n"); + printf("UbixOS v0.01a " __DATE__" " __TIME__ " \n"); if (memcmp(buffer,"exec", 4) == 0) { tmp += 5; + if (!fork()) { exec(tmp); } cPid = fork(); if (!cPid) { - exec(tmp); + exec(tmp); } else { - while (pidStatus(cPid)); + while (pidStatus(cPid)); } } } diff --git a/src/bin/test/main.c b/src/bin/test/main.c index 440c833..014b381 100755 --- a/src/bin/test/main.c +++ b/src/bin/test/main.c @@ -31,8 +31,10 @@ int main() { int i = 0; + printf("This Is A Test Program\n"); for (i=0;i<10;i++) { - printf("A"); + printf("%i",i); } + printf("\nTest Complete\n"); exit(1); } diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index f60f6a0..f4dd6b0 100755 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -81,6 +81,8 @@ for (i=0;feof(fd) == 0;i++) { binarySpace[i] = fgetc(fd); } + //Close The File + fclose(fd); //Set programHeader To Point To Loaded Binary So We Can Gather Info programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); //Loop Through The Header And Load Sections Which Need To Be Loaded diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index 717b542..221dbe9 100755 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -74,43 +74,72 @@ void sysExit() { int *status; asm("":"=b" (status)); - freeProcesspages(_current->id); +// freeProcesspages(_current->id); _current->status = EMPTY; schedule(); } + void sysExec() { - int fd=0,i=0,x=0; + int fd = 0,i = 0,x = 0; + uLong eStart = 0; char *binarySpace = (char *)0x7C0000; char *newLoc; char *file; + struct fileDescriptor *tmpFd = 0x0; elfHeader *binaryHeader = (elfHeader *)0x7C0000; elfProgramheader *programHeader; asm("":"=b"(file)); asm("sti"); fd = (int)fopen(file,1); + //Loop Through The File List To Get Information About This File Descriptor + for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { + if (tmpFd->id == fd) { + break; + } + } + //If We Dont Find the File Return + if (!tmpFd) { + return; + } + //Now We Must Allocate Memory To Load The Binary Into + for (i=0;i<((tmpFd->size+4095)/4096);i++) { + remapPage(findFreePage(_current->id),(0x7C0000 + (0x1000 * i))); + } + //Load The Binary Into Memory Byte For Byte I Should Find A Faster Way for (i=0;feof(fd) == 0;i++) { binarySpace[i] = fgetc(fd); } + //Close The File fclose(fd); + //Set programHeader To Point To Loaded Binary So We Can Gather Info programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); - newLoc = (char *)programHeader->phVaddr; -/* for (x=0;x<=i;x++) { - newLoc[x] = binarySpace[x]; - }*/ + //Loop Through The Header And Load Sections Which Need To Be Loaded for (i=0;iePhnum;i++) { newLoc = (char *)programHeader[i].phVaddr; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Corrent + Settings so it helps us in the future + */ + for (x=0;x<=((programHeader[i].phMemsz & 0xFFFFF000)+4095);x+=4096) { + remapPage(findFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + (0x1000 * x))); + } + //Now Copy The Binary To Its Correct Location for (x=0;xeEntry; + //Now That We Relocated The Binary We Can Unmap And Free Old Pages + for (i=0;i<((tmpFd->size+4095)/4096);i++) { + unmapPage((0x7C0000 + (0x1000 * i)),0); + } + //Jump To Start Of New Binary asm( "jmp *%0\n" : - : "g" (binaryHeader->eEntry) + : "g" (eStart) ); }