diff --git a/src/sys/vmm/getfreekernelpage.c b/src/sys/vmm/getfreekernelpage.c index 8e98f15..037203d 100644 --- a/src/sys/vmm/getfreekernelpage.c +++ b/src/sys/vmm/getfreekernelpage.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002,2009 The UbixOS Project + Copyright (c) 2002, 2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -33,48 +33,81 @@ 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 +06/12/09 - Moved Function From paging.c To Replace This One 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; +void *vmm_getFreeKernelPage(pidType pid, u_int32_t count) { + int x = 0; + int y = 0; + int c = 0; + u_int32_t *pageTableSrc = 0x0; + + #ifdef VMMDEBUG + kprintf("vmm_getFreeKErnelPage"); + #endif 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++) { + pageTableSrc = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (4096 * x)); + + for (y = 0; 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 ((u_int32_t) pageTableSrc[y] == (u_int32_t) 0x0) { + if (count > 1) { + for (c = 0; c < count; c++) { + if (y + c < 1024) { + if ((u_int32_t) pageTableSrc[y + c] != (u_int32_t) 0x0) { + c = -1; + break; + } + } + } + + if (c != -1) { + for (c = 0; c < count; c++) { + if ((vmm_remapPage((u_int32_t) vmm_findFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) + K_PANIC("vmmRemapPage failed: gfkp-1\n"); + vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + ((y + c) * 4096))); + } + + spinUnlock(&vmmGFPlock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + else { + /* Map A Physical Page To The Virtual Page */ + if ((vmm_remapPage((u_int32_t) vmm_findFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) + K_PANIC("vmmRemapPage failed: gfkp-2\n"); + + /* Clear This Page So No Garbage Is There */ + vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))); + /* Return The Address Of The Newly Allocate Page */ + spinUnlock(&vmmGFPlock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } } } - } + /* If No Free Page Was Found Return NULL */ spinUnlock(&vmmGFPlock); return (0x0); -} + } /* end func */ + /*** + $Log$ + END ***/ diff --git a/src/sys/vmm/getphysicaladdr.c b/src/sys/vmm/getphysicaladdr.c index 1c42a54..7ff9337 100644 --- a/src/sys/vmm/getphysicaladdr.c +++ b/src/sys/vmm/getphysicaladdr.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004, 2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -37,22 +37,29 @@ */ -u_int32_t vmm_getPhysicalAddr(uInt32 pageAddr) { - int pageDirectoryIndex = 0x0, pageTableIndex = 0x0; - uInt32 *pageTable = 0x0; +u_int32_t vmm_getPhysicalAddr(u_int32_t pageAddr) { + int pageDirectoryIndex = 0x0; + int pageTableIndex = 0x0; + u_int32_t *pageTable = 0x0; + +#ifdef VMMDEBUG + kprintf("vmm_getPhysicalAddr"); +#endif //Calculate The Page Directory Index - pageDirectoryIndex = (pageAddr >> 22); + pageDirectoryIndex = PDI(pageAddr); //Calculate The Page Table Index - pageTableIndex = ((pageAddr >> 12) & 0x3FF); + pageTableIndex = PTI(pageAddr); /* Set pageTable To The Virtual Address Of Table */ - pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * pageDirectoryIndex)); + pageTable = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * pageDirectoryIndex)); /* Return The Physical Address Of The Page */ - return ((uInt32)(pageTable[pageTableIndex] & 0xFFFFF000)); + return ((u_int32_t)(pageTable[pageTableIndex] & 0xFFFFF000)); } /*** + $Log$ + END ***/ diff --git a/src/sys/vmm/page_fault.S b/src/sys/vmm/page_fault.S index bc6b281..8a1fdf2 100644 --- a/src/sys/vmm/page_fault.S +++ b/src/sys/vmm/page_fault.S @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004,2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -35,24 +35,24 @@ .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 */ + 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 */ + 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 */ + iret /* Return from the interrupt */ /*** diff --git a/src/sys/vmm/pagefault.c b/src/sys/vmm/pagefault.c index 006e468..e7c8cf2 100644 --- a/src/sys/vmm/pagefault.c +++ b/src/sys/vmm/pagefault.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002 The UbixOS Project + Copyright (c) 2002, 2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -37,29 +37,29 @@ /***************************************************************************************** - Function: void vmm_pageFault(uInt32 memAddr,uInt32 eip,uInt32 esp); + Function: void vmm_pageFault(u_int32_t memAddr,u_int32_t eip,u_int32_t 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 + +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 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; +void vmm_pageFault(u_int32_t memAddr,u_int32_t eip,u_int32_t esp) { + u_int32_t i = 0x0, pageTableIndex = 0x0,pageDirectoryIndex = 0x0; + u_int32_t *pageDir = 0x0,*pageTable = 0x0; + u_int32_t *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; + pageDir = (u_int32_t *)PARENT_PAGEDIR_ADDR; /* UBU - This is a temp panic for 0x0 read write later on I will handle this differently */ if (memAddr == 0x0) { @@ -68,10 +68,10 @@ } /* Calculate The Page Directory Index */ - pageDirectoryIndex = (memAddr >> 22); - + pageDirectoryIndex = PDI(memAddr); + /* Calculate The Page Table Index */ - pageTableIndex = ((memAddr >> 12) & 0x3FF); + pageTableIndex = PTI(memAddr); /* UBU - This is a temporary routine for handling access to a page of a non existant page table */ if (pageDir[pageDirectoryIndex] == 0x0) { @@ -81,25 +81,25 @@ } else { /* Set pageTable To Point To Virtual Address Of Page Table */ - pageTable = (uInt32 *)(tablesBaseAddress + (0x1000 * pageDirectoryIndex)); - + pageTable = (u_int32_t *)(PAGE_TABLES_BASE_ADDR + (0x1000 * pageDirectoryIndex)); + /* Test if this is a COW on page */ - if (((uInt32)pageTable[pageTableIndex] & PAGE_COW) == PAGE_COW) { + if (((u_int32_t)pageTable[pageTableIndex] & PAGE_COW) == PAGE_COW) { /* Set Src To Base Address Of Page To Copy */ - src = (uInt32 *)(memAddr & 0xFFFFF000); + src = (u_int32_t *)(memAddr & 0xFFFFF000); /* Allocate A Free Page For Destination */ /* USE vmInfo */ - dst = (uInt32 *) vmmGetFreeVirtualPage(_current->id,1,0x1); + dst = (u_int32_t *) vmmGetFreeVirtualPage(_current->id,1,0x1); /* Copy Memory */ for (i=0;iid); } else if (memAddr < (_current->td.vm_dsize + _current->td.vm_daddr)) { - pageTable[pageTableIndex] = (uInt32)vmmFindFreePage(_current->id) | PAGE_DEFAULT; + pageTable[pageTableIndex] = (u_int32_t)vmm_findFreePage(_current->id) | PAGE_DEFAULT; } 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); - //kprintf("Out Of Stack Space: [0x%X]\n",memAddr & 0xFF0000); + kprintf("Segfault @: 0x%X, ESP: 0x%X, PID: %i, EIP: 0x%X Non Mapped\n",memAddr,esp,_current->id,eip); + spinUnlock(&pageFaultSpinLock); + + /* End this task */ endTask(_current->id); } } @@ -124,14 +127,17 @@ "movl %cr3,%eax\n" "movl %eax,%cr3\n" ); - + /* Release the spin lock */ spinUnlock(&pageFaultSpinLock); return; } - + /*** $Log$ + Revision 1.3 2008/02/29 14:56:31 reddawg + Sync - Working On Getting It To Boot Again + Revision 1.2 2007/01/19 17:08:29 reddawg Lots of fixes diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 47b0f04..9bbca2c 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004,2005,2006,2007 The UbixOS Project + Copyright (c) 2002-2004,2005,2006,2007,2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -28,6 +28,7 @@ *****************************************************************************************/ #include +#include #include #include #include @@ -61,20 +62,21 @@ u_int32_t *pageTable = 0x0; /* Allocate A Page Of Memory For Kernels Page Directory */ - kernelPageDirectory = (uInt32 *) vmmFindFreePage(sysID); + kernelPageDirectory = (u_int32_t *) vmm_findFreePage(sysID); if (kernelPageDirectory == 0x0) { - K_PANIC("Error: vmmFindFreePage Failed"); + K_PANIC("Error: vmm_findFreePage Failed"); return (0x1); } /* end if */ /* Clear The Memory To Ensure There Is No Garbage */ + //QUESTION Can't we do a memset here? for (i = 0x0; i < pageEntries; i++) { kernelPageDirectory[i] = (u_int32_t)0x0; } /* end for */ /* Allocate a page for the first 4MB of memory */ - if ((pageTable = (u_int32_t *) vmmFindFreePage(sysID)) == 0x0) - K_PANIC("Error: vmmFindFreePage Failed"); + if ((pageTable = (u_int32_t *) vmm_findFreePage(sysID)) == 0x0) + K_PANIC("Error: vmm_findFreePage Failed"); kernelPageDirectory[0x0] = (u_int32_t) ((u_int32_t)pageTable | KERNEL_PAGE_DEFAULT); @@ -87,7 +89,7 @@ * 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); + pageTable[i] = (u_int32_t) ((i * 0x1000) | KERNEL_PAGE_DEFAULT); } /* end for */ /* @@ -95,32 +97,32 @@ * for kernel space and will be shared with each process */ for (i = 768; i < pageEntries; i++) { - if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) - K_PANIC("Error: vmmFindFreePage Failed"); + if ((pageTable = (u_int32_t *) vmm_findFreePage(sysID)) == 0x0) + K_PANIC("Error: vmm_findFreePage 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); + kernelPageDirectory[i] = (u_int32_t) ((u_int32_t) (pageTable) | KERNEL_PAGE_DEFAULT); } /* end for */ /* Set Up Memory To Be All The Allocated Page Directories */ - if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) - K_PANIC("Error: vmmFindFreePage Failed"); + if ((pageTable = (u_int32_t *) vmm_findFreePage(sysID)) == 0x0) + K_PANIC("Error: vmm_findFreePage Failed"); /* Clean Page Table */ memset(pageTable,0x0,0x1000); - kernelPageDirectory[767] = ((uInt32) pageTable | KERNEL_PAGE_DEFAULT); + kernelPageDirectory[767] = ((u_int32_t) 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); + pageTable = (u_int32_t *) (kernelPageDirectory[0] & 0xFFFFF000); + pageTable[256] = (u_int32_t) ((u_int32_t) (kernelPageDirectory) | KERNEL_PAGE_DEFAULT); /* Now Lets Turn On Paging With This Initial Page Table */ @@ -131,7 +133,7 @@ "orl $0x80010000,%%eax \n" /* Turn on memory protection */ "movl %%eax,%%cr0 \n" : - : "d"((uInt32 *) (kernelPageDirectory)) + : "d"((u_int32_t *) (kernelPageDirectory)) ); /* Remap The Memory List */ @@ -159,21 +161,30 @@ 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 + 07/08/09 - Cleaned up *****************************************************************************************/ -int vmm_remapPage(uInt32 source,uInt32 dest,uInt16 perms) { - uInt16 destPageDirectoryIndex = 0x0, destPageTableIndex = 0x0; - uInt32 *pageDir = 0x0, *pageTable = 0x0; - short i = 0x0; +int vmm_remapPage(u_int32_t sourceAddr,u_int32_t destAddr,u_int16_t perms) { + u_int16_t destPageDirectoryIndex = 0x0; + u_int16_t destPageTableIndex = 0x0; + u_int32_t *pageDir = 0x0; + u_int32_t *pageTable = 0x0; + short i = 0x0; - if (source == 0x0) +#ifdef VMMDEBUG +kprintf("vmm_remapPage"); +#endif + + if (sourceAddr == 0x0) K_PANIC("source == 0x0"); - if (dest == 0x0) + if (destAddr == 0x0) K_PANIC("dest == 0x0"); + /* Lock this function so to avoid race conditions */ spinLock(&rmpSpinLock); + /* Set default permissions if not spedified */ if (perms == 0x0) perms = KERNEL_PAGE_DEFAULT; @@ -182,22 +193,18 @@ * Directory */ - pageDir = (uInt32 *) parentPageDirAddr; - - /* Check To See If Page Table Exists */ - if (dest == 0x0) - return(0x0); + pageDir = (u_int32_t *)PARENT_PAGEDIR_ADDR; /* Get Index Into The Page Directory */ - destPageDirectoryIndex = (dest / 0x400000); - + destPageDirectoryIndex = PDI(destAddr); + 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; + pageDir[destPageDirectoryIndex] = (u_int32_t) vmm_findFreePage(_current->id) | PAGE_DEFAULT; /* Also Add It To Virtual Space So We Can Make Changes Later */ - pageTable = (uInt32 *) (tablesBaseAddress + 0x2FF000); + pageTable = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + 0x2FF000); pageTable[destPageDirectoryIndex] = pageDir[destPageDirectoryIndex]; /* Reload Page Directory */ @@ -208,38 +215,38 @@ "pop %eax \n" ); - pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * destPageDirectoryIndex)); + pageTable = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * destPageDirectoryIndex)); + /* Zero out the page table */ for (i = 0x0;i < pageEntries;i++) pageTable[i] = 0x0; - } /* Set Address To Page Table */ - pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * destPageDirectoryIndex)); + pageTable = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * destPageDirectoryIndex)); /* Get The Index To The Page Table */ - destPageTableIndex = ((dest - (destPageDirectoryIndex * 0x400000)) / 0x1000); - + destPageTableIndex = PTI(destAddr); /* If The Page Is Mapped In Free It Before We Remap */ if ((pageTable[destPageTableIndex] & PAGE_PRESENT) == PAGE_PRESENT) { if ((pageTable[destPageTableIndex] & PAGE_STACK) == PAGE_STACK) - kprintf("Stack Page: [0x%X]\n",dest); + kprintf("Stack Page: [0x%X]\n",destAddr); if ((pageTable[destPageTableIndex] & PAGE_COW) != PAGE_COW) { kprintf("Page NOT COW\n"); - kprintf("Page Present: [0x%X][0x%X]",dest,pageTable[destPageTableIndex]); - source = 0x0; + kprintf("Page Present: [0x%X][0x%X]",destAddr,pageTable[destPageTableIndex]); + sourceAddr = 0x0; goto rmDone; } - - /* Clear The Page First For Security Reasons */ - freePage(((uInt32) pageTable[destPageTableIndex] & 0xFFFFF000)); + else { + /* Clear The Page First For Security Reasons */ + vmm_freePage(((u_int32_t) pageTable[destPageTableIndex] & 0xFFFFF000)); + } } /* Set The Source Address In The Destination */ - pageTable[destPageTableIndex] = (uInt32) (source | perms); + pageTable[destPageTableIndex] = (u_int32_t) (sourceAddr | perms); /* Reload The Page Table; */ asm volatile( @@ -253,113 +260,48 @@ /* Return */ spinUnlock(&rmpSpinLock); - return (source); + return (sourceAddr); } /* end func */ -/************************************************************************ - -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 *vmm_getFreeKernelPage(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) - K_PANIC("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) - K_PANIC("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); - } /* end func */ /************************************************************************ -Function: void vmmClearVirtualPage(uInt32 pageAddr); +Function: void vmm_clearVirtualPage(u_int32_t pageAddr); Description: This Will Null Out A Page Of Memory Notes: +07/07/2009 - Changed to void it will always return true +07/08/2009 - renamed and cleaned up function + ************************************************************************/ -int -vmmClearVirtualPage(uInt32 pageAddr) -{ - uInt32 *src = 0x0; - int counter = 0x0; +void vmm_clearVirtualPage(u_int32_t pageAddr) { + u_int32_t *src = 0x0; + int counter = 0x0; /* Set Source Pointer To Virtual Page Address */ - src = (uInt32 *) pageAddr; + src = (u_int32_t *) pageAddr; /* Clear Out The Page */ for (counter = 0x0; counter < pageEntries; counter++) { src[counter] = 0x0; + } + } - /* Return */ - return (0x0); -} - -void *vmmMapFromTask(pidType pid,void *ptr,uInt32 size) { +void *vmmMapFromTask(pidType pid,void *ptr,u_int32_t size) { kTask_t *child = 0x0; - uInt32 i = 0x0,x = 0x0,y = 0x0,count = ((size+4095)/0x1000),c = 0x0; + u_int32_t 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; + u_int32_t baseAddr = 0x0,offset = 0x0; + u_int32_t *childPageDir = (u_int32_t *)0x5A00000; + u_int32_t *childPageTable = 0x0; + u_int32_t *pageTableSrc = 0x0; + offset = (u_int32_t)ptr & 0xFFF; + baseAddr = (u_int32_t)ptr & 0xFFFFF000; child = schedFindTask(pid); //Calculate The Page Table Index And Page Directory Index dI = (baseAddr/(1024*4096)); @@ -372,13 +314,13 @@ K_PANIC("Returned NULL"); } for (x=(_current->oInfo.vmStart/(1024*4096));x<1024;x++) { - pageTableSrc = (uInt32 *)(tablesBaseAddress + (4096*x)); + pageTableSrc = (u_int32_t *)(PAGE_TABLES_BASE_ADDR + (4096*x)); for (y=0;y<1024;y++) { //Loop Through The Page Table Find An UnAllocated Page - if ((uInt32)pageTableSrc[y] == (uInt32)0x0) { + if ((u_int32_t)pageTableSrc[y] == (u_int32_t)0x0) { if (count > 1) { for (c=0;((c 1) { for (c = 0; c < count; c++) { if (y + c < 1024) { - if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + if ((u_int32_t) pageTableSrc[y + c] != (u_int32_t) 0x0) { c = -1; break; } @@ -443,22 +385,23 @@ } if (c != -1) { for (c = 0; c < count; c++) { - if (vmm_remapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + ((y + c) * 0x1000)),KERNEL_PAGE_DEFAULT) == 0x0) + if (vmm_remapPage((u_int32_t) vmm_findFreePage(sysID), ((x * 0x400000) + ((y + c) * 0x1000)),KERNEL_PAGE_DEFAULT) == 0x0) K_PANIC("remap Failed"); - vmmClearVirtualPage((uInt32) ((x * 0x400000) + ((y + c) * 0x1000))); + vmm_clearVirtualPage((u_int32_t) ((x * 0x400000) + ((y + c) * 0x1000))); } + spinUnlock(&fkpSpinLock); return ((void *)((x * 0x400000) + (y * 0x1000))); } } else { /* Map A Physical Page To The Virtual Page */ - if (vmm_remapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT) == 0x0) + if (vmm_remapPage((u_int32_t) vmm_findFreePage(sysID), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT) == 0x0) K_PANIC("Failed"); /* Clear This Page So No Garbage Is There */ - vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); + vmm_clearVirtualPage((u_int32_t) ((x * 0x400000) + (y * 0x1000))); /* Return The Address Of The Newly Allocate Page */ spinUnlock(&fkpSpinLock); return ((void *)((x * 0x400000) + (y * 0x1000))); @@ -544,12 +487,12 @@ old = base + ctob(td->vm_dsize); - if (new < base) + if (new < base) K_PANIC("EINVAL"); if (new > old) { for (i = old;i < new;i+= 0x1000) { - if (vmm_remapPage(vmmFindFreePage(_current->id),i,PAGE_DEFAULT) == 0x0) + if (vmm_remapPage(vmm_findFreePage(_current->id),i,PAGE_DEFAULT) == 0x0) K_PANIC("remap Failed"); /* Clear Page */ } @@ -557,7 +500,7 @@ } else if (new < old) { kprintf("0x%X < 0x%X\n",new,old); - //K_PANIC("new < old"); + //K_PANIC("new < old"); td->vm_dsize -= btoc(old - new); } diff --git a/src/sys/vmm/setpageattributes.c b/src/sys/vmm/setpageattributes.c index ad3f1a9..c24855d 100644 --- a/src/sys/vmm/setpageattributes.c +++ b/src/sys/vmm/setpageattributes.c @@ -42,6 +42,10 @@ uInt16 directoryIndex = 0x0, tableIndex = 0x0; uInt32 *pageTable = 0x0; +#ifdef VMMDEBUG + kprintf("vmm_getPageAttributes"); +#endif + /* Calculate The Page Directory Index */ directoryIndex = (memAddr >> 22); @@ -49,7 +53,7 @@ tableIndex = ((memAddr >> 12) & 0x3FF); /* Set Table Pointer */ - if ((pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * directoryIndex))) == 0x0) + if ((pageTable = (uInt32 *) (PAGE_TABLES_BASE_ADDR + (0x1000 * directoryIndex))) == 0x0) kpanic("Error: pageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Set Attribute If Page Is Mapped */ @@ -69,6 +73,9 @@ /*** $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg ubix2 diff --git a/src/sys/vmm/unmappage.c b/src/sys/vmm/unmappage.c index ff77d94..dc2d013 100644 --- a/src/sys/vmm/unmappage.c +++ b/src/sys/vmm/unmappage.c @@ -31,7 +31,7 @@ /************************************************************************ -Function: void vmmUnmapPage(uInt32 pageAddr,int flags); +Function: void vmmUnmapPage(u_int32_t 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 @@ -46,26 +46,28 @@ To Create A New Virtual Space So Now It Has A Flag ************************************************************************/ +#ifdef BOO + void -vmmUnmapPage(uInt32 pageAddr, int flags) +vmmUnmapPage(u_int32_t pageAddr, int flags) { int pageDirectoryIndex = 0, pageTableIndex = 0; - uInt32 *pageTable = 0x0; + u_int32_t *pageTable = 0x0; /* Get The Index To The Page Directory */ - pageDirectoryIndex = (pageAddr >> 22); + pageDirectoryIndex = PDI(pageAddr); //Calculate The Page Table Index - pageTableIndex = ((pageAddr >> 12) & 0x3FF); + pageTableIndex = PTI(pageAddr); /* Set pageTable To The Virtual Address Of Table */ - pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * pageDirectoryIndex)); + pageTable = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (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)); + * freePage((u_int32_t)(pageTable[pageTableIndex] & 0xFFFFF000)); */ } /* Unmap The Page */ @@ -78,12 +80,13 @@ /* Return */ return; } +#endif /************************************************************************ -Function: void vmmUnmapPages(uInt32 pageAddr,int flags); +Function: void vmmUnmapPages(u_int32_t 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 @@ -98,23 +101,37 @@ 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; +void vmm_unmapPages(u_int32_t addr,u_int32_t count,u_int16_t flags) { + u_int32_t baseAddr = (u_int32_t)addr & 0xFFFFF000; + u_int32_t dI = 0x0; + u_int32_t tI = 0x0; + u_int32_t y = 0x0; + u_int32_t *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++) { + dI = PDI(baseAddr); + tI = PTI(baseAddr); + + pageTable = (u_int32_t *)(PAGE_TABLES_BASE_ADDR + (4096*dI)); + + for (y=tI;y<(tI + count);y++) { + if (flags == 0) + vmm_freePage((u_int32_t)(pageTable[y] & 0xFFFFF000)); pageTable[y] = 0x0; } + + /* Rehash The Page Directory */ + asm volatile( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); return; } /*** $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg ubix2 diff --git a/src/sys/vmm/vmm_memory.c b/src/sys/vmm/vmm_memory.c index f9400f7..efc6b7d 100644 --- a/src/sys/vmm/vmm_memory.c +++ b/src/sys/vmm/vmm_memory.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004, 2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -36,7 +36,7 @@ #include #include -static uInt32 freePages = 0; +static u_int32_t freePages = 0; static spinLock_t vmmSpinLock = SPIN_LOCK_INITIALIZER; static spinLock_t vmmCowSpinLock = SPIN_LOCK_INITIALIZER; @@ -102,7 +102,7 @@ ************************************************************************/ int countMemory() { - register uInt32 *mem = 0x0; + register u_int32_t *mem = 0x0; unsigned long memCount = -1, tempMemory = 0x0; unsigned short memKb = 0; unsigned char irq1State, irq2State; @@ -140,7 +140,7 @@ if (memCount == -1) memCount = 0; memCount += 1024 * 1024; - mem = (uInt32 *)memCount; + mem = (u_int32_t *)memCount; tempMemory = *mem; *mem = 0x55AA55AA; asm("": : :"memory"); @@ -175,7 +175,7 @@ /************************************************************************ - Function: uInt32 vmmFindFreePage(pid_t pid); + Function: u_int32_t vmmFindFreePage(pid_t pid); Description: This Returns A Free Physical Page Address Then Marks It Not Available As Well As Setting The PID To The Proccess @@ -183,7 +183,7 @@ Notes: ************************************************************************/ -uInt32 vmmFindFreePage(pidType pid) { +u_int32_t vmm_findFreePage(pidType pid) { int i = 0x0; /* Lets Look For A Free Page */ @@ -211,21 +211,22 @@ } /* If No Free Memory Is Found Return NULL */ - kpanic("Out Of Memory!!!!"); + K_PANIC("Out Of Memory!!!!"); + spinUnlock(&vmmSpinLock); return (0x0); } /************************************************************************ - Function: int freePage(uInt32 pageAddr); + Function: int freePage(u_int32_t pageAddr); Description: This Function Marks The Page As Free Notes: ************************************************************************/ -int freePage(uInt32 pageAddr) { +void vmm_freePage(u_int32_t pageAddr) { int pageIndex = 0x0; assert((pageAddr & 0xFFF) == 0x0); spinLock(&vmmSpinLock); @@ -244,16 +245,14 @@ } else { /* Adjust The COW Counter */ - adjustCowCounter(((uInt32) vmmMemoryMap[pageIndex].pageAddr), -1); + adjustCowCounter(((u_int32_t) vmmMemoryMap[pageIndex].pageAddr), -1); } spinUnlock(&vmmSpinLock); - /* Return */ - return (0); } /************************************************************************ - Function: int adjustCowCounter(uInt32 baseAddr,int adjustment); + Function: int adjustCowCounter(u_int32_t baseAddr,int adjustment); Description: This Adjust The COW Counter For Page At baseAddr It Will Error If The Count Goes Below 0 @@ -263,7 +262,7 @@ 08/01/02 - I Think If Counter Gets To 0 I Should Free The Page ************************************************************************/ -int adjustCowCounter(uInt32 baseAddr, int adjustment) { +int adjustCowCounter(u_int32_t baseAddr, int adjustment) { int vmmMemoryMapIndex = (baseAddr / 4096); assert((baseAddr & 0xFFF) == 0x0); spinLock(&vmmCowSpinLock); @@ -295,19 +294,19 @@ ************************************************************************/ void vmmFreeProcessPages(pidType pid) { int i=0,x=0; - uInt32 *tmpPageTable = 0x0; - uInt32 *tmpPageDir = (uInt32 *)parentPageDirAddr; + u_int32_t *tmpPageTable = 0x0; + u_int32_t *tmpPageDir = (uInt32 *)PARENT_PAGEDIR_ADDR; spinLock(&vmmSpinLock); /* Check Page Directory For An Avail Page Table */ for (i=0;i<=0x300;i++) { if (tmpPageDir[i] != 0) { /* Set Up Page Table Pointer */ - tmpPageTable = (uInt32 *)(tablesBaseAddress + (i * 0x1000)); + tmpPageTable = (u_int32_t *)(PAGE_TABLES_BASE_ADDR + (i * 0x1000)); /* Check The Page Table For COW Pages */ for (x=0;x +#include #include #include #include @@ -40,7 +41,8 @@ u_int32_t *pageTableSrc = 0x0; u_int32_t *pageDir = 0x0; - pageDir = (uInt32 *) parentPageDirAddr; + pageDir = (u_int32_t *) PARENT_PAGEDIR_ADDR; + kprintf("Called: vmm_cleanVirtualSpace(0x%X)\n",addr); #ifdef VMMDEBUG kprintf("Called: vmm_cleanVirtualSpace(0x%X)\n",addr); @@ -50,7 +52,7 @@ /* BUG memory leak this does not update COW counter on master page */ for (x = (addr / (1024 * 4096)); x < 770; x++) { if ((pageDir[x] & PAGE_PRESENT) == PAGE_PRESENT) { - pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + pageTableSrc = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * x)); for (y = 0;y < 1024;y++) { if (pageTableSrc[y] != 0x0) { if ((pageTableSrc[y] & PAGE_COW) == PAGE_COW) { @@ -91,14 +93,14 @@ void *vmmGetFreeVirtualPage(pidType pid, int count,int type) { int x = 0, y = 0, c = 0; - uInt32 *pageTableSrc = 0x0; - uInt32 *pageDir = 0x0; - uInt32 start_page = 0x0; + u_int32_t *pageTableSrc = 0x0; + u_int32_t *pageDir = 0x0; + u_int32_t start_page = 0x0; spinLock(&fvpSpinLock); - pageDir = (uInt32 *)PARENT_PAGEDIR_ADDR; + pageDir = (u_int32_t *)PARENT_PAGEDIR_ADDR; /* Lets Search For A Free Page */ if (_current->oInfo.vmStart <= 0x100000) @@ -126,10 +128,10 @@ 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; + pageDir[x] = (u_int32_t) vmm_findFreePage(_current->id) | PAGE_DEFAULT; /* Also Add It To Virtual Space So We Can Make Changes Later */ - pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * 767)); + pageTableSrc = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (4096 * 767)); pageTableSrc[x] = pageDir[x]; y = 1; @@ -140,11 +142,11 @@ ); } - pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + pageTableSrc = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * x)); if (y != 0x0) { for (y = 0x0;y 0x1) { @@ -176,7 +178,7 @@ /* BUG MEMORY LEAK */ //pageTableSrc[y + c] = 0x0; } - if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + if ((u_int32_t) pageTableSrc[y + c] != (u_int32_t) 0x0) { c = -1; break; } @@ -184,9 +186,9 @@ } if (c != -1) { for (c = 0; c < count; c++) { - if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),PAGE_DEFAULT)) == 0x0) + if ((vmm_remapPage((u_int32_t) vmm_findFreePage(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))); + vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + ((y + c) * 4096))); } if (type == VM_THRD) _current->td.vm_dsize += btoc(count * 0x1000); @@ -198,14 +200,14 @@ /* Map A Physical Page To The Virtual Page */ /* - * remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)) + * remapPage((u_int32_t)vmm_findFreePage(pid),((x*(1024*4096))+(y*4096)) * ,pid); */ - if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),PAGE_DEFAULT)) == 0x0) + if ((vmm_remapPage((u_int32_t) vmm_findFreePage(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))); + vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))); /* Return The Address Of The Newly Allocate Page */ if (type == VM_THRD) { @@ -230,14 +232,14 @@ void *vmmGetFreeVirtualPage_new(pidType pid, int count,int type,u_int32_t start_addr) { int x = 0, y = 0, c = 0; - uInt32 *pageTableSrc = 0x0; - uInt32 *pageDir = 0x0; - uInt32 start_page = 0x0; + u_int32_t *pageTableSrc = 0x0; + u_int32_t *pageDir = 0x0; + u_int32_t start_page = 0x0; spinLock(&fvpSpinLock); - pageDir = (uInt32 *) parentPageDirAddr; + pageDir = (u_int32_t *) PARENT_PAGEDIR_ADDR; /* Lets Search For A Free Page */ if (_current->oInfo.vmStart <= 0x100000) @@ -260,9 +262,9 @@ /* 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; + pageDir[x] = (u_int32_t) vmm_findFreePage(_current->id) | PAGE_DEFAULT; /* Also Add It To Virtual Space So We Can Make Changes Later */ - pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * 767)); + pageTableSrc = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (4096 * 767)); pageTableSrc[x] = pageDir[x]; y = 1; /* Reload Page Directory */ @@ -271,10 +273,10 @@ "movl %eax,%cr3\n" ); } - pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + pageTableSrc = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * x)); if (y != 0x0) { for (y = 0x0;y 0x1) { for (c = 0; c < count; c++) { if (y + c < 1024) { @@ -296,7 +298,7 @@ //pageTableSrc[y + c] = 0x0; } - if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + if ((u_int32_t) pageTableSrc[y + c] != (u_int32_t) 0x0) { c = -1; break; } @@ -304,9 +306,9 @@ } if (c != -1) { for (c = 0; c < count; c++) { - if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),PAGE_DEFAULT)) == 0x0) + if ((vmm_remapPage((u_int32_t) vmm_findFreePage(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))); + vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + ((y + c) * 4096))); } if (type == VM_THRD) _current->td.vm_dsize += btoc(count * 0x1000); @@ -317,14 +319,14 @@ /* Map A Physical Page To The Virtual Page */ /* - * remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)) + * remapPage((u_int32_t)vmm_findFreePage(pid),((x*(1024*4096))+(y*4096)) * ,pid); */ - if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),PAGE_DEFAULT)) == 0x0) + if ((vmm_remapPage((u_int32_t) vmm_findFreePage(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))); + vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))); /* Return The Address Of The Newly Allocate Page */ if (type == VM_THRD) { @@ -364,21 +366,21 @@ void *vmmCopyVirtualSpace(pidType pid) { void *newPageDirectoryAddress = 0x0; - uInt32 *parentPageDirectory = 0x0, *newPageDirectory = 0x0; - uInt32 *parentPageTable = 0x0, *newPageTable = 0x0; - uInt32 *parentStackPage = 0x0, *newStackPage = 0x0; + u_int32_t *parentPageDirectory = 0x0, *newPageDirectory = 0x0; + u_int32_t *parentPageTable = 0x0, *newPageTable = 0x0; + u_int32_t *parentStackPage = 0x0, *newStackPage = 0x0; uInt16 x = 0, i = 0, s = 0; spinLock(&cvsSpinLock); /* Set Address Of Parent Page Directory */ - parentPageDirectory = (uInt32 *) parentPageDirAddr; + parentPageDirectory = (u_int32_t *) PARENT_PAGEDIR_ADDR; /* Allocate A New Page For The New Page Directory */ - if ((newPageDirectory = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + if ((newPageDirectory = (u_int32_t *) 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 */ - newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory); + newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((u_int32_t) newPageDirectory); /* First Set Up A Flushed Page Directory */ memset(newPageDirectory,0x0,0x1000); @@ -397,9 +399,9 @@ /* If Page Table Exists Map It */ if (parentPageDirectory[x] != 0) { /* Set Parent To Propper Page Table */ - parentPageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + parentPageTable = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * x)); /* Allocate A New Page Table */ - if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + if ((newPageTable = (u_int32_t *) vmm_getFreeKernelPage(pid,1)) == 0x0) kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Set Parent And New Pages To COW */ @@ -408,63 +410,63 @@ /* If Page Is Mapped */ if ((parentPageTable[i] & 0xFFFFF000) != 0x0) { /* Check To See If Its A Stack Page */ - if (((uInt32) parentPageTable[i] & PAGE_STACK) == PAGE_STACK) { + if (((u_int32_t) parentPageTable[i] & PAGE_STACK) == PAGE_STACK) { /* Alloc A New Page For This Stack Page */ - if ((newStackPage = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + if ((newStackPage = (u_int32_t *) vmm_getFreeKernelPage(pid,1)) == 0x0) kpanic("Error: newStackPage == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Set Pointer To Parents Stack Page */ - parentStackPage = (uInt32 *) (((1024 * 4096) * x) + (4096 * i)); + parentStackPage = (u_int32_t *) (((1024 * 4096) * x) + (4096 * i)); /* Copy The Tack Byte For Byte (I Should Find A Faster Way) */ for (s = 0x0; s < pageEntries; s++) { newStackPage[s] = parentStackPage[s]; } /* Insert New Stack Into Page Table */ - newPageTable[i] = (vmm_getPhysicalAddr((uInt32) newStackPage) | PAGE_DEFAULT | PAGE_STACK); + newPageTable[i] = (vmm_getPhysicalAddr((u_int32_t) newStackPage) | PAGE_DEFAULT | PAGE_STACK); /* Unmap From Kernel Space */ - vmmUnmapPage((uInt32) newStackPage, 1); + vmm_unmapPages((u_int32_t) newStackPage, 1, 1); } else { /* Set Page To COW In Parent And Child Space */ - newPageTable[i] = (((uInt32) parentPageTable[i] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); + newPageTable[i] = (((u_int32_t) parentPageTable[i] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); /* Increment The COW Counter For This Page */ - if (((uInt32) parentPageTable[i] & PAGE_COW) == PAGE_COW) { - adjustCowCounter(((uInt32) parentPageTable[i] & 0xFFFFF000), 1); + if (((u_int32_t) parentPageTable[i] & PAGE_COW) == PAGE_COW) { + adjustCowCounter(((u_int32_t) parentPageTable[i] & 0xFFFFF000), 1); } else { - adjustCowCounter(((uInt32) parentPageTable[i] & 0xFFFFF000), 2); + adjustCowCounter(((u_int32_t) parentPageTable[i] & 0xFFFFF000), 2); parentPageTable[i] = newPageTable[i]; } } } else { - newPageTable[i] = (uInt32) 0x0; + newPageTable[i] = (u_int32_t) 0x0; } } /* Put New Page Table Into New Page Directory */ - newPageDirectory[x] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + newPageDirectory[x] = (vmm_getPhysicalAddr((u_int32_t) newPageTable) | PAGE_DEFAULT); /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ - vmmUnmapPage((uInt32) newPageTable, 1); + vmm_unmapPages((u_int32_t) newPageTable, 1, 1); } else { - newPageDirectory[x] = (uInt32) 0x0; + newPageDirectory[x] = (u_int32_t) 0x0; } } /* * Allocate A New Page For The The First Page Table Where We Will Map The * Lower Region */ - if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + if ((newPageTable = (u_int32_t *) vmm_getFreeKernelPage(pid,1)) == 0x0) kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Flush The Page From Garbage In Memory */ memset(newPageTable,0x0,0x1000); /* Map This Into The Page Directory */ - newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + newPageDirectory[0] = (vmm_getPhysicalAddr((u_int32_t) newPageTable) | PAGE_DEFAULT); /* Set Address Of Parents Page Table */ - parentPageTable = (uInt32 *) tablesBaseAddress; + parentPageTable = (u_int32_t *) PAGE_TABLES_BASE_ADDR; /* Map The First 1MB Worth Of Pages */ for (x = 0; x < (pageEntries / 4); x++) { newPageTable[x] = parentPageTable[x]; @@ -474,20 +476,20 @@ /* If Page Is Avaiable Map It */ if ((parentPageTable[x] & 0xFFFFF000) != 0x0) { /* Set Pages To COW */ - newPageTable[x] = (((uInt32) parentPageTable[x] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); + newPageTable[x] = (((u_int32_t) parentPageTable[x] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); /* Increment The COW Counter For This Page */ - if (((uInt32) parentPageTable[x] & PAGE_COW) == PAGE_COW) { - adjustCowCounter(((uInt32) parentPageTable[x] & 0xFFFFF000), 1); + if (((u_int32_t) parentPageTable[x] & PAGE_COW) == PAGE_COW) { + adjustCowCounter(((u_int32_t) parentPageTable[x] & 0xFFFFF000), 1); } else { - adjustCowCounter(((uInt32) parentPageTable[x] & 0xFFFFF000), 2); + adjustCowCounter(((u_int32_t) parentPageTable[x] & 0xFFFFF000), 2); parentPageTable[x] = newPageTable[x]; } } else { - newPageTable[x] = (uInt32) 0x0; + newPageTable[x] = (u_int32_t) 0x0; } } /* Set Virtual Mapping For Page Directory */ - newPageTable[256] = (vmm_getPhysicalAddr((uInt32) newPageDirectory) | PAGE_DEFAULT); + newPageTable[256] = (vmm_getPhysicalAddr((u_int32_t) newPageDirectory) | PAGE_DEFAULT); /* * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have @@ -495,20 +497,20 @@ * Become A Security Issue */ /* First Lets Unmap The Previously Allocated Page Table */ - vmmUnmapPage((uInt32) newPageTable, 1); + vmm_unmapPages((u_int32_t) newPageTable, 1, 1); /* Allocate A New Page Table */ - if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + if ((newPageTable = (u_int32_t *) 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; + newPageDirectory[767] = vmm_getPhysicalAddr((u_int32_t) 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); + vmm_unmapPages((u_int32_t) newPageTable, 1, 1); /* Now We Are Done With The Page Directory So Lets Unmap That Too */ - vmmUnmapPage((uInt32) newPageDirectory, 1); + vmm_unmapPages((u_int32_t) newPageDirectory, 1, 1); spinUnlock(&cvsSpinLock); @@ -541,43 +543,48 @@ ************************************************************************/ void *vmmCreateVirtualSpace(pid_t pid) { void *newPageDirectoryAddress = 0x0; - uInt32 *parentPageDirectory = 0x0, *newPageDirectory = 0x0; - uInt32 *parentPageTable = 0x0, *newPageTable = 0x0; + u_int32_t *parentPageDirectory = 0x0, *newPageDirectory = 0x0; + u_int32_t *parentPageTable = 0x0, *newPageTable = 0x0; int x = 0; /* Set Address Of Parent Page Directory */ - parentPageDirectory = (uInt32 *) parentPageDirAddr; + parentPageDirectory = (u_int32_t *) PARENT_PAGEDIR_ADDR; + /* Allocate A New Page For The New Page Directory */ - newPageDirectory = (uInt32 *) vmm_getFreeKernelPage(pid); + newPageDirectory = (u_int32_t *) vmm_getFreeKernelPage(pid,1); + /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ - newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory); + newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((u_int32_t) newPageDirectory); + /* First Set Up A Flushed Page Directory */ for (x = 0; x < pageEntries; x++) { newPageDirectory[x] = 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 *) vmm_getFreeKernelPage(pid); + newPageTable = (u_int32_t *) vmm_getFreeKernelPage(pid,1); /* Flush The Page From Garbage In Memory */ for (x = 0; x < pageEntries; x++) { newPageTable[x] = 0x0; } /* Map This Into The Page Directory */ - newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + newPageDirectory[0] = (vmm_getPhysicalAddr((u_int32_t) newPageTable) | PAGE_DEFAULT); /* Set Address Of Parents Page Table */ - parentPageTable = (uInt32 *) tablesBaseAddress; + parentPageTable = (u_int32_t *) PAGE_TABLES_BASE_ADDR; /* 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); + newPageTable[256] = (vmm_getPhysicalAddr((u_int32_t) newPageDirectory) | PAGE_DEFAULT); /* * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have @@ -585,19 +592,19 @@ * Become A Security Issue */ /* First Lets Unmap The Previously Allocated Page Table */ - vmmUnmapPage((uInt32) newPageTable, 1); + vmm_unmapPages((u_int32_t) newPageTable, 1, 1); /* Allocate A New Page Table */ - newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid); + newPageTable = (u_int32_t *) vmm_getFreeKernelPage(pid,1); /* First Set Our Page Directory To Contain This */ - newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT; + newPageDirectory[767] = vmm_getPhysicalAddr((u_int32_t) 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); + vmm_unmapPages((u_int32_t) newPageTable, 1, 1); /* Now We Are Done With The Page Directory So Lets Unmap That Too */ - vmmUnmapPage((uInt32) newPageDirectory, 1); + vmm_unmapPages((u_int32_t) newPageDirectory, 1, 1); /* Return Physical Address Of Page Directory */ return (newPageDirectoryAddress); } /* End Func */