Add cpuinfo and stack-defining stuff

This commit is contained in:
greg
2015-11-07 17:02:41 -08:00
parent f3605f554e
commit 60b10c3708

View File

@@ -1,11 +1,87 @@
global start
%define VRAM 0xb8000
section .bss
stack_bottom:
resb 64 ;reserve 64 bytes of stack space
stack_top:
section .text
bits 32
start:
mov dword [0xb8000], 0x2f4b2f4f ;write OK
mov esp, stack_top
call test_multiboot
call test_cpuid
call use_cpuid
;mov dword [VRAM], 0x2f4b2f4f ;write OK
hlt
error:
mov dword [VRAM], 0x4f524f45 ;ER
mov dword [VRAM+4], 0x4f3a4f52 ;R:
mov dword [VRAM+8], 0x4f204f20 ; <2 spaces>
mov byte [VRAM+0xa], al
hlt
test_multiboot:
cmp eax, 0x36d76289
jne no_multiboot
ret
no_multiboot:
mov al, "0"
jmp error
test_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
no_cpuid:
mov al, "1"
jmp error
use_cpuid:
jmp print_cpu_string
print_cpu_string:
mov eax, 0x0
cpuid
mov eax, ebx
mov [VRAM+0], al
mov [VRAM+2], ah
shr eax, 16
mov [VRAM+4], al
mov [VRAM+6], ah
mov eax, edx
mov [VRAM+8], al
mov [VRAM+0xa], ah
shr eax, 16
mov [VRAM+0xc], al
mov [VRAM+0xe], ah
mov eax, ecx
mov [VRAM+0x10], al
mov [VRAM+0x12], ah
shr eax, 16
mov [VRAM+0x14], al
mov [VRAM+0x16], ah
mov [VRAM+0x18], byte ' '
ret