diff --git a/src/bin/init/main.c b/src/bin/init/main.c index d9c6141..e6a74ed 100755 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -43,11 +43,10 @@ } printf("Initializing system.\n"); if (!fork()) { - printf("Child\n"); + printf("Child\n"); //exec("shell"); while(1); } - test[0] = 'c'; printf("Parent\n"); while(1); exit(1); diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index 726b0ae..1bf26b3 100755 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -27,59 +27,63 @@ #include -/* Main Fork Function */ +/************************************************************************ + +Function: void sysFork(); +Description: This Function Forks A Task +Notes: + +08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I + Chose The Best Path To Impliment It I Guess We Will See + What The Future May Bring + +************************************************************************/ void sysFork() { + //Lets Find A New Task kTask_t * newProcess = findTask(); pid_t cPid = newProcess->id; - int i = 0,*ret = 0x0; - uChar *src = 0x0,*dst = 0x0; + //Set Up Pointer to Return Value + int *ret = 0x0; asm("":"=b" (ret)); -// schedule(); - src = (uChar *)&_current->tss; - dst = (uChar *)&newProcess->tss; - for (i=0;iid = cPid; - newProcess->status = EMPTY; + //Set Up New Tasks Information + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = _current->tss.esp0; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x10; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x10; + newProcess->tss.eflags = 0x206; + 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; + //Create A Copy Of The VM Space For New Task newProcess->tss.cr3 = (long)copyVirtualSpace(); - newProcess->tss.eip = &&childStart;// _current->tss.eip; + newProcess->tss.eip = (long)&&childStart; + //Set EBP And ESP To The Correct Locations + asm( + "movl %%esp,%0\n" + "movl %%ebp,%1\n" + : + : "g" (newProcess->tss.esp), "g" (newProcess->tss.ebp) + ); newProcess->status = RUNNING; childStart: - kprintf("Pids: [%i][%i]\n",_current->id,cPid); - if (cPid == 0) { while(1); } if (_current->id == cPid) { + //If We Are The Child We Must Return 0 ret[0] = 0; - return; } else { + //If We Are The Parent We Must Return The Childs PID ret[0] = cPid; - return; } - } - -/* -asm( - ".global sysFork \n" - "sysFork: \n" - " pushl %ss \n" - " pushl %esp \n" - " pushf \n" - " pushl %cs \n" - " pushl %ds \n" - " pushl %es \n" - " pushl %fs \n" - " pushl %edx \n" - " pushl %ecx \n" - " pushl %ebx \n" - " pushl $3 \n" - " pushl %gs \n" - " pushl %esi \n" - " pushl %edi \n" - " pushl %ebp \n" - " pushl $1 \n" - " call testFork \n" - ); -*/ - - + //Return + return; + } \ No newline at end of file