Rev 5363 | Rev 7165 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5363 | Rev 7124 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2017. 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: 5363 $ |
8 | $Revision: 7124 $ |
9 | 9 | ||
10 | 10 | ||
Line -... | Line 11... | ||
- | 11 | init_fpu: |
|
- | 12 | clts |
|
- | 13 | fninit |
|
- | 14 | ||
- | 15 | bt [cpu_caps+(CAPS_XSAVE/8)], CAPS_XSAVE mod 8 |
|
- | 16 | jnc .no_xsave |
|
- | 17 | ||
- | 18 | mov ecx, cr4 |
|
- | 19 | or ecx, CR4_OSXSAVE |
|
- | 20 | mov cr4, ecx |
|
- | 21 | ||
- | 22 | mov eax, 0x0d |
|
- | 23 | xor ecx, ecx |
|
- | 24 | cpuid |
|
- | 25 | mov ebx, XCR0_FPU_MMX + XCR0_SSE + XCR0_AVX + XCR0_AVX512 |
|
- | 26 | and ebx, eax |
|
- | 27 | xor ecx, ecx |
|
- | 28 | xgetbv |
|
- | 29 | or eax, ebx |
|
- | 30 | xor ecx, ecx |
|
- | 31 | xsetbv |
|
- | 32 | ||
- | 33 | mov eax, 0x0d |
|
- | 34 | xor ecx, ecx |
|
- | 35 | cpuid |
|
- | 36 | mov [xsave_area_size], ebx |
|
- | 37 | ||
- | 38 | test eax, XCR0_AVX512 |
|
- | 39 | jz @f |
|
- | 40 | call init_avx512 |
|
- | 41 | ret |
|
- | 42 | @@: |
|
- | 43 | test eax, XCR0_AVX |
|
- | 44 | jz @f |
|
- | 45 | call init_avx |
|
- | 46 | ret |
|
- | 47 | @@: |
|
- | 48 | test eax, XCR0_SSE |
|
- | 49 | jz @f |
|
- | 50 | call init_sse |
|
- | 51 | ret |
|
- | 52 | @@: |
|
11 | init_fpu: |
53 | call init_fpu_mmx |
12 | clts |
54 | ret |
- | 55 | .no_xsave: |
|
- | 56 | mov [xsave_area_size], 512 ; enough for FPU/MMX and SSE |
|
- | 57 | bt [cpu_caps], CAPS_SSE |
|
- | 58 | jnc @f |
|
- | 59 | call init_sse |
|
- | 60 | fxsave [fpu_data] |
|
- | 61 | ret |
|
- | 62 | @@: |
|
- | 63 | call init_fpu_mmx |
|
- | 64 | fnsave [fpu_data] |
|
- | 65 | ret |
|
- | 66 | ||
- | 67 | init_fpu_mmx: |
|
- | 68 | mov ecx, cr0 |
|
Line -... | Line 69... | ||
- | 69 | and ecx, not CR0_EM |
|
13 | fninit |
70 | or ecx, CR0_MP + CR0_NE |
14 | 71 | mov cr0, ecx |
|
15 | bt [cpu_caps], CAPS_SSE |
72 | ret |
16 | jnc .no_SSE |
73 | |
Line 17... | Line 74... | ||
17 | 74 | init_sse: |
|
18 | mov ebx, cr4 |
75 | mov ebx, cr4 |
19 | mov ecx, cr0 |
76 | mov ecx, cr0 |
Line 20... | Line 77... | ||
20 | or ebx, CR4_OSFXSR+CR4_OSXMMEXPT |
77 | or ebx, CR4_OSFXSR+CR4_OSXMMEXPT |
21 | mov cr4, ebx |
78 | mov cr4, ebx |
Line 22... | Line 79... | ||
22 | 79 | ||
23 | and ecx, not (CR0_MP+CR0_EM) |
80 | and ecx, not (CR0_EM + CR0_MP) |
24 | or ecx, CR0_NE |
81 | or ecx, CR0_NE |
25 | mov cr0, ecx |
82 | mov cr0, ecx |
26 | 83 | ||
27 | mov dword [esp-4], SSE_INIT |
84 | mov dword [esp-4], MXCSR_INIT |
28 | ldmxcsr [esp-4] |
85 | ldmxcsr [esp-4] |
29 | 86 | ||
30 | xorps xmm0, xmm0 |
- | |
31 | xorps xmm1, xmm1 |
87 | xorps xmm0, xmm0 |
- | 88 | xorps xmm1, xmm1 |
|
32 | xorps xmm2, xmm2 |
89 | xorps xmm2, xmm2 |
- | 90 | xorps xmm3, xmm3 |
|
- | 91 | xorps xmm4, xmm4 |
|
- | 92 | xorps xmm5, xmm5 |
|
- | 93 | xorps xmm6, xmm6 |
|
33 | xorps xmm3, xmm3 |
94 | xorps xmm7, xmm7 |
34 | xorps xmm4, xmm4 |
95 | ret |
35 | xorps xmm5, xmm5 |
96 | |
36 | xorps xmm6, xmm6 |
97 | init_avx: |
- | 98 | mov ebx, cr4 |
|
- | 99 | or ebx, CR4_OSFXSR + CR4_OSXMMEXPT |
|
- | 100 | mov cr4, ebx |
|
- | 101 | ||
- | 102 | mov ecx, cr0 |
|
- | 103 | and ecx, not (CR0_EM + CR0_MP) |
|
- | 104 | or ecx, CR0_NE |
|
- | 105 | mov cr0, ecx |
|
- | 106 | ||
- | 107 | mov dword [esp-4], MXCSR_INIT |
|
- | 108 | vldmxcsr [esp-4] |
|
- | 109 | ||
37 | xorps xmm7, xmm7 |
110 | vzeroall |
- | 111 | ret |
|
- | 112 | ||
- | 113 | init_avx512: |
|
- | 114 | mov ebx, cr4 |
|
- | 115 | or ebx, CR4_OSFXSR + CR4_OSXMMEXPT |
|
- | 116 | mov cr4, ebx |
|
- | 117 | ||
- | 118 | mov ecx, cr0 |
|
- | 119 | and ecx, not (CR0_EM + CR0_MP) |
|
- | 120 | or ecx, CR0_NE |
|
- | 121 | mov cr0, ecx |
|
- | 122 | ||
- | 123 | mov dword [esp-4], MXCSR_INIT |
|
- | 124 | vldmxcsr [esp-4] |
|
- | 125 | ||
- | 126 | vpxorq zmm0, zmm0, zmm0 |
|
38 | fxsave [fpu_data] ;[eax] |
127 | vpxorq zmm1, zmm1, zmm1 |
Line 39... | Line 128... | ||
39 | ret |
128 | vpxorq zmm2, zmm2, zmm2 |
40 | .no_SSE: |
129 | vpxorq zmm3, zmm3, zmm3 |
Line 88... | Line 177... | ||
88 | pop ecx |
177 | pop ecx |
89 | ret |
178 | ret |
Line 90... | Line 179... | ||
90 | 179 | ||
91 | align 4 |
180 | align 4 |
- | 181 | save_context: |
|
- | 182 | bt [cpu_caps+(CAPS_OSXSAVE/8)], CAPS_OSXSAVE mod 8 |
|
- | 183 | jnc .no_xsave |
|
- | 184 | xsave [eax] |
|
- | 185 | ret |
|
92 | save_context: |
186 | .no_xsave: |
93 | bt [cpu_caps], CAPS_SSE |
187 | bt [cpu_caps], CAPS_SSE |
Line 94... | Line 188... | ||
94 | jnc .no_SSE |
188 | jnc .no_SSE |
95 | 189 | ||
Line 113... | Line 207... | ||
113 | mov eax, [CURRENT_TASK] |
207 | mov eax, [CURRENT_TASK] |
114 | cmp ecx, eax |
208 | cmp ecx, eax |
115 | jne .copy |
209 | jne .copy |
Line 116... | Line 210... | ||
116 | 210 | ||
- | 211 | clts |
|
- | 212 | bt [cpu_caps+(CAPS_OSXSAVE/8)], CAPS_OSXSAVE mod 8 |
|
- | 213 | jnc .no_xsave |
|
- | 214 | xrstor [esi] |
|
- | 215 | popfd |
|
- | 216 | pop esi |
|
- | 217 | pop ecx |
|
- | 218 | ret |
|
117 | clts |
219 | .no_xsave: |
118 | bt [cpu_caps], CAPS_SSE |
220 | bt [cpu_caps], CAPS_SSE |
Line 119... | Line 221... | ||
119 | jnc .no_SSE |
221 | jnc .no_SSE |
120 | 222 |