mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Check for Multiboot, CPUID, and Long Mode
This commit is contained in:
@@ -19,6 +19,10 @@ bits 32
|
||||
start:
|
||||
mov esp, stack_top
|
||||
|
||||
call check_multiboot
|
||||
call check_cpuid
|
||||
call check_long_mode
|
||||
|
||||
; print `OK` to screen
|
||||
mov dword [0xb8000], 0x2f4b2f4f
|
||||
hlt
|
||||
@@ -32,6 +36,49 @@ error:
|
||||
mov byte [0xb800a], al
|
||||
hlt
|
||||
|
||||
; Throw error 0 if eax doesn't contain the Multiboot 2 magic value (0x36d76289).
|
||||
check_multiboot:
|
||||
cmp eax, 0x36d76289
|
||||
jne .no_multiboot
|
||||
ret
|
||||
.no_multiboot:
|
||||
mov al, "0"
|
||||
jmp error
|
||||
|
||||
; Throw error 1 if the CPU doesn't support the CPUID command.
|
||||
check_cpuid:
|
||||
pushfd ; Store the FLAGS-register.
|
||||
pop eax ; Restore the A-register.
|
||||
mov ecx, eax ; Set the C-register to the A-register.
|
||||
xor eax, 1 << 21 ; Flip the ID-bit, which is bit 21.
|
||||
push eax ; Store the A-register.
|
||||
popfd ; Restore the FLAGS-register.
|
||||
pushfd ; Store the FLAGS-register.
|
||||
pop eax ; Restore the A-register.
|
||||
push ecx ; Store the C-register.
|
||||
popfd ; Restore the FLAGS-register.
|
||||
xor eax, ecx ; Do a XOR-operation on the A-register and the C-register.
|
||||
jz .no_cpuid ; The zero flag is set, no CPUID.
|
||||
ret ; CPUID is available for use.
|
||||
.no_cpuid:
|
||||
mov al, "1"
|
||||
jmp error
|
||||
|
||||
; Throw error 2 if the CPU doesn't support Long Mode.
|
||||
check_long_mode:
|
||||
mov eax, 0x80000000 ; Set the A-register to 0x80000000.
|
||||
cpuid ; CPU identification.
|
||||
cmp eax, 0x80000001 ; Compare the A-register with 0x80000001.
|
||||
jb .no_long_mode ; It is less, there is no long mode.
|
||||
mov eax, 0x80000000 ; Set the A-register to 0x80000000.
|
||||
cpuid ; CPU identification.
|
||||
cmp eax, 0x80000001 ; Compare the A-register with 0x80000001.
|
||||
jb .no_long_mode ; It is less, there is no long mode.
|
||||
ret
|
||||
.no_long_mode:
|
||||
mov al, "2"
|
||||
jmp error
|
||||
|
||||
section .bss
|
||||
stack_bottom:
|
||||
resb 64
|
||||
|
||||
Reference in New Issue
Block a user