Rev 5356 | Rev 5363 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5356 | Rev 5360 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. 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: 5356 $ |
8 | $Revision: 5360 $ |
9 | 9 | ||
Line 10... | Line 10... | ||
10 | ; Initializes MTRRs. |
10 | ; Initializes MTRRs. |
Line 23... | Line 23... | ||
23 | ret |
23 | ret |
24 | endp |
24 | endp |
Line 25... | Line 25... | ||
25 | 25 | ||
26 | ; Helper procedure for mtrr_reconfigure and set_mtrr, |
26 | ; Helper procedure for mtrr_reconfigure and set_mtrr, |
- | 27 | ; called before changes in MTRRs. |
|
- | 28 | ; 1. disable and flush caches |
|
- | 29 | ; 2. clear PGE bit in cr4 |
|
- | 30 | ; 3. flush TLB |
|
- | 31 | ; 4. disable mtrr |
|
27 | ; called before changes in MTRRs. |
32 | |
28 | proc mtrr_begin_change |
33 | proc mtrr_begin_change |
29 | mov eax, cr0 |
34 | mov eax, cr0 |
30 | or eax, 0x60000000 ;disable caching |
35 | or eax, 0x60000000 ;disable caching |
31 | mov cr0, eax |
36 | mov cr0, eax |
- | 37 | wbinvd ;invalidate cache |
|
- | 38 | ||
- | 39 | bt [cpu_caps], CAPS_PGE |
|
- | 40 | jnc .cr3_flush |
|
- | 41 | ||
- | 42 | mov eax, cr4 |
|
- | 43 | btr eax, 7 ;clear cr4.PGE |
|
- | 44 | mov cr4, eax ;flush TLB |
|
- | 45 | jmp @F ;skip extra serialization |
|
- | 46 | ||
- | 47 | .cr3_flush: |
|
- | 48 | mov eax, cr3 |
|
- | 49 | mov cr3, eax ;flush TLB |
|
- | 50 | @@: |
|
- | 51 | mov ecx, MSR_MTRR_DEF_TYPE |
|
- | 52 | rdmsr |
|
- | 53 | btr eax, 11 ;clear enable flag |
|
32 | wbinvd ;invalidate cache |
54 | wrmsr ;disable mtrr |
33 | ret |
55 | ret |
Line 34... | Line 56... | ||
34 | endp |
56 | endp |
35 | 57 | ||
- | 58 | ; Helper procedure for mtrr_reconfigure and set_mtrr, |
|
- | 59 | ; called after changes in MTRRs. |
|
- | 60 | ; 1. enable mtrr |
|
- | 61 | ; 2. flush all caches |
|
- | 62 | ; 3. flush TLB |
|
36 | ; Helper procedure for mtrr_reconfigure and set_mtrr, |
63 | ; 4. restore cr4.PGE flag, if required |
- | 64 | ||
- | 65 | proc mtrr_end_change |
|
- | 66 | mov ecx, MSR_MTRR_DEF_TYPE |
|
- | 67 | rdmsr |
|
- | 68 | or ah, 8 ; enable variable-ranges MTRR |
|
- | 69 | and al, 0xF0 ; default memtype = UC |
|
37 | ; called after changes in MTRRs. |
70 | wrmsr |
38 | proc mtrr_end_change |
71 | |
39 | wbinvd ;again invalidate |
72 | wbinvd ;again invalidate |
40 | mov eax, cr0 |
73 | mov eax, cr0 |
- | 74 | and eax, not 0x60000000 |
|
- | 75 | mov cr0, eax ; enable caching |
|
- | 76 | ||
- | 77 | mov eax, cr3 |
|
- | 78 | mov cr3, eax ;flush tlb |
|
- | 79 | ||
- | 80 | bt [cpu_caps], CAPS_PGE |
|
- | 81 | jnc @F |
|
- | 82 | ||
- | 83 | mov eax, cr4 |
|
- | 84 | bts eax, 7 ;set cr4.PGE flag |
|
41 | and eax, not 0x60000000 |
85 | mov cr4, eax |
42 | mov cr0, eax ; enable caching |
86 | @@: |
Line 43... | Line 87... | ||
43 | ret |
87 | ret |
44 | endp |
88 | endp |
Line 693... | Line 737... | ||
693 | wrmsr |
737 | wrmsr |
694 | inc ecx |
738 | inc ecx |
695 | jmp @b |
739 | jmp @b |
696 | @@: |
740 | @@: |
Line 697... | Line 741... | ||
697 | 741 | ||
698 | ; 9i. Configure MTRR_DEF_TYPE. |
742 | ; 9i. Check PAT support and reprogram PAT_MASR for write combining memory |
699 | mov ecx, 0x2FF |
743 | bt [cpu_caps], CAPS_PAT |
- | 744 | jnc @F |
|
700 | rdmsr |
745 | |
701 | or ah, 8 ; enable variable-ranges MTRR |
746 | mov ecx, MSR_CR_PAT |
- | 747 | mov eax, PAT_VALUE ;UC UCM WC WB |
|
702 | and al, 0xF0; default memtype = UC |
748 | mov edx, eax |
- | 749 | wrmsr |
|
Line 703... | Line 750... | ||
703 | wrmsr |
750 | @@: |
704 | 751 | ||
Line 705... | Line 752... | ||
705 | ; 9j. Changes are done. |
752 | ; 9j. Changes are done. |
Line 736... | Line 783... | ||
736 | ; no free registers, ignore the call |
783 | ; no free registers, ignore the call |
737 | .ret: |
784 | .ret: |
738 | ret |
785 | ret |
739 | .found: |
786 | .found: |
740 | ; found, write values |
787 | ; found, write values |
- | 788 | push ecx |
|
741 | call mtrr_begin_change |
789 | call mtrr_begin_change |
- | 790 | pop ecx |
|
742 | xor edx, edx |
791 | xor edx, edx |
743 | mov eax, [base] |
792 | mov eax, [base] |
744 | or eax, [mem_type] |
793 | or eax, [mem_type] |
745 | wrmsr |
794 | wrmsr |