diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index a85c026..77cabd2 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -84,7 +84,7 @@ return(tmpDesc); } if ((emptyKernDesc = (struct memDescriptor *)vmm_getFreeMallocPage(4)) == 0x0) - kpanic("Error: vmmGetFreeKernelPage returned NULL\n"); + kpanic("Error: vmm_getFreeKernelPage returned NULL\n"); /* zero out the memory so we know there is no garbage */ memset(emptyKernDesc,0x0,0x4000); @@ -392,6 +392,9 @@ /*** $Log$ + Revision 1.2 2007/06/29 11:31:47 reddawg + Cleaning + Revision 1.1.1.1 2007/01/17 03:31:54 reddawg UbixOS diff --git a/src/sys/vmm/Makefile b/src/sys/vmm/Makefile index 87a81a5..c02c625 100644 --- a/src/sys/vmm/Makefile +++ b/src/sys/vmm/Makefile @@ -6,7 +6,7 @@ include ../Makefile.inc # Objects -OBJS = page_fault.o pagefault.o setpageattributes.o unmappage.o getphysicaladdr.o getfreepage.o vmm_memory.o paging.o vmm_init.o vmm_virtual.o +OBJS = page_fault.o pagefault.o setpageattributes.o unmappage.o getphysicaladdr.o getfreekernelpage.o vmm_memory.o paging.o vmm_init.o vmm_virtual.o all: $(OBJS) diff --git a/src/sys/vmm/getfreekernelpage.c b/src/sys/vmm/getfreekernelpage.c new file mode 100644 index 0000000..8e98f15 --- /dev/null +++ b/src/sys/vmm/getfreekernelpage.c @@ -0,0 +1,80 @@ +/***************************************************************************************** + Copyright (c) 2002,2009 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 + +static spinLock_t vmmGFPlock = SPIN_LOCK_INITIALIZER; + +/************************************************************************ + +Function: void *vmm_getFreeKernelPage(pidType pid); + +Description: Returns A Free Page Mapped To The VM Space + +Notes: + +02/13/09 - Renamed function to vmm_getFreeKernelPage +07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel + +************************************************************************/ +void *vmm_getFreeKernelPage(pidType pid) { + u_int16 x = 0x0, y = 0x0; + u_int32 *pageTableSrc = 0x0; + + spinLock(&vmmGFPlock); + + /* Lets Search For A Free Page */ + for (x = 768; x < 1024; x++) { + + /* Set Page Table Address */ + pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + for (y = 0x0; y < 1024; y++) { + /* Loop Through The Page Table Find An UnAllocated Page */ + if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { + /* Map A Physical Page To The Virtual Page */ + if ((vmm_remapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT)) == 0x0) + kpanic("vmmRemapPage: vmm_getFreeKernelPage\n"); + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); + /* Return The Address Of The Newly Allocate Page */ + spinUnlock(&vmmGFPlock); + return ((void *)((x * 0x400000) + (y * 0x1000))); + } + } + } + /* If No Free Page Was Found Return NULL */ + spinUnlock(&vmmGFPlock); + return (0x0); +} + +/*** + END + ***/ diff --git a/src/sys/vmm/getfreepage.c b/src/sys/vmm/getfreepage.c deleted file mode 100644 index a6d6115..0000000 --- a/src/sys/vmm/getfreepage.c +++ /dev/null @@ -1,82 +0,0 @@ -/***************************************************************************************** - Copyright (c) 2002 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 - -static spinLock_t vmmGFPlock = SPIN_LOCK_INITIALIZER; - -/************************************************************************ - -Function: void *vmmGetFreeKernelPage(pidType pid); - -Description: Returns A Free Page Mapped To The VM Space - -Notes: - -07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel - -************************************************************************/ -void * -vmmGetFreeKernelPage(pidType pid) -{ - uInt16 x = 0x0, y = 0x0; - uInt32 *pageTableSrc = 0x0; - - spinLock(&vmmGFPlock); - - /* Lets Search For A Free Page */ - for (x = 768; x < 1024; x++) { - - /* Set Page Table Address */ - pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); - for (y = 0x0; y < 1024; y++) { - /* Loop Through The Page Table Find An UnAllocated Page */ - if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { - /* Map A Physical Page To The Virtual Page */ - if ((vmm_remapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT)) == 0x0) - kpanic("vmmRemapPage: vmmGetFreeKernelPage\n"); - /* Clear This Page So No Garbage Is There */ - vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); - /* Return The Address Of The Newly Allocate Page */ - spinUnlock(&vmmGFPlock); - return ((void *)((x * 0x400000) + (y * 0x1000))); - } - } - } - /* If No Free Page Was Found Return NULL */ - spinUnlock(&vmmGFPlock); - return (0x0); -} - -/*** - END - ***/ - diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index e2658f1..47b0f04 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -258,14 +258,14 @@ /************************************************************************ -Function: void *vmmGetFreeKernelPage(pidType pid); +Function: void *vmm_getFreeKernelPage(pidType pid); Description: Returns A Free Page Mapped To The VM Space Notes: 07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel ************************************************************************/ -void *vmmGetFreeKernelPage(pidType pid, uInt16 count) { +void *vmm_getFreeKernelPage(pidType pid, uInt16 count) { int x = 0, y = 0, c = 0; uInt32 *pageTableSrc = 0x0; diff --git a/src/sys/vmm/vmm_virtual.c b/src/sys/vmm/vmm_virtual.c index 1113121..fbea4a9 100644 --- a/src/sys/vmm/vmm_virtual.c +++ b/src/sys/vmm/vmm_virtual.c @@ -374,7 +374,7 @@ /* Set Address Of Parent Page Directory */ parentPageDirectory = (uInt32 *) parentPageDirAddr; /* Allocate A New Page For The New Page Directory */ - if ((newPageDirectory = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + if ((newPageDirectory = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) kpanic("Error: newPageDirectory == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ @@ -399,7 +399,7 @@ /* Set Parent To Propper Page Table */ parentPageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); /* Allocate A New Page Table */ - if ((newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Set Parent And New Pages To COW */ @@ -410,7 +410,7 @@ /* Check To See If Its A Stack Page */ if (((uInt32) parentPageTable[i] & PAGE_STACK) == PAGE_STACK) { /* Alloc A New Page For This Stack Page */ - if ((newStackPage = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + if ((newStackPage = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) kpanic("Error: newStackPage == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Set Pointer To Parents Stack Page */ @@ -455,7 +455,7 @@ * Allocate A New Page For The The First Page Table Where We Will Map The * Lower Region */ - if ((newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Flush The Page From Garbage In Memory */ @@ -497,7 +497,7 @@ /* First Lets Unmap The Previously Allocated Page Table */ vmmUnmapPage((uInt32) newPageTable, 1); /* Allocate A New Page Table */ - if ((newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid,1)) == 0x0) + if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* First Set Our Page Directory To Contain This */ newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT; @@ -548,7 +548,7 @@ /* Set Address Of Parent Page Directory */ parentPageDirectory = (uInt32 *) parentPageDirAddr; /* Allocate A New Page For The New Page Directory */ - newPageDirectory = (uInt32 *) vmmGetFreeKernelPage(pid); + newPageDirectory = (uInt32 *) vmm_getFreeKernelPage(pid); /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory); /* First Set Up A Flushed Page Directory */ @@ -563,7 +563,7 @@ * Allocate A New Page For The The First Page Table Where We Will Map The * Lower Region */ - newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid); + newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid); /* Flush The Page From Garbage In Memory */ for (x = 0; x < pageEntries; x++) { newPageTable[x] = 0x0; @@ -587,7 +587,7 @@ /* First Lets Unmap The Previously Allocated Page Table */ vmmUnmapPage((uInt32) newPageTable, 1); /* Allocate A New Page Table */ - newPageTable = (uInt32 *) vmmGetFreeKernelPage(pid); + newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid); /* First Set Our Page Directory To Contain This */ newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT; /* Now Lets Build The Page Table */