diff --git a/src/bin/init/main.c b/src/bin/init/main.c index e6a7246..da11cc2 100755 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -40,6 +40,7 @@ exit(1); } printf("Initializing system.\n"); + while (1); if (!fork()) { exec("shell"); while(1); diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 201bdc8..bee8181 100755 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -89,7 +89,7 @@ initUbixFS(); //Initialize File System execThread(idleThread,0xAFFF,"Idle Thread"); execThread(testThread,0xBfff,"Test Thread"); - //execFile("init"); Needs To Be ReWriten + execFile("init"); enableIrq(0); while (1); } diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 7b999c7..a4f2269 100755 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -24,123 +24,162 @@ #include #include #include -#include #include +#include #include +/************************************************************************ + +Function: void execFile(char *file); +Description: This Function Executes A Kile Into A New VM Space With Out + Having To Fork +Notes: + +07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few + Memory Leaks The Memory Allocated To Load The Binary Into Is + Now Unmapped So It Can Be Used Again And Not Held Onto Until + The Program Exits + +07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up + The Freshly Allocated Pages With The Correct Permissions + +************************************************************************/ void execFile(char *file) { - long *pd,*pdn; - int fd=0,i=0,x=0,eStart=0,pid; + int fd=0,i=0,x=0,eStart=0; char *binarySpace = (char *)0x7C0000; char *newLoc; - kTask_t * newProcess; + struct fileDescriptor *tmpFd = 0x0; elfHeader *binaryHeader = (elfHeader *)0x7C0000; elfProgramheader *programHeader; - newProcess = findTask(); - pid = newProcess->id; -// pdn = (uLong *)allocPage(); - for (i=0;i<1024;i++) { - pdn[i] = 0x0; - } - if ((_current->id >= 0) && (_current->id <= numTasks)) { - pd = (uLong *)_current->tss.cr3; - } - else { - pd = (uLong *)pageDirectory; - } - taskList[pid].tss.cr3 = (uLong)pdn; - pdn[0] = pd[0]; - for (i=768;i<1024;i++) { - pdn[i] = pd[i]; - } - if (pid > 1) { pdn = pageDirectory; } - _current = &taskList[pid]; + //Get A New Task For This Proccess + _current = findTask(); + //Now We Must Create A Virtual Space For This Proccess To Run In + _current->tss.cr3 = (uLong)createVirtualSpace(); + //To Better Load This Application We Will Switch Over To Its VM Space asm( "movl %0,%%eax \n" "movl %%eax,%%cr3 \n" - : : "d" ((uLong *)(pdn)) - ); + : : "d" ((uLong *)(_current->tss.cr3)) + ); + //Lets Find The File fd = fopen(file,1); - for (i=0;i<=(fdTable[fd].size+4095);i+=4096) { -// remapPage(allocPage(),(0x7C0000 + (0x1000 * i))); + //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); } + //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 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(allocPage(),((programHeader[i].phVaddr & 0xFFFFF000) + (0x1000 * x))); + 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); + } + //Now Lets Make A Clean Stack newLoc = (char *)0x5DC000; -// remapPage(allocPage(),0x5DC000); + remapPage(findFreePage(_current->id),0x5DC000); for (i=0;i<4096;i++) { newLoc[i] = 0x0; } i = 0x5DC000+4095; - taskList[pid].tss.back_link = 0x0; - taskList[pid].tss.esp0 = i; - taskList[pid].tss.ss0 = 0x10; - taskList[pid].tss.esp1 = 0x0; - taskList[pid].tss.ss1 = 0x10; - taskList[pid].tss.esp2 = 0x0; - taskList[pid].tss.ss2 = 0x10; - taskList[pid].tss.cr3 = (long)pdn; - taskList[pid].tss.eip = (long)eStart; - taskList[pid].tss.eflags = 0x206; - taskList[pid].tss.esp = i; - taskList[pid].tss.ebp = i; - taskList[pid].tss.esi = 0x0; - taskList[pid].tss.edi = 0x0; - taskList[pid].tss.es = 0x10; - taskList[pid].tss.cs = 0x08; - taskList[pid].tss.ss = 0x10; - taskList[pid].tss.ds = 0x10; - taskList[pid].tss.fs = 0x10; - taskList[pid].tss.gs = 0x10; - taskList[pid].tss.ldt = 0x18; - taskList[pid].tss.trace_bitmap = 0x80000000; - taskList[pid].status = READY; + //Set All The Proper Information For The Task + _current->tss.back_link = 0x0; + _current->tss.esp0 = i; + _current->tss.ss0 = 0x10; + _current->tss.esp1 = 0x0; + _current->tss.ss1 = 0x10; + _current->tss.esp2 = 0x0; + _current->tss.ss2 = 0x10; + _current->tss.eip = (long)eStart; + _current->tss.eflags = 0x206; + _current->tss.esp = i; + _current->tss.ebp = i; + _current->tss.esi = 0x0; + _current->tss.edi = 0x0; + _current->tss.es = 0x10; + _current->tss.cs = 0x08; + _current->tss.ss = 0x10; + _current->tss.ds = 0x10; + _current->tss.fs = 0x10; + _current->tss.gs = 0x10; + _current->tss.ldt = 0x18; + _current->tss.trace_bitmap = 0x80000000; + _current->status = READY; + //Switch Back To The Kernels VM Space asm( "movl %0,%%eax \n" "movl %%eax,%%cr3 \n" - : : "d" ((uLong *)(pd)) + : : "d" ((uLong *)(kernelPageDirectory)) ); + //Finally Return + return; } +/************************************************************************ + +Function: void execThread(void (* tproc)(void),int stack,char *descr); +Description: This Function Executes A New Thread For Kernel And Does + Not Create Its Own VM Space +Notes: + +************************************************************************/ void execThread(void (* tproc)(void),int stack,char *descr) { - int pid = 0; kTask_t * newProcess; + //Find A New Thread newProcess = findTask(); - pid = newProcess->id; - kprintf("Task ID: [%i]\n",pid); - taskList[pid].tss.back_link = 0x0; - taskList[pid].tss.esp0 = stack; - taskList[pid].tss.ss0 = 0x10; - taskList[pid].tss.esp1 = 0x0; - taskList[pid].tss.ss1 = 0x10; - taskList[pid].tss.esp2 = 0x0; - taskList[pid].tss.ss2 = 0x10; - taskList[pid].tss.cr3 = (unsigned int)kernelPageDirectory; - taskList[pid].tss.eip = (unsigned int)tproc; - taskList[pid].tss.eflags = 0x206; - taskList[pid].tss.esp = stack; - taskList[pid].tss.ebp = stack; - taskList[pid].tss.esi = 0x0; - taskList[pid].tss.edi = 0x0; - taskList[pid].tss.es = 0x10; - taskList[pid].tss.cs = 0x08; - taskList[pid].tss.ss = 0x10; - taskList[pid].tss.ds = 0x10; - taskList[pid].tss.fs = 0x10; - taskList[pid].tss.gs = 0x10; - taskList[pid].tss.ldt = 0x18; - taskList[pid].tss.trace_bitmap = 0x80000000; - taskList[pid].status = READY; + //Set All The Correct Thread Attributes + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = stack; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x10; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x10; + newProcess->tss.cr3 = (unsigned int)kernelPageDirectory; + newProcess->tss.eip = (unsigned int)tproc; + newProcess->tss.eflags = 0x206; + newProcess->tss.esp = stack; + newProcess->tss.ebp = stack; + newProcess->tss.esi = 0x0; + newProcess->tss.edi = 0x0; + newProcess->tss.es = 0x10; + newProcess->tss.cs = 0x08; + newProcess->tss.ss = 0x10; + newProcess->tss.ds = 0x10; + newProcess->tss.fs = 0x10; + newProcess->tss.gs = 0x10; + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x80000000; + newProcess->status = READY; + //Return + return; } diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 05a9004..fe89f45 100755 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -68,8 +68,8 @@ pageTable[i] = (uLong)((i*0x1000) | pageDefault); } //Create Page Tables For The Top 1GB Of VM Space This Is To Be Shared With All VM Spaces - for (i=767;iid); + for (i=768;i