Subversion Repositories Kolibri OS

Rev

Rev 983 | Rev 1055 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 983 Rev 1030
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 983 $
8
$Revision: 1030 $
9
 
9
 
Line 1166... Line 1166...
1166
           mov cr0, eax
1166
           mov cr0, eax
1167
           wbinvd               ;invalidate cache
1167
           wbinvd               ;invalidate cache
Line 1168... Line 1168...
1168
 
1168
 
1169
           mov ecx, 0x2FF
1169
           mov ecx, 0x2FF
-
 
1170
           rdmsr                ;
-
 
1171
; has BIOS already initialized MTRRs?
-
 
1172
           test ah, 8
-
 
1173
           jnz .skip_init
-
 
1174
; rarely needed, so mainly placeholder
1170
           rdmsr                ;
1175
; main memory - cached
Line 1171... Line -...
1171
           push eax
-
 
1172
 
-
 
1173
           xor edx, edx
-
 
1174
           xor eax, eax
-
 
1175
           mov ecx, 0x2FF
-
 
1176
           wrmsr                ;disable all MTRR
1176
           push eax
1177
 
1177
 
1178
           mov eax, [MEM_AMOUNT]
1178
           mov eax, [MEM_AMOUNT]
1179
; round eax up to next power of 2
1179
; round eax up to next power of 2
1180
           dec eax
1180
           dec eax
1181
           bsr ecx, eax
1181
           bsr ecx, eax
1182
           mov eax, 2
1182
           mov ebx, 2
1183
           shl eax, cl
1183
           shl ebx, cl
1184
           stdcall set_mtrr, edx,edx,eax,MEM_WB
1184
           dec ebx
-
 
1185
; base of memory range = 0, type of memory range = MEM_WB
-
 
1186
           xor edx, edx
-
 
1187
           mov eax, MEM_WB
-
 
1188
           mov ecx, 0x200
-
 
1189
           wrmsr
-
 
1190
; mask of memory range = 0xFFFFFFFFF - (size - 1), ebx = size - 1
-
 
1191
           mov eax, 0xFFFFFFFF
-
 
1192
           mov edx, 0x0000000F
-
 
1193
           sub eax, ebx
-
 
1194
           sbb edx, 0
-
 
1195
           or eax, 0x800
-
 
1196
           inc ecx
1185
           stdcall set_mtrr, 1,[LFBAddress],[LFBSize],MEM_WC
1197
           wrmsr
1186
           xor edx, edx
-
 
1187
           xor eax, eax
1198
; clear unused MTRRs
1188
           mov ecx, 0x204
1199
           xor eax, eax
1189
           mov ebx, 6
-
 
1190
@@:
-
 
1191
           wrmsr                ;disable unused MTRR
1200
           xor edx, edx
1192
           inc ecx
1201
@@:
1193
           wrmsr
1202
           wrmsr
1194
           inc ecx
1203
           inc ecx
1195
           dec ebx
-
 
1196
           jnz @b
1204
           cmp ecx, 0x210
1197
 
-
 
1198
           wbinvd               ;again invalidate
1205
           jb @b
1199
 
1206
; enable MTRRs
1200
           pop eax
1207
           pop eax
1201
           or eax, 0x800        ;set default memtype to UC
1208
           or ah, 8
-
 
1209
           and al, 0xF0 ; default memtype = UC
-
 
1210
           mov ecx, 0x2FF
-
 
1211
           wrmsr
-
 
1212
.skip_init:
1202
           and al, 0xF0
1213
           stdcall set_mtrr, [LFBAddress],[LFBSize],MEM_WC
Line 1203... Line 1214...
1203
           mov ecx, 0x2FF
1214
 
1204
           wrmsr                ;and enable MTRR
1215
           wbinvd               ;again invalidate
1205
 
1216
 
1206
           mov eax, cr0
1217
           mov eax, cr0
1207
           and eax, not 0x60000000
1218
           and eax, not 0x60000000
1208
           mov cr0, eax         ; enable caching
1219
           mov cr0, eax         ; enable caching
Line 1209... Line 1220...
1209
.exit:
1220
.exit:
1210
           ret
1221
           ret
-
 
1222
endp
-
 
1223
 
1211
endp
1224
align 4
-
 
1225
proc set_mtrr stdcall, base:dword,size:dword,mem_type:dword
-
 
1226
; find unused register
-
 
1227
           mov ecx, 0x201
-
 
1228
@@:
-
 
1229
           rdmsr
-
 
1230
           dec ecx
-
 
1231
           test ah, 8
-
 
1232
           jz .found
-
 
1233
           rdmsr
-
 
1234
           mov al, 0 ; clear memory type field
-
 
1235
           cmp eax, [base]
-
 
1236
           jz .ret
-
 
1237
           add ecx, 3
-
 
1238
           cmp ecx, 0x210
-
 
1239
           jb @b
-
 
1240
; no free registers, ignore the call
1212
 
1241
.ret:
1213
align 4
1242
           ret
1214
proc set_mtrr stdcall, reg:dword,base:dword,size:dword,mem_type:dword
1243
.found:
1215
 
-
 
1216
           xor edx, edx
-
 
1217
           mov eax, [base]
1244
; found, write values
Line 1218... Line 1245...
1218
           or eax, [mem_type]
1245
           xor edx, edx
1219
           mov ecx, [reg]
1246
           mov eax, [base]
1220
           lea ecx, [0x200+ecx*2]
1247
           or eax, [mem_type]