Subversion Repositories Kolibri OS

Rev

Rev 7132 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4610 clevermous 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
MEM_WB     equ 6               ;write-back memory
116
MEM_WC     equ 1               ;write combined memory
117
MEM_UC     equ 0               ;uncached memory
118
include 'mtrr.inc'
119
 
120
BOOT_VARS = 0
121
BOOT_MTRR       db      1
122
align 4
123
cpu_caps        dd      1 shl CAPS_MTRR
124
LFBAddress      dd      0xE0000000
125
LFBSize         dd      0x10000000
126
MEM_AMOUNT      dd      0       ; not used, needed for compilation
127
 
128
align 4
129
; Test 1: input
130
test1_in_data:
131
test1_phys_addr_width   db      36
132
                        rb      3
133
test1_in_mtrrcap        dq      0xD08
134
test1_in_mtrr_def_type dq 0xC00
135
test1_in_mtrrs:
136
                dq      0x000000006, 0xF00000800
137
                dq      0x100000006, 0xFC0000800
138
                dq      0x0BC000000, 0xFFC000800
139
                dq      0x0C0000000, 0xFC0000800
140
                dq      0x138000000, 0xFF8000800
141
                dq      0, 0
142
                dq      0, 0
143
                dq      0, 0
144
                dq      -1, -1  ; not used
145
                dq      -1, -1  ; not used
146
; Test 1: output
147
test1_out_data:
148
                dd      36      ; phys_addr_width, readonly
149
                dq      0xD08   ; MTRRCAP, readonly
150
                dq      0xC00   ; MTRR_DEF_TYPE, should be the same
151
                dq      0x000000006, 0xF80000800
152
                dq      0x080000006, 0xFC0000800
153
                dq      0x0BC000000, 0xFFC000800
154
                dq      0x100000006, 0xFC0000800
155
                dq      0x138000000, 0xFF8000800
156
                dq      0x0E0000001, 0xFFF000800        ; added for [LFBAddress]
157
                dq      0, 0
158
                dq      0, 0
159
                dq      -1, -1  ; not used
160
                dq      -1, -1  ; not used
161
 
162
; Test 2: input
163
test2_in_data:
164
test2_phys_addr_width   db      39
165
                        rb      3
166
test2_in_mtrrcap        dq      0xD0A
167
test2_in_mtrr_def_type  dq      0xC00
168
test2_in_mtrrs:
169
                dq      0x0000000006, 0x7F00000800
170
                dq      0x0100000006, 0x7FE0000800
171
                dq      0x00E0000000, 0x7FE0000800
172
                dq      0x00DC000000, 0x7FFC000800
173
                dq      0x00DBC00000, 0x7FFFC00800
174
                dq      0x011F800000, 0x7FFF800800
175
                dq      0x011F400000, 0x7FFFC00800
176
                dq      0x011F200000, 0x7FFFE00800
177
                dq      0, 0
178
                dq      0, 0
179
 
180
; Test 2: output
181
test2_out_data:
182
                dd      39      ; phys_addr_width, readonly
183
                dq      0xD0A   ; MTRRCAP, readonly
184
                dq      0xC00   ; MTRR_DEF_TYPE, should be the same
185
                dq      0x0000000006, 0x7F80000800
186
                dq      0x0080000006, 0x7FC0000800
187
                dq      0x00C0000006, 0x7FE0000800
188
                dq      0x00DC000000, 0x7FFC000800
189
                dq      0x00DBC00000, 0x7FFFC00800
190
                dq      0x0100000006, 0x7FE0000800
191
                dq      0x011F800000, 0x7FFF800800
192
                dq      0x011F400000, 0x7FFFC00800
193
                dq      0x011F200000, 0x7FFFE00800
194
                dq      0x00E0000001, 0x7FFF000800      ; added for [LFBAddress]
195
IncludeIGlobals
196
align 4
197
mtrrdata:
198
cpu_phys_addr_width     db      ?
199
                rb      3
200
mtrrcap         dq      ?
201
mtrr_def_type   dq      ?
202
mtrr            rq      MAX_VARIABLE_MTRR*2
203
mtrrdata_size = $ - mtrrdata
204
IncludeUGlobals