diff --git a/src/sys/mm/Makefile b/src/sys/mm/Makefile deleted file mode 100644 index 602497a..0000000 --- a/src/sys/mm/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# (C) 2002 The UbixOS Project -# $Id$ - -# Include Global 'Source' Options -include ../../Makefile.inc -include ../Makefile.inc - -# Objects -OBJS = page_fault.o pagefault.o vmminit.o getfreevirtualpage.o copyvirtualspace.o setpageattributes.o unmappage.o getphysicaladdr.o getfreepage.o createvirtualspace.o memory.o paging.o - -all: $(OBJS) - -# Compile Types -.cc.o: - $(CXX) ${CFLAGS} $(INCLUDES) -c -o $@ $< -.cc.s: - $(CXX) ${CFLAGS} $(INCLUDES) -S -o $@ $< -.c.o: - $(CC) ${CFLAGS} $(INCLUDES) -c -o $@ $< -.c.s: - $(CC) ${CFLAGS} $(INCLUDES) -S -o $@ $< -.S.o: - $(CC) ${CFLAGS} $(INCLUDES) -c -o $@ $< - -# Clean up the junk -clean: - $(REMOVE) $(OBJS) diff --git a/src/sys/mm/copyvirtualspace.c b/src/sys/mm/copyvirtualspace.c deleted file mode 100644 index c96e196..0000000 --- a/src/sys/mm/copyvirtualspace.c +++ /dev/null @@ -1,123 +0,0 @@ -/***************************************************************************************** - 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 -#include -#include -#include -#include - -void vmmCopyVirtualSpace2(kTask_t *task, kTask_t *new) -{ - mMap *tmp, *tmp2 , *prev; - - tmp = task->FirstPage; - - if(tmp != NULL) - { - tmp2 = (mMap *)kmalloc(sizeof(mMap)); - new->FirstPage = tmp2; - prev = NULL; - } - else - { - new->FirstPage = NULL; - new->LastPage = NULL; - return; - } - if(tmp->Next == NULL) - { - tmp2->Next = NULL; - tmp2->Previous = NULL; - new->LastPage = tmp2; - } - else - { - for(;;) - { - tmp2->Previous = prev; - tmp2->pid = new->id; - tmp2->pageAddr = tmp->pageAddr; - tmp2->status = tmp->status; - prev = tmp2; - tmp2 = (mMap *) kmalloc(sizeof(mMap)); - prev->Next = tmp2; - tmp = tmp->Next; - if(tmp == NULL) - { - kfree(tmp2); - prev->Next = NULL; - new->LastPage = prev; - break; - } - } - } - return; -} - -/*** - $Log$ - Revision 1.10 2005/08/10 06:01:59 fsdfs - cleaned up dependencies. rewrote vmmCopyVirtualSpace. does not compile - CVSn: ---------------------------------------------------------------------- - - Revision 1.9 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.7 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.6 2004/07/26 19:15:49 reddawg - test code, fixes and the like - - Revision 1.5 2004/07/25 06:04:00 reddawg - Last of my fixes for the morning - - Revision 1.4 2004/07/20 22:29:55 reddawg - assert: remade assert - - Revision 1.3 2004/07/19 01:58:12 reddawg - vmmCopyVirtualSpace: cleaned up one full page memory leak we were still using old sysID over pid - - Revision 1.2 2004/06/15 12:35:05 reddawg - Cleaned Up - - Revision 1.1.1.1 2004/04/15 12:06:51 reddawg - UbixOS v1.0 - - Revision 1.14 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ diff --git a/src/sys/mm/createvirtualspace.c b/src/sys/mm/createvirtualspace.c deleted file mode 100644 index 7a6c5c9..0000000 --- a/src/sys/mm/createvirtualspace.c +++ /dev/null @@ -1,146 +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. - - $Log$ - Revision 1.5 2005/08/10 06:01:59 fsdfs - cleaned up dependencies. rewrote vmmCopyVirtualSpace. does not compile - CVSn: ---------------------------------------------------------------------- - - Revision 1.4 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.2 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.1.1.1 2004/04/15 12:06:51 reddawg - UbixOS v1.0 - - Revision 1.8 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - - - $Id$ - -*****************************************************************************************/ - -#include -#include - -/************************************************************************ - -Function: void *vmmCreateVirtualSpace(pid_t); -Description: Creates A Virtual Space For A New Task -Notes: - -07/30/02 - This Is Going To Create A New VM Space However Its Going To - Share The Same Top 1GB Space With The Kernels VM And Lower - 1MB Of VM Space With The Kernel - -07/30/02 - Note This Is Going To Get The Top 1Gig And Lower 1MB Region - From The Currently Loaded Page Directory This Is Safe Because - All VM Spaces Will Share These Regions - -07/30/02 - Note I Realized A Mistake The First Page Table Will Need To Be - A Copy But The Page Tables For The Top 1GB Will Not Reason For - This Is That We Just Share The First 1MB In The First Page Table - So We Will Just Share Physical Pages. - -08/02/02 - Added Passing Of pid_t pid For Better Tracking Of Who Has Which - Set Of Pages - -************************************************************************/ -void * -vmmCreateVirtualSpace(pid_t pid) -{ - void *newPageDirectoryAddress = 0x0; - uInt32 *parentPageDirectory = 0x0, *newPageDirectory = 0x0; - uInt32 *parentPageTable = 0x0, *newPageTable = 0x0; - int x = 0; - - /* Set Address Of Parent Page Directory */ - parentPageDirectory = (uInt32 *) parentPageDirAddr; - /* Allocate A New Page For The New Page Directory */ - newPageDirectory = (uInt32 *) vmmGetFreePage(pid); - /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ - newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory); - /* First Set Up A Flushed Page Directory */ - for (x = 0; x < pageEntries; x++) { - (uInt32) newPageDirectory[x] = (uInt32) 0x0; - } - /* Map The Top 1GB Region Of The VM Space */ - for (x = 768; x < pageEntries; x++) { - newPageDirectory[x] = parentPageDirectory[x]; - } - /* - * Allocate A New Page For The The First Page Table Where We Will Map The - * Lower Region - */ - newPageTable = (uInt32 *) vmmGetFreePage(pid); - /* Flush The Page From Garbage In Memory */ - for (x = 0; x < pageEntries; x++) { - (uInt32) newPageTable[x] = (uInt32) 0x0; - } - /* Map This Into The Page Directory */ - newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); - /* Set Address Of Parents Page Table */ - parentPageTable = (uInt32 *) tablesBaseAddress; - /* Map The First 1MB Worth Of Pages */ - for (x = 0; x < (pageEntries / 4); x++) { - newPageTable[x] = parentPageTable[x]; - } - /* Set Virtual Mapping For Page Directory */ - newPageTable[256] = (vmm_getPhysicalAddr((uInt32) newPageDirectory) | PAGE_DEFAULT); - - /* - * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have - * To Worry About Mapping Them In Later How Ever I'm Concerned This May - * Become A Security Issue - */ - /* First Lets Unmap The Previously Allocated Page Table */ - vmmUnmapPage((uInt32) newPageTable, 1); - /* Allocate A New Page Table */ - newPageTable = (uInt32 *) vmmGetFreePage(pid); - /* First Set Our Page Directory To Contain This */ - newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT; - /* Now Lets Build The Page Table */ - for (x = 0; x < pageEntries; x++) { - newPageTable[x] = newPageDirectory[x]; - } - /* Now We Are Done So Lets Unmap This Page */ - vmmUnmapPage((uInt32) newPageTable, 1); - /* Now We Are Done With The Page Directory So Lets Unmap That Too */ - vmmUnmapPage((uInt32) newPageDirectory, 1); - /* Return Physical Address Of Page Directory */ - return (newPageDirectoryAddress); -} - -/*** - END - ***/ - diff --git a/src/sys/mm/getfreepage.c b/src/sys/mm/getfreepage.c deleted file mode 100644 index c4d301c..0000000 --- a/src/sys/mm/getfreepage.c +++ /dev/null @@ -1,148 +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 -#include -#include -static spinLock_t vmmGFPlock = SPIN_LOCK_INITIALIZER; - -/************************************************************************ - -Function: void *vmmGetFreePage(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 * vmmGetFreePage2(kTask_t *task) -{ - mMap *tmp; - - /* remove the first free entry from the free pages list */ - tmp = vmmFreePages->First; - freePages--; - vmmFreePages->First = vmmFreePages->First->Next; - vmmFreePages->First->Previous = NULL; - - /* add the free entry to the task's pages list */ - usedPages++; - tmp->Next = NULL; - tmp->Previous = task->LastPage; - task->LastPage = tmp; - return tmp; -} - -void * -vmmGetFreePage(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: vmmGetFreePage\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); -} - -/*** - $Log$ - Revision 1.12 2005/08/10 06:01:59 fsdfs - cleaned up dependencies. rewrote vmmCopyVirtualSpace. does not compile - CVSn: ---------------------------------------------------------------------- - - Revision 1.11 2005/08/10 04:58:18 fsdfs - updated mememory management - - Revision 1.10 2005/08/10 04:35:03 fsdfs - updates. gcc is still barking at me for adding new items to the headers. - - Revision 1.9 2005/08/10 04:14:04 fsdfs - reworking memory management and WTF is with all the errors in the headers - it won't let me add anything!? - - Revision 1.8 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.6 2004/09/11 16:57:27 apwillia - Add locking get GetFreePage - - Revision 1.5 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.4 2004/07/28 00:17:05 reddawg - Major: - Disconnected page 0x0 from the system... Unfortunately this broke many things - all of which have been fixed. This was good because nothing deferences NULL - any more. - - Things affected: - malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file - - Revision 1.3 2004/07/24 23:04:44 reddawg - Changes... mark let me know if you fault at pid 185 when you type stress - - Revision 1.2 2004/07/20 22:29:55 reddawg - assert: remade assert - - Revision 1.1.1.1 2004/04/15 12:06:51 reddawg - UbixOS v1.0 - - Revision 1.6 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ diff --git a/src/sys/mm/getfreevirtualpage.c b/src/sys/mm/getfreevirtualpage.c deleted file mode 100644 index 65561b7..0000000 --- a/src/sys/mm/getfreevirtualpage.c +++ /dev/null @@ -1,156 +0,0 @@ -/***************************************************************************************** - 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 -#include - -static spinLock_t fvpSpinLock = SPIN_LOCK_INITIALIZER; - -/************************************************************************ - -Function: void *vmmGetFreeVirtualPage(pidType pid,int count); -Description: Returns A Free Page Mapped To The VM Space -Notes: - -08/11/02 - This Will Return Next Avilable Free Page Of Tasks VM Space - -************************************************************************/ -void * -vmmGetFreeVirtualPage(pidType pid, int count) -{ - int x = 0, y = 0, c = 0; - uInt32 *pageTableSrc = 0x0; - uInt32 *pageDir = 0x0; - - spinLock(&fvpSpinLock); - - pageDir = (uInt32 *) parentPageDirAddr; - - /* Lets Search For A Free Page */ - if (_current->oInfo.vmStart <= 0x100000) - kpanic("Invalid vmStart\n"); - for (x = (_current->oInfo.vmStart / (1024 * 4096)); x < 1024; x++) { - /* Set Page Table Address */ - if ((pageDir[x] & PAGE_PRESENT) != PAGE_PRESENT) { - /* If Page Table Is Non Existant Then Set It Up */ - pageDir[x] = (uInt32) vmmFindFreePage(_current->id) | PAGE_DEFAULT; - /* Also Add It To Virtual Space So We Can Make Changes Later */ - pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * 767)); - pageTableSrc[x] = pageDir[x]; - y = 1; - /* Reload Page Directory */ - asm( - "movl %cr3,%eax\n" - "movl %eax,%cr3\n" - ); - } - pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); - if (y != 0x0) { - for (y = 0x0;y 0x1) { - for (c = 0; c < count; c++) { - if (y + c < 1024) { - if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { - c = -1; - break; - } - } - } - if (c != -1) { - for (c = 0; c < count; c++) { - if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),PAGE_DEFAULT)) == 0x0) - kpanic("vmmRemapPage: getFreeVirtualPage-1: [0x%X]\n",((x * (1024 * 4096)) + ((y + c) * 4096))); - vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); - } - spinUnlock(&fvpSpinLock); - return ((void *)((x * (1024 * 4096)) + (y * 4096))); - } - } else { - /* Map A Physical Page To The Virtual Page */ - - /* - * remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)) - * ,pid); - */ - if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),PAGE_DEFAULT)) == 0x0) - kpanic("vmmRemapPage: getFreeVirtualPage-2\n"); - /* Clear This Page So No Garbage Is There */ - vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); - /* Return The Address Of The Newly Allocate Page */ - spinUnlock(&fvpSpinLock); - return ((void *)((x * (1024 * 4096)) + (y * 4096))); - } - } - } - } - /* If No Free Page Was Found Return NULL */ - spinUnlock(&fvpSpinLock); - return (0x0); -} - -/*** - $Log$ - Revision 1.6 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.4 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.3 2004/07/28 00:17:05 reddawg - Major: - Disconnected page 0x0 from the system... Unfortunately this broke many things - all of which have been fixed. This was good because nothing deferences NULL - any more. - - Things affected: - malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file - - Revision 1.2 2004/07/24 23:21:25 reddawg - ok last of my commits for the night I'm going to bed - - Revision 1.1.1.1 2004/04/15 12:06:51 reddawg - UbixOS v1.0 - - Revision 1.10 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ - diff --git a/src/sys/mm/getphysicaladdr.c b/src/sys/mm/getphysicaladdr.c deleted file mode 100644 index d74e11e..0000000 --- a/src/sys/mm/getphysicaladdr.c +++ /dev/null @@ -1,49 +0,0 @@ -/***************************************************************************************** - 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 - -uInt32 vmm_getPhysicalAddr(uInt32 pageAddr) -{ - int pageDirectoryIndex = 0x0, pageTableIndex = 0x0; - uInt32 *pageTable = 0x0; - - /* Calculate The Page Directory Index */ - pageDirectoryIndex = (pageAddr >> 22); - - /* Calculate The Page Table Index */ - pageTableIndex = ((pageAddr >> 12) & 0x3FF); - - /* Set pageTable To The Virtual Address Of Table */ - pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * pageDirectoryIndex)); - - /* Return The Physical Address Of The Page */ - return ((uInt32)(pageTable[pageTableIndex] & 0xFFFFF000)); -} - diff --git a/src/sys/mm/memory.c b/src/sys/mm/memory.c deleted file mode 100644 index 345d44b..0000000 --- a/src/sys/mm/memory.c +++ /dev/null @@ -1,226 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -int numPages = 0; - -void -mmFreeTaskPages(kTask_t *task) -{ - /* just move the list to tail of the free page list */ - if(task->FirstPage != NULL) - { - vmmFreePages->Last->Next = task->FirstPage; - task->FirstPage->Previous = vmmFreePages->Last; - vmmFreePages->Last = task->LastPage; - /* TODO: zero out the memory last used */ - kprintf("mmFreeTaskPages: Memory has been wiped\n"); - } - else - kprintf("mmFreeTaskPages: Nothing to free!\n"); -} - -void -mmFreeVirtualPage(kTask_t *task, uInt32 memAddr) -{ - mMap *tmp; - - for(tmp = task->FirstPage ; tmp != NULL ; tmp = tmp->Next) - { - if(tmp->pageAddr == memAddr) - { - /* remove the page from the task's used list */ - if(tmp == task->FirstPage) - { - task->FirstPage = task->FirstPage->Next; - } - else - { - tmp->Previous->Next = tmp->Next; - tmp->Next->Previous = tmp->Previous; - tmp->Next = NULL; - tmp->Previous = NULL; - } - - /* add the page to the end free pages list */ - vmmFreePages->Last->Next = tmp; - tmp->Previous = vmmFreePages->Last; - vmmFreePages->Last = tmp; - kprintf("vmmFreeVirtualPage: %d has been freed\n", memAddr); - return; - } - } - kpanic("vmmFreeVirtualPage: attempted to free non-existant page\n"); - return; -} - -void * -mmGetFreeVirtualPage(kTask_t *task) -{ - mMap *tmp; - - if(vmmFreePages == NULL) - { - kprintf("Out of memory\n"); - return NULL; - } - - /* remove the first page from the list and return it */ - tmp = vmmFreePages->First; - vmmFreePages->First = vmmFreePages->First->Next; - vmmFreePages->First->Previous = NULL; - return tmp; -} - -int -mmMemMapInit() -{ - uInt32 memStart, z; - mMap *tmpMap; - - /* Count System Memory */ - numPages = countMemory(); - - /* calculate the start of memory */ - memStart = 0x101; - memStart += (((sizeof(mMap) * numPages) + (sizeof(mMap) - 1)) / 0x1000); - - /* initialize free pages */ - for(z = memStart ; z < numPages; z++) - { - if(vmmFreePages == NULL) - { - //UBU: replace this with static location - vmmFreePages = kmalloc(sizeof(mMap)); - vmmFreePages->First = vmmFreePages; - vmmFreePages->Last = vmmFreePages; - vmmFreePages->Next = NULL; - vmmFreePages->Previous = NULL; - vmmFreePages->pid = vmmID; - vmmFreePages->pageAddr = z * 4096; - vmmFreePages->status = memAvail; - } - else - { - //UBU: replace this with static location - tmpMap = kmalloc(sizeof(mMap)); - vmmFreePages->Last->Next = tmpMap; - tmpMap->Previous = vmmFreePages->Last; - vmmFreePages->Last = tmpMap; - tmpMap->pid = vmmID; - tmpMap->pageAddr = z * 4096; - tmpMap->status = memAvail; - } - } - - /* initialize used pages (kernel space) */ - for(z = 0 ; z < memStart; z++) - { - if(vmmUsedPages == NULL) - { - vmmUsedPages = kmalloc(sizeof(mMap)); - vmmUsedPages->First = vmmUsedPages; - vmmUsedPages->Last = vmmUsedPages; - vmmUsedPages->Next = NULL; - vmmUsedPages->Previous = NULL; - vmmUsedPages->pid = vmmID; - vmmUsedPages->pageAddr = z * 4096; - vmmUsedPages->status = memNotavail; - } - else - { - tmpMap = kmalloc(sizeof(mMap)); - vmmUsedPages->Last->Next = tmpMap; - tmpMap->Previous = vmmUsedPages->Last; - vmmUsedPages->Last = tmpMap; - tmpMap->pid = vmmID; - tmpMap->pageAddr = z * 4096; - tmpMap->status = memNotavail; - } - } - - /* Print Out Memory Information */ - kprintf("Real Memory: %iMB\n", ((numPages * 4096) / 1024) / 1024 ); - kprintf("Available Memory: %iMB\n", ((freePages * 4096) / 1024) / 1024 ); - kprintf("Used Memory: %iMB\n", ((usedPages * 4096) / 1024) / 1024 ); - - /* Return */ - return (0); -} - -int countMemory() { - register uInt32 *mem = 0x0; - unsigned long memCount = -1, tempMemory = 0x0; - 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 - */ - irq1State = inportByte(0x21); - irq2State = inportByte(0xA1); - - /* Turn Off IRQ 1 And 2 To Prevent Chances Of Faults While Examining Memory */ - outportByte(0x21, 0xFF); - outportByte(0xA1, 0xFF); - - /* Save The State Of Register CR0 */ - asm volatile ( - "movl %%cr0, %%ebx\n" - : "=a" (cr0) - : - : "ebx" - ); - - asm volatile ("wbinvd"); - asm volatile ( - "movl %%ebx, %%cr0\n" - : - : "a" (cr0 | 0x00000001 | 0x40000000 | 0x20000000) - : "ebx" - ); - - while (memKb < 4096 && memCount != 0) { - memKb++; - if (memCount == -1) - memCount = 0; - memCount += 1024 * 1024; - mem = (uInt32 *)memCount; - tempMemory = *mem; - *mem = 0x55AA55AA; - asm("": : :"memory"); - if (*mem != 0x55AA55AA) { - memCount = 0; - } - else { - *mem = 0xAA55AA55; - asm("": : :"memory"); - if (*mem != 0xAA55AA55) { - memCount = 0; - } - } - asm("": : :"memory"); - *mem = tempMemory; - } - - asm volatile ( - "movl %%ebx, %%cr0\n" - : - : "a" (cr0) - : "ebx" - ); - - /* 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); - } diff --git a/src/sys/mm/page_fault.S b/src/sys/mm/page_fault.S deleted file mode 100644 index ebdaf51..0000000 --- a/src/sys/mm/page_fault.S +++ /dev/null @@ -1,77 +0,0 @@ -/***************************************************************************************** - 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$ - -*****************************************************************************************/ - -/* - Page fault wrapper this will aquire some values we need for later use - */ - -.globl _vmm_pageFault -.text -.code32 -_vmm_pageFault: - xchgl %eax,(%esp) /* Save EAX */ - movl 4(%esp),%eax /* Move EIP into EAX to use later */ - pushl %ebx /* Save EBX */ - movl 20(%esp),%ebx /* Save ESP for ring 3 to use later */ - pushl %ecx /* Save ECX,EDX */ - pushl %edx - push %ebx /* Push ESP */ - push %eax /* Push EIP */ - movl %cr2,%eax /* Push the faulted address */ - pushl %eax - sti /* Turn interrupts back on we are now entrant safe */ - call vmm_pageFault /* Call our page fault handler */ - addl $0xC,%esp /* Adjust the stack to compensate for pushed values */ - popl %edx /* Restore EAX,EBX,ECX,EDX */ - popl %ecx - popl %ebx - popl %eax - iret /* Return from the interrupt */ - - -/*** - $Log$ - Revision 1.6 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.4 2004/08/14 11:23:03 reddawg - Changes - - Revision 1.3 2004/07/28 22:23:02 reddawg - make sure it still works before I goto bed - - Revision 1.2 2004/07/26 19:15:49 reddawg - test code, fixes and the like - - Revision 1.1 2004/07/24 23:13:21 reddawg - Oh yeah try this one - - END - ***/ - diff --git a/src/sys/mm/pagefault.c b/src/sys/mm/pagefault.c deleted file mode 100644 index 39a3dc2..0000000 --- a/src/sys/mm/pagefault.c +++ /dev/null @@ -1,223 +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 -#include -#include -#include -#include -static spinLock_t pageFaultSpinLock = SPIN_LOCK_INITIALIZER; - -/***************************************************************************************** - - Function: void vmm_pageFault(uInt32 memAddr,uInt32 eip,uInt32 esp); - Description: This is the page fault handler, it will handle COW and trap all other - exceptions and segfault the thread. - - Notes: - -07/30/02 - Fixed COW However I Need To Think Of A Way To Impliment - A Paging System Also Start To Add Security Levels - -07/27/04 - Added spin locking to ensure that we are thread safe. I know that spining a - cpu is a waste of resources but for now it prevents errors. - -*****************************************************************************************/ -void LoadPageIntoMemory(mMap *page); - -void vmm_pageFault2(uInt32 memAddr, uInt32 eip, uInt32 esp) -{ - kTask_t *tmp = _current; - mMap *m = tmp->FirstPage; - - for( ; m != NULL ; m = m->Next) - { - if(m->pageAddr == memAddr) - { - LoadPageIntoMemory(m); - return; - } - } - kpanic("pagefault: Requested a page which does not exist\n"); - -} - -void LoadPageIntoMemory(mMap *page) -{ - return; -} - -void vmm_pageFault(uInt32 memAddr,uInt32 eip,uInt32 esp) { - uInt32 i = 0x0, pageTableIndex = 0x0,pageDirectoryIndex = 0x0; - uInt32 *pageDir = 0x0,*pageTable = 0x0; - uInt32 *src = 0x0,*dst = 0x0; - - /* Try to aquire lock otherwise spin till we do */ - spinLock(&pageFaultSpinLock); - - /* Set page dir pointer to the address of the visable page directory */ - pageDir = (uInt32 *)parentPageDirAddr; - - /* UBU - This is a temp panic for 0x0 read write later on I will handle this differently */ - if (memAddr == 0x0) { - kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X]\n",memAddr,esp,_current->id,eip); - kpanic("Error We Wrote To 0x0\n"); - } - - /* Calculate The Page Directory Index */ - pageDirectoryIndex = (memAddr >> 22); - - /* Calculate The Page Table Index */ - pageTableIndex = ((memAddr >> 12) & 0x3FF); - - /* UBU - This is a temporary routine for handling access to a page of a non existant page table */ - if (pageDir[pageDirectoryIndex] == 0x0) { - kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X], Not A Valid Page Table\n",memAddr,esp,_current->id,eip); - spinUnlock(&pageFaultSpinLock); - endTask(_current->id); - } - else { - /* Set pageTable To Point To Virtual Address Of Page Table */ - pageTable = (uInt32 *)(tablesBaseAddress + (0x1000 * pageDirectoryIndex)); - - /* Test if this is a COW on page */ - if (((uInt32)pageTable[pageTableIndex] & pageCow) == pageCow) { - /* Set Src To Base Address Of Page To Copy */ - src = (uInt32 *)(memAddr & 0xFFFFF000); - /* Allocate A Free Page For Destination */ - dst = (uInt32 *) vmmGetFreeVirtualPage(_current->id,1); - /* Copy Memory */ - for (i=0;iid,eip); - spinUnlock(&pageFaultSpinLock); - endTask(_current->id); - } - else { - spinUnlock(&pageFaultSpinLock); - /* Need To Create A Routine For Attempting To Access Non Mapped Memory */ - kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X] Non Mapped\n",memAddr,esp,_current->id,eip); - spinUnlock(&pageFaultSpinLock); - endTask(_current->id); - } - } - asm volatile( - "movl %cr3,%eax\n" - "movl %eax,%cr3\n" - ); - - /* Release the spin lock */ - spinUnlock(&pageFaultSpinLock); - return; - } - -/*** - $Log$ - Revision 1.20 2005/08/10 07:07:03 fsdfs - vmm_pageFault2() implemented - - Revision 1.19 2005/08/10 06:01:59 fsdfs - cleaned up dependencies. rewrote vmmCopyVirtualSpace. does not compile - CVSn: ---------------------------------------------------------------------- - - Revision 1.18 2005/08/10 04:58:18 fsdfs - updated mememory management - - Revision 1.17 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.14 2004/08/25 22:02:41 reddawg - task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly - - Revision 1.13 2004/08/24 05:24:37 reddawg - TCA Is A BONER!!!! - - Revision 1.12 2004/08/14 11:23:03 reddawg - Changes - - Revision 1.11 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.10 2004/07/28 00:22:56 reddawg - bah - - Revision 1.9 2004/07/28 00:17:05 reddawg - Major: - Disconnected page 0x0 from the system... Unfortunately this broke many things - all of which have been fixed. This was good because nothing deferences NULL - any more. - - Things affected: - malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file - - Revision 1.8 2004/07/27 07:09:38 reddawg - Put in a test for 0x0 - - Revision 1.7 2004/07/26 19:15:49 reddawg - test code, fixes and the like - - Revision 1.6 2004/07/24 23:04:44 reddawg - Changes... mark let me know if you fault at pid 185 when you type stress - - Revision 1.5 2004/07/24 20:00:51 reddawg - Lots of changes to the vmm subsystem.... Page faults have been adjust to now be blocking on a per thread basis not system wide. This has resulted in no more deadlocks.. also the addition of per thread locking has removed segfaults as a result of COW in which two tasks fault the same COW page and try to modify it. - - Revision 1.4 2004/07/24 17:47:28 reddawg - vmm_pageFault: deadlock resolved thanks to a propper solution suggested by geist - - Revision 1.3 2004/07/19 02:05:26 reddawg - vmmPageFault: had a potential memory leak here for one page it was still using sysID on certain COW scenarios - - Revision 1.2 2004/06/10 22:23:56 reddawg - Volatiles - - Revision 1.1.1.1 2004/04/15 12:06:52 reddawg - UbixOS v1.0 - - Revision 1.4 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ diff --git a/src/sys/mm/paging.c b/src/sys/mm/paging.c deleted file mode 100644 index 5fda014..0000000 --- a/src/sys/mm/paging.c +++ /dev/null @@ -1,497 +0,0 @@ - /***************************************************************************************** - 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 -#include -#include -#include -#include -#include -#include - -uInt32 *kernelPageDirectory = 0x0; - - -static spinLock_t fkpSpinLock = SPIN_LOCK_INITIALIZER; -static spinLock_t rmpSpinLock = SPIN_LOCK_INITIALIZER; - - -/***************************************************************************************** - 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 *) vmmFindFreePage(sysID); - if (kernelPageDirectory == 0x0) { - kpanic("Error: vmmFindFreePage Failed"); - return (0x1); - } /* end if */ - - /* Clear The Memory To Ensure There Is No Garbage */ - for (i = 0; i < pageEntries; i++) { - (uInt32) kernelPageDirectory[i] = (uInt32) 0x0; - } /* end for */ - - /* Allocate a page for the first 4MB of memory */ - if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) - kpanic("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 < (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 < pageEntries; i++) { - if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) - kpanic("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 *) vmmFindFreePage(sysID)) == 0x0) - kpanic("Error: vmmFindFreePage Failed"); - - /* Clean Page Table */ - memset(pageTable,0x0,0x1000); - - kernelPageDirectory[767] = ((uInt32) pageTable | KERNEL_PAGE_DEFAULT); - for (i = 0; i < 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 = 0x101000; i <= (0x101000 + (numPages * sizeof(mMap))); i += 0x1000) { - if ((vmm_remapPage(i, (vmmMemoryMapAddr + (i - 0x101000)),KERNEL_PAGE_DEFAULT)) == 0x0) - kpanic("vmmRemapPage failed\n"); - } - /* Set New Address For Memory Map Since Its Relocation */ - vmmMemoryMap = (mMap *) vmmMemoryMapAddr; - - /* Print information on paging */ - kprintf("paging0 - Address: [0x%X], PagingISR Address: [0x%X]\n", kernelPageDirectory, &_vmm_pageFault); - - /* 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) -{ - 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 *) 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) vmmFindFreePage(_current->id) | PAGE_DEFAULT; - - /* Also Add It To Virtual Space So We Can Make Changes Later */ - pageTable = (uInt32 *) (tablesBaseAddress + 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 *) (tablesBaseAddress + (0x1000 * destPageDirectoryIndex)); - for (i = 0x0;i < pageEntries;i++) - pageTable[i] = 0x0; - } - /* Set Address To Page Table */ - pageTable = (uInt32 *) (tablesBaseAddress + (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 */ - 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); -} - -/************************************************************************ - -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 count) -{ - int x = 0, y = 0, c = 0; - uInt32 *pageTableSrc = 0x0; - - spinLock(&fkpSpinLock); - /* Lets Search For A Free Page */ - for (x = 768; x < 1024; x++) { - /* Set Page Table Address */ - pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * x)); - for (y = 0; y < 1024; y++) { - /* Loop Through The Page Table Find An UnAllocated Page */ - if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { - if (count > 1) { - for (c = 0; c < count; c++) { - if (y + c < 1024) { - if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { - c = -1; - break; - } - } - } - if (c != -1) { - for (c = 0; c < count; c++) { - if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) - kpanic("vmmRemapPage failed: gfkp-1\n"); - vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); - } - spinUnlock(&fkpSpinLock); - return ((void *)((x * (1024 * 4096)) + (y * 4096))); - } - } else { - /* Map A Physical Page To The Virtual Page */ - - if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) - kpanic("vmmRemapPage failed: gfkp-2\n"); - /* Clear This Page So No Garbage Is There */ - vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); - /* Return The Address Of The Newly Allocate Page */ - spinUnlock(&fkpSpinLock); - return ((void *)((x * (1024 * 4096)) + (y * 4096))); - } - } - } - } - /* If No Free Page Was Found Return NULL */ - spinUnlock(&fkpSpinLock); - return (0x0); -} - - -/************************************************************************ - -Function: void vmmClearVirtualPage(uInt32 pageAddr); - -Description: This Will Null Out A Page Of Memory - -Notes: - -************************************************************************/ -int -vmmClearVirtualPage(uInt32 pageAddr) -{ - uInt32 *src = 0x0; - int counter = 0x0; - - /* Set Source Pointer To Virtual Page Address */ - src = (uInt32 *) pageAddr; - - /* Clear Out The Page */ - for (counter = 0x0; counter < pageEntries; counter++) { - (uInt32) src[counter] = (uInt32) 0x0; - } - - /* Return */ - return (0x0); -} - - -void *vmmMapFromTask(pidType pid,void *ptr,uInt32 size) { - kTask_t *child = 0x0; - uInt32 i = 0x0,x = 0x0,y = 0x0,count = ((size+4095)/0x1000),c = 0x0; - uInt16 dI = 0x0,tI = 0x0; - uInt32 baseAddr = 0x0,offset = 0x0; - uInt32 *childPageDir = (uInt32 *)0x5A00000; - uInt32 *childPageTable = 0x0; - uInt32 *pageTableSrc = 0x0; - offset = (uInt32)ptr & 0xFFF; - baseAddr = (uInt32)ptr & 0xFFFFF000; - child = schedFindTask(pid); - //Calculate The Page Table Index And Page Directory Index - dI = (baseAddr/(1024*4096)); - tI = ((baseAddr-(dI*(1024*4096)))/4096); - vmm_remapPage(child->tss.cr3,0x5A00000,KERNEL_PAGE_DEFAULT); - for (i=0;i<0x1000;i++) { - vmm_remapPage(childPageDir[i],0x5A01000 + (i * 0x1000),KERNEL_PAGE_DEFAULT); - } - for (x=(_current->oInfo.vmStart/(1024*4096));x<1024;x++) { - pageTableSrc = (uInt32 *)(tablesBaseAddress + (4096*x)); - for (y=0;y<1024;y++) { - //Loop Through The Page Table Find An UnAllocated Page - if ((uInt32)pageTableSrc[y] == (uInt32)0x0) { - if (count > 1) { - for (c=0;((c= 0x1000) { - dI++; - tI = 0-c; - } - childPageTable = (uInt32 *)(0x5A01000 + (0x1000 * dI)); - vmm_remapPage(childPageTable[tI+c],((x*(1024*4096))+((y+c)*4096)),KERNEL_PAGE_DEFAULT); - } - vmmUnmapPage(0x5A00000,1); - for (i=0;i<0x1000;i++) { - vmmUnmapPage((0x5A01000 + (i*0x1000)),1); - } - return((void *)((x*(1024*4096))+(y*4096)+offset)); - } - } - else { - //Map A Physical Page To The Virtual Page - childPageTable = (uInt32 *)(0x5A01000 + (0x1000 * dI)); - vmm_remapPage(childPageTable[tI],((x*(1024*4096))+(y*4096)),KERNEL_PAGE_DEFAULT); - //Return The Address Of The Mapped In Memory - vmmUnmapPage(0x5A00000,1); - for (i=0;i<0x1000;i++) { - vmmUnmapPage((0x5A01000 + (i*0x1000)),1); - } - return((void *)((x*(1024*4096))+(y*4096)+offset)); - } - } - } - } - return(0x0); - } - -void *vmm_getFreeMallocPage(uInt16 count) { - uInt16 x = 0x0, y = 0x0; - int c = 0x0; - uInt32 *pageTableSrc = 0x0; - - spinLock(&fkpSpinLock); - /* Lets Search For A Free Page */ - for (x = 960; x < 1024; x++) { - /* Set Page Table Address */ - pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); - for (y = 0; y < 1024; y++) { - /* Loop Through The Page Table Find An UnAllocated Page */ - if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { - if (count > 1) { - for (c = 0; c < count; c++) { - if (y + c < 1024) { - if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { - c = -1; - break; - } - } - } - if (c != -1) { - for (c = 0; c < count; c++) { - vmm_remapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + ((y + c) * 0x1000)),KERNEL_PAGE_DEFAULT); - vmmClearVirtualPage((uInt32) ((x * 0x400000) + ((y + c) * 0x1000))); - } - spinUnlock(&fkpSpinLock); - return ((void *)((x * 0x400000) + (y * 0x1000))); - } - } else { - /* Map A Physical Page To The Virtual Page */ - vmm_remapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT); - /* Clear This Page So No Garbage Is There */ - vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); - /* Return The Address Of The Newly Allocate Page */ - spinUnlock(&fkpSpinLock); - return ((void *)((x * 0x400000) + (y * 0x1000))); - } - } - } - } - /* If No Free Page Was Found Return NULL */ - spinUnlock(&fkpSpinLock); - return (0x0); -} - -/*** - $Log$ - Revision 1.20 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.18 2004/09/07 21:54:38 reddawg - ok reverted back to old scheduling for now.... - - Revision 1.16 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.15 2004/07/28 00:17:05 reddawg - Major: - Disconnected page 0x0 from the system... Unfortunately this broke many things - all of which have been fixed. This was good because nothing deferences NULL - any more. - - Things affected: - malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file - - Revision 1.14 2004/07/27 12:02:01 reddawg - chg: fixed marks bug readFile did a lookup which is why it looked like it was loopping so much - - Revision 1.13 2004/07/27 07:15:21 reddawg - chg: made page 0x0 writeable should boot now - - Revision 1.12 2004/07/27 06:48:26 flameshadow - chg: fixed ubu's typo - - Revision 1.11 2004/07/27 06:47:01 reddawg - Try now TCA - - Revision 1.10 2004/07/26 19:15:49 reddawg - test code, fixes and the like - - Revision 1.9 2004/07/24 23:13:21 reddawg - Oh yeah try this one - - Revision 1.8 2004/07/24 20:00:51 reddawg - Lots of changes to the vmm subsystem.... Page faults have been adjust to now be blocking on a per thread basis not system wide. This has resulted in no more deadlocks.. also the addition of per thread locking has removed segfaults as a result of COW in which two tasks fault the same COW page and try to modify it. - - Revision 1.7 2004/07/22 17:32:25 reddawg - I broke it hopefully - - Revision 1.6 2004/07/19 02:06:35 reddawg - cleaned out some debug code - - Revision 1.5 2004/07/17 15:54:52 reddawg - kmalloc: added assert() - bioscall: fixed some potential problem by not making 16bit code - paging: added assert() - - Revision 1.4 2004/06/10 22:23:56 reddawg - Volatiles - - Revision 1.3 2004/06/10 15:24:35 reddawg - Fixed an asm statement - - Revision 1.2 2004/05/22 21:46:37 reddawg - Fixed some bugs - - Revision 1.1.1.1 2004/04/15 12:06:52 reddawg - UbixOS v1.0 - - Revision 1.30 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ diff --git a/src/sys/mm/setpageattributes.c b/src/sys/mm/setpageattributes.c deleted file mode 100644 index d24e33c..0000000 --- a/src/sys/mm/setpageattributes.c +++ /dev/null @@ -1,100 +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 - -/************************************************************************ - -Function: void vmmSetPageAttributes(uInt32 pageAddr,int attributes; -Description: This Function Will Set The Page Attributes Such As - A Read Only Page, Stack Page, COW Page, ETC. -Notes: - -************************************************************************/ -int vmm_setPageAttributes(uInt32 memAddr,uInt16 attributes) { - uInt16 directoryIndex = 0x0, tableIndex = 0x0; - uInt32 *pageTable = 0x0; - - /* Calculate The Page Directory Index */ - directoryIndex = (memAddr >> 22); - - /* Calculate The Page Table Index */ - tableIndex = ((memAddr >> 12) & 0x3FF); - - /* Set Table Pointer */ - if ((pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * directoryIndex))) == 0x0) - kpanic("Error: pageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); - - /* Set Attribute If Page Is Mapped */ - if (pageTable[tableIndex] != 0x0) - pageTable[tableIndex] = ((pageTable[tableIndex] & 0xFFFFF000) | attributes); - - /* Reload The Page Table; */ - asm volatile( - "push %eax \n" - "movl %cr3,%eax\n" - "movl %eax,%cr3\n" - "pop %eax \n" - ); - /* Return */ - return(0x0); - } - -/*** - $Log$ - Revision 1.7 2005/08/10 06:01:59 fsdfs - cleaned up dependencies. rewrote vmmCopyVirtualSpace. does not compile - CVSn: ---------------------------------------------------------------------- - - Revision 1.6 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.4 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.3 2004/07/20 22:29:55 reddawg - assert: remade assert - - Revision 1.2 2004/06/10 22:23:56 reddawg - Volatiles - - Revision 1.1.1.1 2004/04/15 12:06:53 reddawg - UbixOS v1.0 - - Revision 1.6 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ - diff --git a/src/sys/mm/unmappage.c b/src/sys/mm/unmappage.c deleted file mode 100644 index 26ab655..0000000 --- a/src/sys/mm/unmappage.c +++ /dev/null @@ -1,139 +0,0 @@ -/***************************************************************************************** - 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 - -/************************************************************************ - -Function: void vmmUnmapPage(uInt32 pageAddr,int flags); -Description: This Function Will Unmap A Page From The Kernel VM Space - The Flags Variable Decides If Its To Free The Page Or Not - A Flag Of 0 Will Free It And A Flag Of 1 Will Keep It -Notes: - -07/30/02 - I Have Decided That This Should Free The Physical Page There - Is No Reason To Keep It Marked As Not Available - -07/30/02 - Ok A Found A Reason To Keep It Marked As Available I Admit - Even I Am Not Perfect Ok The Case Where You Wouldn't Want To - Free It Would Be On Something Like Where I Allocated A Page - To Create A New Virtual Space So Now It Has A Flag - -************************************************************************/ -void -vmmUnmapPage(uInt32 pageAddr, int flags) -{ - int pageDirectoryIndex = 0, pageTableIndex = 0; - uInt32 *pageTable = 0x0; - - /* Get The Index To The Page Directory */ - pageDirectoryIndex = (pageAddr >> 22); - - //Calculate The Page Table Index - pageTableIndex = ((pageAddr >> 12) & 0x3FF); - - /* Set pageTable To The Virtual Address Of Table */ - pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * pageDirectoryIndex)); - /* Free The Physical Page If Flags Is 0 */ - if (flags == 0) { - - /* - * This is temp i think its still an issue clearVirtualPage(pageAddr); - * freePage((uInt32)(pageTable[pageTableIndex] & 0xFFFFF000)); - */ - } - /* Unmap The Page */ - pageTable[pageTableIndex] = 0x0; - /* Rehash The Page Directory */ - asm volatile( - "movl %cr3,%eax\n" - "movl %eax,%cr3\n" - ); - /* Return */ - return; -} - - - -/************************************************************************ - -Function: void vmmUnmapPages(uInt32 pageAddr,int flags); -Description: This Function Will Unmap A Page From The Kernel VM Space - The Flags Variable Decides If Its To Free The Page Or Not - A Flag Of 0 Will Free It And A Flag Of 1 Will Keep It -Notes: - -07/30/02 - I Have Decided That This Should Free The Physical Page There - Is No Reason To Keep It Marked As Not Available - -07/30/02 - Ok A Found A Reason To Keep It Marked As Available I Admit - Even I Am Not Perfect Ok The Case Where You Wouldn't Want To - Free It Would Be On Something Like Where I Allocated A Page - To Create A New Virtual Space So Now It Has A Flag - -************************************************************************/ -void vmmUnmapPages(void *ptr,uInt32 size) { - uInt32 baseAddr = (uInt32)ptr & 0xFFFFF000; - uInt32 dI = 0x0,tI = 0x0; - uInt32 y = 0x0; - uInt32 *pageTable = 0x0; - - dI = (baseAddr/(1024*4096)); - tI = ((baseAddr-(dI*(1024*4096)))/4096); - pageTable = (uInt32 *)(tablesBaseAddress + (4096*dI)); - for (y=tI;y<(tI+((size+4095)/4096));y++) { - pageTable[y] = 0x0; - } - return; - } - -/*** - $Log$ - Revision 1.5 2005/08/10 06:01:59 fsdfs - cleaned up dependencies. rewrote vmmCopyVirtualSpace. does not compile - CVSn: ---------------------------------------------------------------------- - - Revision 1.4 2004/07/26 19:15:49 reddawg - test code, fixes and the like - - Revision 1.3 2004/06/15 12:35:05 reddawg - Cleaned Up - - Revision 1.2 2004/06/10 22:23:56 reddawg - Volatiles - - Revision 1.1.1.1 2004/04/15 12:06:53 reddawg - UbixOS v1.0 - - Revision 1.7 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ diff --git a/src/sys/mm/vmminit.c b/src/sys/mm/vmminit.c deleted file mode 100644 index bffbc68..0000000 --- a/src/sys/mm/vmminit.c +++ /dev/null @@ -1,79 +0,0 @@ -/***************************************************************************************** - 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 -/***************************************************************************************** - Function: int vmm_init() - - Description: Initializes the vmm subsystem - - Notes: - -*****************************************************************************************/ -int vmm_init() { - if (vmmMemMapInit() != 0x0) { - return (0x1); - } - if (vmm_pagingInit() != 0x0) { - return (0x1); - } - return (0x0); - } - -/*** - $Log$ - Revision 1.8 2005/08/10 06:01:59 fsdfs - cleaned up dependencies. rewrote vmmCopyVirtualSpace. does not compile - CVSn: ---------------------------------------------------------------------- - - Revision 1.7 2005/08/09 08:45:40 fsdfs - reverting to old vmm. i may have modified something accidently when i wasted time indenting the code. - - Revision 1.4 2004/07/28 15:05:43 reddawg - Major: - Pages now have strict security enforcement. - Many null dereferences have been resolved. - When apps loaded permissions set for pages rw and ro - - Revision 1.3 2004/07/09 12:18:19 reddawg - Updating Initialization Procedures - - Revision 1.2 2004/05/21 14:36:55 reddawg - Cleaned up - - Revision 1.1.1.1 2004/04/15 12:06:53 reddawg - UbixOS v1.0 - - Revision 1.4 2004/04/13 16:36:34 reddawg - Changed our copyright, it is all now under a BSD-Style license - - END - ***/ -