Cpu.inc
[ Return to Browse Source Page ]
IFNDEF nocpudetect

vendorid2 db CRLF,"Vendor ID ",0
vendorid db "   "
vendorid1 db "         ",0
cpu_numstring db 0,0,0
cpu_processor db "Processor ",0
class_cpu db "86 Class CPU" ;,CRLF,0
cpu_linefeed db CRLF,0
bad_chip db CRLF,"Err: CPU Check Failed",0
cpu_family db " Family ",0
cpu_model db ", Model ",0
cpu_step db ", Step ",0


;Processor :  586 Class CPU
;             Family 5, Model 1, Step 5
;Vendor ID :  GenuineIntel

cpudetect:
        push ds
        xor ax,ax
        mov ds,ax
        mov ds:[(500h+PDA_CPUID)],ax
        pop ds

        mov si,offset cpu_processor
        call realboldstring
        pushf
        pop ax
        push ax
        or ah,0F0h
        push ax
        popf
        pushf
        pop ax
        popf
        and ah,0F0h
        jnz cpu_3
        
        jmp cpumode_error

        .386P
cpu_3:  mov bp,sp
        and sp,0FFFCh
        pushfd
        pop eax
        push eax
        mov ebx,080000h
        or eax,ebx
        push eax
        popfd
        pushfd
        pop eax
        and eax,ebx
        popfd
        jnz cpu_4
        mov sp,bp
        mov al,3
        call cpu_disp
        jmp no_cpuid_entry
        
cpu_4:  pushfd
        pop eax
        push eax
        mov ebx,00200000h
        or eax,ebx
        push eax
        popfd
        pushfd
        pop eax
        popfd
        and eax,ebx
        mov sp,bp
        jnz cpu_5
        cpu_id_reentry:
        mov al,4
        call cpu_disp
        jmp no_cpuid_entry


        .586
cpu_5:  mov eax,1
        push ds
        xor bx,bx
        mov ds,bx
        cpuid
        mov word ptr ds:[501h],ax
        pop ds
        ;  (TP) FAM  MOD  STEP  
        ;  0000 0000:0000 0000
        rol ax,08
        and al,0Fh
        ; MOD  STEP      FAM
        ; 0000 0000:0000 0000

        call cpu_disp

        mov bl,al
        mov dx,offset realmodestring
        mov si,offset vendorid1
        call realboldstring
        mov si,offset cpu_family
        call dx
        mov si,offset cpu_numstring
        call dx
        mov si,offset cpu_model
        call dx
        rol ax,4
        call al2numstring
        mov si,offset cpu_numstring
        call dx
        mov si,offset cpu_step
        call dx
        rol ax,4
        call al2numstring
        mov si,offset cpu_numstring
        call dx

        xor eax,eax
        cpuid
        mov si,offset vendorid
        mov [si],ebx
        mov [si+4],edx
        mov [si+8],ecx
        mov si,offset vendorid2
        call realboldstring
        mov si,offset vendorid
        call realmodestring

        .386P
        no_cpuid_entry:
        mov dx,offset realmodestring
        mov si,offset cpu_linefeed
        call dx
        call dx
        
        mov eax,cr0
        and al,01
        jnz cpumode_error
        ret
        
cpumode_error:
        mov si,offset bad_chip
        call realmodestring
        jmp $

cpu_disp:
        push ds
        xor bx,bx
        mov ds,bx
        mov byte ptr ds:[(0500h+PDA_CPU)],al
        pop ds
        call al2numstring
        mov bx,offset realmodestring
        mov si,offset cpu_numstring
        call bx
        mov si,offset class_cpu
        call bx
        ret
        
al2numstring:
        push ax
        and al,0Fh
        mov di,offset cpu_numstring
        cmp al,9
        ja al2numstring_2digits
        al2numstring_reentry:
        add al,030h
        stosb
        mov byte ptr [di],0
        pop ax
        ret
        al2numstring_2digits:
        add al,-10
        mov byte ptr [di],031h
        inc di
        jmp al2numstring_reentry
        
ELSE

cpudetect:
pushf
pop ax
push ax
or ah,0F0h
push ax
popf
pushf
pop ax
popf
and ah,0F0h
jz cpudetect_error
.386P
mov eax,cr0
and al,1
jnz cpudetect_error
ret

cpudetect_error:
mov si,offset cpu_error
call realmodestring
hang: jmp hang

cpu_error db "Err: CPU/CPU Mode Test Failed.",CRLF,CRLF,"SYSTEM HALTED",0

ENDIF


Download this file.


[ Return to Browse Source Page ]
Copyright 2000, Ed Pizzi