comparison cos/kernel/kernel.h @ 30:0148f55bfe24

Added static asserts and fixed pages
author windel
date Thu, 29 Dec 2011 23:51:35 +0100
parents 7e3bdcb391dc
children 3a6a9b929db0
comparison
equal deleted inserted replaced
29:7e3bdcb391dc 30:0148f55bfe24
68 uint64_t accessed : 1; 68 uint64_t accessed : 1;
69 uint64_t ignored : 1; 69 uint64_t ignored : 1;
70 uint64_t ps : 1; // must be 0. 70 uint64_t ps : 1; // must be 0.
71 uint64_t ignored2 : 4; 71 uint64_t ignored2 : 4;
72 // 12 bits so far 72 // 12 bits so far
73 uint64_t address : 48; // address of page directory pointer table. 73 uint64_t address : 40; // address of page directory pointer table.
74 uint64_t ignored3 : 11; 74 uint64_t ignored3 : 11;
75 uint64_t xd : 1; // execute disable 75 uint64_t xd : 1; // execute disable
76 } PML4E_t; // 64 bits wide, PML4 table must be 4096 byte aligned. 76 } PML4E_t; // 64 bits wide, PML4 table must be 4096 byte aligned.
77 77
78 typedef struct 78 typedef struct
92 uint64_t accessed : 1; 92 uint64_t accessed : 1;
93 uint64_t ignored : 1; 93 uint64_t ignored : 1;
94 uint64_t ps : 1; // page size, must be 0, otherwise maps a 1 GB page. 94 uint64_t ps : 1; // page size, must be 0, otherwise maps a 1 GB page.
95 uint64_t ignored2 : 4; 95 uint64_t ignored2 : 4;
96 // 12 bits so far 96 // 12 bits so far
97 uint64_t address : 48; // address of page directory table. 97 uint64_t address : 40; // address of page directory table.
98 uint64_t ignored3 : 11; 98 uint64_t ignored3 : 11;
99 uint64_t xd : 1; // execute disable 99 uint64_t xd : 1; // execute disable
100 } PDPTE_t; // Page directory pointer table entry, 64 bits wide. 4-kB aligned. 100 } PDPTE_t; // Page directory pointer table entry, 64 bits wide. 4-kB aligned.
101 101
102 // Page directory pointer table: 102 // Page directory pointer table:
116 uint64_t accessed : 1; 116 uint64_t accessed : 1;
117 uint64_t ignored : 1; 117 uint64_t ignored : 1;
118 uint64_t ps : 1; // page size, must be 0, otherwise maps a 2-MB page. 118 uint64_t ps : 1; // page size, must be 0, otherwise maps a 2-MB page.
119 uint64_t ignored2 : 4; 119 uint64_t ignored2 : 4;
120 // 12 bits so far 120 // 12 bits so far
121 uint64_t address : 48; // address of page table. 121 uint64_t address : 40; // address of page table.
122 uint64_t ignored3 : 11; 122 uint64_t ignored3 : 11;
123 uint64_t xd : 1; // execute disable 123 uint64_t xd : 1; // execute disable
124 } PDE_t; 124 } PDE_t;
125 125
126 // Page directory: 126 // Page directory:
128 { 128 {
129 PDE_t table[512]; 129 PDE_t table[512];
130 uint64_t physicalAddress; 130 uint64_t physicalAddress;
131 } PD_t; 131 } PD_t;
132 132
133 typedef struct 133
134 { 134 typedef struct
135 uint64_t present : 1; 135 {
136 unsigned present : 1;
136 uint64_t rw : 1; 137 uint64_t rw : 1;
137 uint64_t us : 1; // user or supervisor 138 uint64_t us : 1; // user or supervisor
138 uint64_t pwt : 1; 139 uint64_t pwt : 1;
139 uint64_t pcd : 1; // page cache disable 140 uint64_t pcd : 1; // page cache disable
140 uint64_t accessed : 1; 141 uint64_t accessed : 1;
141 uint64_t dirty : 1; 142 uint64_t dirty : 1;
142 uint64_t pat : 1; // memory type? 143 uint64_t pat : 1; // memory type?
143 uint64_t g : 1; // Global? 144 uint64_t g : 1; // Global?
144 uint64_t ignored : 3; 145 uint64_t ignored : 3;
145 146
146 uint64_t address : 48; 147 uint64_t address : 40;
147 uint64_t ignored2 : 11; 148 uint64_t ignored2 : 11;
148 uint64_t xd : 1; 149 uint64_t xd : 1;
149 } page_t; 150 } page_t;
151
152 _Static_assert(sizeof(page_t) == 8, "sizeof(page_t) != 8");
153 _Static_assert(sizeof(PDE_t) == 8, "sizeof(PDE_t) != 8");
154 _Static_assert(sizeof(PDPTE_t) == 8, "sizeof(PDPTE_t) != 8");
155 _Static_assert(sizeof(PML4E_t) == 8, "sizeof(PML4E_t) != 8");
150 156
151 // Page table: 157 // Page table:
152 typedef struct 158 typedef struct
153 { 159 {
154 page_t table[512]; 160 page_t table[512];