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