getfreepage.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002 The UbixOS Project
00003  All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are
00006 permitted provided that the following conditions are met:
00007 
00008 Redistributions of source code must retain the above copyright notice, this list of
00009 conditions, the following disclaimer and the list of authors.  Redistributions in binary
00010 form must reproduce the above copyright notice, this list of conditions, the following
00011 disclaimer and the list of authors in the documentation and/or other materials provided
00012 with the distribution. Neither the name of the UbixOS Project nor the names of its
00013 contributors may be used to endorse or promote products derived from this software
00014 without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026  $Id: getfreepage_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
00027 
00028 *****************************************************************************************/
00029 
00030 #include <vmm/vmm.h>
00031 #include <ubixos/kpanic.h>
00032 #include <ubixos/spinlock.h>
00033 
00034 static spinLock_t vmmGFPlock = SPIN_LOCK_INITIALIZER;
00035 
00036 /************************************************************************
00037 
00038 Function: void *vmmGetFreePage(pidType pid);
00039 
00040 Description: Returns A Free Page Mapped To The VM Space
00041 
00042 Notes:
00043 
00044 07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel
00045 
00046 ************************************************************************/
00047 void           *
00048 vmmGetFreePage(pidType pid)
00049 {
00050   uInt16             x = 0x0, y = 0x0;
00051   uInt32         *pageTableSrc = 0x0;
00052   
00053   spinLock(&vmmGFPlock);
00054   
00055   /* Lets Search For A Free Page */
00056   for (x = 768; x < 1024; x++) {
00057 
00058     /* Set Page Table Address */
00059     pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x));
00060     for (y = 0x0; y < 1024; y++) {
00061       /* Loop Through The Page Table Find An UnAllocated Page */
00062       if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) {
00063         /* Map A Physical Page To The Virtual Page */
00064         if ((vmm_remapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT)) == 0x0)
00065           kpanic("vmmRemapPage: vmmGetFreePage\n");
00066         /* Clear This Page So No Garbage Is There */
00067         vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000)));
00068         /* Return The Address Of The Newly Allocate Page */
00069         spinUnlock(&vmmGFPlock);
00070         return ((void *)((x * 0x400000) + (y * 0x1000)));
00071       }
00072     }
00073   }
00074   /* If No Free Page Was Found Return NULL */
00075   spinUnlock(&vmmGFPlock);
00076   return (0x0);
00077 }
00078 
00079 /***
00080  END
00081  ***/
00082 

Generated on Fri Dec 15 11:18:55 2006 for UbixOS V2 by  doxygen 1.4.7