diff --git a/src/sys/vmm/page_fault.S b/src/sys/vmm/page_fault.S new file mode 100644 index 0000000..b0ab6af --- /dev/null +++ b/src/sys/vmm/page_fault.S @@ -0,0 +1,60 @@ +/***************************************************************************************** + 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$ + +*****************************************************************************************/ + +.globl _vmm_pageFault +.text +.code32 +_vmm_pageFault: + xchgl %eax,(%esp) + movl 4(%esp),%eax + pushl %ecx + pushl %edx + push %ds + push %es + push %fs + push %eax + movl %cr2,%eax + pushl %eax + sti + call vmm_pageFault + addl $0x8,%esp + pop %fs + pop %es + pop %ds + popl %edx + popl %ecx + popl %eax + iret + + +/*** + $Log$ + END + ***/ + diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index e9a048b..561b743 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -33,11 +33,16 @@ #include #include #include +#include #include uInt32 *kernelPageDirectory = 0x0; +static spinLock_t fkpSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t rmpSpinLock = SPIN_LOCK_INITIALIZER; + + /************************************************************************ Function: int vmmPagingInit() @@ -160,6 +165,7 @@ uInt32 *pageDir = 0x0, *pageTable = 0x0; short i = 0x0; + spinLock(&rmpSpinLock); /* * Set Pointer pageDirectory To Point To The Virtual Mapping Of The Page * Directory @@ -207,6 +213,7 @@ "movl %eax,%cr3\n" ); /* Return */ + spinUnlock(&rmpSpinLock); return (source); } @@ -225,6 +232,7 @@ 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 */ @@ -244,6 +252,7 @@ vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096))); vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); } + spinUnlock(&fkpSpinLock); return ((void *)((x * (1024 * 4096)) + (y * 4096))); } } else { @@ -257,12 +266,14 @@ /* 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); } @@ -360,6 +371,9 @@ /*** $Log$ + 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