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

  1. ;
  2.  
  3. ; This program was hacked together for the K5-PR166
  4. ; This is for internal use only
  5. ;
  6. ; Chris Gray / Mike Wisor -- NOV-1996
  7. ;
  8.     PAGE    59, 132
  9.        .586P
  10.  
  11. CODE    SEGMENT BYTE PUBLIC use16 'CODE'
  12.         ASSUME CS:CODE,DS:CODE,ES:CODE,SS:CODE
  13.  
  14. ;This program was created by Mike Wisor and should be treated as AMD
  15. ;Confidential Information
  16.  
  17. ;Revision 1.2 added WBINVD before disabling caches ~~mtw 2/15/95
  18.  
  19.     org     100h                            ;.com file
  20. start:
  21.     jmp     hwcr_main
  22.  
  23. ;****** constants
  24. debug           equ     0h                      ;if one then debug mode
  25.  
  26. cr              equ     0dh
  27. lf              equ     0ah
  28.  
  29. ;****** macros and routines for the program
  30. ;wrmsr           macro           
  31. ;        db      0fh,30h
  32. ;        endm
  33.  
  34. ;rdmsr           macro
  35. ;        db      0fh,32h
  36. ;        endm
  37.  
  38. ;wbinvd          macro                           ;~~mtw 2/15/95
  39. ;                db      0fh,09h                 ;~~mtw 2/15/95
  40. ;                endm                            ;~~mtw 2/15/95
  41.  
  42. cpu_id          macro   case
  43.         mov     eax,case
  44.         db      0fh,0a2h
  45.         endm
  46.  
  47. tag_it          macro   addr                    ;set patch tag macro
  48.         mov     ecx,81h
  49.         mov     eax,addr
  50.         wrmsr
  51.         endm
  52.  
  53. enable_hwcr     macro
  54.         mov     ecx,83h
  55.         rdmsr
  56.         or      eax,00002000h   ;set bit 13
  57.         mov     edx,0c0de0000h
  58.         wrmsr
  59.         endm
  60.     
  61. convert PROC
  62.     push    bx
  63.     mov     bx,ax
  64.     xchg    ah,al                   ;contains most significant
  65.     mov     ah,0
  66.     cmp     al,39h
  67.     jbe     not_char
  68.     sub     ax,57h
  69.     rol     ax,4
  70.     jmp     chk_nxt
  71.  
  72. not_char:
  73.     and     ax,000fh                ;convert ascii to hex
  74.     rol     ax,4
  75.  
  76. chk_nxt:
  77.     mov     bh,0
  78.     cmp     bl,39h
  79.     jbe     not_char1
  80.     sub     bx,57h
  81.     jmp     sum_up
  82.  
  83. not_char1:
  84.     and     bx,000fh
  85.  
  86. sum_up:
  87.     add     ax,bx                   ;result of conversion
  88.     pop     bx
  89.     ret
  90. convert ENDP
  91.  
  92. hex_to_ascii    PROC
  93. ;convert hex to ascii - input is eax and si for storage pointer 
  94.     mov     ebx,eax
  95.     mov     cl,10h
  96.     ror     ebx,cl          ;place upper 16 bits into lower bx area
  97.  
  98.     push    bx
  99.     mov     bl,bh
  100.     and     bx,0f00fh
  101.     mov     cl,4
  102.     ror     bh,cl
  103.     call    ascii_adjust
  104.     mov     byte ptr [si],bh
  105.     inc     si
  106.     mov     byte ptr [si],bl
  107.     inc     si
  108.     pop     bx
  109.  
  110.     mov     bh,bl
  111.     and     bx,0f00fh
  112.     mov     cl,4
  113.     ror     bh,cl
  114.     call    ascii_adjust
  115.     mov     byte ptr [si],bh
  116.     inc     si
  117.     mov     byte ptr [si],bl
  118.     inc     si
  119.  
  120.     mov     ebx,eax
  121.     push    bx
  122.     mov     bl,bh
  123.     and     bx,0f00fh
  124.     mov     cl,4
  125.     ror     bh,cl
  126.     call    ascii_adjust
  127.     mov     byte ptr [si],bh
  128.     inc     si
  129.     mov     byte ptr [si],bl
  130.     inc     si
  131.     pop     bx
  132.  
  133.     mov     bh,bl
  134.     and     bx,0f00fh
  135.     mov     cl,4
  136.     ror     bh,cl
  137.     call    ascii_adjust
  138.     mov     byte ptr [si],bh
  139.     inc     si
  140.     mov     byte ptr [si],bl
  141.     inc     si
  142.     
  143.     ret
  144. hex_to_ascii    ENDP
  145.  
  146. ascii_adjust    PROC
  147. ;bx is input in ready to be adjusted format
  148.     cmp     bh,9h
  149.     ja      not_number
  150.     add     bh,30h
  151.     jmp     do_bl
  152.  
  153. not_number:
  154.     add     bh,37h
  155.  
  156. do_bl:
  157.     cmp     bl,9h
  158.     ja      not_number1
  159.     add     bl,30h
  160.     jmp     xit_ascii_adjust
  161.  
  162. not_number1:
  163.     add     bl,37h
  164.  
  165. xit_ascii_adjust:
  166.     ret
  167. ascii_adjust    ENDP
  168.  
  169. ;****** data area
  170. ;mtw added messages
  171. help_msg                db      'k5_tr12 [options]',cr,lf
  172.             db      '     /? - help',cr,lf
  173.             db      '     /r - Read hardware configuration register. (default)',cr,lf
  174.             db      '     /w00000000 - Write specified value to the hardware configuration register.',cr,lf
  175.             db    '     /pxxxxxxxx - Programmable Memory Range ( Write Allocate)',cr,lf
  176.             db    '          bits 31-16 Range : yyyy',cr,lf
  177.             db    '          bits 15-0 Range  : xxxx',cr,lf
  178.             db    '     /txxxxxxxx - Programmable Memory Range ( Write Allocate)',cr,lf
  179.             db    '          bit  18   : Top of Memory Enable',cr,lf
  180.             db    '          bit  17   : Programmable Range Enable',cr,lf
  181.             db    '          bit  16   : Fixed Range Enable ',cr,lf
  182.             db    '          bits 15-0 : Top of Memory Range ',cr,lf
  183.  
  184.             db      cr,lf
  185.             db      '     K5_TR12 ' ,cr,lf
  186.             db      '     To select the desired function set the bit to a 1.',cr,lf
  187.             db      '       bits not listed are not used (set to zero)',cr,lf
  188.             db    '       bit 31     - Disable write to anything pipelining',cr,lf
  189.             db    '       bit 30     - Disable I to I pipelining ',cr,lf
  190.             db    '       bit 23     - Enable FAST FDIV ',cr,lf
  191.             db    '       bit 18     - Disable Pipeline ',cr,lf
  192.             db      '       bit 07     - disable data cache',cr,lf
  193.             db      '       bit 06     - disable instruction cache',cr,lf
  194.             db      '       bit 05     - disable branch predication',cr,lf
  195.             db      '       bit 04     - enable write allocate',cr,lf
  196.             db      '       bit 00     - disable stop_clock at enter_freeze',cr,lf
  197.             db      '$'
  198.  
  199. cmd_line_error          db      CR,LF,CR,LF,'Check the command line parameters - ERROR detected!',CR,LF,CR,LF,'$'
  200. hwcr_write83_msg        db      cr,lf,' NOTHINGh has been written into the HWCR.',cr,lf
  201. hwcr_write85_msg        db      cr,lf,' NOTHINGh has been written into MSR 85h.',cr,lf
  202. hwcr_write86_msg        db      cr,lf,' NOTHINGh has been written into MSR 86h.',cr,lf,'$'
  203. hwcr_read83_msg         db      cr,lf,' NOTHINGh has been read from the HWCR.',cr,lf
  204. hwcr_read85_msg         db      cr,lf,' NOTHINGh has been read from MSR 85h.',cr,lf
  205. hwcr_read86_msg         db      cr,lf,' NOTHINGh has been read from MSR 86h.',cr,lf,'$'
  206. cpu_msg                 db      cr,lf,'An AMD-K5 CPU supporting CPUID is in place.',cr,lf,'$'
  207. not_amd            db    cr,lf,'An AMD-K5 CPU is not in place. Aborting!',cr,lf,'$'
  208. sign_on_msg             db      cr,lf,'K5 TR12 Feature Bit Program - Version .00002',cr,lf
  209.             db            'Maintained by Chris Gray.',cr,lf,'$'
  210. cpu_id_string           db      cr,lf,'000000000000',cr,lf,'$'
  211.  
  212. bytes_read              db      0       ;bytes read from command line
  213. stepID            db    0    ;dfault stepping model to !4
  214. invalid_step        db    cr,lf,'Invalid Stepping ID for this operation. Aborting!',cr,lf,'$'
  215.  
  216. ;******* main program
  217.  
  218. hwcr_main:
  219.     mov     ax,cs
  220.     mov     ds,ax
  221.     mov     ah,9
  222.     mov     dx,offset sign_on_msg
  223.     int     21h
  224.  
  225. cpu_id_ok:
  226.     cpu_id   0                       ;case 0
  227.     mov     si,offset cpu_id_string
  228.     push    ecx
  229.     mov     eax,ecx
  230.     mov     [si+10],al
  231.     mov     [si+11],ah
  232.     mov     cl,10h
  233.     ror     eax,cl
  234.     mov     [si+12],al
  235.     mov     [si+13],ah
  236.  
  237.     mov     [si+6],dl
  238.     mov     [si+7],dh
  239.     mov     cl,10h
  240.     ror     edx,cl
  241.     mov     [si+8],dl
  242.     mov     [si+9],dh
  243.  
  244.     mov     [si+2],bl
  245.     mov     [si+3],bh
  246.     mov     cl,10h
  247.     ror     ebx,cl
  248.     mov     [si+4],bl
  249.     mov     [si+5],bh
  250.  
  251.  
  252.     mov     ah,9h
  253.     mov     dx,offset cpu_id_string
  254.     int     21h
  255.     pop     ecx
  256.     cmp     ecx,444D4163h
  257.     je      amd_cpu
  258.     mov    dx, offset not_amd
  259.     mov    ah, 09h
  260.     int    21h
  261.     jmp    exit
  262.  
  263. amd_cpu:
  264.     mov     ah,9
  265.     mov     dx,offset cpu_msg
  266.     int     21h
  267.  
  268. ; Now find out stepping model ;
  269.     cpu_id    1            ;case 1
  270.     and    eax, 0Fh        ;get stepping ID
  271.     mov    stepID,al
  272.     
  273.     mov     ah,62h                  ;get PSP segment
  274.     int     21h
  275.     mov     es,bx                   ;bx contains the segment
  276.     cld                             ;clear direction
  277.     mov     al,'/'                  ;scan line delimiter
  278.     mov     cl,byte ptr es:[80h]    ;length of scan line
  279.     mov     byte ptr bytes_read,cl
  280.     mov     di,81h                  ;scan line start
  281.     cmp     byte ptr es:[80h],0     ;nothing entered
  282.     je      get_help                ;if nothing show get help
  283.  
  284. cont_scan:
  285.     mov     cx,0
  286.     mov     cl,byte ptr bytes_read
  287.     mov     al,'/'                  ;scan line delimiter
  288.     repne   scasb                   ;look for '/'
  289.     pushf
  290.     cmp     cx,0
  291.     je      done_with_line
  292.     popf
  293.     mov     byte ptr bytes_read,cl
  294.     je      chk_param
  295.     jmp     exit
  296.  
  297. done_with_line:
  298.     popf
  299.     jmp     exit
  300.  
  301. chk_param:
  302. ;first check for help and patch addresses
  303.     cmp     byte ptr es:[di],'?'    ;HELP!!!!!!!!!!!
  304.     je      get_help
  305.     cmp     byte ptr es:[di],'r'    
  306.     je      read_hwcr
  307.     cmp     byte ptr es:[di],'w'    
  308.     je      write_hwcr
  309.     cmp    byte ptr es:[di],'p'
  310.     je    get_program
  311.     cmp    byte ptr es:[di],'t'
  312.     je    get_topmem
  313.     
  314.  
  315.  
  316. errinline:
  317.     mov     ah,9
  318.     mov     dx,offset cmd_line_error
  319.     int     21h
  320.  
  321. get_help:
  322.     mov     ah,9
  323.     mov     dx,offset help_msg
  324.     int     21h
  325.     jmp     exit
  326.  
  327. get_program:
  328.     cmp    stepID, 3h
  329.     jae    Ok_program    
  330.     mov    dx, offset invalid_step
  331.     mov    ah, 09h
  332.     int    21h
  333.     jmp    exit
  334.  
  335. Ok_program:
  336.     mov     ecx,86h
  337.     rdmsr                           ;eax contains the hwcr data
  338.     
  339.     mov     ah,byte ptr es:[di+1]   ;read hwcr data
  340.     mov     al,byte ptr es:[di+2]
  341.     mov     bx,ax                   ;save
  342.     mov     ah,byte ptr es:[di+3]   ;
  343.     mov     al,byte ptr es:[di+4]   ;
  344.     call    convert                 ;convert ax ascii to hex in al
  345.     xchg    bx,ax                   ;save converted result
  346.     call    convert
  347.     shl     ax,8h                   ;adjust to ah
  348.     mov     al,bl                   ;ax holds data
  349.  
  350.     mov     cl,10h
  351.     rol     eax,cl                  ;place into upper 16 bits of eax
  352.  
  353.     mov     ah,byte ptr es:[di+5]   ;read hwcr data
  354.     mov     al,byte ptr es:[di+6]
  355.     mov     bx,ax                   ;save
  356.     mov     ah,byte ptr es:[di+7]   ;
  357.     mov     al,byte ptr es:[di+8]   ;
  358.     call    convert                 ;convert ax ascii to hex in al
  359.     xchg    bx,ax                   ;save converted result
  360.     call    convert
  361.     shl     ax,8h                   ;adjust to ah
  362.     mov     al,bl                   ;eax holds data
  363.  
  364. ; EDX is the same from the read above
  365.     mov     ecx,86h
  366.     wrmsr
  367.  
  368.         mov     ecx,86h                 ;~~mtw 12/11/96 read back data
  369.         rdmsr
  370.  
  371.         mov     si,offset hwcr_write86_msg + 2
  372.     call    hex_to_ascii
  373.  
  374.     mov     ah,9
  375.         mov     dx,offset hwcr_write86_msg
  376.     int     21h
  377.  
  378.     jmp    cont_scan
  379.  
  380.  
  381. get_topmem:
  382.     
  383.     cmp    stepID, 3h
  384.     jae    Ok_topmem
  385.     mov    dx, offset invalid_step
  386.     mov    ah, 09h
  387.     int    21h
  388.     jmp    exit
  389.  
  390. Ok_topmem:
  391.     mov     ecx,85h
  392.     rdmsr                                   ;eax contains the hwcr data
  393.     push    eax
  394.     
  395.     mov     ah,byte ptr es:[di+1]   ;read hwcr data
  396.     mov     al,byte ptr es:[di+2]
  397.     mov     bx,ax                   ;save
  398.     mov     ah,byte ptr es:[di+3]   ;
  399.     mov     al,byte ptr es:[di+4]   ;
  400.     call    convert                 ;convert ax ascii to hex in al
  401.     xchg    bx,ax                   ;save converted result
  402.     call    convert
  403.     shl     ax,8h                   ;adjust to ah
  404.     mov     al,bl                   ;ax holds data
  405.  
  406.     mov     cl,10h
  407.     rol     eax,cl                  ;place into upper 16 bits of eax
  408.  
  409.     mov     ah,byte ptr es:[di+5]   ;read hwcr data
  410.     mov     al,byte ptr es:[di+6]
  411.     mov     bx,ax                   ;save
  412.     mov     ah,byte ptr es:[di+7]   ;
  413.     mov     al,byte ptr es:[di+8]   ;
  414.     call    convert                 ;convert ax ascii to hex in al
  415.     xchg    bx,ax                   ;save converted result
  416.     call    convert
  417.     shl     ax,8h                   ;adjust to ah
  418.     mov     al,bl                   ;eax holds data
  419.  
  420. ; have to mask off some bits in EAX
  421.     pop    ebx            ; restore prev eax in EBX
  422.     and    ebx, 0FF80000h
  423.     and    eax, 07FFFFh
  424.     or    ebx, eax
  425.     xchg    eax, ebx
  426.  
  427. ; EDX is the same from the read above
  428.     mov     ecx,85h
  429.     wrmsr
  430.  
  431.         mov     ecx,85h                 ;~~mtw 12/11/96 read back data
  432.         rdmsr
  433.  
  434.         mov     si,offset hwcr_write85_msg + 2
  435.     call    hex_to_ascii
  436.  
  437.     mov     ah,9
  438.         mov     dx,offset hwcr_write85_msg
  439.     int     21h
  440.  
  441.     jmp    cont_scan
  442.  
  443. read_hwcr:
  444.  
  445.     mov     ecx,83h
  446.     rdmsr                                     ;eax contains the hwcr data
  447.         mov     si,offset hwcr_read83_msg + 2     ;starting point for storage
  448.     call    hex_to_ascii
  449.  
  450.     cmp    stepID, 4h
  451.     jb    bypass_others
  452.  
  453.         mov     ecx,85h                         ;read TOM register
  454.         rdmsr
  455.         mov     si,offset hwcr_read85_msg + 2
  456.         call    hex_to_ascii
  457.  
  458.         mov     ecx,86h                         ;read PRR register
  459.         rdmsr
  460.         mov     si,offset hwcr_read86_msg + 2
  461.         call    hex_to_ascii
  462.     jmp    continue_read
  463.  
  464. bypass_others:
  465.     mov     bx, offset hwcr_read85_msg
  466.     mov    byte ptr [bx], '$'
  467. continue_read:
  468.  
  469.         mov     ah,9h                           ;print read data for 83,85,86
  470.         mov     dx,offset hwcr_read83_msg
  471.     int     21h
  472.     jmp     cont_scan
  473.  
  474. write_hwcr:
  475.  
  476.     mov     ah,byte ptr es:[di+1]   ;read hwcr data
  477.     mov     al,byte ptr es:[di+2]
  478.     mov     bx,ax                   ;save
  479.     mov     ah,byte ptr es:[di+3]   ;
  480.     mov     al,byte ptr es:[di+4]   ;
  481.     call    convert                 ;convert ax ascii to hex in al
  482.     xchg    bx,ax                   ;save converted result
  483.     call    convert
  484.     shl     ax,8h                   ;adjust to ah
  485.     mov     al,bl                   ;ax holds data
  486.  
  487.     mov     cl,10h
  488.     rol     eax,cl                  ;place into upper 16 bits of eax
  489.  
  490.     mov     ah,byte ptr es:[di+5]   ;read hwcr data
  491.     mov     al,byte ptr es:[di+6]
  492.     mov     bx,ax                   ;save
  493.     mov     ah,byte ptr es:[di+7]   ;
  494.     mov     al,byte ptr es:[di+8]   ;
  495.     call    convert                 ;convert ax ascii to hex in al
  496.     xchg    bx,ax                   ;save converted result
  497.     call    convert
  498.     shl     ax,8h                   ;adjust to ah
  499.     mov     al,bl                   ;eax holds data
  500.  
  501.     wbinvd                          ;~~mtw 2/15/95
  502.     mov     ecx,83h
  503.     wrmsr
  504.  
  505.         mov     ecx,83h                 ;~~mtw 12/11/96 - read back data written
  506.         rdmsr
  507.  
  508.         mov     si,offset hwcr_write83_msg + 2
  509.     call    hex_to_ascii
  510.     
  511.     cmp    stepID, 4h
  512.     jae    continue_write
  513.     mov    bx, offset hwcr_write85_msg
  514.     mov    byte ptr [bx], '$'
  515.  
  516. continue_write:
  517.     mov     ah,9
  518.         mov     dx,offset hwcr_write83_msg
  519.     int     21h
  520.     jmp     cont_scan
  521.  
  522. exit:        
  523.  
  524.     mov     ax,4c00h
  525.     int     21h                     ;return to dos
  526.  
  527. code    ends
  528.     end         start
  529.