diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h index d86f648..f26188a 100644 --- a/src/sys/include/vmm/paging.h +++ b/src/sys/include/vmm/paging.h @@ -37,16 +37,15 @@ #define VM_THRD 0 #define VM_TASK 1 -#define pageLength 0x00000400 +#define pageLength 0x00000400 #define PAGE_TABLES_BASE_ADDR 0xBFC00000 /* Base address of page tables in virtual area 3GB - 4MB */ #define PARENT_PAGEDIR_ADDR 0x100000 /* Address at which the page directory is stored */ - -#define PAGE_COW 0x00000200 -#define PAGE_STACK 0x00000400 -#define PAGE_WIRED 0x00000600 -#define PAGE_PRESENT 0x00000001 -#define PAGE_WRITE 0x00000002 -#define PAGE_USER 0x00000004 +#define PAGE_COW 0x00000200 +#define PAGE_STACK 0x00000400 +#define PAGE_WIRED 0x00000600 +#define PAGE_PRESENT 0x00000001 +#define PAGE_WRITE 0x00000002 +#define PAGE_USER 0x00000004 #define PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE|PAGE_USER) #define KERNEL_PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE) @@ -54,6 +53,7 @@ #define PAGE_SIZE (1<> 12) & 0x3FF) #define PDI(x) (x >> 22) @@ -62,13 +62,14 @@ #define ctob(x) ((x)<>PAGE_SHIFT) - +int vmm_cleanVirtualSpace(u_int32_t addr); int vmm_zeroVirtualPage(u_int32_t pageAddr); void vmm_unmapPages(u_int32_t addr,u_int32_t count,u_int16_t flags); void *vmm_mapFromTask(pidType pid,u_int32_t baseAddr,u_int32_t size); -void *vmmCopyVirtualSpace(pidType); +void *vmm_copyVirtualSpace(pidType); void *vmmCreateVirtualSpace(pidType); -void *vmmGetFreeVirtualPage(pidType,int,int); +void *vmm_getFreeVirtualPage_old(pidType,int,int); +void *vmm_getFreeVirtualPage(pidType,int,int,u_int32_t); void *vmm_getFreeKernelPage(pidType pid,u_int32_t count); u_int32_t vmm_getPhysicalAddr(u_int32_t); diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index ae58e16..72de9e4 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -548,7 +548,7 @@ if (argv[1] != 0x0) { //UBU argc = (int)argv[0]; - args = (char *)vmmGetFreeVirtualPage(_current->id,1,VM_TASK); + args = (char *)vmm_getFreeVirtualPage(_current->id,1,VM_TASK,-1); //! do we need this? memset(args,0x0,0x1000); x = 0x0; @@ -724,7 +724,7 @@ if (argv[1] != 0x0) { argc = (int)argv[0]; - args = (char *)vmmGetFreeVirtualPage(_current->id,1,VM_TASK); + args = (char *)vmm_getFreeVirtualPage(_current->id,1,VM_TASK,-1); memset(args,0x0,0x1000); x = 0x0; argvNew = (char **)kmalloc(sizeof(char *) * argc); @@ -762,7 +762,7 @@ tmp[i + 1] = (u_int32_t)argv[i]; } //! Build ENV - args = (char *)vmmGetFreeVirtualPage(_current->id,1,VM_TASK); + args = (char *)vmm_getFreeVirtualPage(_current->id,1,VM_TASK,-1); memset(args,0x0,0x1000); strcpy(args,"LIBRARY_PATH=/lib"); diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index a91a496..f1e9575 100644 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -89,7 +89,7 @@ newProcess->tss.io_map = 0x8000; /* Create A Copy Of The VM Space For New Task */ - newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); + newProcess->tss.cr3 = (uInt32)vmm_copyVirtualSpace(newProcess->id); newProcess->state = FORK; /* Fix gcc optimization problems */ diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index 379d4ca..0de61f6 100644 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.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 @@ -198,9 +198,9 @@ void sysGetFreePage(long *ptr,int count,int type) { if (ptr) { if (type == 2) - *ptr = (long) vmmGetFreeVirtualPage(_current->id,count,VM_THRD); + *ptr = (long) vmm_getFreeVirtualPage(_current->id,count,VM_THRD,-1); else - *ptr = (long) vmmGetFreeVirtualPage(_current->id,count,VM_TASK); + *ptr = (long) vmm_getFreeVirtualPage(_current->id,count,VM_TASK,-1); } return; } @@ -256,6 +256,8 @@ } /*** + $Log$ + END ***/ diff --git a/src/sys/vmm/getfreekernelpage.c b/src/sys/vmm/getfreekernelpage.c index ee076f2..6e6e6de 100644 --- a/src/sys/vmm/getfreekernelpage.c +++ b/src/sys/vmm/getfreekernelpage.c @@ -51,10 +51,6 @@ int c = 0; u_int32_t *pageTableSrc = 0x0; - #ifdef VMMDEBUG - kprintf("vmm_getFreeKErnelPage"); - #endif - spinLock(&vmmGFPlock); /* Lets Search For A Free Page */ @@ -111,6 +107,9 @@ /*** $Log$ + Revision 1.3 2009/07/08 21:20:13 reddawg + Getting There + Revision 1.2 2009/07/08 16:05:56 reddawg Sync diff --git a/src/sys/vmm/getphysicaladdr.c b/src/sys/vmm/getphysicaladdr.c index fc850e9..7b55994 100644 --- a/src/sys/vmm/getphysicaladdr.c +++ b/src/sys/vmm/getphysicaladdr.c @@ -43,10 +43,6 @@ int pageTableIndex = 0x0; u_int32_t *pageTable = 0x0; -#ifdef VMMDEBUG - kprintf("vmm_getPhysicalAddr"); -#endif - //Calculate The Page Directory Index pageDirectoryIndex = PDI(pageAddr); @@ -61,6 +57,9 @@ /*** $Log$ + Revision 1.3 2009/07/08 21:20:13 reddawg + Getting There + Revision 1.2 2009/07/08 16:05:56 reddawg Sync diff --git a/src/sys/vmm/pagefault.c b/src/sys/vmm/pagefault.c index 42c770d..6854725 100644 --- a/src/sys/vmm/pagefault.c +++ b/src/sys/vmm/pagefault.c @@ -89,7 +89,7 @@ src = (u_int32_t *)(memAddr & 0xFFFFF000); /* Allocate A Free Page For Destination */ /* USE vmInfo */ - dst = (u_int32_t *) vmmGetFreeVirtualPage(_current->id,1,0x1); + dst = (u_int32_t *) vmm_getFreeVirtualPage(_current->id,1,0x1,-1); /* Copy Memory */ for (i = 0;i < PAGE_ENTRIES;i++) { dst[i] = src[i]; @@ -135,6 +135,9 @@ /*** $Log$ + Revision 1.5 2009/07/08 21:20:13 reddawg + Getting There + Revision 1.4 2009/07/08 16:05:56 reddawg Sync diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 0cb542b..4280887 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -171,9 +171,8 @@ u_int32_t *pageTable = 0x0; short i = 0x0; -#ifdef VMMDEBUG -kprintf("vmm_remapPage"); -#endif + assert((sourceAddr & 0xFFF) == 0x0); + assert((destAddr & 0xFFF) == 0x0); if (sourceAddr == 0x0) K_PANIC("source == 0x0"); @@ -456,7 +455,7 @@ if (uap->fd == -1) { /* NEED ROUND PAGE */ - td->td_retval[0] = (int)vmmGetFreeVirtualPage(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK); + td->td_retval[0] = (int)vmm_getFreeVirtualPage(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK,-1); } else { #ifdef VMMDEBUG @@ -470,9 +469,9 @@ #endif getfd(td,&fd,uap->fd); if (uap->addr == 0x0) - tmp = (char *)vmmGetFreeVirtualPage(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK); + tmp = (char *)vmm_getFreeVirtualPage(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK,-1); else { - tmp = (char *)vmmGetFreeVirtualPage_new(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK,uap->addr); + tmp = (char *)vmm_getFreeVirtualPage(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK,(u_int32_t)uap->addr); } fd->offset = uap->pos; diff --git a/src/sys/vmm/vmm_virtual.c b/src/sys/vmm/vmm_virtual.c index ddf3e54..b926802 100644 --- a/src/sys/vmm/vmm_virtual.c +++ b/src/sys/vmm/vmm_virtual.c @@ -33,7 +33,8 @@ #include #include #include -#include +#include +#include int vmm_cleanVirtualSpace(u_int32_t addr) { int x = 0x0; @@ -41,6 +42,8 @@ u_int32_t *pageTableSrc = 0x0; u_int32_t *pageDir = 0x0; + assert((addr & 0xFFF) == 0x0); + pageDir = (u_int32_t *) PARENT_PAGEDIR_ADDR; #ifdef VMMDEBUG @@ -49,21 +52,25 @@ /* Loop through the users virtual space flushing out COW pages */ /* BUG memory leak this does not update COW counter on master page */ - for (x = (addr / (1024 * 4096)); x < 770; x++) { + for (x = PDI(addr); x < 770; x++) { if ((pageDir[x] & PAGE_PRESENT) == PAGE_PRESENT) { 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) { - //kprintf("COWi*"); + vmm_adjustCowCounter(pageTableSrc[y] & PAGE_UNMASK,-1); pageTableSrc[y] = 0x0; } else if ((pageTableSrc[y] & PAGE_STACK) == PAGE_STACK) { //pageTableSrc[y] = 0x0; - //kprintf("STACK: (%i:%i)",x,y); + #ifdef VMMDEBUG2 + kprintf("STACK: (%i:%i)",x,y); + #endif } else { - //kprintf("+"); + #ifdef VMMDEBUG2 + kprintf("[0x%X]",pageTableSrc[y] & PAGE_MASK); + #endif } } } @@ -90,11 +97,13 @@ ************************************************************************/ static spinLock_t fvpSpinLock = SPIN_LOCK_INITIALIZER; -void *vmmGetFreeVirtualPage(pidType pid, int count,int type) { - int x = 0, y = 0, c = 0; - u_int32_t *pageTableSrc = 0x0; - u_int32_t *pageDir = 0x0; - u_int32_t start_page = 0x0; +void *vmm_getFreeVirtualPage_old(pidType pid, int count,int type) { + int x = 0x0; + int y = 0x0; + int c = 0x0; + u_int32_t *pageTableSrc = 0x0; + u_int32_t *pageDir = 0x0; + u_int32_t start_page = 0x0; spinLock(&fvpSpinLock); @@ -121,7 +130,7 @@ else K_PANIC("Invalid Type"); - for (x = (start_page / (1024 * 4096)); x < 1024; x++) { + for (x = PDI(start_page); x < 1024; x++) { /* Set Page Table Address */ if ((pageDir[x] & PAGE_PRESENT) != PAGE_PRESENT) { @@ -143,11 +152,8 @@ pageTableSrc = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * x)); - if (y != 0x0) { - for (y = 0x0;y < PAGE_ENTRIES;y++) { - pageTableSrc[y] = (u_int32_t)0x0; - } - } + if (y != 0x0) + vmm_zeroVirtualPage((u_int32_t)pageTableSrc); for (y = 0; y < 1024; y++) { @@ -231,7 +237,7 @@ return (0x0); } /* end func */ -void *vmmGetFreeVirtualPage_new(pidType pid, int count,int type,u_int32_t start_addr) { +void *vmm_getFreeVirtualPage(pidType pid, int count,int type,u_int32_t start_addr) { int x = 0, y = 0, c = 0; u_int32_t *pageTableSrc = 0x0; u_int32_t *pageDir = 0x0; @@ -256,10 +262,14 @@ else K_PANIC("Invalid Type"); -start_page = start_addr; + if (start_addr != -1) { + start_page = start_addr; + #ifdef VMM_DEBUG + kprintf("Start_ADDR"); + #endif + } - //for (x = ((_current->td.vm_daddr + _current->td.vm_dsize) / (1024 * 4096)); x < 1024; x++) { - for (x = (start_page / (1024 * 4096)); x < 1024; x++) { + for (x = PDI(start_page); x < 1024; x++) { /* Set Page Table Address */ if ((pageDir[x] & PAGE_PRESENT) != PAGE_PRESENT) { /* If Page Table Is Non Existant Then Set It Up */ @@ -367,20 +377,26 @@ ************************************************************************/ static spinLock_t cvsSpinLock = SPIN_LOCK_INITIALIZER; -void *vmmCopyVirtualSpace(pidType pid) { - void *newPageDirectoryAddress = 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; +void *vmm_copyVirtualSpace(pidType pid) { + void *newPageDirectoryAddress = 0x0; + u_int32_t *parentPageDirectory = 0x0; + u_int32_t *newPageDirectory = 0x0; + u_int32_t *parentPageTable = 0x0; + u_int32_t *newPageTable = 0x0; + u_int32_t *parentStackPage = 0x0; + u_int32_t *newStackPage = 0x0; + u_int16_t x = 0x0; + u_int16_t i = 0x0; + u_int16_t s = 0x0; spinLock(&cvsSpinLock); /* Set Address Of Parent Page Directory */ parentPageDirectory = (u_int32_t *) PARENT_PAGEDIR_ADDR; + /* Allocate A New Page For The New Page Directory */ - if ((newPageDirectory = (u_int32_t *) vmm_getFreeKernelPage(pid,1)) == 0x0) - kpanic("Error: newPageDirectory == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + if ((newPageDirectory = (u_int32_t *)vmm_getFreeKernelPage(pid,1)) == 0x0) + K_PANIC("Error: newPageDirectory == NULL"); /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((u_int32_t) newPageDirectory); @@ -615,5 +631,7 @@ } /* End Func */ /* + $Log$ + END */