FEATURE_FLAGS          EQU 0x01
EXTENDED_FEATURE_FLAGS EQU 0x80000001

APIC_PRESENT     EQU 1<<9
LONGMODE_ENABLED EQU 1<<29

GLOBAL capabilities_is_64bit
GLOBAL capabilities_has_apic

; XXX verify that the CPU supports CPUID!

capabilities_is_64bit:
    PUSH EBX
    PUSH ECX
    PUSH EDX

    MOV EAX, EXTENDED_FEATURE_FLAGS
    CPUID

    MOV EAX, 0
    AND EDX, LONGMODE_ENABLED
    SETNZ AL

    POP EDX
    POP ECX
    POP EBX

    RET

capabilities_has_apic:
    PUSH EBX
    PUSH ECX
    PUSH EDX

    MOV EAX, FEATURE_FLAGS
    CPUID

    MOV EAX, 0
    AND EDX, APIC_PRESENT
    SETNZ AL

    POP EDX
    POP ECX
    POP EBX

    RET

FEATURE_FLAGS          EQU 0x01
EXTENDED_FEATURE_FLAGS EQU 0x80000001

APIC_PRESENT     EQU 1<<9
LONGMODE_ENABLED EQU 1<<29

; XXX verify that the CPU supports CPUID!

; name, EAX_VALUE, REG, BIT
%MACRO GEN_CAPS 4
GLOBAL %1
%1:
    PUSH EBX
    PUSH ECX
    PUSH EDX

    MOV EAX, %2
    CPUID

    MOV EAX, 0
    AND %3, %4
    SETNZ AL

    POP EDX
    POP ECX
    POP EBX

    RET
%ENDMACRO

GEN_CAPS capabilities_is_64bit, EXTENDED_FEATURE_FLAGS, EDX, LONGMODE_ENABLED
GEN_CAPS capabilities_has_apic, FEATURE_FLAGS, EDX, APIC_PRESENT

Make capability checking functions a macro
Make capability checking functions a macro
