home *** CD-ROM | disk | FTP | other *** search
/ 98 Driver Collection MD-0164 / DRIVER_KING_98.iso / CPU / cyrix / CPUID.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-12-20  |  3.2 KB  |  118 lines

  1. assume  cs:_TEXT
  2.  
  3. public    _is_cpuid_supported
  4. public    _get_cpuid_info
  5.  
  6. _TEXT    segment byte public 'CODE'
  7.  
  8. ;**************************************************************************    
  9. ;       Function:    int is_cpuid_supported ()
  10. ;
  11. ;       Purpose:        Check for existence of CPUID instruction.
  12. ;                       If exists execute CPUID with eax==0.
  13. ;
  14. ;       Inputs:         none
  15. ;                       
  16. ;       Output:         
  17. ;                       
  18. ;       Returns:        0 - no CPUID instruction supported
  19. ;                       1 - CPUID instruction supported
  20. ;**************************************************************************
  21.  
  22. cpuid macro 
  23.         db 0fh, 0a2h
  24. endm
  25.  
  26. _is_cpuid_supported        proc    near
  27. .386
  28.     push    bp
  29.     mov    bp, sp
  30.         sub     sp, 40
  31.  
  32.         push    eax
  33.         push    ebx
  34.  
  35.         pushfd                  ; get extended flags
  36.         pop     eax
  37.         mov     ebx, eax        ; save current flags
  38.  
  39.         xor     eax, 200000h    ; toggle bit 21
  40.         push    eax             ; put new flags on stack
  41.         popfd                   ; flags updated now in flags
  42.  
  43.         pushfd                  ; get extended flags
  44.         pop     eax             
  45.         xor     eax, ebx        ; if bit 21 r/w then eax <> 0
  46.  
  47.         pop     ebx
  48.         pop     eax
  49.  
  50.         je      no_cpuid        ; can't toggle id bit (21) no cpuid here
  51.  
  52.         mov     ax, 1           ; cpuid supported
  53.  
  54.         jmp     done_cpuid_sup
  55.  
  56. no_cpuid:
  57.         mov     ax, 0           ; cpuid not supported
  58.  
  59. done_cpuid_sup:
  60.         mov     sp, bp
  61.         pop     bp
  62.     ret
  63. _is_cpuid_supported        endp
  64.  
  65. ;**************************************************************************    
  66. ;       Function:    int cpuid_supported (long level,
  67. ;                                            long ®_eax,
  68. ;                                            long ®_ebx,
  69. ;                                            long ®_ecx,
  70. ;                                            long ®_edx)
  71. ;
  72. ;       Purpose:        Execute CPUID instruction at level (eax==level)
  73. ;
  74. ;       Inputs:         level - eax value when CPU is executed
  75. ;                       
  76. ;       Output:         reg_eax - eax after executing CPUID 
  77. ;                       reg_ebx - ebx after executing CPUID 
  78. ;                       reg_ecx - ecx after executing CPUID 
  79. ;                       reg_edx - edx after executing CPUID 
  80. ;**************************************************************************
  81. _get_cpuid_info        proc    near
  82. .386
  83.     push    bp
  84.     mov    bp, sp
  85.         sub     sp, 4
  86.  
  87.         push    esi
  88.  
  89.     mov    eax, dword ptr [bp+4]      ; get level
  90.  
  91.         cpuid                   
  92.  
  93.         mov     esi, ebx        ; save ebx value 
  94.  
  95.     mov    bx,word ptr [bp+8]
  96.     mov    dword ptr [bx],eax        ; reg_eax := eax
  97.  
  98.     mov    bx,word ptr [bp+10]
  99.     mov    dword ptr [bx],esi        ; reg_ebx := ebx (via esi)
  100.  
  101.         mov    bx,word ptr [bp+12]
  102.     mov    dword ptr [bx],ecx        ; reg_ecx := ecx
  103.  
  104.         mov    bx,word ptr [bp+14]       ; reg_edx := edx 
  105.     mov    dword ptr [bx],edx
  106.  
  107.         pop     esi
  108.  
  109.         mov     sp,bp
  110.         pop     bp
  111.     ret
  112. _get_cpuid_info        endp
  113.  
  114.  
  115.  
  116. _TEXT    ends
  117.     end
  118.