home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / GRDBDL17.ZIP / CPUID.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-10-26  |  1.5 KB  |  113 lines

  1. ;
  2. ; GRDB
  3. ;
  4. ; Copyright(c) LADsoft
  5. ;
  6. ; David Lindauer, camille@bluegrass.net
  7. ;
  8. ;
  9. ; cpuid.asm
  10. ;
  11. ; Function: Generic CPU identification
  12. ;
  13.  
  14.     .model small
  15.     .586
  16. ;cpuid    macro
  17. ;    db    0fh,0a2h
  18. ;endm
  19.  
  20.     public    checkcpu, cpumodel, cpufeatures
  21.  
  22.     .data
  23. cpufeatures    dd    0    ;holds features available
  24. cpumodel    db    0    ;model (3,4,5,6 etc.)
  25.  
  26.     .code
  27. checkcpu    PROC
  28. ;
  29. ; 8086 has bits 12-15 of flags stuck on
  30. ;
  31.     pushf
  32.     pop    bx
  33.     mov    ax,0fffh
  34.     and    ax,bx
  35.     push    ax
  36.     popf
  37.     pushf
  38.     pop    ax
  39.     and    ax,0f000h
  40.     cmp    ax,0f000h
  41.     jz    failed
  42. ;
  43. ; 80286 has bits 12-15 of flags stuck off
  44. ;
  45.     mov    [cpumodel],2
  46.     mov    ax,0f000h
  47.     or    ax,bx
  48.     push    ax
  49.     popf
  50.     pushf
  51.     pop    ax
  52.     and    ax,0f000h
  53.     jz    failed
  54. ;
  55. ; Now we have a 386 or better.  On a 386 the AC bit (bit 18)
  56. ; may not be toggled
  57. ;
  58.     mov    [cpumodel],3
  59.     pushfd
  60.     pop    eax
  61.     cli
  62.     mov    dx,sp
  63.     and    sp,NOT 3
  64.     mov    ebx,eax
  65.     btc    eax,18
  66.     push    eax
  67.     popfd
  68.     pushfd
  69.     pop    eax
  70.     push    ebx
  71.     popfd
  72.     mov    sp,dx
  73.     xor    eax,ebx
  74.     bt    eax,18
  75.     jnc    gotid
  76. ;
  77. ; Now see if a is a pentium or better.  CPUID flag (bit 21) may not
  78. ; be toggled on a 486
  79.     mov    [cpumodel],4
  80.     mov    eax,ebx
  81.     btc    eax,21
  82.     push    eax
  83.     popfd
  84.     pushfd
  85.     pop    eax
  86.     xor    eax,ebx
  87.     bt    eax,21
  88.     jnc    gotid
  89.     
  90. ;
  91. ; It is a pentium or better
  92. ;
  93. ; so issue a CPUID instruction (level 1) to get the model # and features dword
  94. ;
  95.     push    ebx
  96.     mov    eax,1
  97.     cpuid
  98.     mov    [cpufeatures],edx
  99.     and    ah,15
  100.     mov    [cpumodel],ah
  101.     pop    ebx
  102. gotid:
  103.     push    ebx
  104.     popfd
  105.     clc
  106.     ret
  107. failed:
  108.     push    bx
  109.     popf
  110.     stc
  111.     ret
  112. checkcpu    ENDP
  113.     END