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

  1. ; CPUTYPE.INC/CPU586P6.ASM CPU/FPU Generation Detection v1.3 for
  2. ; CPU: 8086/80186, 80286, 80386, 80486, 80586 Pentium, 80686 P6 and higher(!)
  3. ; FPU: 8087, 80287, 80387, 80487, and higher (see 1.) and 2.))
  4. ;
  5. ; 1995 by XMAS coding (Dominik Freche, address see below)
  6. ; updated 1996 by Frank Heckenbach
  7. ;
  8. ; About version 1.3:
  9. ; This is actually only version 1.2, with a supplement to include CpuType
  10. ; into C programs. No other extensions were made.
  11. ;
  12. ; IMPORTANT NOTE: There will probalby NOT be any newer version of CpuType.
  13. ; Dominik has stopped working on it due to some unexpected problems and other
  14. ; projects he's doing. Please do NOT mail to Frank (see below) just to ask
  15. ; for a new version.
  16. ;
  17. ; 1. How to determine CPU type
  18. ; 2. How to determine FPU type
  19. ; 3. !!!!! THIS SOURCECODE IS FREEWARE !!!!!
  20. ; 4. Including routines in high level languages (Pascal,C,C++,etc);
  21. ; 5. Address
  22. ; 6. Sourcecode of program
  23. ; Program to determine CPU (Central Processing Unit) type
  24. ; and FPU (Floating Point Unit(=math coprocessor)) type
  25. ; for all computer generations of the IBM standard,
  26. ; except pocket calculators like some earlier Personal Computers, so
  27. ; NOTE : the program does not differ between 8086/8088/80186/80188 and
  28. ; V20/V30-clones.
  29. ; Each release defines some new features. THIS PROGRAM HELPS TO
  30. ; TAKE ADVANTAGE OF IT. The following table contains the features of
  31. ; each new generation.
  32. ;  80286 Protected mode, hardware-multitasking, addressing of
  33. ;        max. 16 MB of memory
  34. ;  80386 32-Bit instructions, addressing of max. 4 GB (GigaByte) of memory,
  35. ;        Virtual86 mode (V86 - each task runs on an virtual 8086 processor;
  36. ;        EMM driver, OS2 and Win'95 use this)
  37. ;  80486 Internal coprocessor
  38. ;  80586 System Management mode (SMM - a "Standby"-mode, an
  39. ;        "Internal green PC"), very high performance
  40. ;  80686 Strongly high performance ("Pentium double speed"),
  41. ;        ??? (other features are secret)
  42. ; 1.)
  43. ; How to determine the CPU(=main processor) type
  44. ; Each Generation defines some new flags. If a specific flag is
  45. ; set and the flag is not defined, the processor clears
  46. ; this flag to 0.
  47. ; Besides, the Pentium defines a new instruction to determine
  48. ; the type. If the ID-Bit in EFLAGS is set to 1 and EAX contains 1,
  49. ; the 80586-instruction "CPUID" returns a 5 in EAX for 80586, a 6
  50. ; for 80686 and so on. NOTE : even some newer i80486 (manufactured
  51. ; after may 1994) support the instruction "CPUID", so it is necessary
  52. ; to execute this instruction if the ID-Bit in EFLEGS can be set to 1.
  53. ; Intel will include this instruction in each processor after
  54. ; the i80486, so even following generations can be determined.
  55. ; 2.)
  56. ; How to determine the FPU(=math coprocessor) type
  57. ; Executing the coprocessor-instruction "FNINIT", the CPU-status word
  58. ; will be cleared and the CPU-control word will be updated
  59. ; (the program restores the old status word and control word after executing
  60. ; the initialization for compatibility). By comparing some flags in the
  61. ; CPU-control word the existence of a FPU can be determined. Determining the
  62. ; generation of coprocessor is quite simple. A CPU type after 80386 has got
  63. ; an internal math coprocessor for standard, except some 80486SX do not
  64. ; (SX=Single, no coprocessor - DX=Double, coprocessor exists),
  65. ; but an external 80487 does not exist (the 80487 is an 80486 with internal
  66. ; coprocessor). That means, if an 80486 or higher is detected and a FPU
  67. ; does exist, an internal 80487 or higher is installed. Other FPU
  68. ; generations (80387,80287,8087) are external coprocessors.
  69. ; For these coprocessors the program determines the FPU type because it is
  70. ; possible to combine different CPU and FPU types (e.g. 80386 and 80287).
  71. ; The program uses different execution results of the same instructions on
  72. ; different coprocessors to determine FPU type.
  73. ; 3.)
  74. ; If you believe this program to be useful, it can be copied freely !
  75. ; This sourcecode cannot be sold !
  76. ; !!!!! THIS SOURCECODE IS FREEWARE !!!!!
  77. ; 4.)
  78. ; For including the routines to determine CPU/FPU type in a high level
  79. ; language (like Pascal,C,C++,etc), just see CPUTYPE.INC.
  80. ; 5.)
  81. ; If you have got any problems or if you want to contact me, do not hesitate,
  82. ; please write to the following address :
  83. ;   Dominik Freche
  84. ;   Vondernstrasse 45
  85. ;   45357 Essen
  86. ;   Germany
  87. ; or email to :
  88. ;   heckenb@mi.uni-erlangen.de (Frank Heckenbach)
  89. ; since I do not have email access. Frank will forward your mails asap,
  90. ; but sometimes it may take up to some weeks (esp. during holidays ;-)
  91. ;
  92. ; Dominik Freche, Mar 26 1995
  93. ; 6.) Program :
  94.         LOCALS  @@
  95.  
  96. CPUID   EQU     DB 0FH,0A2H     ;80586 Instruction to determine CPU type
  97.  
  98. SSeg    SEGMENT STACK
  99.   SStack        DB  64 DUP (0)
  100. SSeg    ENDS
  101.  
  102. DSeg    SEGMENT
  103.   Cpu8086    DB  "8086/8088/80186/80188$"
  104.   Cpu80286   DB  "80286$"
  105.   Cpu80386   DB  "80386$"
  106.   Cpu80486   DB  "80486$"
  107.   Cpu80586   DB  "80586 Pentium$"
  108.   Cpu80686   DB  "80686 P6$"
  109.   Cpu80x86   DB  "80786 or higher$"
  110.   FpuNone    DB  "None$"
  111.   Fpu8087    DB  "8087$"
  112.   Fpu80287   DB  "80287$"
  113.   Fpu80387   DB  "80387$"
  114.   Fpu80487   DB  "80487 (Internal)$"
  115.   FpuInteg   DB  "Internal$"
  116.  
  117.  
  118.   PrnMsg01   DB  "CPU Generation Detection",13,10,"$"
  119.   PrnMsg02   DB  "1995 by XMAS coding (Dominik Freche)",13,10,"$"
  120.   PrnMsg03   DB  "!!!!! THIS SOURCECODE IS FREEWARE !!!!!",13,10,"$"
  121.   PrnMsg04   DB  13,10,"CPU Type $"
  122.   PrnMsg05   DB  13,10,"FPU Type $"
  123.   PrnMsg06   DB  13,10,"CPU586P6.ASM v1.3",13,10,"$"
  124.   PrnMsg07   DB  13,10,"$"
  125.  
  126.   Temp       DW  0FFFFH
  127.   FEnv       DW  7 DUP (0)
  128. DSeg    ENDS
  129.  
  130. CSeg    SEGMENT
  131.         ASSUME CS:CSeg,DS:DSeg,SS:SSeg
  132.  
  133.         .8086
  134.  
  135. CPUType PROC    ;>AX CpuType (1=86,2=286,3=386,4=486,5=586,6=686,etc.)
  136.         MOV     AX,1
  137.         PUSHF
  138.         POP     BX
  139.         AND     BH,0FH
  140.         PUSH    BX
  141.         POPF
  142.         PUSHF
  143.         POP     CX
  144.         AND     CH,0F0H
  145.         CMP     CH,0F0H
  146.         JE      @@1                     ;8086 or below 80286
  147.         INC     AX
  148.         OR      BH,0F0H
  149.         PUSH    BX
  150.         POPF
  151.         PUSHF
  152.         POP     CX
  153.         AND     CH,0F0H
  154.         JE      @@1                     ;80286
  155.         .386
  156.         INC     AX
  157.         MOV     EBX,ESP
  158.         AND     ESP,0FFFCH
  159.         PUSHFD
  160.         POP     EDX
  161.         MOV     ECX,EDX
  162.         XOR     EDX,000040000H
  163.         PUSH    EDX
  164.         POPFD
  165.         PUSHFD
  166.         POP     EDX
  167.         PUSH    ECX
  168.         POPFD
  169.         XOR     EDX,ECX
  170.         AND     EDX,000040000H          ;Test Alignment Check Bit
  171.         MOV     ESP,EBX
  172.         JZ      @@1                     ;80386
  173.         ;.486
  174.         INC     AX
  175.         PUSHFD
  176.         POP     EDX
  177.         MOV     ECX,EDX
  178.         XOR     EDX,000200000H
  179.         PUSH    EDX
  180.         POPFD
  181.         PUSHFD
  182.         POP     EDX
  183.         PUSH    ECX
  184.         POPFD
  185.         XOR     EDX,ECX                 ;Test ID Bit
  186.         JZ      @@1                     ;80486
  187.         MOV     EAX,1
  188.         ;.586 or higher, CPUID returns Cpu Generation Number in AX Bits 8-11
  189.         CPUID
  190.         AND     AH,0FH
  191.         SHR     AX,8
  192.         .8086
  193.         .8087
  194. @@1:    RET
  195. CPUType ENDP
  196.  
  197. FPUType PROC    ;>AX FpuType (0=None (SX),1=87,2=287,3=387,
  198.                 ;4=487,5=586 or higher (FPU always internal))
  199.         FNSTENV FEnv
  200.         FNINIT
  201.         FNSTSW  Temp
  202.         CMP     BYTE PTR Temp,0
  203.         JNE     @@1
  204.         FNSTCW  Temp
  205.         CMP     BYTE PTR [Temp+1],3
  206.         JNE     @@1
  207.         FLDENV  FEnv                    ;FPU exists
  208.         CALL    CPUType                 ;Determine CPU type
  209.         CMP     AX,4                    ;Test CPU(in AX)>=80486
  210.         JAE     @@2                     ;CPU=80486,FPU exists=80487 (Internal)
  211.                                         ;CPU>=80586,FPU=Internal
  212.         MOV     AX,3
  213.         FLD1
  214.         FLDZ
  215.         FDIVP   ST(1),ST
  216.         FLD     ST(0)
  217.         FCHS
  218.         FCOMPP
  219.         FSTSW   Temp
  220.         FWAIT
  221.         TEST    Temp,100H
  222.         JNZ     @@2                     ;80387
  223.         DEC     AX
  224.         FLD