home *** CD-ROM | disk | FTP | other *** search
/ Bila Vrana / BILA_VRANA.iso / 027A / CPUTYP13.ZIP / CPUTYPE.ASM < prev    next >
Assembly Source File  |  1996-10-22  |  5KB  |  162 lines

  1. ; CPUTYPE.INC Routines to determine CPU type for high level languages
  2. ; (Pascal,C,C++,etc)
  3. ; CPU: 8086/80186, 80286, 80386, 80486, 80586 Pentium, 80686 P6 and higher(!)
  4. ; FPU: 8087, 80287, 80387, 80487, and higher (see 1. and 2. in CPU586P6.ASM)
  5. ;
  6. ; 1995 by XMAS coding (Dominik Freche, address see below)
  7. ; ********************** NOTE **********************
  8. ; For further pieces of information see CPU586P6.ASM
  9. ; **************************************************
  10. ;
  11. ; !!!!! THIS SOURCECODE IS FREEWARE !!!!!
  12. ; Including routines in high level languages (Pascal,C,C++,etc) :
  13. ; First assemble this file (for TASM : TASM CPUTYPE.INC) to an Object-file
  14. ; (*.OBJ). This file can be included in your high level language program.
  15. ; Add these lines in your high level language main (!) program
  16. ; (e.g. for Turbo-Pascal) :
  17. ;  {$L CPUTYPE.OBJ}
  18. ;  Function CPUType : Word; External;{1=86,2=286,3=386,4=486,5=586,etc.}
  19. ;  Function FPUType : Word; External;{0=None,1=87,2=287,3=387,4=487,Internal}
  20. ; For other languages use another syntax.
  21. ;
  22. ; If you have got any problems or if you want to contact me, do not hesitate,
  23. ; please write to the following address :
  24. ;   Dominik Freche
  25. ;   Vondernstrasse 45
  26. ;   45357 Essen
  27. ;   Germany
  28. ; or email to :
  29. ;   heckenb@mi.uni-erlangen.de (Frank Heckenbach)
  30. ;
  31. ; Dominik Freche, Mar 26 1995
  32. ; Inclusion routines :
  33.  
  34.         LOCALS  @@
  35.  
  36. CPUID   EQU     DB 0FH,0A2H     ;80586 Instruction to determine CPU type
  37.  
  38. DSeg    SEGMENT
  39.   Temp       DW  0FFFFH
  40.   FEnv       DW  7 DUP (0)
  41. DSeg    ENDS
  42.  
  43. CSeg    SEGMENT
  44.         ASSUME CS:CSeg,DS:DSeg
  45.  
  46.         PUBLIC CPUType,FPUType
  47.  
  48.         .8086
  49.  
  50. CPUType PROC    ;>AX CpuType (1=86,2=286,3=386,4=486,5=586,6=686,etc.)
  51.         MOV     AX,1
  52.         PUSHF
  53.         POP     BX
  54.         AND     BH,0FH
  55.         PUSH    BX
  56.         POPF
  57.         PUSHF
  58.         POP     CX
  59.         AND     CH,0F0H
  60.         CMP     CH,0F0H
  61.         JE      @@1                     ;8086 or below 80286
  62.         INC     AX
  63.         OR      BH,0F0H
  64.         PUSH    BX
  65.         POPF
  66.         PUSHF
  67.         POP     CX
  68.         AND     CH,0F0H
  69.         JE      @@1                     ;80286
  70.         .386
  71.         INC     AX
  72.         MOV     EBX,ESP
  73.         AND     ESP,0FFFCH
  74.         PUSHFD
  75.         POP     EDX
  76.         MOV     ECX,EDX
  77.         XOR     EDX,000040000H
  78.         PUSH    EDX
  79.         POPFD
  80.         PUSHFD
  81.         POP     EDX
  82.         PUSH    ECX
  83.         POPFD
  84.         XOR     EDX,ECX
  85.         AND     EDX,000040000H          ;Test Alignment Check Bit
  86.         MOV     ESP,EBX
  87.         JZ      @@1                     ;80386
  88.         ;.486
  89.         INC     AX
  90.         PUSHFD
  91.         POP     EDX
  92.         MOV     ECX,EDX
  93.         XOR     EDX,000200000H
  94.         PUSH    EDX
  95.         POPFD
  96.         PUSHFD
  97.         POP     EDX
  98.         PUSH    ECX
  99.         POPFD
  100.         XOR     EDX,ECX                 ;Test ID Bit
  101.         JZ      @@1                     ;80486
  102.         MOV     EAX,1
  103.         ;.586 or higher, CPUID returns Cpu Generation Number in AX Bits 8-11
  104.         CPUID
  105.         AND     AH,0FH
  106.         SHR     AX,8
  107.         .8086
  108.         .8087
  109. @@1:    RET
  110. CPUType ENDP
  111.  
  112. FPUType PROC    ;>AX FpuType (0=None (SX),1=87,2=287,3=387,
  113.                 ;4=487,5=586 or higher (FPU always internal))
  114.         FNSTENV FEnv
  115.         FNINIT
  116.         FNSTSW  Temp
  117.         CMP     BYTE PTR Temp,0
  118.         JNE     @@1
  119.         FNSTCW  Temp
  120.         CMP     BYTE PTR [Temp+1],3
  121.         JNE     @@1
  122.         FLDENV  FEnv                    ;FPU exists
  123.         CALL    CPUType                 ;Determine CPU type
  124.         CMP     AX,4                    ;Test CPU(in AX)>=80486
  125.         JAE     @@2                     ;CPU=80486,FPU exists=80487(Internal)
  126.                                         ;CPU>=80586,FPU=Internal
  127.         MOV     AX,3
  128.         FLD1
  129.         FLDZ
  130.         FDIVP   ST(1),ST
  131.         FLD     ST(0)
  132.         FCHS
  133.         FCOMPP
  134.         FSTSW   Temp
  135.         FWAIT
  136.         TEST    Temp,100H
  137.         JNZ     @@2                     ;80387
  138.         DEC     AX
  139.         FLD1
  140. @@0:    FISTP   Temp
  141.         FSTENV  FEnv
  142.         MOV     BX,CS
  143.         SHL     BX,1
  144.         SHL     BX,1
  145.         SHL     BX,1
  146.         SHL     BX,1
  147.         ADD     BX,OFFSET @@0
  148.         INC     BX
  149.         FWAIT
  150.         CMP     BX,[FEnv+6]
  151.         JE      @@2                     ;80287
  152.         DEC     AX                      ;8087
  153.         RET
  154. @@1:    XOR     AX,AX                   ;None
  155. @@2:    RET
  156. FPUType ENDP
  157.  
  158.   IDString   DB  "1995 by XMAS coding (Dominik Freche)"
  159.  
  160. CSeg    ENDS
  161.  
  162.         END