diff --git a/bin/init/main.c b/bin/init/main.c index 63bd3be..2c783eb 100644 --- a/bin/init/main.c +++ b/bin/init/main.c @@ -88,7 +88,6 @@ i = fork(); printf("FORKED: %i!\n", i); -while(1); if (0 == i) { printf("Starting Login Daemon.\n"); diff --git a/sys/i386/fork.c b/sys/i386/fork.c index 6436b4c..ece4534 100644 --- a/sys/i386/fork.c +++ b/sys/i386/fork.c @@ -94,13 +94,12 @@ newProcess->td.vm_dsize = _current->td.vm_dsize; newProcess->td.vm_daddr = _current->td.vm_daddr; - //MrOlsen 2018 kprintf("Copying Mem Space! [0x%X:0x%X:0x%X:0x%X:0x%X:%i:%i]\n", newProcess->tss.esp0, newProcess->tss.esp, newProcess->tss.ebp, td->frame->tf_esi, td->frame->tf_eip, newProcess->id, _current->id); + //kprintf("Copying Mem Space! [0x%X:0x%X:0x%X:0x%X:0x%X:%i:%i]\n", newProcess->tss.esp0, newProcess->tss.esp, newProcess->tss.ebp, td->frame->tf_esi, td->frame->tf_eip, newProcess->id, _current->id); newProcess->tss.cr3 = (uInt32) vmm_copyVirtualSpace(newProcess->id); //kprintf( "Copied Mem Space!\n" ); newProcess->state = FORK; - /* Fix gcc optimization problems */ while (newProcess->state == FORK) sched_yield(); @@ -109,7 +108,6 @@ _current->children++; /* Return Id of Proccess */ - //MrOlsen 2018kprintf("Returning! [%i][0x%X]\n", _current->id, newProcess->tss.cr3); td->td_retval[0] = newProcess->id; return (0); @@ -184,7 +182,8 @@ while (tmpProcPtr->state == FORK) sched_yield(); /* Return Id of Proccess */ - //MrOlsen 2018kprintf("Returning! [%i]", _current->id); + kprintf("Returning! [%i]", _current->id); + return (newProcess->id); } diff --git a/sys/i386/i386_exec.c b/sys/i386/i386_exec.c index 319b780..c6b260d 100644 --- a/sys/i386/i386_exec.c +++ b/sys/i386/i386_exec.c @@ -369,17 +369,19 @@ /* Set Up Stack Space */ //MrOlsen (2016-01-14) FIX: is the stack start supposed to be addressable xhcnage x= 1 to x=0 //x = 0 because GS= stack address not address -1 fix! - for (x = 0; x <= 100; x++) { - vmm_remapPage(vmm_findFreePage(newProcess->id), STACK_ADDR - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK, newProcess->id); - bzero(STACK_ADDR - (x * 0x1000), 0x1000); + for (x = 1; x <= 100; x++) { + vmm_remapPage(vmm_findFreePage(newProcess->id), (STACK_ADDR+1) - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK, newProcess->id); + bzero((STACK_ADDR+1) - (x * 0x1000), 0x1000); } /* Kernel Stack 0x2000 bytes long */ //vmm_remapPage(vmm_findFreePage(newProcess->id), 0x5BC000, KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id); //vmm_remapPage(vmm_findFreePage(newProcess->id), 0x5BB000, KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id); + /* for (x = 0; x < 2; x++) vmm_remapPage(vmm_findFreePage(newProcess->id), 0xFFFFF000 - (PAGE_SIZE * x), KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id); + */ /* Set All The Proper Information For The Task */ newProcess->tss.back_link = 0x0; diff --git a/sys/i386/sched.c b/sys/i386/sched.c index f5a0bae..9da2ca2 100644 --- a/sys/i386/sched.c +++ b/sys/i386/sched.c @@ -44,8 +44,6 @@ #include -#define STACK_ADDR 0xC800000 - static kTask_t *taskList = 0x0; static kTask_t *delList = 0x0; static uint32_t nextID = 1; diff --git a/sys/include/vmm/vmm.h b/sys/include/vmm/vmm.h index ec5084c..83b7d0b 100644 --- a/sys/include/vmm/vmm.h +++ b/sys/include/vmm/vmm.h @@ -36,7 +36,7 @@ extern "C" { #endif -#define STACK_ADDR 0xC800000 // Default App Stack Address +#define STACK_ADDR 0xBFFFFFFF//0xC800000 // Default App Stack Address #define memAvail 1 #define memNotavail 2 diff --git a/sys/init/main.c b/sys/init/main.c index d78e605..d103497 100644 --- a/sys/init/main.c +++ b/sys/init/main.c @@ -86,7 +86,7 @@ ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)), ubixStandardDescriptor(0x6200, (sizeof(struct tssStruct)), (dTss)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl0)), -ubixStandardDescriptor(0xC800000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), +ubixStandardDescriptor(0xBFC00000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), }; struct { diff --git a/sys/init/start.S b/sys/init/start.S index 6f8e4cc..d835596 100644 --- a/sys/init/start.S +++ b/sys/init/start.S @@ -63,12 +63,14 @@ ltr %ax ljmp $0x08,$start_next start_next: - push 8(%edx) + call vmm_init + pushl %esp + mov %esp,%ebp + mov $0xFFFFFFFF,%eax + mov %eax, %esp + pushl $0xDEAD; // Stack + pushl $0xBEEF; // Marker + subl $0xE,%esp; call kmain - .data .comm kStack,0x2000 - -/*** - END - ***/ diff --git a/sys/vmm/copyvirtualspace.c b/sys/vmm/copyvirtualspace.c index d82c13a..9607090 100644 --- a/sys/vmm/copyvirtualspace.c +++ b/sys/vmm/copyvirtualspace.c @@ -82,8 +82,42 @@ /* Map The Kernel Stack Region */ for (x = PD_INDEX(VMM_KERN_STACK_START); x <= PD_INDEX(VMM_KERN_STACK_END); x++) { - if ((parentPageDirectory[x] & PAGE_PRESENT) == PAGE_PRESENT) - newPageDirectory[x] = parentPageDirectory[x] | PAGE_COW; + if ((parentPageDirectory[x] & PAGE_PRESENT) == PAGE_PRESENT) { + /* Set Parent To Propper Page Table */ + parentPageTable = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * x)); + + /* Allocate A New Page Table */ + if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); + + bzero(newPageTable, PAGE_SIZE); + + for (i = 0; i < PT_ENTRIES; i++) { + if ((parentPageTable[i] & PAGE_PRESENT) == PAGE_PRESENT) { + + /* Alloc A New Page For This Stack Page */ + if ((newStackPage = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) + kpanic("Error: newStackPage == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); + + /* Set Pointer To Parents Stack Page */ + parentStackPage = (uint32_t *) (((PAGE_SIZE * PD_ENTRIES) * x) + (PAGE_SIZE * i)); + + /* Copy The Stack Byte For Byte (I Should Find A Faster Way) */ + //kprintf("SP(%i[0x%X]:%i[0x%X]): 0x%X, 0x%X", x, (PAGE_SIZE * PD_ENTRIES) * x, i, i * PAGE_SIZE, newStackPage, parentStackPage); + memcpy(newStackPage, parentStackPage, PAGE_SIZE); + + /* Insert New Stack Into Page Table */ + newPageTable[i] = (vmm_getPhysicalAddr((uint32_t) newStackPage) | PAGE_DEFAULT | PAGE_STACK); + + /* Unmap From Kernel Space */ + vmm_unmapPage((uint32_t) newStackPage, 1); + } + } + /* Put New Page Table Into New Page Directory */ + newPageDirectory[x] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); + /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ + vmm_unmapPage((uint32_t) newPageTable, 1); + } } /* diff --git a/sys/vmm/createvirtualspace.c b/sys/vmm/createvirtualspace.c index a126df2..4469f0d 100644 --- a/sys/vmm/createvirtualspace.c +++ b/sys/vmm/createvirtualspace.c @@ -78,6 +78,22 @@ newPageDirectory[x] = parentPageDirectory[x]; } + /* Allocate Stack Pages */ + newPageTable = (uint32_t *) vmm_getFreePage(pid); + bzero(newPageTable, PAGE_SIZE); + + newPageDirectory[1023] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | KERNEL_PAGE_DEFAULT); + + parentPageTable = (uint32_t *)(PT_BASE_ADDR + (PAGE_SIZE * 1023)); + newPageTable[1023] = parentPageTable[1023] | PAGE_COW; + adjustCowCounter(((uint32_t) parentPageTable[1023] & 0xFFFFF000), 2); + newPageTable[1022] = parentPageTable[1022] | PAGE_COW; + adjustCowCounter(((uint32_t) parentPageTable[1022] & 0xFFFFF000), 2); + + + vmm_unmapPage((uint32_t) newPageTable, 1); + + /* * Allocate A New Page For The The First Page Table Where We Will Map The * Lower Region diff --git a/sys/vmm/paging.c b/sys/vmm/paging.c index 37e0bb0..f3f6863 100644 --- a/sys/vmm/paging.c +++ b/sys/vmm/paging.c @@ -108,6 +108,11 @@ kernelPageDirectory[i] = (uint32_t) ((uint32_t) (pageTable) | KERNEL_PAGE_DEFAULT | PAGE_GLOBAL); } /* end for */ + kernelPageDirectory[1023] = (uint32_t) ((uint32_t) (pageTable) | KERNEL_PAGE_DEFAULT); + pageTable = (uint32_t *) (kernelPageDirectory[1023] & 0xFFFFF000); + pageTable[1023] = (vmm_findFreePage(sysID) | KERNEL_PAGE_DEFAULT | PAGE_STACK); + pageTable[1022] = (vmm_findFreePage(sysID) | KERNEL_PAGE_DEFAULT | PAGE_STACK); + /* * Map Page Tables Into VM Space * The First Page Table (4MB) Maps To All Page Directories @@ -152,10 +157,6 @@ if ((pageTable = (uint32_t *) vmm_findFreePage(sysID)) == 0x0) K_PANIC("ERROR: vmm_findFreePage Failed"); - kernelPageDirectory[1023] = (uint32_t) ((uint32_t) (pageTable) | KERNEL_PAGE_DEFAULT); - pageTable = (uint32_t *) (kernelPageDirectory[PD_INDEX(PD_BASE_ADDR)] & 0xFFFFF000); - pageTable[1023] = (vmm_findFreePage(sysID) | KERNEL_PAGE_DEFAULT | PAGE_STACK); - pageTable[1022] = (vmm_findFreePage(sysID) | KERNEL_PAGE_DEFAULT | PAGE_STACK); /* Now Lets Turn On Paging With This Initial Page Table */ asm volatile( @@ -583,24 +584,21 @@ kprintf("PDE*PS: 0x%X", (PD_ENTRIES * PAGE_SIZE)); for (x = (addr / (PD_ENTRIES * PAGE_SIZE)); x < PD_INDEX(VMM_USER_END); x++) { - kprintf("X: 0x%X", x); + //kprintf("X: 0x%X,0x%X]", x, pageDir[x]); if ((pageDir[x] & PAGE_PRESENT) == PAGE_PRESENT) { - kprintf("X: 0x%X", x); pageTableSrc = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * x)); kprintf("X: 0x%X", x); - kprintf("pTS: 0x%X\n", pageTableSrc); + kprintf("pTS: 0x%X(0x%X)\n", pageTableSrc,pageDir[x]); for (y = 0; y < PAGE_SIZE; y++) { - kprintf("pTS[%x:%i]: 0x%X", x, y, pageTableSrc[y]); if ((pageTableSrc[y] & PAGE_PRESENT) == PAGE_PRESENT) { - + kprintf("pTS[%i:%i]: 0x%X", x, y, pageTableSrc[y]); if ((pageTableSrc[y] & PAGE_COW) == PAGE_COW) { kprintf("[aCC.E: %i(0x%X)]", y, pageTableSrc[y]); adjustCowCounter(((uint32_t) pageTableSrc[y] & 0xFFFFF000), -1); kprintf("[aCC.X: %i(0x%X)]", y, pageTableSrc[y]); pageTableSrc[y] = 0x0; - } else if ((pageTableSrc[y] & PAGE_STACK) == PAGE_STACK) { //TODO: We need to fix this so we can clean the stack! diff --git a/sys/vmm/vmm_init.c b/sys/vmm/vmm_init.c index 80784aa..85fab6b 100644 --- a/sys/vmm/vmm_init.c +++ b/sys/vmm/vmm_init.c @@ -44,13 +44,5 @@ if (vmm_pagingInit() != 0x0) K_PANIC("Couldn't Initialize paging system"); - asm( - "mov $0xFFFFFFFF, %esp\n" - "push $0xDEAD\n" // STACK MARKER - "push $0xBEEF\n"// STACK MARKER - "mov $0x0, %eax\n" - "jmp $0x4(%ebp)\n" - ); - /* NEVER REACHED */ return (0x0); }