diff --git a/src/sys/include/sys/idt.h b/src/sys/include/sys/idt.h new file mode 100644 index 0000000..4265a3b --- /dev/null +++ b/src/sys/include/sys/idt.h @@ -0,0 +1,50 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _IDT_H +#define _IDT_H + +#include +#include + +#define EFLAG_TF 0x100 +#define EFLAG_IF 0x200 +#define EFLAG_IOPL3 0x3000 +#define EFLAG_VM 0x20000 + +int idt_init(); +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor); +void setTaskVector(uInt8 interrupt,uInt16 controlMajor,uInt8 selector); + +#endif + +/*** + END + ***/ + diff --git a/src/sys/include/sys/tss.h b/src/sys/include/sys/tss.h index 6bcc794..0b20b5d 100644 --- a/src/sys/include/sys/tss.h +++ b/src/sys/include/sys/tss.h @@ -96,10 +96,8 @@ uInt32 edx; uInt32 ecx; uInt32 eax; - /* uInt32 vector; uInt32 error_code; - */ uInt32 eip; uInt32 cs; uInt32 flags; @@ -111,6 +109,9 @@ /*** $Log$ + Revision 1.1 2004/10/08 21:03:28 reddawg + Ubix32 Shell Completed!!! Time to add features back in one by one... nobody shall touch this tree till I ok it + Revision 1.6 2004/07/27 07:42:29 reddawg *burp* diff --git a/src/sys/include/ubixos/init.h b/src/sys/include/ubixos/init.h index 72e5a9b..b71f14c 100644 --- a/src/sys/include/ubixos/init.h +++ b/src/sys/include/ubixos/init.h @@ -30,6 +30,7 @@ #ifndef _INIT_H #define _INIT_H +#include #include typedef int (*intFunctionPTR)(void); @@ -38,6 +39,7 @@ intFunctionPTR init_tasks[] = { static_constructors, + idt_init, vmm_init, }; diff --git a/src/sys/include/vmm/vmm.h b/src/sys/include/vmm/vmm.h index cc58f87..264c480 100644 --- a/src/sys/include/vmm/vmm.h +++ b/src/sys/include/vmm/vmm.h @@ -35,15 +35,22 @@ #define VMM_PAGECOW 0x00000200 #define VMM_MEMAVAIL 1 #define VMM_MEMNOTAVAIL 2 +#define VMM_SYS_ID -1 #define VMM_ID -3 #define VMM_PARENTPAGEDIRADDR 0x00100000 #define VMM_TABLESBASEADDR 0xBFC00000 #define VMM_PAGELENGTH 0x00000400 #define VMM_PAGESIZE 4096 #define VMM_PAGEENTRIES (VMM_PAGESIZE/4) +#define VMM_MEMORYMAPADDR 0xE6667000 - +#define PAGE_STACK 0x00000400 +#define PAGE_PRESENT 0x00000001 +#define PAGE_WRITE 0x00000002 +#define PAGE_USER 0x00000004 +#define PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE|PAGE_USER) +#define KERNEL_PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE) typedef struct { uInt32 pageAddr; @@ -53,12 +60,20 @@ int cowCounter; } mMap; -void vmm_freeProcessPages(pidType); -int vmm_adjustCowCounter(uInt32,int); -int vmm_freePage(uInt32); -uInt32 vmm_findFreePage(pidType); -int vmm_buildMemoryMap(); -int vmm_init(); +void vmm_pageFault(); +void _vmm_pageFault(); +int vmm_pagingInit(); +int vmm_remapPage(uInt32,uInt32,uInt16,pidType); +void vmm_freeProcessPages(pidType); +int vmm_adjustCowCounter(uInt32,int); +int vmm_freePage(uInt32); +uInt32 vmm_findFreePage(pidType); +int vmm_buildMemoryMap(); +int vmm_init(); + + +extern uInt32 vmm_numPages; +extern mMap *vmm_memoryMap; #endif diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 6d26d75..357f43a 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -79,6 +79,7 @@ int main() { int i = 0x0; + uInt32 *test = 0x0; /* Modify src/sys/include/ubixos/init.h to add a startup routine */ for (i=0x0;i + +#define wsize sizeof(uInt) +#define wmask (wsize - 1) +#define VAL c0 +#define WIDEVAL c + +void *memset(void *dst0, int c0, size_t length) { + size_t t; + uInt c; + uInt8 *dst; + + dst = dst0; + + if (length < 3 * wsize) { + while (length != 0) { + *dst++ = VAL; + --length; + } + return(dst0); + } + + if ((c = (uInt8)c0) != 0) { /* Fill the word. */ + c = (c << 8) | c; /* u_int is 16 bits. */ + c = (c << 16) | c; /* u_int is 32 bits. */ + } + + /* Align destination by filling in bytes. */ + if ((t = (long)dst & wmask) != 0) { + t = wsize - t; + length -= t; + do { + *dst++ = VAL; + } while (--t != 0); + } + + /* Fill words. Length was >= 2*words so we know t >= 1 here. */ + t = length / wsize; + do { + *(u_int *)dst = WIDEVAL; + dst += wsize; + } while (--t != 0); + + /* Mop up trailing bytes, if any. */ + t = length & wmask; + if (t != 0) + do { + *dst++ = VAL; + } while (--t != 0); + return(dst0); + } + + +/*** + END + ***/ + diff --git a/src/sys/sys/Makefile b/src/sys/sys/Makefile index 5bf18d0..37d6099 100644 --- a/src/sys/sys/Makefile +++ b/src/sys/sys/Makefile @@ -7,7 +7,7 @@ include ../Makefile.inc # Objects -OBJS = spinlock.o display.o io.o +OBJS = idt.o spinlock.o display.o io.o all: $(OBJS) diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c new file mode 100644 index 0000000..d52c13a --- /dev/null +++ b/src/sys/sys/idt.c @@ -0,0 +1,123 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +#define FP_TO_LINEAR(seg, off) ((void*) ((((uInt16) (seg)) << 4) + ((uInt16) (off)))) + +static void intNull(); + +static ubixDescriptorTable(ubixIDT, 256) { }; + +static struct { + unsigned short limit __attribute__((packed)); + union descriptorTableUnion *idt __attribute__((packed)); + } loadidt = { + (256 * sizeof(union descriptorTableUnion) - 1), ubixIDT + }; + +/************************************************************************ + +Function: int idtInit() +Description: This function is used to enable our IDT subsystem +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +int idt_init() { + int i = 0x0; + + /* Set up default vector table for all possible 256 interrupts */ + for (i = 0x0; i < 256; i++) { + setVector(intNull, i, dPresent + dInt + dDpl3); + } + + /* Load the IDT into the system */ + asm volatile( + "cli \n" + "lidt (%0) \n" /* Load the IDT */ + "pushfl \n" /* Clear the NT flag */ + "andl $0xffffbfff,(%%esp) \n" + "popfl \n" + "sti \n" + : + : "r" ((char *)&loadidt) + ); + + /* Print out information for the IDT */ + kprintf("idt0 - Address: [0x%X]\n", &ubixIDT); + + /* Return so we know all went well */ + return (0x0); + } + + +/* Sets Up IDT Vector */ +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor) { + unsigned short codesegment = 0x08; + asm volatile ("movw %%cs,%0":"=g" (codesegment)); + + ubixIDT[interrupt].gate.offsetLow = (unsigned short)(((unsigned long)handler) & 0xffff); + ubixIDT[interrupt].gate.selector = codesegment; + ubixIDT[interrupt].gate.access = controlMajor; + ubixIDT[interrupt].gate.offsetHigh = (unsigned short)(((unsigned long)handler) >> 16); +} + +/************************************************************************ + +Function: void setTaskVector(uInt8,uInt16,uInt8); +Description: This Function Sets Up An IDT Task Vector +Notes: + +************************************************************************/ +void +setTaskVector(uInt8 interrupt, uInt16 controlMajor, uInt8 selector) +{ + uInt16 codesegment = 0x08; + asm volatile ("movw %%cs,%0":"=g" (codesegment)); + + ubixIDT[interrupt].gate.offsetLow = 0x0; + ubixIDT[interrupt].gate.selector = selector; + ubixIDT[interrupt].gate.access = controlMajor; + ubixIDT[interrupt].gate.offsetHigh = 0x0; +} + + +/* Null Intterupt Descriptor */ +static void intNull() { + kprintf("Invalid Interrupt\n"); + while (1); + } + +/*** + END + ***/ diff --git a/src/sys/vmm/Makefile b/src/sys/vmm/Makefile index 1b4121b..35c895f 100644 --- a/src/sys/vmm/Makefile +++ b/src/sys/vmm/Makefile @@ -7,7 +7,7 @@ include ../Makefile.inc # Objects -OBJS = vmminit.o memory.o +OBJS = pagefault.o page_fault.o paging.o vmminit.o memory.o all: $(OBJS) diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c index b768fc8..ddc01c5 100644 --- a/src/sys/vmm/memory.c +++ b/src/sys/vmm/memory.c @@ -36,9 +36,10 @@ #include #include -static uInt32 freePages = 0x0; -static uInt32 numPages = 0x0; -mMap *vmm_memoryMap = (mMap *) 0x0; +static uInt32 freePages = 0x0; + +uInt32 vmm_numPages = 0x0; +mMap *vmm_memoryMap = (mMap *) 0x0; static int vmm_countMemory(); @@ -59,32 +60,42 @@ int vmm_buildMemoryMap() { int i = 0x0; int memStart = 0x0; - + + /* Make sure no garbage in global variables */ + freePages = 0x0; + vmm_numPages = 0x0; + + kprintf("NO"); /* Count System Memory */ - numPages = vmm_countMemory(); + vmm_numPages = vmm_countMemory(); + kprintf("MO"); /* Set Memory Map To Point To First Physical Page That We Will Use */ vmm_memoryMap = (mMap *) 0x100000; + kprintf("FO"); /* Initialize Map Make All Pages Not Available */ - for (i = 0x0; i < numPages; i++) { + for (i = 0x0; i < vmm_numPages; i++) { vmm_memoryMap[i].cowCounter = 0x0; vmm_memoryMap[i].status = VMM_MEMNOTAVAIL; vmm_memoryMap[i].pid = VMM_ID; - vmm_memoryMap[i].pageAddr = i * 4096; + vmm_memoryMap[i].pageAddr = i * 0x1000; } + kprintf("HO"); /* Calculate Start Of Free Memory */ memStart = (0x100000 / 0x1000); - memStart += (((sizeof(mMap) * numPages) + (sizeof(mMap) - 1)) / 0x1000); + memStart += (((sizeof(mMap) * vmm_numPages) + (sizeof(mMap) - 1)) / 0x1000); + kprintf("JO"); - for (i = memStart; i < numPages; i++) { + for (i = memStart; i < vmm_numPages; i++) { vmm_memoryMap[i].status = VMM_MEMAVAIL; freePages++; } + kprintf("SO"); /* Print Out Amount Of Memory */ - kprintf("Real Memory: %iKB\n", numPages * 4); + kprintf("Real Memory: %iKB\n", vmm_numPages * 4); kprintf("Available Memory: %iKB\n", freePages * 4); /* Return */ @@ -106,7 +117,7 @@ unsigned short memKb = 0; unsigned char irq1State, irq2State; unsigned long cr0 = 0x0; - + /* * Save The States Of Both IRQ 1 And 2 So We Can Turn Them Off And Restore * Them Later @@ -167,7 +178,7 @@ /* Restore States For Both IRQ 1 And 2 */ outportByte(0x21, irq1State); outportByte(0xA1, irq2State); - + /* Return Amount Of Memory In Pages */ return ((memKb * 1024 * 1024) / 4096); } @@ -186,14 +197,14 @@ int i = 0x0; /* Lets Look For A Free Page */ - if (pid < 0x0) { - //kpanic("Error: invalid PID %i\n",pid); + if (pid < VMM_SYS_ID) { kprintf("Error: invalid PID %i\n",pid); + return(0x0); } spinLock(&vmm_spinLock); - for (i = 0; i <= numPages; i++) { + for (i = 0; i <= vmm_numPages; i++) { /* * If We Found A Free Page Set It To Not Available After That Set Its Own @@ -320,7 +331,7 @@ } /* Loop Through Pages To Find Pages Owned By Process */ - for (i=0;i +#include + +/***************************************************************************************** + Function: void vmm_pageFault() + + Description: Main page fault handler + + Notes: + +*****************************************************************************************/ +void vmm_pageFault() { + kprintf("page fault!\n"); + while (1); + } + +/*** + END + ***/ + diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c new file mode 100644 index 0000000..f679dcf --- /dev/null +++ b/src/sys/vmm/paging.c @@ -0,0 +1,229 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + + /* + This file containers all the paging abstractions + */ + +#include +#include +#include +#include +#include + +static spinLock_t rmpSpinLock = SPIN_LOCK_INITIALIZER; +static uInt32 *kernelPageDirectory = 0x0; + + +/***************************************************************************************** + Function: int vmm_pagingInit(); + + Description: This Function Will Initialize The Operating Systems Paging + Abilities. + + Notes: + 02/20/2004 - Looked Over Code And Have Approved Its Quality + 07/28/3004 - All pages are set for ring-0 only no more user accessable + +*****************************************************************************************/ + +int vmm_pagingInit(){ + uInt32 i = 0x0; + uInt32 *pageTable = 0x0; + + /* Allocate A Page Of Memory For Kernels Page Directory */ + kernelPageDirectory = (uInt32 *) vmm_findFreePage(VMM_SYS_ID); + if (kernelPageDirectory == 0x0) { + kprintf("Error: vmmFindFreePage Failed"); + return (0x1); + } /* end if */ + + /* Clear The Memory To Ensure There Is No Garbage */ + for (i = 0; i < VMM_PAGEENTRIES; i++) { + (uInt32) kernelPageDirectory[i] = (uInt32) 0x0; + } /* end for */ + + /* Allocate a page for the first 4MB of memory */ + if ((pageTable = (uInt32 *) vmm_findFreePage(VMM_SYS_ID)) == 0x0) + kprintf("Error: vmmFindFreePage Failed"); + kernelPageDirectory[0] = (uInt32) ((uInt32) (pageTable) | KERNEL_PAGE_DEFAULT); + + /* Make Sure The Page Table Is Clean */ + memset(pageTable,0x0,0x1000); + + /* + * Map the first 1MB of Memory to the kernel MM space because our kernel starts + * at 0x30000 + * Do not map page at address 0x0 this is reserved for null... + */ + for (i = 0x1; i < (VMM_PAGEENTRIES / 0x4); i++) { + pageTable[i] = (uInt32) ((i * 0x1000) | KERNEL_PAGE_DEFAULT); + } /* end for */ + + /* + * Create page tables for the top 1GB of VM space. This space is set aside + * for kernel space and will be shared with each process + */ + for (i = 768; i < VMM_PAGEENTRIES; i++) { + if ((pageTable = (uInt32 *) vmm_findFreePage(VMM_SYS_ID)) == 0x0) + kprintf("Error: vmmFindFreePage Failed"); + + /* Make Sure The Page Table Is Clean */ + memset(pageTable,0x0,0x1000); + + /* Map In The Page Directory */ + kernelPageDirectory[i] = (uInt32) ((uInt32) (pageTable) | KERNEL_PAGE_DEFAULT); + } /* end for */ + + /* Set Up Memory To Be All The Allocated Page Directories */ + if ((pageTable = (uInt32 *) vmm_findFreePage(VMM_SYS_ID)) == 0x0) + kprintf("Error: vmmFindFreePage Failed"); + + /* Clean Page Table */ + memset(pageTable,0x0,0x1000); + + kernelPageDirectory[767] = ((uInt32) pageTable | KERNEL_PAGE_DEFAULT); + for (i = 0; i < VMM_PAGEENTRIES; i++) { + pageTable[i] = kernelPageDirectory[i]; + } /* end for */ + + /* Also Set Up Page Directory To Be The The First Page In 0xE0400000 */ + pageTable = (uInt32 *) (kernelPageDirectory[0] & 0xFFFFF000); + pageTable[256] = (uInt32) ((uInt32) (kernelPageDirectory) | KERNEL_PAGE_DEFAULT); + + /* Now Lets Turn On Paging With This Initial Page Table */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + "movl %%cr0,%%eax \n" + "orl $0x80010000,%%eax \n" /* Turn on memory protection */ + "movl %%eax,%%cr0 \n" + : + : "d"((uInt32 *) (kernelPageDirectory)) + ); + + /* Remap The Memory List */ + for (i = 0x100000; i <= (0x100000 + (vmm_numPages * sizeof(mMap))); i += 0x1000) { + if ((vmm_remapPage(i, (VMM_MEMORYMAPADDR + (i - 0x100000)),KERNEL_PAGE_DEFAULT,VMM_SYS_ID)) == 0x0) + kprintf("vmmRemapPage failed\n"); + } + /* Set New Address For Memory Map Since Its Relocation */ + vmm_memoryMap = (mMap *) VMM_MEMORYMAPADDR; + + /* Print information on paging */ + kprintf("paging0 - Address: [0x%X], PagingISR Address: [0x%X]\n", kernelPageDirectory, &_vmm_pageFault); + + setVector(_vmm_pageFault, 14, dPresent + dInt + dDpl0); + + /* Return so we know everything went well */ + return (0x0); + } /* END */ + +/***************************************************************************************** + Function: int vmmRemapPage(Physical Source,Virtual Destination) + + Description: This Function Will Remap A Physical Page Into Virtual Space + + Notes: + 07/29/02 - Rewrote This To Work With Our New Paging System + 07/30/02 - Changed Address Of Page Tables And Page Directory + 07/28/04 - If perms == 0x0 set to PAGE_DEFAULT + +*****************************************************************************************/ +int vmm_remapPage(uInt32 source,uInt32 dest,uInt16 perms,pidType pid) { + uInt16 destPageDirectoryIndex = 0x0, destPageTableIndex = 0x0; + uInt32 *pageDir = 0x0, *pageTable = 0x0; + short i = 0x0; + + spinLock(&rmpSpinLock); + + if (perms == 0x0) + perms = KERNEL_PAGE_DEFAULT; + + /* + * Set Pointer pageDirectory To Point To The Virtual Mapping Of The Page + * Directory + */ + pageDir = (uInt32 *) VMM_PARENTPAGEDIRADDR; + /* Check To See If Page Table Exists */ + if (dest == 0x0) + return(0x0); + + /* Get Index Into The Page Directory */ + destPageDirectoryIndex = (dest / 0x400000); + + if ((pageDir[destPageDirectoryIndex] & PAGE_PRESENT) != PAGE_PRESENT) { + /* If Page Table Is Non Existant Then Set It Up */ + /* UBU Why does the page table need to be user writable? */ + pageDir[destPageDirectoryIndex] = (uInt32) vmm_findFreePage(pid) | PAGE_DEFAULT; + + /* Also Add It To Virtual Space So We Can Make Changes Later */ + pageTable = (uInt32 *) (VMM_TABLESBASEADDR + 0x2FF000); + pageTable[destPageDirectoryIndex] = pageDir[destPageDirectoryIndex]; + /* Reload Page Directory */ + asm volatile( + "push %eax \n" + "mov %cr3,%eax \n" + "mov %eax,%cr3 \n" + "pop %eax \n" + ); + pageTable = (uInt32 *) (VMM_TABLESBASEADDR + (0x1000 * destPageDirectoryIndex)); + for (i = 0x0;i < VMM_PAGEENTRIES;i++) + pageTable[i] = 0x0; + } + /* Set Address To Page Table */ + pageTable = (uInt32 *) (VMM_TABLESBASEADDR + (0x1000 * destPageDirectoryIndex)); + + /* Get The Index To The Page Table */ + destPageTableIndex = ((dest - (destPageDirectoryIndex * 0x400000)) / 0x1000); + /* If The Page Is Mapped In Free It Before We Remap */ + if ((pageTable[destPageTableIndex] & PAGE_PRESENT) == PAGE_PRESENT) { + /* Clear The Page First For Security Reasons */ + vmm_freePage(((uInt32) pageTable[destPageTableIndex] & 0xFFFFF000)); + } + /* Set The Source Address In The Destination */ + pageTable[destPageTableIndex] = (uInt32) (source | perms); + //kprintf("[0x%X]",pageTable[destPageTableIndex]); + /* Reload The Page Table; */ + asm volatile( + "push %eax \n" + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + "pop %eax \n" + ); + /* Return */ + spinUnlock(&rmpSpinLock); + return (source); +} + +/*** + END + ***/ + + \ No newline at end of file diff --git a/src/sys/vmm/vmminit.c b/src/sys/vmm/vmminit.c index 3d8e4c9..3b56f6d 100644 --- a/src/sys/vmm/vmminit.c +++ b/src/sys/vmm/vmminit.c @@ -41,11 +41,9 @@ if (vmm_buildMemoryMap() != 0x0) { return (0x1); } - /* if (vmm_pagingInit() != 0x0) { return (0x1); } - */ return (0x0); }