...
This commit is contained in:
43
src/boot.s
43
src/boot.s
@@ -42,16 +42,53 @@ gdt64_end:
|
|||||||
.code32
|
.code32
|
||||||
.global _start
|
.global _start
|
||||||
_start:
|
_start:
|
||||||
mov stack_top, esp
|
mov esp, stack_top
|
||||||
|
|
||||||
|
// Multiboot will place a magic value in eax
|
||||||
|
// If this magic value is not present, then we might not have multiboot info in ebx,
|
||||||
|
// therefore we throw an error
|
||||||
cmp eax, 0x2BADB002
|
cmp eax, 0x2BADB002
|
||||||
jne error
|
jne error
|
||||||
|
|
||||||
|
// Check if cpuid is available by flipping the 22-nth youngest bit
|
||||||
|
// in the eflags register and checking if the cpu flipped it back
|
||||||
|
pushfd
|
||||||
|
pop eax
|
||||||
|
mov ecx, eax
|
||||||
|
xor eax, 1 << 21
|
||||||
|
push eax
|
||||||
|
popfd
|
||||||
|
pushfd
|
||||||
|
pop eax
|
||||||
|
// If cpuid is available, eax should be different than ecx
|
||||||
|
xor eax, ecx
|
||||||
|
jz error
|
||||||
|
// Finally restore eflags register to the original value
|
||||||
|
push ecx
|
||||||
|
popfd
|
||||||
|
|
||||||
|
// Check if extended cpuid is available by calling cpuid with 0x80000000,
|
||||||
|
// If cpuid is available, eax will be greater than 0x80000000 after the call
|
||||||
|
mov eax, 0x80000000
|
||||||
|
cpuid
|
||||||
|
cmp eax, 0x80000001
|
||||||
|
jb error
|
||||||
|
|
||||||
|
// Check if long mode is available by calling cpuid with 0x80000001
|
||||||
|
// this will place the extended features of the cpu in edx
|
||||||
|
// The 30-nth youngest bit tells us if long mode is supported or not
|
||||||
|
mov eax, 0x80000001
|
||||||
|
cpuid
|
||||||
|
test edx, 1 << 29
|
||||||
|
jz error
|
||||||
|
|
||||||
|
// todo(nub31): setup paging
|
||||||
|
// todo(nub31): enter long mode
|
||||||
|
|
||||||
|
// Load global descriptor table which is set up for 64 bit
|
||||||
lgdt [gdt64_descriptor]
|
lgdt [gdt64_descriptor]
|
||||||
|
|
||||||
push ebx
|
|
||||||
call kernel_main
|
call kernel_main
|
||||||
add esp, 4
|
|
||||||
jmp error
|
jmp error
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|||||||
Reference in New Issue
Block a user