Subversion Repositories Kolibri OS

Rev

Rev 4610 | Rev 7133 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; Simple test for ring-3 debugging of mtrr.inc.
  2. ; Contains some inputs taken from real-life MTRRs and expected outputs.
  3. format PE console
  4. ;include 'win32a.inc'
  5. macro $Revision [args]
  6. {
  7. }
  8. include '../proc32.inc'
  9. include '../struct.inc'
  10. entry start
  11.  
  12. ; one test has 8, another test has 10
  13. ; this is the maximal value for storing/copying, real value is in MTRRCAP
  14. MAX_VARIABLE_MTRR = 10
  15.  
  16. start:
  17. ; Copy test inputs, run init_mtrr, compare with test outputs. Repeat.
  18.         mov     esi, test1_in_data
  19.         mov     edi, mtrrdata
  20.         mov     ecx, mtrrdata_size / 4
  21.         rep movsd
  22.         call    init_mtrr
  23.         mov     esi, test1_out_data
  24.         mov     edi, mtrrdata
  25.         mov     ecx, mtrrdata_size / 4
  26.         repz cmpsd
  27.         jnz     .fail
  28.         mov     esi, test2_in_data
  29.         mov     edi, mtrrdata
  30.         mov     ecx, mtrrdata_size / 4
  31.         rep movsd
  32.         call    init_mtrr
  33.         mov     esi, test2_out_data
  34.         mov     edi, mtrrdata
  35.         mov     ecx, mtrrdata_size / 4
  36.         repz cmpsd
  37.         jnz     .fail
  38.         ret
  39.  
  40. .fail:
  41.         int3
  42.         jmp     $
  43.  
  44. ; Helper procedure for _rdmsr/_wrmsr, replacements of rdmsr/wrmsr.
  45. ; Returns pointer to memory containing the given MSR.
  46. ; in: ecx = MSR
  47. ; out: esi -> MSR data
  48. proc get_msr_ptr
  49.         mov     esi, mtrrcap
  50.         cmp     ecx, 0xFE
  51.         jz      .ok
  52.         mov     esi, mtrr_def_type
  53.         cmp     ecx, 0x2FF
  54.         jz      .ok
  55.         lea     esi, [ecx-0x200]
  56.         cmp     esi, MAX_VARIABLE_MTRR*2
  57.         jae     .fail
  58.         lea     esi, [mtrr+esi*8]
  59. .ok:
  60.         ret
  61. .fail:
  62.         int3
  63.         ret
  64. endp
  65.  
  66. ; Emulates rdmsr.
  67. proc _rdmsr
  68.         push    esi
  69.         call    get_msr_ptr
  70.         mov     eax, [esi]
  71.         mov     edx, [esi+4]
  72.         pop     esi
  73.         ret
  74. endp
  75.  
  76. ; Emulates wrmsr.
  77. proc _wrmsr
  78.         push    esi
  79.         call    get_msr_ptr
  80.         mov     [esi], eax
  81.         mov     [esi+4], edx
  82.         pop     esi
  83.         ret
  84. endp
  85.  
  86. ; Macro to substitute rdmsr/wrmsr with emulating code.
  87. macro rdmsr
  88. {
  89.         call    _rdmsr
  90. }
  91. macro wrmsr
  92. {
  93.         call    _wrmsr
  94. }
  95. ; Our emulation of rdmsr/wrmsr has nothing to do with real cache
  96. ; and system-wide settings,
  97. ; remove all attempts to wbinvd and disable/enable cache in cr0.
  98. macro wbinvd
  99. {
  100. }
  101. macro mov a,b
  102. {
  103. if ~(a eq cr0) & ~(b eq cr0)
  104.         mov     a, b
  105. end if
  106. }
  107. macro movi r,i
  108. {
  109.         push    i
  110.         pop     r
  111. }
  112.  
  113. include '../kglobals.inc'
  114. CAPS_MTRR equ 12
  115. MSR_MTRR_DEF_TYPE equ 0x2FF
  116. CAPS_PGE  equ 13
  117. CAPS_PAT  equ 16
  118. MSR_CR_PAT equ 0x277
  119. PAT_VALUE  equ 0x00070106 ; (UC<<24)|(UCM<<16)|(WC<<8)|WB
  120. MEM_WB     equ 6               ;write-back memory
  121. MEM_WC     equ 1               ;write combined memory
  122. MEM_UC     equ 0               ;uncached memory
  123. include 'mtrr.inc'
  124.  
  125. BOOT_VARS = 0
  126. BOOT.mtrr       db      1
  127. align 4
  128. cpu_caps        dd      1 shl CAPS_MTRR
  129. LFBAddress      dd      0xE0000000
  130. LFBSize         dd      0x10000000
  131. MEM_AMOUNT      dd      0       ; not used, needed for compilation
  132.  
  133. align 4
  134. ; Test 1: input
  135. test1_in_data:
  136. test1_phys_addr_width   db      36
  137.                         rb      3
  138. test1_in_mtrrcap        dq      0xD08
  139. test1_in_mtrr_def_type dq 0xC00
  140. test1_in_mtrrs:
  141.                 dq      0x000000006, 0xF00000800
  142.                 dq      0x100000006, 0xFC0000800
  143.                 dq      0x0BC000000, 0xFFC000800
  144.                 dq      0x0C0000000, 0xFC0000800
  145.                 dq      0x138000000, 0xFF8000800
  146.                 dq      0, 0
  147.                 dq      0, 0
  148.                 dq      0, 0
  149.                 dq      -1, -1  ; not used
  150.                 dq      -1, -1  ; not used
  151. ; Test 1: output
  152. test1_out_data:
  153.                 dd      36      ; phys_addr_width, readonly
  154.                 dq      0xD08   ; MTRRCAP, readonly
  155.                 dq      0xC00   ; MTRR_DEF_TYPE, should be the same
  156.                 dq      0x000000006, 0xF80000800
  157.                 dq      0x080000006, 0xFC0000800
  158.                 dq      0x0BC000000, 0xFFC000800
  159.                 dq      0x100000006, 0xFC0000800
  160.                 dq      0x138000000, 0xFF8000800
  161.                 dq      0x0E0000001, 0xFFF000800        ; added for [LFBAddress]
  162.                 dq      0, 0
  163.                 dq      0, 0
  164.                 dq      -1, -1  ; not used
  165.                 dq      -1, -1  ; not used
  166.  
  167. ; Test 2: input
  168. test2_in_data:
  169. test2_phys_addr_width   db      39
  170.                         rb      3
  171. test2_in_mtrrcap        dq      0xD0A
  172. test2_in_mtrr_def_type  dq      0xC00
  173. test2_in_mtrrs:
  174.                 dq      0x0000000006, 0x7F00000800
  175.                 dq      0x0100000006, 0x7FE0000800
  176.                 dq      0x00E0000000, 0x7FE0000800
  177.                 dq      0x00DC000000, 0x7FFC000800
  178.                 dq      0x00DBC00000, 0x7FFFC00800
  179.                 dq      0x011F800000, 0x7FFF800800
  180.                 dq      0x011F400000, 0x7FFFC00800
  181.                 dq      0x011F200000, 0x7FFFE00800
  182.                 dq      0, 0
  183.                 dq      0, 0
  184.  
  185. ; Test 2: output
  186. test2_out_data:
  187.                 dd      39      ; phys_addr_width, readonly
  188.                 dq      0xD0A   ; MTRRCAP, readonly
  189.                 dq      0xC00   ; MTRR_DEF_TYPE, should be the same
  190.                 dq      0x0000000006, 0x7F80000800
  191.                 dq      0x0080000006, 0x7FC0000800
  192.                 dq      0x00C0000006, 0x7FE0000800
  193.                 dq      0x00DC000000, 0x7FFC000800
  194.                 dq      0x00DBC00000, 0x7FFFC00800
  195.                 dq      0x0100000006, 0x7FE0000800
  196.                 dq      0x011F800000, 0x7FFF800800
  197.                 dq      0x011F400000, 0x7FFFC00800
  198.                 dq      0x011F200000, 0x7FFFE00800
  199.                 dq      0x00E0000001, 0x7FFF000800      ; added for [LFBAddress]
  200. IncludeIGlobals
  201. align 4
  202. mtrrdata:
  203. cpu_phys_addr_width     db      ?
  204.                 rb      3
  205. mtrrcap         dq      ?
  206. mtrr_def_type   dq      ?
  207. mtrr            rq      MAX_VARIABLE_MTRR*2
  208. mtrrdata_size = $ - mtrrdata
  209. IncludeUGlobals
  210.