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