summaryrefslogtreecommitdiff
path: root/kernel/paging.c
blob: 58c42931c331f6fe678ac756c9f23576cad1503f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "paging.h"
#include "kernel.h"

#define invlpg(page) asm volatile("invlpg (%0)" :: "r" (page))

void paging_reinit() {
	map_p1.l[(uint32_t)&map_p2 >> 12] = (uint32_t)&entry_map_p2 | P1_P | P1_W | P1_G;
	map_p1.l[(uint32_t)&framebuffer >> 12] = 0xb8000 | P1_P | P1_W | P1_G;
	
	invlpg(&map_p2);
	
	for(unsigned int i = 0; i < 1024; i++) {
		if(map_p2[i] & P2_P && !(map_p2[i] & P2_G)) {
			map_p2[i] = 0;
		}
		
		if(map_p1.b[0x300][i] & P1_P && !(map_p1.b[0x300][i] & P1_G)) {
			map_p1.b[0x300][i] = 0;
		}
		
		if(map_p1.b[0x3ff][i] & P1_P && !(map_p1.b[0x3ff][i] & P1_G)) {
			map_p1.b[0x3ff][i] = 0;
		}
	}
	
	asm volatile(
		"mov %%cr4, %%eax\n"
		"or $0x00000080, %%eax\n"
		"mov %%eax, %%cr4\n"
		::: "%eax"
	);
	
}