UbixOS V2  2.0
paging.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _VMM_PAGING_H_
30 #define _VMM_PAGING_H_
31 
32 #include <sys/types.h>
33 #include <sys/sysproto_posix.h>
34 #include <sys/thread.h>
35 
36 #define PAGE_SHIFT 12 // Page Shift
37 #define PAGE_SIZE 0x1000 // Page Size
38 #define PAGE_MASK (PAGE_SIZE-1) // Page Mask
39 
40 #define PD_INDEX(v_addr) (v_addr >> 22) // Calc Page Directory Index
41 #define PD_OFFSET(v_addr) (v_addr >> 0xA) // Calc Page Directory OFfset
42 #define PT_INDEX(v_addr) ((v_addr >> 12) & 0x03FF) // Calc Page Table Offset
43 #define PD_BASE_ADDR2 ((PAGE_SIZE << 0xA) + VMM_KERN_START) // Find Out What This Was For
44 
45 #define PD_BASE_ADDR 0xC0400000 // Page Directory Addressable Base Address
46 #define PT_BASE_ADDR 0xC0000000 // Page Table Addressable Base Address
47 
48 #define PD_ENTRIES (PAGE_SIZE/4) //Return Page Directory Entries
49 #define PT_ENTRIES (PAGE_SIZE/4) //Return Page Table Entries
50 
51 #define VM_THRD 0 // Thread
52 #define VM_TASK 1 // Task
53 
54 // Page Flags
55 #define PAGE_PRESENT 0x00000001
56 #define PAGE_WRITE 0x00000002
57 #define PAGE_USER 0x00000004
58 #define PAGE_WRITE_THROUGH 0x00000008
59 #define PAGE_CACHE_DISABLED 0x00000010
60 #define PAGE_ACCESSED 0x00000020
61 #define PAGE_DIRTY 0x00000040
62 #define PAGE_GLOBAL 0x00000080
63 #define PAGE_ 0x00000100
64 #define PAGE_COW 0x00000200
65 #define PAGE_STACK 0x00000400
66 #define PAGE_WIRED 0x00000800
67 
68 #define PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE|PAGE_USER)
69 #define KERNEL_PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE)
70 
71 #define trunc_page(x) ((x) & ~PAGE_MASK)
72 #define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK)
73 
74 #define ctob(x) ((x)<<PAGE_SHIFT)
75 #define btoc(x) (((vm_offset_t)(x)+PAGE_MASK)>>PAGE_SHIFT)
76 
77 int vmmClearVirtualPage(uint32_t pageAddr);
78 
79 void *vmm_mapFromTask(pidType, void *, uint32_t);
82 void *vmm_getFreeKernelPage(pidType pid, uint16_t count);
84 void *vmm_getFreeVirtualPage(pidType, int, int);
85 
89 int vmm_remapPage(uint32_t, uint32_t, uint16_t, pidType, int haveLock);
90 int vmm_pagingInit();
91 void *vmm_getFreeMallocPage(uint16_t count);
92 //void vmm_pageFault( uint32_t, uint32_t, uint32_t );
93 void vmm_pageFault(struct trapframe *, uint32_t);
94 void _vmm_pageFault();
95 int mmap(struct thread *, struct sys_mmap_args *);
96 int obreak(struct thread *, struct obreak_args *);
97 int munmap(struct thread *, struct sys_munmap_args *);
98 
100 void *vmm_getFreeVirtualPage(pidType pid, int count, int type);
101 
103 
104 #endif
vmm_cleanVirtualSpace
int vmm_cleanVirtualSpace(uint32_t)
Definition: paging.c:587
vmm_createVirtualSpace
void * vmm_createVirtualSpace(pidType)
Definition: createvirtualspace.c:53
sysproto_posix.h
thread
Definition: thread.h:40
vmm_getPhysicalAddr
uint32_t vmm_getPhysicalAddr(uint32_t)
Definition: getphysicaladdr.c:38
types.h
vmm_pagingInit
int vmm_pagingInit()
Definition: paging.c:58
uint16_t
__uint16_t uint16_t
Definition: types.h:45
vmm_getFreeVirtualPage
void * vmm_getFreeVirtualPage(pidType, int, int)
Definition: getfreevirtualpage.c:47
vmm_setPageAttributes
int vmm_setPageAttributes(uint32_t, uint16_t)
Definition: setpageattributes.c:39
vmm_pageFault
void vmm_pageFault(struct trapframe *, uint32_t)
Definition: pagefault.c:53
kernelPageDirectory
uint32_t * kernelPageDirectory
Definition: paging.c:41
vmmClearVirtualPage
int vmmClearVirtualPage(uint32_t pageAddr)
mmap
int mmap(struct thread *, struct sys_mmap_args *)
vmm_getRealAddr
uint32_t vmm_getRealAddr(uint32_t)
Definition: getphysicaladdr.c:56
vmm_remapPage
int vmm_remapPage(uint32_t, uint32_t, uint16_t, pidType, int haveLock)
Definition: paging.c:199
uint32_t
__uint32_t uint32_t
Definition: types.h:46
trapframe
Definition: trap.h:34
obreak_args
Definition: sysproto_posix.h:417
obreak
int obreak(struct thread *, struct obreak_args *)
Definition: paging.c:546
pidType
int pidType
Definition: types.h:75
vmm_copyVirtualSpace
void * vmm_copyVirtualSpace(pidType)
Definition: copyvirtualspace.c:51
vmm_getFreeMallocPage
void * vmm_getFreeMallocPage(uint16_t count)
vmm_getFreePage
void * vmm_getFreePage(pidType)
Definition: getfreepage.c:45
sys_mmap_args
Definition: sysproto_posix.h:378
_vmm_pageFault
void _vmm_pageFault()
vmm_getFreeKernelPage
void * vmm_getFreeKernelPage(pidType pid, uint16_t count)
Definition: paging.c:291
munmap
int munmap(struct thread *, struct sys_munmap_args *)
vmm_mapFromTask
void * vmm_mapFromTask(pidType, void *, uint32_t)
Definition: paging.c:372
thread.h
sys_munmap_args
Definition: sysproto_posix.h:439