getfreepage.c
vmm/vmm.h
ubixos/kpanic.h
ubixos/spinlock.h
sys/thread.h
ubixos/kpanic.h
ubixos/spinlock.h
ubixos/types.h
sys/_types.h
vmm/paging.h
vmm/vmm.h
sys/sysproto.h
sys/signal.h
src/sys/vmm/getfreepage.c
void * void* vmmGetFreePage (pidType pid) vmmGetFreePage pidType pid KERNEL_PAGE_DEFAULT kpanic spinLock spinUnlock tablesBaseAddress vmm_remapPage vmmClearVirtualPage vmmFindFreePage vmmGFPlock x1000 vmmCreateVirtualSpace
spinLock_t spinLock_t vmmGFPlock vmmGFPlock SPIN_LOCK_INITIALIZER vmmGetFreePage

    /*****************************************************************************************
    Copyright(c)2002TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Id: getfreepage_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<vmm/vmm.h>
    #include<ubixos/kpanic.h>
    #include<ubixos/spinlock.h>

    staticspinLock_tvmmGFPlock=SPIN_LOCK_INITIALIZER;

    /************************************************************************

    Function:void*vmmGetFreePage(pidTypepid);

    Description:ReturnsAFreePageMappedToTheVMSpace

    Notes:

    07/30/02-ThisReturnsAFreePageInTheTop1GBForTheKernel

    ************************************************************************/
    void*
    vmmGetFreePage(pidTypepid)
    {
    uInt16x=0x0,y=0x0;
    uInt32*pageTableSrc=0x0;

    spinLock(&vmmGFPlock);

    /*LetsSearchForAFreePage*/
    for(x=768;x<1024;x++){

    /*SetPageTableAddress*/
    pageTableSrc=(uInt32*)(tablesBaseAddress+(0x1000*x));
    for(y=0x0;y<1024;y++){
    /*LoopThroughThePageTableFindAnUnAllocatedPage*/
    if((uInt32)pageTableSrc[y]==(uInt32)0x0){
    /*MapAPhysicalPageToTheVirtualPage*/
    if((vmm_remapPage(vmmFindFreePage(pid),((x*0x400000)+(y*0x1000)),KERNEL_PAGE_DEFAULT))==0x0)
    kpanic("vmmRemapPage:vmmGetFreePage\n");
    /*ClearThisPageSoNoGarbageIsThere*/
    vmmClearVirtualPage((uInt32)((x*0x400000)+(y*0x1000)));
    /*ReturnTheAddressOfTheNewlyAllocatePage*/
    spinUnlock(&vmmGFPlock);
    return((void*)((x*0x400000)+(y*0x1000)));
    }
    }
    }
    /*IfNoFreePageWasFoundReturnNULL*/
    spinUnlock(&vmmGFPlock);
    return(0x0);
    }

    /***
    END
    ***/