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

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