Subversion Repositories Kolibri OS

Rev

Rev 1161 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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