summaryrefslogtreecommitdiff
path: root/kernel/src/arch/i686/paging.asm
blob: f74cc5552a311a7f5b70d8210e50d89a9cd7443e (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
global page_directory
global paging_init
global paging_finish
global KERNEL_MAPPING

KERNEL_MAPPING   equ  0xC0000000
VGABUF   equ  0x000B8000

section .bss
align 4096
page_directory:
resb 4096
page_table1:
resb 4096

section .bootstrap.text
align 8
paging_init:
    extern kernel_start
    extern kernel_end

paging_load:
    mov edi, page_table1 - KERNEL_MAPPING
    mov esi, 0
    mov ecx, 1023

paging_cmp:
    cmp esi, kernel_start
    jl paging_add
    cmp esi, kernel_end - KERNEL_MAPPING
    jge paging_map

    mov edx, esi
    or edx, 0x003
    mov [edi], edx

paging_add:
    add esi, 4096
    add edi, 4
    loop paging_cmp

paging_map:
    mov dword [page_table1 - KERNEL_MAPPING + 1023 * 4], VGABUF | 0x003
    mov dword [page_directory - KERNEL_MAPPING + 0], page_table1 - KERNEL_MAPPING + 0x003
    mov dword [page_directory - KERNEL_MAPPING + 768 * 4], page_table1 - KERNEL_MAPPING + 0x003 

    mov ecx, page_directory - KERNEL_MAPPING
    mov cr3, ecx

    mov ecx, cr0
    or ecx, 0x80010000
    mov cr0, ecx

    ret

section .text
align 8
paging_finish:
    mov dword [page_directory], 0
    mov ecx, cr3
    mov cr3, ecx
    ret