Rev 431 | Rev 465 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
425 | victor | 1 | $Revision: 435 $ |
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] |
435 | serge | 62 | mov esi, [CURRENT_TASK] |
63 | cmp ecx, esi |
||
378 | serge | 64 | jne .save |
435 | serge | 65 | |
66 | call save_context |
||
67 | jmp .exit |
||
68 | .save: |
||
69 | mov [fpu_owner], esi |
||
70 | |||
71 | shl ecx, 8 |
||
72 | mov eax, [ecx+SLOT_BASE+APPDATA.fpu_state] |
||
73 | |||
74 | call save_context |
||
75 | |||
76 | shl esi, 8 |
||
77 | mov esi, [esi+SLOT_BASE+APPDATA.fpu_state] |
||
378 | serge | 78 | mov ecx, 512/4 |
79 | cld |
||
80 | rep movsd |
||
81 | fninit |
||
435 | serge | 82 | .exit: |
378 | serge | 83 | popfd |
84 | pop edi |
||
85 | pop esi |
||
86 | pop ecx |
||
87 | ret |
||
88 | |||
435 | serge | 89 | align 4 |
90 | save_context: |
||
221 | serge | 91 | bt [cpu_caps], CAPS_SSE |
214 | serge | 92 | jnc .no_SSE |
93 | |||
435 | serge | 94 | fxsave [eax] |
95 | ret |
||
214 | serge | 96 | .no_SSE: |
435 | serge | 97 | fnsave [eax] |
98 | ret |
||
214 | serge | 99 | |
100 | align 4 |
||
378 | serge | 101 | fpu_restore: |
102 | push ecx |
||
103 | push esi |
||
104 | |||
105 | mov esi, eax |
||
106 | |||
107 | pushfd |
||
108 | cli |
||
109 | |||
110 | mov ecx, [fpu_owner] |
||
111 | mov eax, [CURRENT_TASK] |
||
112 | cmp ecx, eax |
||
113 | jne .copy |
||
114 | |||
115 | clts |
||
221 | serge | 116 | bt [cpu_caps], CAPS_SSE |
214 | serge | 117 | jnc .no_SSE |
118 | |||
378 | serge | 119 | fxrstor [esi] |
120 | popfd |
||
121 | pop esi |
||
122 | pop ecx |
||
214 | serge | 123 | ret |
124 | .no_SSE: |
||
125 | fnclex ;fix possible problems |
||
378 | serge | 126 | frstor [esi] |
127 | popfd |
||
128 | pop esi |
||
129 | pop ecx |
||
214 | serge | 130 | ret |
378 | serge | 131 | .copy: |
132 | shl eax, 8 |
||
380 | serge | 133 | mov edi, [eax+SLOT_BASE+APPDATA.fpu_state] |
378 | serge | 134 | mov ecx, 512/4 |
135 | cld |
||
136 | rep movsd |
||
137 | popfd |
||
138 | pop esi |
||
139 | pop ecx |
||
140 | ret |
||
214 | serge | 141 | |
142 | align 4 |
||
143 | e7: ;#NM exception handler |
||
435 | serge | 144 | save_ring3_context |
145 | clts |
||
146 | mov ax, os_data |
||
147 | mov ds, ax |
||
148 | mov es, ax |
||
214 | serge | 149 | |
435 | serge | 150 | mov ebx, [fpu_owner] |
151 | cmp ebx, [CURRENT_TASK] |
||
152 | je .exit |
||
214 | serge | 153 | |
435 | serge | 154 | shl ebx, 8 |
155 | mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state] |
||
156 | bt [cpu_caps], CAPS_SSE |
||
157 | jnc .no_SSE |
||
214 | serge | 158 | |
435 | serge | 159 | fxsave [eax] |
160 | mov ebx, [CURRENT_TASK] |
||
161 | mov [fpu_owner], ebx |
||
162 | shl ebx, 8 |
||
163 | mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state] |
||
164 | fxrstor [eax] |
||
214 | serge | 165 | .exit: |
435 | serge | 166 | restore_ring3_context |
167 | iret |
||
214 | serge | 168 | |
169 | .no_SSE: |
||
435 | serge | 170 | fnsave [eax] |
171 | mov ebx, [CURRENT_TASK] |
||
172 | mov [fpu_owner], ebx |
||
173 | shl ebx, 8 |
||
174 | mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state] |
||
175 | frstor [eax] |
||
176 | restore_ring3_context |
||
177 | iret |
||
214 | serge | 178 | |
179 | iglobal |
||
180 | fpu_owner dd 1 |
||
181 | endg |
||
182 | |||
183 | reg_eip equ ebp+4 |
||
184 | reg_cs equ ebp+8 |
||
185 | reg_eflags equ ebp+12 |
||
186 | reg_esp equ ebp+16 |
||
187 | reg_ss equ ebp+20 |
||
188 | |||
189 | align 4 |
||
190 | except_16: ;fpu native exceptions handler |
||
191 | push ebp |
||
192 | mov ebp, esp |
||
193 | |||
194 | push eax |
||
195 | push ebx |
||
196 | push ecx |
||
197 | push edx |
||
198 | |||
199 | mov ebx, [ss:CURRENT_TASK] |
||
200 | shl ebx, 8 |
||
201 | |||
380 | serge | 202 | mov eax, [ss:ebx+SLOT_BASE+APPDATA.fpu_handler] |
214 | serge | 203 | test eax, eax |
204 | jz .default |
||
205 | |||
206 | mov ecx, [reg_eip] |
||
207 | mov edx, [reg_esp] |
||
208 | sub edx, 4 |
||
209 | mov [ss:edx+new_app_base], ecx |
||
210 | mov [reg_esp], edx |
||
211 | mov dword [reg_eip], eax |
||
212 | |||
213 | pop edx |
||
214 | pop ecx |
||
215 | pop ebx |
||
216 | pop eax |
||
217 | |||
218 | leave |
||
219 | iretd |
||
220 | |||
221 | .default: |
||
222 | pop edx |
||
223 | pop ecx |
||
224 | pop ebx |
||
225 | pop eax |
||
226 | leave |
||
227 | |||
228 | save_ring3_context ;debugger support |
||
229 | |||
230 | mov bl, 16 |
||
231 | jmp exc_c |
||
232 | |||
233 | align 4 |
||
234 | except_19: ;sse exceptions handler |
||
235 | push ebp |
||
236 | mov ebp, esp |
||
237 | |||
238 | push eax |
||
239 | push ebx |
||
240 | push ecx |
||
241 | push edx |
||
242 | |||
243 | mov ebx, [ss:CURRENT_TASK] |
||
244 | shl ebx, 8 |
||
245 | |||
380 | serge | 246 | mov eax, [ss:ebx+SLOT_BASE+APPDATA.sse_handler] |
214 | serge | 247 | test eax, eax |
248 | jz .default |
||
249 | |||
250 | mov ecx, [reg_eip] |
||
251 | mov edx, [reg_esp] |
||
252 | sub edx, 4 |
||
253 | mov [ss:edx+new_app_base], ecx |
||
254 | mov [reg_esp], edx |
||
255 | mov dword [reg_eip], eax |
||
256 | |||
257 | pop edx |
||
258 | pop ecx |
||
259 | pop ebx |
||
260 | pop eax |
||
261 | |||
262 | leave |
||
263 | iretd |
||
264 | |||
265 | .default: |
||
266 | pop edx |
||
267 | pop ecx |
||
268 | pop ebx |
||
269 | pop eax |
||
270 | leave |
||
271 | |||
272 | save_ring3_context ;debugger support |
||
273 | |||
274 | mov bl, 19 |
||
275 | jmp exc_c |
||
276 | |||
277 | restore reg_eip |
||
278 | restore reg_cs |
||
279 | restore reg_eflags |
||
280 | restore reg_esp |
||
281 | restore reg_ss |
||
282 |