Rev 425 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
425 | victor | 1 | $Revision: 431 $ |
431 | serge | 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3 | ;; ;; |
||
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
||
5 | ;; Distributed under terms of the GNU General Public License ;; |
||
6 | ;; ;; |
||
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
214 | serge | 8 | |
9 | init_fpu: |
||
10 | clts |
||
11 | fninit |
||
12 | |||
221 | serge | 13 | bt [cpu_caps], CAPS_SSE |
14 | jnc .no_SSE |
||
214 | serge | 15 | |
16 | mov ebx, cr4 |
||
17 | mov ecx, cr0 |
||
18 | or ebx, CR4_OSFXSR+CR4_OSXMMEXPT |
||
19 | mov cr4, ebx |
||
20 | |||
21 | and ecx, not (CR0_MP+CR0_EM) |
||
22 | or ecx, CR0_NE |
||
23 | mov cr0, ecx |
||
24 | |||
25 | mov dword [esp-4], SSE_INIT |
||
26 | ldmxcsr [esp-4] |
||
27 | |||
28 | xorps xmm0, xmm0 |
||
29 | xorps xmm1, xmm1 |
||
30 | xorps xmm2, xmm2 |
||
31 | xorps xmm3, xmm3 |
||
32 | xorps xmm4, xmm4 |
||
33 | xorps xmm5, xmm5 |
||
34 | xorps xmm6, xmm6 |
||
35 | xorps xmm7, xmm7 |
||
357 | serge | 36 | fxsave [fpu_data] ;[eax] |
214 | serge | 37 | ret |
221 | serge | 38 | .no_SSE: |
214 | serge | 39 | mov ecx, cr0 |
40 | and ecx, not CR0_EM |
||
41 | or ecx, CR0_MP+CR0_NE |
||
42 | mov cr0, ecx |
||
357 | serge | 43 | fnsave [fpu_data] |
214 | serge | 44 | ret |
45 | |||
378 | serge | 46 | ; param |
47 | ; eax= 512 bytes memory area |
||
48 | |||
214 | serge | 49 | align 4 |
378 | serge | 50 | fpu_save: |
51 | push ecx |
||
52 | push esi |
||
53 | push edi |
||
54 | |||
55 | pushfd |
||
56 | cli |
||
57 | |||
214 | serge | 58 | clts |
378 | serge | 59 | mov edi, eax |
214 | serge | 60 | |
378 | serge | 61 | mov ecx, [fpu_owner] |
62 | mov eax, [CURRENT_TASK] |
||
63 | cmp ecx, eax |
||
64 | jne .save |
||
65 | .copy: |
||
66 | shl eax, 8 |
||
380 | serge | 67 | mov esi, [eax+SLOT_BASE+APPDATA.fpu_state] |
378 | serge | 68 | mov ecx, 512/4 |
69 | cld |
||
70 | rep movsd |
||
71 | fninit |
||
72 | |||
73 | popfd |
||
74 | pop edi |
||
75 | pop esi |
||
76 | pop ecx |
||
77 | ret |
||
78 | .save: |
||
79 | mov [fpu_owner], eax |
||
80 | |||
81 | shl ecx, 8 |
||
380 | serge | 82 | mov ecx, [ecx+SLOT_BASE+APPDATA.fpu_state] |
378 | serge | 83 | |
221 | serge | 84 | bt [cpu_caps], CAPS_SSE |
214 | serge | 85 | jnc .no_SSE |
86 | |||
378 | serge | 87 | fxsave [ecx] |
88 | jmp .copy |
||
214 | serge | 89 | .no_SSE: |
378 | serge | 90 | fnsave [ecx] |
91 | jmp .copy |
||
214 | serge | 92 | |
93 | align 4 |
||
378 | serge | 94 | fpu_restore: |
95 | push ecx |
||
96 | push esi |
||
97 | |||
98 | mov esi, eax |
||
99 | |||
100 | pushfd |
||
101 | cli |
||
102 | |||
103 | mov ecx, [fpu_owner] |
||
104 | mov eax, [CURRENT_TASK] |
||
105 | cmp ecx, eax |
||
106 | jne .copy |
||
107 | |||
108 | clts |
||
109 | |||
221 | serge | 110 | bt [cpu_caps], CAPS_SSE |
214 | serge | 111 | jnc .no_SSE |
112 | |||
378 | serge | 113 | fxrstor [esi] |
114 | popfd |
||
115 | pop esi |
||
116 | pop ecx |
||
214 | serge | 117 | ret |
118 | .no_SSE: |
||
119 | fnclex ;fix possible problems |
||
378 | serge | 120 | frstor [esi] |
121 | popfd |
||
122 | pop esi |
||
123 | pop ecx |
||
214 | serge | 124 | ret |
378 | serge | 125 | .copy: |
126 | shl eax, 8 |
||
380 | serge | 127 | mov edi, [eax+SLOT_BASE+APPDATA.fpu_state] |
378 | serge | 128 | mov ecx, 512/4 |
129 | cld |
||
130 | rep movsd |
||
131 | popfd |
||
132 | pop esi |
||
133 | pop ecx |
||
134 | ret |
||
214 | serge | 135 | |
136 | align 4 |
||
137 | e7: ;#NM exception handler |
||
138 | save_ring3_context |
||
139 | clts |
||
140 | mov ax, os_data |
||
141 | mov ds, ax |
||
142 | mov es, ax |
||
143 | |||
144 | mov ebx, [fpu_owner] |
||
145 | cmp ebx, [CURRENT_TASK] |
||
146 | je .exit |
||
147 | |||
148 | shl ebx, 8 |
||
380 | serge | 149 | mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state] |
221 | serge | 150 | bt [cpu_caps], CAPS_SSE |
214 | serge | 151 | jnc .no_SSE |
152 | |||
153 | fxsave [eax] |
||
154 | mov ebx, [CURRENT_TASK] |
||
155 | mov [fpu_owner], ebx |
||
156 | shl ebx, 8 |
||
380 | serge | 157 | mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state] |
214 | serge | 158 | fxrstor [eax] |
159 | .exit: |
||
160 | restore_ring3_context |
||
161 | iret |
||
162 | |||
163 | .no_SSE: |
||
164 | fnsave [eax] |
||
165 | mov ebx, [CURRENT_TASK] |
||
166 | mov [fpu_owner], ebx |
||
167 | shl ebx, 8 |
||
380 | serge | 168 | mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state] |
214 | serge | 169 | frstor [eax] |
170 | restore_ring3_context |
||
171 | iret |
||
172 | |||
173 | iglobal |
||
174 | fpu_owner dd 1 |
||
175 | endg |
||
176 | |||
177 | reg_eip equ ebp+4 |
||
178 | reg_cs equ ebp+8 |
||
179 | reg_eflags equ ebp+12 |
||
180 | reg_esp equ ebp+16 |
||
181 | reg_ss equ ebp+20 |
||
182 | |||
183 | align 4 |
||
184 | except_16: ;fpu native exceptions handler |
||
185 | push ebp |
||
186 | mov ebp, esp |
||
187 | |||
188 | push eax |
||
189 | push ebx |
||
190 | push ecx |
||
191 | push edx |
||
192 | |||
193 | mov ebx, [ss:CURRENT_TASK] |
||
194 | shl ebx, 8 |
||
195 | |||
380 | serge | 196 | mov eax, [ss:ebx+SLOT_BASE+APPDATA.fpu_handler] |
214 | serge | 197 | test eax, eax |
198 | jz .default |
||
199 | |||
200 | mov ecx, [reg_eip] |
||
201 | mov edx, [reg_esp] |
||
202 | sub edx, 4 |
||
203 | mov [ss:edx+new_app_base], ecx |
||
204 | mov [reg_esp], edx |
||
205 | mov dword [reg_eip], eax |
||
206 | |||
207 | pop edx |
||
208 | pop ecx |
||
209 | pop ebx |
||
210 | pop eax |
||
211 | |||
212 | leave |
||
213 | iretd |
||
214 | |||
215 | .default: |
||
216 | pop edx |
||
217 | pop ecx |
||
218 | pop ebx |
||
219 | pop eax |
||
220 | leave |
||
221 | |||
222 | save_ring3_context ;debugger support |
||
223 | |||
224 | mov bl, 16 |
||
225 | jmp exc_c |
||
226 | |||
227 | align 4 |
||
228 | except_19: ;sse exceptions handler |
||
229 | push ebp |
||
230 | mov ebp, esp |
||
231 | |||
232 | push eax |
||
233 | push ebx |
||
234 | push ecx |
||
235 | push edx |
||
236 | |||
237 | mov ebx, [ss:CURRENT_TASK] |
||
238 | shl ebx, 8 |
||
239 | |||
380 | serge | 240 | mov eax, [ss:ebx+SLOT_BASE+APPDATA.sse_handler] |
214 | serge | 241 | test eax, eax |
242 | jz .default |
||
243 | |||
244 | mov ecx, [reg_eip] |
||
245 | mov edx, [reg_esp] |
||
246 | sub edx, 4 |
||
247 | mov [ss:edx+new_app_base], ecx |
||
248 | mov [reg_esp], edx |
||
249 | mov dword [reg_eip], eax |
||
250 | |||
251 | pop edx |
||
252 | pop ecx |
||
253 | pop ebx |
||
254 | pop eax |
||
255 | |||
256 | leave |
||
257 | iretd |
||
258 | |||
259 | .default: |
||
260 | pop edx |
||
261 | pop ecx |
||
262 | pop ebx |
||
263 | pop eax |
||
264 | leave |
||
265 | |||
266 | save_ring3_context ;debugger support |
||
267 | |||
268 | mov bl, 19 |
||
269 | jmp exc_c |
||
270 | |||
271 | restore reg_eip |
||
272 | restore reg_cs |
||
273 | restore reg_eflags |
||
274 | restore reg_esp |
||
275 | restore reg_ss |
||
276 |