home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / actlib12.zip / TOOLS.ZIP / CPUTYPE.ASM < prev    next >
Assembly Source File  |  1993-03-04  |  3KB  |  117 lines

  1. ;  FUNCTION:  cpu_type
  2. ;    Determine CPU class.
  3. ;
  4. ; RETURNS:
  5. ;    AX = CPU type
  6. ;    0086 if 8088/8086
  7. ;    0286 if 80286
  8. ;    0386 if 80386
  9. ;    0486 if 80486
  10. ;
  11. ;    All regs preserved except AX.
  12. ;
  13. ;
  14. ; int cpu_type( void ) - returns 86, 186, 286, 386, 486
  15. ;
  16. ;-----------------------------------------------------------------------------
  17.  
  18. TITLE cpu_type - returns cpu type (86, 186, 286, 386, 486)
  19.  
  20. PAGE 66,132
  21.  
  22. .MODEL large
  23.  
  24. if (@CodeSize EQ 1)
  25.     x    equ    6
  26. else
  27.     x    equ    4
  28. endif
  29.  
  30.     sgmnt    equ    0
  31.     offst    equ    2
  32.  
  33. if (@DataSize EQ 1) OR (@DataSize EQ 2)
  34.     s_off    equ    4
  35.     s_seg    equ    6
  36.     len        equ    8
  37. else
  38.     string    equ    4
  39.     len        equ    6
  40. endif
  41.  
  42. .386p
  43. .code
  44.     public    _cpu_type
  45. _cpu_type    proc
  46.     push    bp            ;Save regs
  47.     mov        bp,sp        ;set up our stack addressability
  48.     pushf                ;save the real flags register
  49.  
  50.     pop    ax            ;get register off stack
  51.     push    ax            ;and save it again
  52.  
  53.     and    ax,0fffh        ;zero out bits 12-15
  54.     push    ax
  55.     popf                ;try to put into flags
  56.     pushf
  57.     pop    ax            ;let's see what came out
  58.                       ;of flags
  59.     and    ax,0F000h        ;mask off bits 12-15
  60.     cmp    ax,0F000h        ;were these bits all 1's
  61.     je    short is_86            ;if so, it's an 8086
  62.  
  63.     pop    ax            ;get flags register to AX
  64.     push    ax            ;and save it again
  65.  
  66.          or    ax,0F000h        ;now try to set bits 12-15
  67.     push    ax
  68.     popf                ;of the flags register
  69.     pushf
  70.     pop    ax            ;and see what came out
  71.     and    ax,0F000h        ;are high bits set
  72.     je    short is_286            ;if so, we have a 386 or 486
  73. ;-----------------------------
  74.     mov    edx,esp      ; Save stack pointer
  75.     and    esp,not 3    ; Align stack pointer to prevent a fault
  76.                              ;  when we set the AC flag on a 486
  77.     pushfd               ; Copy the EFLAGS register
  78.     pop    eax          ;   into register eax
  79.     mov    ecx,eax      ; Save the original EFLAGS value
  80.     xor    eax,40000H   ; Flip the AC flag bit
  81.     push    eax         ; Try to put the modified value back
  82.     popfd            ;   into the EFLAGS register
  83.     pushfd            ; Copy the EFLAGS register again
  84.     pop     eax          ;   into eax
  85.     xor     eax,ecx      ; Compare the old and new AC bits
  86.     shr     eax,18       ; Shift and mask to get the AC comparison bit
  87.          and     eax,1        ;   in the low order position of eax
  88.     push    ecx
  89.     popfd                ; Restore EFLAGS that were saved on entry
  90.     mov     esp,edx      ; And restore stack pointer to saved value
  91.     ;;
  92.     ;; at this point ax = 0 on a 386
  93.     ;;               ax = 1 on a 486
  94.     cmp    ax,0
  95.     je    short is_386
  96.  
  97. is_486:    mov    ax,0486
  98.     jmp    short    cpu_exit
  99.  
  100. ;----------------------------------
  101.  
  102. is_386:    mov    ax,0386
  103.     jmp    short    cpu_exit
  104.  
  105. is_286:    mov    ax,0286
  106.     jmp    short    cpu_exit
  107.  
  108. is_86:    mov    ax,86
  109.  
  110. cpu_exit:
  111.     popf            ;restore flags
  112.     pop    bp
  113.     ret
  114. _cpu_type    endp
  115.  
  116.     end
  117.