More work on x86_64 port, also cleaned up a little of the API.
[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
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]
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 gGDT:
49         dd      0,0
50         dd      0x00000000, 0x00209800  ; 0x08: 64-bit Code
51         dd      0x00000000, 0x00009000  ; 0x10: 64-bit Data
52         dd      0x00000000, 0x00209800  ; 0x18: 64-bit User Code
53         dd      0x00000000, 0x00209000  ; 0x20: 64-bit User Data
54         dd      0x00000000, 0x00209800  ; 0x38: 32-bit User Code
55         dd      0x00000000, 0x00209000  ; 0x30: 32-bit User Data
56         times MAX_CPUS  dd      0, 0, 0, 0      ; 0x38+16*n: TSS 0
57 gGDTPtr:
58         dw      $-gGDT-1
59         dd      gGDT
60         dd      0
61
62 [section .padata]
63 gInitialPML4:   ; Covers 256 TiB (Full 48-bit Virtual Address Space)
64         dd      gInitialPDP - KERNEL_BASE + 3, 0        ; Identity Map Low 4Mb
65         times 256-1 dq  0
66         dd      gInitialPDP - KERNEL_BASE + 3, 0        ; Map Low 4Mb to kernel base
67         times 256-1 dq 0
68
69 gInitialPDP:    ; Covers 512 GiB
70         dd      gInitialPD - KERNEL_BASE + 3, 0
71         times 511 dq    0
72
73 gInitialPD:     ; Covers 1 GiB
74         dd      gInitialPT1 - KERNEL_BASE + 3, 0
75         dd      gInitialPT2 - KERNEL_BASE + 3, 0
76
77 gInitialPT1:    ; Covers 2 MiB
78         %assign i 1
79         %rep 512
80         dq      i*4096+3
81         %assign i i+1
82         %endrep
83 gInitialPT2:    ; 2 MiB
84         %assign i 512
85         %rep 512
86         dq      i*4096+3
87         %assign i i+1
88         %endrep
89
90

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