diff --git a/.cproject b/.cproject index c611a22..fb3afd4 100644 --- a/.cproject +++ b/.cproject @@ -5,6 +5,7 @@ + @@ -15,55 +16,55 @@ - - - - - + + + + + + + - - - - - - - + + + + + - - - - - @@ -84,6 +85,9 @@ + + + @@ -98,8 +102,11 @@ - - - + + + + + + diff --git a/include/sys/_types.h b/include/sys/_types.h index c998ff6..f9ea7b9 100644 --- a/include/sys/_types.h +++ b/include/sys/_types.h @@ -29,30 +29,27 @@ #ifndef _SYS__TYPES_H_ #define _SYS__TYPES_H_ -typedef char __int8_t; -typedef unsigned char __uint8_t; -typedef short __int16_t; -typedef unsigned short __uint16_t; -typedef int __int32_t; -typedef unsigned int __uint32_t; -typedef long long __int64_t; -typedef unsigned long long __uint64_t; +#include +#include -typedef unsigned long __clock_t; -typedef __uint32_t __ino_t; typedef __int32_t __ssize_t;/* stat types */ +typedef __uint32_t __ino_t; typedef __uint32_t __dev_t;/* device number */ -typedef __uint16_t __mode_t; typedef __uint16_t __nlink_t;/* link count */ -typedef __uint32_t __uid_t; typedef __uint32_t __gid_t; typedef __int32_t __time_t; typedef __int64_t __blkcnt_t;/* file block count */ +typedef __uint16_t __mode_t; +typedef __uint16_t __nlink_t;/* link count */ +typedef __uint32_t __uid_t; +typedef __uint32_t __gid_t; +typedef __int32_t __time_t; +typedef __int64_t __blkcnt_t;/* file block count */ typedef __uint32_t __blksize_t;/* file block size */ typedef __uint32_t __fflags_t;/* file flags */ -typedef __int8_t __int_fast8_t; typedef __uint8_t __uint_fast8_t; typedef __int16_t __int_fast16_t; typedef __uint16_t __uint_fast16_t; typedef __int32_t __int_fast32_t; typedef __uint32_t __uint_fast32_t; typedef __int64_t __int_fast64_t; typedef __uint64_t __uint_fast64_t; typedef __int32_t __intptr_t; typedef __uint32_t __uintptr_t; typedef __uint32_t __uintfptr_t; typedef __uint32_t __size_t; typedef __int64_t __intmax_t; typedef __uint64_t __uintmax_t; typedef __int32_t __ptrdiff_t; typedef __uint8_t __uint_least8_t; typedef __uint16_t __uint_least16_t; typedef __uint32_t __uint_least32_t; typedef __uint64_t __uint_least64_t; typedef __int8_t __int_least8_t; typedef __int16_t __int_least16_t; typedef __int32_t __int_least32_t; typedef __int64_t __int_least64_t; typedef -int ___wchar_t; +typedef int ___wchar_t; typedef long __suseconds_t; /* microseconds (signed) */ typedef __int32_t __pid_t;/* process [group] */ #if !defined(__clang__) || !defined(__cplusplus) -typedef __uint_least16_t __char16_t; typedef __uint_least32_t __char32_t; +typedef __uint_least16_t __char16_t; +typedef __uint_least32_t __char32_t; #endif -#endif +#endif /* !_SYS__TYPES_H_ */ diff --git a/include/sys/types.h b/include/sys/types.h index 4020cce..806fcd6 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -30,7 +30,7 @@ #define _SYS_TYPES_H_ #include -#include +// XXX #include #ifndef NULL #define NULL 0x0 @@ -40,6 +40,9 @@ typedef char *caddr_t; +/* POSIX integrals that should only appear only in */ +#include + /* unsigned integrals */ typedef __uint8_t uint8_t; typedef __uint16_t uint16_t; diff --git a/include/ubixos/spinlock.h b/include/ubixos/spinlock.h index 2ebfa2a..d5eff8c 100644 --- a/include/ubixos/spinlock.h +++ b/include/ubixos/spinlock.h @@ -26,21 +26,19 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _UBIXOS_SPINLOCK_H -#define _UBIXOS_SPINLOCK_H +#ifndef _UBIXOS_SPINLOCK_H_ +#define _UBIXOS_SPINLOCK_H_ #include #define LOCKED 1 #define UNLOCKED 0 -#define SPIN_LOCK_INITIALIZER {NULL, 0} +#define SPIN_LOCK_INITIALIZER { 0x0, 0x0 } #define LLOCK_FLAG 1 -//typedef volatile int spinLock_t; - struct spinLock { - struct spinLock *next; - uint32_t locked; + struct spinLock *next; + u_int32_t locked; }; typedef struct spinLock *spinLock_t; @@ -58,39 +56,39 @@ /* Atomic exchange (of various sizes) */ static inline u_long xchg_64(volatile uint32_t *ptr, u_long x) { - __asm__ __volatile__("xchgq %1,%0" - :"+r" (x), - "+m" (*ptr)); + __asm__ __volatile__("xchgq %1,%0" + :"+r" (x), + "+m" (*ptr)); - return x; + return x; } static inline unsigned xchg_32(volatile uint32_t *ptr, uint32_t x) { - __asm__ __volatile__("xchgl %1,%0" - :"+r" (x), - "+m" (*ptr)); + __asm__ __volatile__("xchgl %1,%0" + :"+r" (x), + "+m" (*ptr)); - return x; + return x; } static inline unsigned short xchg_16(volatile uint32_t *ptr, uint16_t x) { - __asm__ __volatile__("xchgw %1,%0" - :"+r" (x), - "+m" (*ptr)); + __asm__ __volatile__("xchgw %1,%0" + :"+r" (x), + "+m" (*ptr)); - return x; + return x; } /* Test and set a bit */ static inline char atomic_bitsetandtest(void *ptr, int x) { - char out; - __asm__ __volatile__("lock; bts %2,%1\n" - "sbb %0,%0\n" - :"=r" (out), "=m" (*(volatile long long *)ptr) - :"Ir" (x) - :"memory"); + char out; + __asm__ __volatile__("lock; bts %2,%1\n" + "sbb %0,%0\n" + :"=r" (out), "=m" (*(volatile long long *)ptr) + :"Ir" (x) + :"memory"); - return out; + return out; } -#endif +#endif /* !_UBIXOS_SPINLOCK_H_ */ diff --git a/include_old/machine/_types.h b/include_old/machine/_types.h index d57eb23..84c2324 100644 --- a/include_old/machine/_types.h +++ b/include_old/machine/_types.h @@ -1,72 +1,46 @@ /*- - * Copyright (c) 2002 Mike Barcroft - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2002-2018 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: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * This was developed by Christopher W. Olsen for the UbixOS Project. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: * - * From: @(#)ansi.h 8.2 (Berkeley) 1/4/94 - * From: @(#)types.h 8.3 (Berkeley) 1/5/94 - * $FreeBSD: src/sys/i386/include/_types.h,v 1.7 2003/03/30 05:24:52 jake Exp $ + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) 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. + * 3) 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 AUTHOR 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. */ #ifndef _MACHINE__TYPES_H_ #define _MACHINE__TYPES_H_ -/* - * Basic types upon which most other types are built. - */ +// Basic types upon which most other types are built. typedef __signed char __int8_t; typedef unsigned char __uint8_t; -typedef short __int16_t; +typedef short __int16_t; typedef unsigned short __uint16_t; -typedef int __int32_t; +typedef int __int32_t; typedef unsigned int __uint32_t; - -#if defined(lint) -/* LONGLONG */ -typedef long long __int64_t; -/* LONGLONG */ +typedef long long __int64_t; typedef unsigned long long __uint64_t; -#elif defined(__GNUC__) -typedef int __attribute__((__mode__(__DI__))) __int64_t; -typedef unsigned int __attribute__((__mode__(__DI__))) __uint64_t; -#else -/* LONGLONG */ -typedef long long __int64_t; -/* LONGLONG */ -typedef unsigned long long __uint64_t; -#endif -/* - * Standard type definitions. - */ +// Standard type definitions. + typedef unsigned long __clock_t; /* clock()... */ typedef __int32_t __critical_t; typedef double __double_t; @@ -102,25 +76,8 @@ typedef __uint32_t __u_register_t; typedef __uint32_t __vm_offset_t; typedef __int64_t __vm_ooffset_t; -#ifdef PAE -typedef __uint64_t __vm_paddr_t; -#else typedef __uint32_t __vm_paddr_t; -#endif typedef __uint64_t __vm_pindex_t; typedef __uint32_t __vm_size_t; -/* - * Unusual type definitions. - */ -#if defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ > 95 || __GNUC__ >= 3) -typedef __builtin_va_list __va_list; /* internally known to gcc */ -#else -typedef char * __va_list; -#endif /* post GCC 2.95 */ -#if defined __GNUC__ && !defined(__GNUC_VA_LIST) && !defined(__NO_GNUC_VA_LIST) -#define __GNUC_VA_LIST -typedef __va_list __gnuc_va_list; /* compatibility w/GNU headers*/ -#endif - #endif /* !_MACHINE__TYPES_H_ */ diff --git a/sys/vmm/copyvirtualspace.c b/sys/vmm/copyvirtualspace.c index dba354b..78936c1 100644 --- a/sys/vmm/copyvirtualspace.c +++ b/sys/vmm/copyvirtualspace.c @@ -31,7 +31,6 @@ #include #include #include -#include static struct spinLock cvsSpinLock = SPIN_LOCK_INITIALIZER; @@ -50,227 +49,259 @@ ************************************************************************/ void *vmm_copyVirtualSpace(pidType pid) { - void *newPageDirectoryAddress = 0x0; + void *newPageDirectoryAddress = 0x0; - uint32_t *parentPageDirectory = 0x0, *newPageDirectory = 0x0; - uint32_t *parentPageTable = 0x0, *newPageTable = 0x0; - uint32_t *parentStackPage = 0x0, *newStackPage = 0x0; - uint16_t x = 0, i = 0, s = 0; + uint32_t *parentPageDirectory = 0x0, *newPageDirectory = 0x0; + uint32_t *parentPageTable = 0x0, *newPageTable = 0x0; + uint32_t *parentStackPage = 0x0, *newStackPage = 0x0; + uint16_t x = 0, i = 0, s = 0; - spinLock(&cvsSpinLock); + spinLock(&cvsSpinLock); - /* Set Address Of Parent Page Directory */ - parentPageDirectory = (uint32_t *) PD_BASE_ADDR; + /* Set Address Of Parent Page Directory */ + parentPageDirectory = (uint32_t *) PD_BASE_ADDR; - /* Allocate A New Page For The New Page Directory */ - if ((newPageDirectory = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) - kpanic("Error: newPageDirectory == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); + /* Allocate A New Page For The New Page Directory */ + if ((newPageDirectory = (uint32_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_t) newPageDirectory); + /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ + newPageDirectoryAddress = (void *) vmm_getPhysicalAddr( + (uint32_t) newPageDirectory); - /* First Set Up A Flushed Page Directory */ - bzero(newPageDirectory, PAGE_SIZE); + /* First Set Up A Flushed Page Directory */ + bzero(newPageDirectory, PAGE_SIZE); - /* Map Kernel Code Region Entries 0 & 1 */ - newPageDirectory[0] = parentPageDirectory[0]; - //XXX: We Dont Need This - newPageDirectory[1] = parentPageDirectory[1]; + /* Map Kernel Code Region Entries 0 & 1 */ + newPageDirectory[0] = parentPageDirectory[0]; + //XXX: We Dont Need This - newPageDirectory[1] = parentPageDirectory[1]; - if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) - kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); + if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", __FILE__, + __LINE__); - parentPageTable = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * 1)); + parentPageTable = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * 1)); - for (x = 0; x < PT_ENTRIES; x++) { - if (((parentPageTable[x]) & PAGE_PRESENT) == PAGE_PRESENT) { + for (x = 0; x < PT_ENTRIES; x++) { + if (((parentPageTable[x]) & PAGE_PRESENT) == PAGE_PRESENT) { - /* Set Page To COW In Parent And Child Space */ - newPageTable[x] = (((uint32_t) parentPageTable[x] & 0xFFFFF000) | (KERNEL_PAGE_DEFAULT | PAGE_COW)); + /* Set Page To COW In Parent And Child Space */ + newPageTable[x] = (((uint32_t) parentPageTable[x] & 0xFFFFF000) + | (KERNEL_PAGE_DEFAULT | PAGE_COW)); - /* Increment The COW Counter For This Page */ - if (((uint32_t) parentPageTable[x] & PAGE_COW) == PAGE_COW) { - adjustCowCounter(((uint32_t) parentPageTable[x] & 0xFFFFF000), 1); - } - else { - /* Add Two If This Is The First Time Setting To COW */ - adjustCowCounter(((uint32_t) parentPageTable[x] & 0xFFFFF000), 2); - parentPageTable[x] |= PAGE_COW; // newPageTable[i]; - } + /* Increment The COW Counter For This Page */ + if (((uint32_t) parentPageTable[x] & PAGE_COW) == PAGE_COW) { + adjustCowCounter(((uint32_t) parentPageTable[x] & 0xFFFFF000), + 1); + } else { + /* Add Two If This Is The First Time Setting To COW */ + adjustCowCounter(((uint32_t) parentPageTable[x] & 0xFFFFF000), + 2); + parentPageTable[x] |= PAGE_COW; // newPageTable[i]; + } - } - else - newPageTable[x] = parentPageTable[x]; - } + } else + newPageTable[x] = parentPageTable[x]; + } - newPageDirectory[1] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | KERNEL_PAGE_DEFAULT); + newPageDirectory[1] = (vmm_getPhysicalAddr((uint32_t) newPageTable) + | KERNEL_PAGE_DEFAULT); - vmm_unmapPage((uint32_t) newPageTable, 1); + vmm_unmapPage((uint32_t) newPageTable, 1); - newPageTable = 0x0; + newPageTable = 0x0; - /* Map The Kernel Memory Region Entry 770 Address 0xC0800000 */ - for (x = PD_INDEX(VMM_KERN_START); x <= PD_INDEX(VMM_KERN_END); x++) - newPageDirectory[x] = parentPageDirectory[x]; + /* Map The Kernel Memory Region Entry 770 Address 0xC0800000 */ + for (x = PD_INDEX(VMM_KERN_START); x <= PD_INDEX(VMM_KERN_END); x++) + newPageDirectory[x] = parentPageDirectory[x]; - /* Map The Kernel Stack Region */ - for (x = PD_INDEX(VMM_KERN_STACK_START); x <= PD_INDEX(VMM_KERN_STACK_END); x++) { - if ((parentPageDirectory[x] & PAGE_PRESENT) == PAGE_PRESENT) { - /* Set Parent To Propper Page Table */ - parentPageTable = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * x)); + /* Map The Kernel Stack Region */ + for (x = PD_INDEX(VMM_KERN_STACK_START); x <= PD_INDEX(VMM_KERN_STACK_END); + x++) { + if ((parentPageDirectory[x] & PAGE_PRESENT) == PAGE_PRESENT) { + /* Set Parent To Propper Page Table */ + parentPageTable = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * x)); - /* Allocate A New Page Table */ - if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) - kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); + /* Allocate A New Page Table */ + if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) + == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", + __FILE__, __LINE__); - bzero(newPageTable, PAGE_SIZE); + bzero(newPageTable, PAGE_SIZE); - for (i = 0; i < PT_ENTRIES; i++) { - if ((parentPageTable[i] & PAGE_PRESENT) == PAGE_PRESENT) { + for (i = 0; i < PT_ENTRIES; i++) { + if ((parentPageTable[i] & PAGE_PRESENT) == PAGE_PRESENT) { - /* Alloc A New Page For This Stack Page */ - if ((newStackPage = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) - kpanic("Error: newStackPage == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); + /* Alloc A New Page For This Stack Page */ + if ((newStackPage = (uint32_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_t *) (((PAGE_SIZE * PD_ENTRIES) * x) + (PAGE_SIZE * i)); + /* Set Pointer To Parents Stack Page */ + parentStackPage = (uint32_t *) (((PAGE_SIZE * PD_ENTRIES) + * x) + (PAGE_SIZE * i)); - /* Copy The Stack Byte For Byte (I Should Find A Faster Way) */ - memcpy(newStackPage, parentStackPage, PAGE_SIZE); + /* Copy The Stack Byte For Byte (I Should Find A Faster Way) */ + memcpy(newStackPage, parentStackPage, PAGE_SIZE); - /* Insert New Stack Into Page Table */ - newPageTable[i] = (vmm_getPhysicalAddr((uint32_t) newStackPage) | PAGE_DEFAULT | PAGE_STACK); + /* Insert New Stack Into Page Table */ + newPageTable[i] = + (vmm_getPhysicalAddr((uint32_t) newStackPage) + | PAGE_DEFAULT | PAGE_STACK); - /* Unmap From Kernel Space */ - vmm_unmapPage((uint32_t) newStackPage, 1); - } - } - /* Put New Page Table Into New Page Directory */ - newPageDirectory[x] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); - /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ - vmm_unmapPage((uint32_t) newPageTable, 1); - } - } + /* Unmap From Kernel Space */ + vmm_unmapPage((uint32_t) newStackPage, 1); + } + } + /* Put New Page Table Into New Page Directory */ + newPageDirectory[x] = (vmm_getPhysicalAddr((uint32_t) newPageTable) + | PAGE_DEFAULT); + /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ + vmm_unmapPage((uint32_t) newPageTable, 1); + } + } - /* - * Now For The Fun Stuff For Page Tables 2-767 We Must Map These And Set - * The Permissions On Every Mapped Pages To COW This Will Conserve Memory - * Because The Two VM Spaces Will Be Sharing Pages Unless an EXECVE Happens - * - * We start at the 4MB boundary as the first 4MB is special - */ + /* + * Now For The Fun Stuff For Page Tables 2-767 We Must Map These And Set + * The Permissions On Every Mapped Pages To COW This Will Conserve Memory + * Because The Two VM Spaces Will Be Sharing Pages Unless an EXECVE Happens + * + * We start at the 4MB boundary as the first 4MB is special + */ - for (x = PD_INDEX(VMM_USER_START); x <= PD_INDEX(VMM_USER_END); x++) { + for (x = PD_INDEX(VMM_USER_START); x <= PD_INDEX(VMM_USER_END); x++) { - /* If Page Table Exists Map It */ - if ((parentPageDirectory[x] & PAGE_PRESENT) == PAGE_PRESENT) { + /* If Page Table Exists Map It */ + if ((parentPageDirectory[x] & PAGE_PRESENT) == PAGE_PRESENT) { - /* Set Parent To Propper Page Table */ - parentPageTable = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * x)); + /* Set Parent To Propper Page Table */ + parentPageTable = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * x)); - /* Allocate A New Page Table */ - if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) - kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); + /* Allocate A New Page Table */ + if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) + == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", + __FILE__, __LINE__); - bzero(newPageTable, PAGE_SIZE); + bzero(newPageTable, PAGE_SIZE); - /* Set Parent And New Pages To COW */ - for (i = 0; i < PD_ENTRIES; i++) { + /* Set Parent And New Pages To COW */ + for (i = 0; i < PD_ENTRIES; i++) { - /* If Page Is Mapped */ - if ((parentPageTable[i] & PAGE_PRESENT) == PAGE_PRESENT) { + /* If Page Is Mapped */ + if ((parentPageTable[i] & PAGE_PRESENT) == PAGE_PRESENT) { - /* Check To See If Its A Stack Page */ - if (((uint32_t) parentPageTable[i] & PAGE_STACK) == PAGE_STACK) { + /* Check To See If Its A Stack Page */ + if (((uint32_t) parentPageTable[i] & PAGE_STACK) + == PAGE_STACK) { - /* Alloc A New Page For This Stack Page */ - if ((newStackPage = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) - kpanic("Error: newStackPage == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); + /* Alloc A New Page For This Stack Page */ + if ((newStackPage = (uint32_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_t *) (((PAGE_SIZE * PD_ENTRIES) * x) + (PAGE_SIZE * i)); + /* Set Pointer To Parents Stack Page */ + parentStackPage = + (uint32_t *) (((PAGE_SIZE * PD_ENTRIES) * x) + + (PAGE_SIZE * i)); - /* Copy The Stack Byte For Byte (I Should Find A Faster Way) */ - memcpy(newStackPage, parentStackPage, PAGE_SIZE); + /* Copy The Stack Byte For Byte (I Should Find A Faster Way) */ + memcpy(newStackPage, parentStackPage, PAGE_SIZE); - /* Insert New Stack Into Page Table */ - newPageTable[i] = (vmm_getPhysicalAddr((uint32_t) newStackPage) | PAGE_DEFAULT | PAGE_STACK); + /* Insert New Stack Into Page Table */ + newPageTable[i] = (vmm_getPhysicalAddr( + (uint32_t) newStackPage) | PAGE_DEFAULT + | PAGE_STACK); - /* Unmap From Kernel Space */ - vmm_unmapPage((uint32_t) newStackPage, 1); + /* Unmap From Kernel Space */ + vmm_unmapPage((uint32_t) newStackPage, 1); - } - else { + } else { - /* Set Page To COW In Parent And Child Space */ - newPageTable[i] = (((uint32_t) parentPageTable[i] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); + /* Set Page To COW In Parent And Child Space */ + newPageTable[i] = (((uint32_t) parentPageTable[i] + & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); - /* Increment The COW Counter For This Page */ - if (((uint32_t) parentPageTable[i] & PAGE_COW) == PAGE_COW) { - adjustCowCounter(((uint32_t) parentPageTable[i] & 0xFFFFF000), 1); - } - else { - /* Add Two If This Is The First Time Setting To COW */ - adjustCowCounter(((uint32_t) parentPageTable[i] & 0xFFFFF000), 2); - parentPageTable[i] |= PAGE_COW; // newPageTable[i]; - } - } - } - else { - newPageTable[i] = (uint32_t) 0x0; - } - } + /* Increment The COW Counter For This Page */ + if (((uint32_t) parentPageTable[i] & PAGE_COW) + == PAGE_COW) { + adjustCowCounter( + ((uint32_t) parentPageTable[i] & 0xFFFFF000), + 1); + } else { + /* Add Two If This Is The First Time Setting To COW */ + adjustCowCounter( + ((uint32_t) parentPageTable[i] & 0xFFFFF000), + 2); + parentPageTable[i] |= PAGE_COW; // newPageTable[i]; + } + } + } else { + newPageTable[i] = (uint32_t) 0x0; + } + } - /* Put New Page Table Into New Page Directory */ - newPageDirectory[x] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); - /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ - vmm_unmapPage((uint32_t) newPageTable, 1); - } - } + /* Put New Page Table Into New Page Directory */ + newPageDirectory[x] = (vmm_getPhysicalAddr((uint32_t) newPageTable) + | PAGE_DEFAULT); + /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ + vmm_unmapPage((uint32_t) newPageTable, 1); + } + } - /* - * Allocate A New Page For The The First Page Table Where We Will Map The - * Lower Region First 4MB - */ + /* + * Allocate A New Page For The The First Page Table Where We Will Map The + * Lower Region First 4MB + */ - /* - * - * Map Page Directory Into VM Space - * First Page After Page Tables - * This must be mapped into the page directory before we map all 1024 page directories into the memory space - */ - newPageTable = (uint32_t *) vmm_getFreePage(pid); + /* + * + * Map Page Directory Into VM Space + * First Page After Page Tables + * This must be mapped into the page directory before we map all 1024 page directories into the memory space + */ + newPageTable = (uint32_t *) vmm_getFreePage(pid); - newPageDirectory[PD_INDEX(PD_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); + newPageDirectory[PD_INDEX(PD_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr( + (uint32_t) newPageTable) | PAGE_DEFAULT); - newPageTable[0] = (uint32_t) ((uint32_t) (newPageDirectoryAddress) | PAGE_DEFAULT); + newPageTable[0] = (uint32_t) ((uint32_t) (newPageDirectoryAddress) + | PAGE_DEFAULT); - vmm_unmapPage((uint32_t) newPageTable, 1); + vmm_unmapPage((uint32_t) newPageTable, 1); - /* - * - * Map Page Tables Into VM Space - * The First Page Table (4MB) Maps To All Page Directories - * - */ + /* + * + * Map Page Tables Into VM Space + * The First Page Table (4MB) Maps To All Page Directories + * + */ - newPageTable = (uint32_t *) vmm_getFreePage(pid); + newPageTable = (uint32_t *) vmm_getFreePage(pid); - newPageDirectory[PD_INDEX(PT_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); + newPageDirectory[PD_INDEX(PT_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr( + (uint32_t) newPageTable) | PAGE_DEFAULT); - /* Flush The Page From Garbage In Memory */ - bzero(newPageTable, PAGE_SIZE); + /* Flush The Page From Garbage In Memory */ + bzero(newPageTable, PAGE_SIZE); - for (x = 0; x < PD_ENTRIES; x++) - newPageTable[x] = newPageDirectory[x]; + for (x = 0; x < PD_ENTRIES; x++) + newPageTable[x] = newPageDirectory[x]; - /* Unmap Page From Virtual Space */ - vmm_unmapPage((uint32_t) newPageTable, 1); + /* Unmap Page From Virtual Space */ + vmm_unmapPage((uint32_t) newPageTable, 1); - /* Now We Are Done With The Page Directory So Lets Unmap That Too */ - vmm_unmapPage((uint32_t) newPageDirectory, 1); + /* Now We Are Done With The Page Directory So Lets Unmap That Too */ + vmm_unmapPage((uint32_t) newPageDirectory, 1); - spinUnlock(&cvsSpinLock); + spinUnlock(&cvsSpinLock); - /* Return Physical Address Of Page Directory */ - return (newPageDirectoryAddress); + /* Return Physical Address Of Page Directory */ + return (newPageDirectoryAddress); }