home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 1998 February / Tuning-CD.bin / hardtun / CPU / MSR / MSR.EXE / cpuspeed.asm < prev    next >
Encoding:
Assembly Source File  |  1996-12-03  |  18.0 KB  |  585 lines

  1. ;****************************************************
  2. ;  This program is used to calculate the cpu's speed
  3. ;
  4. ; $Author: Hnguyen $Han Nguyen
  5. ; $History: cpuspeed.asm $
  6. ; *****************  Version 5  *****************
  7. ; User: Hnguyen      Date: 11/26/96   Time: 5:28a
  8. ; Updated in $/General Utilities/CPU Speed Check
  9. ;
  10. ; *****************  Version 2  *****************
  11. ; User: Hnguyen      Date: 11/07/96   Time: 4:52p
  12. ; Updated in $/General Utilities/CPU Speed Check
  13. ; $Log: /General Utilities/CPU Speed Check/cpuspeed.asm $
  14. ; 5     11/26/96 5:28a Hnguyen
  15. ;
  16. ; 2     11/07/96 4:52p Hnguyen
  17. ; $Logfile: /General Utilities/CPU Speed Check/cpuspeed.asm $
  18. ;
  19. ;****************************************************
  20. .MODEL large
  21. .586
  22. .STACK
  23. .CODE
  24.  
  25. TIMER_CNT       EQU    30
  26.  
  27. cpuspeed        PROC
  28.                 .STARTUP
  29.  
  30.         pushfd                          ; save flags
  31.         pop     eax                     ; pop into eax
  32.         mov     ebx,eax                 ; save for later use
  33.         xor     eax,00200000            ; try to toggle bit 21
  34.         push    eax
  35.         popfd                           ; pop eflags
  36.         pushfd
  37.         pop     eax
  38.         cmp     eax,ebx                 ; check if bit 21 toggles
  39.         jz      no_cpuid                ; if it is not, no CPUID
  40.         jmp     cpuid_ok
  41.  
  42. no_cpuid:                               ; display message to notify that the
  43.                                         ; CPUID is not supported
  44.         mov     ah, 9h
  45.         mov     dx, offset nocpuid_msg
  46.         int     21h
  47.         jmp     abort
  48.  
  49. cpuid_ok:                               ; display message that the CPUID is
  50.                                         ; supported
  51.         mov     ah, 9h
  52.         mov     dx, offset cpuid_msg
  53.         int     21h
  54.         mov     eax, 0                  ; function 0
  55.         db      0fh,0a2h                ; CPUID opcode
  56.         cmp     ecx,444d4163h           ; check if the CPU is AMD's CPU
  57.         je      amd_cpu
  58.         mov     ah, 9h
  59.         mov     dx, offset ptium_msg
  60.         int     21h
  61.         jmp     speed
  62.  
  63. amd_cpu:
  64.         mov     eax, 1                  ; function1
  65.         db      0fh,0a2h                ; CPUID opcode
  66.         mov     ebx,eax
  67.         and     ebx,00000FF0h
  68.  
  69.         cmp     ebx,00000500h           ; if it is a class 5 CPU
  70.         je      K5_model0
  71.         cmp     ebx,00000510h
  72.         je      K5_model1
  73.         cmp     ebx,00000520h
  74.         je      K5_model2
  75.         cmp     ebx,00000530h
  76.         je      K5_model3
  77.         cmp     ebx,00000560h           ; if it is a class 6 CPU
  78.         je      K6
  79.         jmp     speed
  80.  
  81.  
  82. K5_model0:                            ; display the message that the CPU is a K5-model 0
  83.         mov     ah, 9h
  84.         mov     dx, offset model0_msg
  85.         int     21h
  86.         jmp     speed
  87.  
  88. K5_model1:
  89.         mov     model,1
  90.         mov     ah,09h
  91.         mov     dx, offset model1_msg
  92.         int     21h
  93.         jmp     speed
  94.  
  95. K5_model2:
  96.         mov     model,2
  97.         mov     ah,9h
  98.         mov     dx,offset model2_msg
  99.         int     21h
  100.         jmp     speed
  101.  
  102. K5_model3:
  103.         mov     model,3
  104.         mov     ah,9h
  105.         mov     dx,offset model3_msg
  106.         int     21h
  107.         jmp     speed
  108.  
  109. message:                                ; display the message and terminate the
  110.         mov     ah,9h                   ; program if the CPU is not a K5 or K6
  111.         mov     dx,offset msg
  112.         int     21h
  113.         jmp     abort
  114.  
  115. K6:                                     ; display the message that the CPU is a K6
  116.         mov     model,6
  117.         mov     ah,9h
  118.         mov     dx, offset K6_msg
  119.         int     21h
  120.  
  121. speed:
  122. ;       wbinvd                          ; validate the cache
  123. ;       mov     eax,CR0                 ; disable the cache
  124. ;       or      eax,60000000h
  125. ;       mov     CR0,eax
  126. ;       wbinvd
  127.  
  128.  
  129.  
  130.         mov     ax,0h                   ; set extra segment to 0
  131.         mov     es,ax
  132.         mov     bx,46ch
  133.         mov     eax,es:[bx]
  134.  
  135. delay:
  136.         cmp     es:[bx],eax             ; synchronize the timer
  137.         je      delay
  138.         mov     ecx,es:[bx]             ; save the current time
  139.         mov     time_Orig,ecx
  140.         xor     ecx,ecx
  141.         cli                             ; disable interrupts
  142.         mov     es:[bx],ecx             ; set timer to 0
  143.         sti                             ; enable interrupts
  144.         rdtsc                           ; read time stamp counter
  145.         mov     esi,edx                 ; save upper 32 bits to esi
  146.         mov     edi,eax                 ; save lower 32 bits to edi
  147.  
  148. ; This is a dummy loop and it can have any kind of instructions
  149. exeloop:
  150.         mov     bx,0
  151.         mov     ax,8000h
  152.         bsf     bx,ax                   ; scan the bit in the second operand
  153.                                         ; starting with bit 0
  154.         mov     bx,0
  155.         mov     ax,0001h
  156.         bsr     bx,ax                   ; scan the bit in the second operand
  157.                                         ; from the most significant bit
  158.         mov     bx, 80
  159.  
  160. cont:
  161.         mov     ax,50
  162.         mov     dx,10
  163.         idiv    dl                      ; signed divide ax by 10
  164.         dec     bx                      ; decrement bx by 1
  165.         jnz     cont
  166.         mov     ax,10
  167.         mov     dx,100
  168.         sub     dx,dx
  169. ;        loop    exeloop
  170.         xor     ecx,ecx
  171.         mov     bx, 46ch
  172.         rdtsc                           ; read time stamp counter again
  173.         mov     ecx,es:[bx]             ; save the number of timer ticks
  174.         cmp     ecx, TIMER_CNT          ; do the loop until the number of timer
  175.                                         ; ticks are equal to TIMER_CNT
  176.         jne     exeloop
  177.         mov     ticks_end,ecx
  178.         add     ecx,time_Orig           ; restore the time
  179.         mov     es:[bx],ecx
  180.  
  181. cont_prog:
  182.         mov     endl,eax                ; save the upper 32 bit of the TSC
  183.                                         ; after executing the loop in endl
  184.         mov     end1,edx                ; save the lower 32 bits of the TSC
  185.                                         ; after executing the loop in end1
  186.  
  187.         sub     endl,edi                ; calculate the total cycles
  188.         sbb     end1,esi                ; upper 32 bits are stored in endl
  189.                                         ; lower 32 bits are stored in end1
  190.  
  191.         mov     eax, endl               ; store the upper 32 bits of the total
  192.         mov     totcyc,eax              ; cycle
  193.  
  194.         mov     eax,end1                ; store the lower 32 bits of the total
  195.         mov     totcyc1,eax             ; cycle
  196.  
  197.         xor     ebx,ebx
  198.         xor     eax,eax
  199.         finit                           ; initialize fpu unit
  200.         fild    dword ptr ticks_end     ; load the integer onto the top of stack
  201.         fmul    dword ptr real          ; multiply the integer by real
  202.         fist    dword ptr totime        ; store the result as an integer into
  203.                                         ; totime
  204.  
  205.         mov     edx,totcyc1             ; freq = cycle / time (in sec)
  206.         mov     eax,totcyc
  207.         mov     ecx,totime
  208.         div     ecx
  209.         mov     res,eax
  210.         cmp     model,2
  211.         je      print_exact_result
  212.         jmp     continue
  213.  
  214. print_exact_result:
  215.         cmp     res,84
  216.         jge     msg_87mhz
  217.         jmp     continue
  218.  
  219. msg_87mhz:
  220.         cmp     res,90
  221.         jle     display_msg
  222.         cmp     res,100
  223.         jge     msg_105mhz
  224.         jmp     continue
  225.  
  226. msg_105mhz:
  227.         cmp     res,108
  228.         jle     display_msg1
  229.         cmp     res,120
  230.         jle     result
  231.         jmp     continue
  232.  
  233.  
  234. display_msg1:
  235.         mov     ah,09h
  236.         mov     dx,offset mul_bus_105msg
  237.         int     21h
  238.         xor     eax,eax
  239.         mov     eax,res
  240.         call    far ptr Print_result
  241.         jmp     abort
  242.  
  243. display_msg:
  244.         mov     ah,09h
  245.         mov     dx,offset mul_bus_87msg
  246.         int     21h
  247.         xor     eax,eax
  248.         mov     eax,res
  249.         call    far ptr Print_result
  250.         jmp     abort
  251.  
  252.  
  253. result:
  254.         mov     ah,09h
  255.         mov     dx,offset rate_message
  256.         int     21h
  257.         xor     eax,eax
  258.         mov     eax,res
  259.         call    far ptr Print_result
  260.         jmp     abort
  261.  
  262. continue:
  263.         cmp     eax,65                  ; if the freq is in the range
  264.         jg      jump_75                 ; 65 < freq <= 75, then display 75 Mhz
  265. jump_75:
  266.         cmp     eax,80
  267.         jle     Display_75
  268.  
  269.  
  270.         cmp     eax,85                  ; if the freq is in the range
  271.         jg      jump_90                 ; 85 < freq <= 95, then display 90 Mhz
  272. jump_90:
  273.         cmp     eax,95
  274.         jle     Display_90
  275.  
  276.  
  277.         cmp     eax,95                  ; if the freq is in the range
  278.         jg      jump_100                ; 95 < freq <= 105, then display 100Mhz
  279. jump_100:
  280.         cmp     eax,105
  281.         jle     Display_100
  282.  
  283.         cmp     eax,115                 ; if the freq is in the range
  284.         jg      jump_120                ; 115 < freq <= 125, then display 120 Mhz
  285. jump_120:
  286.         cmp     eax,125
  287.         jle     Display_120
  288.  
  289.         cmp     eax,128                 ; if the freq is in the range
  290.         jg      jump_133                ; 128 < freq <= 138, then display 133 Mhz
  291. jump_133:
  292.         cmp     eax,138
  293.         jle     Display_133
  294.  
  295.         cmp     eax,145                 ; if the freq is in the range
  296.         jg      jump_150                ; 145 < freq <= 155, then display 150 Mhz
  297. jump_150:
  298.         cmp     eax,155
  299.         jle     Display_150
  300.  
  301.         cmp     eax,161                 ; if the freq is in the range
  302.         jg      jump_166                ; 161 < freq <= 171, then display 166 Mhz
  303. jump_166:
  304.         cmp     eax,171
  305.         jle     Display_166
  306.  
  307.         cmp     eax,175                 ; if the freq is in the range
  308.         jg      jump_180                ; 175 < freq <= 185, then display 180 Mhz
  309. jump_180:
  310.         cmp     eax,185
  311.         jle     Display_180
  312.  
  313.         cmp     eax,195                 ; if the freq is in the range
  314.         jg      jump_200                ; 195 < freq <= 200, then display 200 Mhz
  315. jump_200:
  316.         cmp     eax,205
  317.         jle     Display_200
  318.  
  319.         cmp     eax,205                 ; if the freq is in the range
  320.         jg      jump_210                ; 205 < freq <= 215, then display 210 Mhz
  321. jump_210:
  322.         cmp     eax,215
  323.         jle     Display_210
  324.  
  325.         cmp     eax,228                 ; if the freq is in the range
  326.         jg      jump_233                ; 228 < freq <= 238, then display 233 Mhz
  327. jump_233:
  328.         cmp     eax,238
  329.         jle     Display_233
  330.         jmp     abort
  331.  
  332.  
  333. Display_75:                             ; display 75 Mhz message
  334.         mov     ah,9h
  335.         mov     dx,offset msg_75
  336.         int     21h
  337.         jmp     abort
  338.  
  339. Display_90:                             ; display 90 Mhz message
  340.         cmp     model,6
  341.         je      K6_90mhz
  342.         mov     ah,9h
  343.         mov     dx,offset msg_90
  344.         int     21h
  345.         jmp     abort
  346.  
  347. Display_100:                            ; display 100 Mhz message
  348.         cmp     model,1
  349.         je      display_rate
  350.         cmp     model,6
  351.         je      K6_100mhz
  352.         mov     ah,9h
  353.         mov     dx,offset msg_100
  354.         int     21h
  355.         jmp     abort
  356.  
  357. display_rate:
  358.         mov     ah,09h
  359.         mov     dx,offset rate1_msg
  360.         int     21h
  361.         jmp     abort
  362.  
  363.  
  364. Display_120:                            ; display 120 Mhz message
  365.         cmp     model,6
  366.         je      K6_120mhz
  367.         mov     ah,9h
  368.         mov     dx,offset msg_120
  369.         int     21h
  370.         jmp     abort
  371.  
  372. Display_133:                            ; display 133 Mhz message
  373.         cmp     model,6
  374.         je      K6_133mhz
  375.         mov     ah,9h
  376.         mov     dx,offset msg_133
  377.         int     21h
  378.         jmp     abort
  379.  
  380. Display_150:                            ; display 150 Mhz message
  381.         mov     ah,9h
  382.         mov     dx,offset msg_150
  383.         int     21h
  384.         jmp     abort
  385.  
  386. Display_166:
  387.         mov     ah,9h                   ; display 166 Mhz message
  388.         mov     dx,offset msg_166
  389.         int     21h
  390.         jmp     abort
  391.  
  392. Display_180:                            ; display 180 Mhz message
  393.         mov     ah,9h
  394.         mov     dx,offset msg_180
  395.         int     21h
  396.         jmp     abort
  397.  
  398. Display_200:                            ; display 200 Mhz message
  399.         mov     ah,9h
  400.         mov     dx,offset msg_200
  401.         int     21h
  402.         jmp     abort
  403.  
  404. Display_210:                            ; display 210 Mhz message
  405.         mov     ah,9h
  406.         mov     dx,offset msg_210
  407.         int     21h
  408.         jmp     abort
  409.  
  410. Display_233:                            ; display 233 Mhz message
  411.         mov     ah,9h
  412.         mov     dx,offset msg_233
  413.         int     21h
  414.         jmp     abort
  415.  
  416. K6_90mhz:
  417.         mov     ah,9h
  418.         mov     dx,offset K6_90_msg
  419.         int     21h
  420.         jmp     abort
  421.  
  422. K6_100mhz:
  423.         mov     ah,9h
  424.         mov     dx,offset K6_100_msg
  425.         int     21h
  426.         jmp     abort
  427.  
  428. K6_120mhz:
  429.         mov     ah,9h
  430.         mov     dx,offset K6_120_msg
  431.         int     21h
  432.         jmp     abort
  433.  
  434. K6_133mhz:
  435.         mov     ah,9h
  436.         mov     dx,offset K6_133_msg
  437.         int     21h
  438.  
  439. abort:
  440.         mov     ax,4c00h                ; terminate the program
  441.         int     21h
  442.  
  443. cpuspeed        ENDP
  444.  
  445. ;----------------------------------------------------------------------------------------------
  446. ;convert the frequency into ASCii
  447. ;This procedure is used when you want to display some value in decimal
  448. ;This procedure has nothing to do in this program
  449. ;----------------------------------------------------------------------------------------------
  450. Print_result    PROC    FAR
  451.  
  452.                 push    eax                     ; save the value in eax
  453.                 push    ebx                     ; ebx
  454.                 push    edx                     ; edx
  455.                 push    edi                     ; edi
  456.  
  457.                 xor     ebx,ebx
  458.                 xor     edx,edx
  459.                 mov     ebx,10
  460.                 mov     di,2
  461. dloop:          div     ebx                     ; divide eax by 10
  462.                 add     dl,30h                  ; make remainder ASCII
  463.                 mov     click[di],dl
  464.                 xor     edx,edx
  465.                 dec     di
  466.                 jns     dloop
  467.  
  468.                 mov     dx, offset click
  469.                 mov     ax, 0900h
  470.                 int     021h
  471.  
  472.  
  473.                 pop     edi                     ; pop edi,edx,ebx,eax off the
  474.                 pop     edx                     ; stack
  475.                 pop     ebx
  476.                 pop     eax
  477.  
  478.                 ret
  479.  
  480. Print_result    ENDP
  481. ;-------------------------------------------------------------------
  482.  
  483.  
  484. .DATA
  485.  
  486. K6_90_msg       db      0dh,0ah
  487.                 db        '90 Mhz CPU Clock',0dh,0ah,'$'
  488.  
  489. K6_100_msg      db      0dh,0ah
  490.                 db        '100 Mhz CPU Clock',0dh,0ah,'$'
  491.  
  492. K6_120_msg      db      0dh,0ah
  493.                 db        '120 Mhz CPU Clock',0dh,0ah,'$'
  494.  
  495. K6_133_msg      db      0dh,0ah
  496.                 db        '133 Mhz CPU Clock',0dh,0ah,'$'
  497.  
  498. model0_msg      db      0dh,0ah
  499.                 db        'AMD K5 (Model 0 )',0dh,0ah,'$'
  500.  
  501. model1_msg      db      0dh,0ah
  502.                 db        'AMD K5 (Model 1)',0dh,0ah,'$'
  503.  
  504. model2_msg      db      0dh,0ah
  505.                 db        'AMD K5 (Model 2)',0dh,0ah,'$'
  506.  
  507. model3_msg      db      0dh,0ah
  508.                 db        'AMD K5 (Model 3)',0dh,0ah,'$'
  509.  
  510. K6_msg          db      0dh,0ah
  511.                 db        'AMD-K6',0dh,0ah,'$'
  512.  
  513. msg_75          db      0dh,0ah
  514.                 db        '1.5x - 50mhz bus, 75 Mhz CPU Clock',0dh,0ah,'$'
  515.  
  516. msg_90          db      0dh,0ah
  517.                 db        'PR-120: 1.5x-60mhz bus, 90 Mhz CPU Clock',0dh,0ah,'$'
  518.  
  519. msg_100         db      0dh,0ah
  520.                 db        '2x - 50mhz bus,100 Mhz CPU Clock',0dh,0ah,'$'
  521.  
  522. msg_120         db      0dh,0ah
  523.                 db        'PR-150: 2x-60mhz bus, 120 Mhz CPU Clock',0dh,0ah,'$'
  524.  
  525. msg_133         db      0dh,0ah
  526.                 db        'PR-200: 2x-66mhz bus, 133 Mhz CPU Clock',0dh,0ah,'$'
  527.  
  528. msg_150         db      0dh,0ah
  529.                 db        '150 Mhz CPU Clock',0dh,0ah,'$'
  530.  
  531. msg_166         db      0dh,0ah
  532.                 db        '166 Mhz CPU Clock',0dh,0ah,'$'
  533.  
  534. msg_180         db      0dh,0ah
  535.                 db        '180 Mhz CPU Clock',0dh,0ah,'$'
  536.  
  537. msg_200         db      0dh,0ah
  538.                 db        '200 Mhz CPU Clock',0dh,0ah,'$'
  539.  
  540. msg_210         db      0dh,0ah
  541.                 db        '210 Mhz CPU Clock',0dh,0ah,'$'
  542.  
  543. msg_233         db      0dh,0ah
  544.                 db        '233 Mhz CPU Clock',0dh,0ah,'$'
  545.  
  546. rate1_msg       db      0dh,0ah
  547.                 db        'PR-133: 1.5x - 66mhz bus, 100 Mhz CPU Clock',0dh,0ah,'$'
  548.  
  549. nocpuid_msg     db      0dh,0ah
  550.                 db        'CPUID is not supported by this processor', 0dh,0ah,'$'
  551.  
  552. cpuid_msg       db      0dh,0ah
  553.                 db        'This processor support CPUID', 0dh, 0ah,'$'
  554.  
  555. ptium_msg       db      0dh,0ah
  556.                 db        'PENTIUM CPU',0dh,0ah,'$'
  557.  
  558. msg             db      0dh,0ah
  559.                 db        'This program is not used for class 4 or below',0dh,0ah,'$'
  560.  
  561. rate_message    db      0dh,0ah
  562.                 db        'PR-166: 1.75x - 66mhz bus',0dh,0ah,'$'
  563.  
  564. mul_bus_87msg   db      0dh,0ah
  565.                 db        '1.75x - 50mhz bus',0dh,0ah,'$'
  566.  
  567. mul_bus_105msg  db      0dh,0ah
  568.                 db        '1.75x - 60mhz bus',0dh,0ah,'$'
  569.  
  570. click           db      '   '
  571.                 db      "MHz CPU Clock",0ah,0dh,'$'
  572. model           WORD    0
  573. res             DWORD   0
  574. totcyc          DWORD   0
  575. totcyc1         DWORD   0
  576. totime          DWORD   0
  577. ticks_end       DWORD   0
  578. real            real4   5.4924E4
  579. end1            DWORD   0
  580. endl            DWORD   0
  581. time_Orig       DWORD   0
  582. END
  583.