4 ;KERNEL_BASE equ 0xFFFF800000000000
5 KERNEL_BASE equ 0xFFFFFFFF80000000
9 ; Multiboot macros to make a few lines later more readable
10 MULTIBOOT_PAGE_ALIGN equ 1<<0
11 MULTIBOOT_MEMORY_INFO equ 1<<1
12 MULTIBOOT_AOUT_KLUDGE equ 1<<16
13 MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
14 MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO; | MULTIBOOT_AOUT_KLUDGE
15 MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
17 ; This is the GRUB Multiboot header. A boot signature
18 dd MULTIBOOT_HEADER_MAGIC
19 dd MULTIBOOT_HEADER_FLAGS
25 dd mboot ; Location of Multiboot Header
26 dd __load_addr ; Load address
27 dd __bss_start - KERNEL_BASE ; End of .data
28 dd gKernelEnd - KERNEL_BASE ; End of .bss (and kernel)
29 dd start - KERNEL_BASE ; Entrypoint
36 mov [gMultibootMagic - KERNEL_BASE], eax
37 mov [gMultibootPtr - KERNEL_BASE], ebx
39 ; Check for Long Mode support
42 cmp eax, 0x80000001 ; Compare the A-register with 0x80000001.
49 ; Enable PGE (Page Global Enable)
50 ; + PAE (Physical Address Extension)
51 ; + PSE (Page Size Extensions)
53 or eax, 0x80|0x20|0x10
57 mov eax, gInitialPML4 - KERNEL_BASE
60 ; Enable long/compatability mode
72 lgdt [gGDTPtr - KERNEL_BASE]
73 jmp 0x08:start64 - KERNEL_BASE
78 mov esi, csNot64BitCapable - KERNEL_BASE
95 dd 0x00000000, 0x00209A00 ; 0x08: 64-bit Code
96 dd 0x00000000, 0x00009200 ; 0x10: 64-bit Data
97 dd 0x00000000, 0x0020FA00 ; 0x18: 64-bit User Code
98 dd 0x00000000, 0x0000F200 ; 0x20: 64-bit User Data
99 dd 0x00000000, 0x0040FA00 ; 0x28: 32-bit User Code
100 dd 0x00000000, 0x0040F200 ; 0x30: 32-bit User Data
101 times MAX_CPUS dd 0, 0x00008900, 0, 0 ; 0x38+16*n: TSS 0
106 [global gMultibootPtr]
107 [global gMultibootMagic]
114 [global gInitialPML4]
115 gInitialPML4: ; Covers 256 TiB (Full 48-bit Virtual Address Space)
116 dd gInitialPDP - KERNEL_BASE + 3, 0 ; Identity Map Low 4Mb
118 dd gStackPDP - KERNEL_BASE + 3, 0
119 times 512-4-($-gInitialPML4)/8 dq 0
120 dd gInitialPML4 - KERNEL_BASE + 3, 0 ; Fractal Mapping
123 dd gHighPDP - KERNEL_BASE + 3, 0 ; Map Low 4Mb to kernel base
125 gInitialPDP: ; Covers 512 GiB
126 dd gInitialPD - KERNEL_BASE + 3, 0
130 dd gStackPD - KERNEL_BASE + 3, 0
133 gHighPDP: ; Covers 512 GiB
135 ;dq 0 + 0x143 ; 1 GiB Page from zero
136 dd gInitialPD - KERNEL_BASE + 3, 0
139 gInitialPD: ; Covers 1 GiB
140 ; dq 0 + 0x143 ; 1 GiB Page from zero
141 dd gInitialPT1 - KERNEL_BASE + 3, 0
142 dd gInitialPT2 - KERNEL_BASE + 3, 0
146 dd gKStackPT - KERNEL_BASE + 3, 0
149 gKStackPT: ; Covers 2 MiB
150 ; Initial stack - 64KiB
154 dd gInitialKernelStack - KERNEL_BASE + i*0x1000 + 0x103, 0
172 [global gInitialKernelStack]
174 times 0x1000*(16-1) db 0 ; 16 Pages
178 db "Not 64-bit Capable",0