More memory management functions implemented, other fixes too
[tpg/acess2.git] / Kernel / arch / x86_64 / start32.asm
1
2 [BITS 32]
3
4 KERNEL_BASE     equ     0xFFFF800000000000
5
6 [section .multiboot]
7 mboot:
8         MULTIBOOT_MAGIC equ     0x1BADB002
9         dd      MULTIBOOT_MAGIC
10
11 [extern start64]
12
13 [section .text]
14 [global start]
15 start:
16         ; Enable PAE
17         mov eax, cr4
18         or eax, 0x80|0x20
19         mov cr4, eax
20
21         ; Load PDP4
22         mov eax, gInitialPML4 - KERNEL_BASE
23         mov cr3, eax
24
25         ; Enable long/compatability mode
26         mov ecx, 0xC0000080
27         rdmsr
28         or ax, 0x100
29         wrmsr
30
31         ; Enable paging
32         mov eax, cr0
33         or eax, 0x80000000
34         mov cr0, eax
35
36         ; Load GDT
37         lgdt [gGDTPtr - KERNEL_BASE]
38         mov ax, 0x10
39         mov ss, ax
40         mov ds, ax
41         mov es, ax
42         mov fs, ax
43         mov gs, ax
44
45         jmp 0x08:start64 - KERNEL_BASE
46
47 [section .data]
48 [global gGDT]
49 gGDT:
50         dd      0,0
51         dd      0x00000000, 0x00209800  ; 0x08: 64-bit Code
52         dd      0x00000000, 0x00009000  ; 0x10: 64-bit Data
53         dd      0x00000000, 0x00209800  ; 0x18: 64-bit User Code
54         dd      0x00000000, 0x00209000  ; 0x20: 64-bit User Data
55         dd      0x00000000, 0x00209800  ; 0x38: 32-bit User Code
56         dd      0x00000000, 0x00209000  ; 0x30: 32-bit User Data
57         times MAX_CPUS  dd      0, 0, 0, 0      ; 0x38+16*n: TSS 0
58 gGDTPtr:
59         dw      $-gGDT-1
60         dd      gGDT-KERNEL_BASE
61         dd      0
62
63 [section .padata]
64 [global gInitialPML4]
65 gInitialPML4:   ; Covers 256 TiB (Full 48-bit Virtual Address Space)
66         dd      gInitialPDP - KERNEL_BASE + 3, 0        ; Identity Map Low 4Mb
67         times 256-1 dq  0
68         dd      gInitialPDP - KERNEL_BASE + 3, 0        ; Map Low 4Mb to kernel base
69         times 256-1 dq 0
70
71 gInitialPDP:    ; Covers 512 GiB
72         dd      gInitialPD - KERNEL_BASE + 3, 0
73         times 511 dq    0
74
75 gInitialPD:     ; Covers 1 GiB
76         dd      gInitialPT1 - KERNEL_BASE + 3, 0
77         dd      gInitialPT2 - KERNEL_BASE + 3, 0
78
79 gInitialPT1:    ; Covers 2 MiB
80         %assign i 1
81         %rep 512
82         dq      i*4096+3
83         %assign i i+1
84         %endrep
85 gInitialPT2:    ; 2 MiB
86         %assign i 512
87         %rep 512
88         dq      i*4096+3
89         %assign i i+1
90         %endrep
91
92

UCC git Repository :: git.ucc.asn.au