5 %include "arch/x86_64/include/common.inc.asm"
9 ;KERNEL_BASE equ 0xFFFF800000000000
10 KERNEL_BASE equ 0xFFFFFFFF80000000
14 ; Multiboot macros to make a few lines later more readable
15 MULTIBOOT_PAGE_ALIGN equ 1<<0
16 MULTIBOOT_MEMORY_INFO equ 1<<1
17 MULTIBOOT_AOUT_KLUDGE equ 1<<16
18 MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
19 MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO; | MULTIBOOT_AOUT_KLUDGE
20 MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
22 ; This is the GRUB Multiboot header. A boot signature
23 dd MULTIBOOT_HEADER_MAGIC
24 dd MULTIBOOT_HEADER_FLAGS
30 dd mboot ; Location of Multiboot Header
31 dd __load_addr ; Load address
32 dd __bss_start - KERNEL_BASE ; End of .data
33 dd gKernelEnd - KERNEL_BASE ; End of .bss (and kernel)
34 dd start - KERNEL_BASE ; Entrypoint
41 mov [gMultibootMagic - KERNEL_BASE], eax
42 mov [gMultibootPtr - KERNEL_BASE], ebx
44 ; Check for Long Mode support
47 cmp eax, 0x80000001 ; Compare the A-register with 0x80000001.
54 ; Enable PGE (Page Global Enable)
55 ; + PAE (Physical Address Extension)
56 ; + PSE (Page Size Extensions)
58 or eax, 0x80|0x20|0x10
62 mov eax, gInitialPML4 - KERNEL_BASE
65 ; Enable long/compatability mode
77 lgdt [gGDTPtr - KERNEL_BASE]
78 jmp 0x08:start64 - KERNEL_BASE
83 mov esi, csNot64BitCapable - KERNEL_BASE
100 dd 0x00000000, 0x00209A00 ; 0x08: 64-bit Code
101 dd 0x00000000, 0x00009200 ; 0x10: 64-bit Data
102 dd 0x00000000, 0x0040FA00 ; 0x18: 32-bit User Code
103 dd 0x00000000, 0x0040F200 ; 0x20: User Data
104 dd 0x00000000, 0x0020FA00 ; 0x28: 64-bit User Code
105 dd 0x00000000, 0x0000F200 ; 0x30: User Data (64 version)
106 times MAX_CPUS dd 0, 0x00008900, 0, 0 ; 0x38+16*n: TSS 0
111 [global gMultibootPtr]
112 [global gMultibootMagic]
119 [global gInitialPML4]
120 gInitialPML4: ; Covers 256 TiB (Full 48-bit Virtual Address Space)
121 dd gInitialPDP - KERNEL_BASE + 3, 0 ; Identity Map Low 4Mb
123 dd gStackPDP - KERNEL_BASE + 3, 0
124 times 512-4-($-gInitialPML4)/8 dq 0
125 dd gInitialPML4 - KERNEL_BASE + 3, 0 ; Fractal Mapping
128 dd gHighPDP - KERNEL_BASE + 3, 0 ; Map Low 4Mb to kernel base
130 gInitialPDP: ; Covers 512 GiB
131 dd gInitialPD - KERNEL_BASE + 3, 0
135 dd gStackPD - KERNEL_BASE + 3, 0
138 gHighPDP: ; Covers 512 GiB
140 ;dq 0 + 0x143 ; 1 GiB Page from zero
141 dd gInitialPD - KERNEL_BASE + 3, 0
144 gInitialPD: ; Covers 1 GiB
145 ; dq 0 + 0x143 ; 1 GiB Page from zero
146 dd gInitialPT1 - KERNEL_BASE + 3, 0
147 dd gInitialPT2 - KERNEL_BASE + 3, 0
151 dd gKStackPT - KERNEL_BASE + 3, 0
154 gKStackPT: ; Covers 2 MiB
155 ; Initial stack - 64KiB
158 %rep INITIAL_KSTACK_SIZE-1
159 dd gInitialKernelStack - KERNEL_BASE + i*0x1000 + 0x103, 0
162 times 512-INITIAL_KSTACK_SIZE dq 0
177 [global gInitialKernelStack]
179 times 0x1000*(INITIAL_KSTACK_SIZE-1) db 0 ; 8 Pages
183 db "Not 64-bit Capable",0