summaryrefslogtreecommitdiff
path: root/boot/page.inc
blob: ec2a8ad210022ae27df3b3805c27b06443ec8023 (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
34
35
36
37
38
39
40
41
42
43
44
PAGE_SIZE = 0x1000

PAGE_PRESENT = (1 shl 0)
PAGE_WRITE   = (1 shl 1)

macro page_table_init_real pml4_table* {
	local page_table

	; zero out page table
	mov edi, pml4_table
	push di
	mov ecx, (PAGE_SIZE*4)/4
	xor eax, eax
	cld
	rep stosd
	pop di

	virtual at di
		label page_table
		.PML4T rb PAGE_SIZE
		.PDPT  rb PAGE_SIZE
		.PDT   rb PAGE_SIZE
		.PT    rb PAGE_SIZE
		.sizeof = $ - page_table
	end virtual

	; create first entry
	mov word [.PML4T], (pml4_table + .PDPT - page_table) or PAGE_PRESENT or PAGE_WRITE
	mov word [.PDPT],  (pml4_table + .PDT  - page_table) or PAGE_PRESENT or PAGE_WRITE
	mov word [.PDT],   (pml4_table + .PT   - page_table) or PAGE_PRESENT or PAGE_WRITE

	; identity map pages
	push di
	mov di, (pml4_table + .PT - page_table)
	mov ax, (PAGE_PRESENT or PAGE_WRITE)
@@:
	mov [di], eax
	add eax, PAGE_SIZE
	add di, 8
	cmp di, pml4_table + .sizeof
	jb @b

	pop di
}