Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


updated test_vm
[palacios.git] / misc / test_vm / include / geekos / paging.h
1 /*
2  * Paging (virtual memory) support
3  * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
4  * Copyright (c) 2003,2004 David H. Hovemeyer <daveho@cs.umd.edu>
5  * $Revision: 1.2 $
6  * 
7  * This is free software.  You are permitted to use,
8  * redistribute, and modify it as specified in the file "COPYING".
9  */
10
11 #ifndef GEEKOS_PAGING_H
12 #define GEEKOS_PAGING_H
13
14 #include <geekos/ktypes.h>
15 #include <geekos/defs.h>
16 #include <geekos/bootinfo.h>
17 #include <geekos/list.h>
18
19 struct Page;
20 struct User_Context;
21
22 #define NUM_PAGE_TABLE_ENTRIES  1024
23 #define NUM_PAGE_DIR_ENTRIES    1024
24
25 #define PAGE_DIRECTORY_INDEX(x) ((((uint_t)x) >> 22) & 0x3ff)
26 #define PAGE_TABLE_INDEX(x)     ((((uint_t)x) >> 12) & 0x3ff)
27 #define PAGE_OFFSET(x)          ((((uint_t)x) & 0xfff))
28
29 #define PAGE_ALLIGNED_ADDR(x)   (((uint_t) (x)) >> 12)
30 #define PAGE_ADDR(x)   (PAGE_ALLIGNED_ADDR(x) << 12)
31
32 /*
33  * Bits for flags field of pde_t and pte_t.
34  */
35 #define VM_WRITE   1     /* Memory is writable */
36 #define VM_USER    2     /* Memory is accessible to user code */
37 #define VM_NOCACHE 8     /* Memory should not be cached */
38 #define VM_READ    0     /* Memory can be read (ignored for x86) */
39 #define VM_EXEC    0     /* Memory can be executed (ignored for x86) */
40
41
42 /*
43  * Page directory entry datatype.
44  * If marked as present, it specifies the physical address
45  * and permissions of a page table.
46  */
47 typedef struct {
48     uint_t present:1;
49     uint_t flags:4;
50     uint_t accessed:1;
51     uint_t reserved:1;
52     uint_t largePages:1;
53     uint_t globalPage:1;
54     uint_t kernelInfo:3;
55     uint_t pageTableBaseAddr:20;
56 } pde_t;
57
58 /*
59  * Page table entry datatype.
60  * If marked as present, it specifies the physical address
61  * and permissions of a page of memory.
62  */
63 typedef struct {
64     uint_t present:1;
65     uint_t flags:4;
66     uint_t accessed:1;
67     uint_t dirty:1;
68     uint_t pteAttribute:1;
69     uint_t globalPage:1;
70     uint_t kernelInfo:3;
71     uint_t pageBaseAddr:20;
72 } pte_t;
73
74 /*
75  * Datatype representing the hardware error code
76  * pushed onto the stack by the processor on a page fault.
77  * The error code is stored in the "errorCode" field
78  * of the Interrupt_State struct.
79  */
80 typedef struct {
81     uint_t protectionViolation:1;
82     uint_t writeFault:1;
83     uint_t userModeFault:1;
84     uint_t reservedBitFault:1;
85     uint_t reserved:28;
86 } faultcode_t;
87
88 /*
89  * Bits used in the kernelInfo field of the PTE's:
90  */
91 #define KINFO_PAGE_ON_DISK      0x4      /* Page not present; contents in paging file */
92
93 void Init_VM(struct Boot_Info *bootInfo);
94 void Init_Paging(void);
95
96 extern void Flush_TLB(void);
97 extern void Set_PDBR(pde_t *pageDir);
98 extern pde_t *Get_PDBR(void);
99 extern void Enable_Paging(pde_t *pageDir);
100 extern void Invalidate_PG(void * addr);
101
102 /*
103  * Return the address that caused a page fault.
104  */
105 static __inline__ ulong_t Get_Page_Fault_Address(void)
106 {
107     ulong_t faultAddress;
108     __asm__ __volatile__ (
109         "mov %%cr2, %0"
110         : "=r" (faultAddress)
111     );
112     return faultAddress;
113 }
114
115 void PrintPD(pde_t *pde);
116 void PrintPT(void *starting_address, pte_t *pte);
117 void PrintPDE(void *virtual_address, pde_t *pde);
118 void PrintPTE(void *virtual_address,pte_t *pte);
119 void DumpPageTables(pde_t *pde);
120
121 pte_t *LookupPage(void *vaddr);
122
123 pte_t *MapPage(void *vaddr, pte_t *pte, int alloc_pde);
124 pte_t *UnMapPage(void *vaddr);
125
126 int Find_Space_On_Paging_File(void);
127 void Free_Space_On_Paging_File(int pagefileIndex);
128 void Write_To_Paging_File(void *paddr, ulong_t vaddr, int pagefileIndex);
129 void Read_From_Paging_File(void *paddr, ulong_t vaddr, int pagefileIndex);
130
131
132 void VM_Test(struct Boot_Info *bootInfo, uint_t num_test_pages);
133
134 #endif