2007-03-26 16:18:08 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-07-27 17:52:03 +04:00
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
2006-11-20 10:06:00 +03:00
|
|
|
init_fpu:
|
|
|
|
clts
|
|
|
|
fninit
|
|
|
|
|
2006-11-27 13:07:51 +03:00
|
|
|
bt [cpu_caps], CAPS_SSE
|
|
|
|
jnc .no_SSE
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
mov ebx, cr4
|
|
|
|
mov ecx, cr0
|
|
|
|
or ebx, CR4_OSFXSR+CR4_OSXMMEXPT
|
|
|
|
mov cr4, ebx
|
|
|
|
|
|
|
|
and ecx, not (CR0_MP+CR0_EM)
|
|
|
|
or ecx, CR0_NE
|
|
|
|
mov cr0, ecx
|
|
|
|
|
|
|
|
mov dword [esp-4], SSE_INIT
|
|
|
|
ldmxcsr [esp-4]
|
|
|
|
|
|
|
|
xorps xmm0, xmm0
|
|
|
|
xorps xmm1, xmm1
|
|
|
|
xorps xmm2, xmm2
|
|
|
|
xorps xmm3, xmm3
|
|
|
|
xorps xmm4, xmm4
|
|
|
|
xorps xmm5, xmm5
|
|
|
|
xorps xmm6, xmm6
|
|
|
|
xorps xmm7, xmm7
|
2007-02-17 13:09:23 +03:00
|
|
|
fxsave [fpu_data] ;[eax]
|
2006-11-20 10:06:00 +03:00
|
|
|
ret
|
2006-11-27 13:07:51 +03:00
|
|
|
.no_SSE:
|
2006-11-20 10:06:00 +03:00
|
|
|
mov ecx, cr0
|
|
|
|
and ecx, not CR0_EM
|
|
|
|
or ecx, CR0_MP+CR0_NE
|
|
|
|
mov cr0, ecx
|
2007-02-17 13:09:23 +03:00
|
|
|
fnsave [fpu_data]
|
2006-11-20 10:06:00 +03:00
|
|
|
ret
|
|
|
|
|
2007-02-27 14:47:52 +03:00
|
|
|
; param
|
|
|
|
; eax= 512 bytes memory area
|
|
|
|
|
2006-11-20 10:06:00 +03:00
|
|
|
align 4
|
2007-02-27 14:47:52 +03:00
|
|
|
fpu_save:
|
|
|
|
push ecx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
|
2006-11-20 10:06:00 +03:00
|
|
|
clts
|
2007-02-27 14:47:52 +03:00
|
|
|
mov edi, eax
|
|
|
|
|
|
|
|
mov ecx, [fpu_owner]
|
2007-03-28 21:06:08 +04:00
|
|
|
mov esi, [CURRENT_TASK]
|
|
|
|
cmp ecx, esi
|
2007-02-27 14:47:52 +03:00
|
|
|
jne .save
|
2007-03-28 21:06:08 +04:00
|
|
|
|
|
|
|
call save_context
|
|
|
|
jmp .exit
|
|
|
|
.save:
|
|
|
|
mov [fpu_owner], esi
|
|
|
|
|
|
|
|
shl ecx, 8
|
|
|
|
mov eax, [ecx+SLOT_BASE+APPDATA.fpu_state]
|
|
|
|
|
|
|
|
call save_context
|
|
|
|
|
|
|
|
shl esi, 8
|
|
|
|
mov esi, [esi+SLOT_BASE+APPDATA.fpu_state]
|
2007-02-27 14:47:52 +03:00
|
|
|
mov ecx, 512/4
|
|
|
|
cld
|
|
|
|
rep movsd
|
|
|
|
fninit
|
2007-03-28 21:06:08 +04:00
|
|
|
.exit:
|
2007-02-27 14:47:52 +03:00
|
|
|
popfd
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ecx
|
|
|
|
ret
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-03-28 21:06:08 +04:00
|
|
|
align 4
|
|
|
|
save_context:
|
2006-11-27 13:07:51 +03:00
|
|
|
bt [cpu_caps], CAPS_SSE
|
2006-11-20 10:06:00 +03:00
|
|
|
jnc .no_SSE
|
|
|
|
|
2007-03-28 21:06:08 +04:00
|
|
|
fxsave [eax]
|
|
|
|
ret
|
2006-11-20 10:06:00 +03:00
|
|
|
.no_SSE:
|
2007-03-28 21:06:08 +04:00
|
|
|
fnsave [eax]
|
|
|
|
ret
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
align 4
|
2007-02-27 14:47:52 +03:00
|
|
|
fpu_restore:
|
|
|
|
push ecx
|
|
|
|
push esi
|
|
|
|
|
|
|
|
mov esi, eax
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
|
|
|
|
mov ecx, [fpu_owner]
|
|
|
|
mov eax, [CURRENT_TASK]
|
|
|
|
cmp ecx, eax
|
|
|
|
jne .copy
|
|
|
|
|
|
|
|
clts
|
2006-11-27 13:07:51 +03:00
|
|
|
bt [cpu_caps], CAPS_SSE
|
2006-11-20 10:06:00 +03:00
|
|
|
jnc .no_SSE
|
|
|
|
|
2007-02-27 14:47:52 +03:00
|
|
|
fxrstor [esi]
|
|
|
|
popfd
|
|
|
|
pop esi
|
|
|
|
pop ecx
|
2006-11-20 10:06:00 +03:00
|
|
|
ret
|
|
|
|
.no_SSE:
|
|
|
|
fnclex ;fix possible problems
|
2007-02-27 14:47:52 +03:00
|
|
|
frstor [esi]
|
|
|
|
popfd
|
|
|
|
pop esi
|
|
|
|
pop ecx
|
|
|
|
ret
|
|
|
|
.copy:
|
|
|
|
shl eax, 8
|
2007-02-28 13:51:05 +03:00
|
|
|
mov edi, [eax+SLOT_BASE+APPDATA.fpu_state]
|
2007-02-27 14:47:52 +03:00
|
|
|
mov ecx, 512/4
|
|
|
|
cld
|
|
|
|
rep movsd
|
|
|
|
popfd
|
|
|
|
pop esi
|
|
|
|
pop ecx
|
2006-11-20 10:06:00 +03:00
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
e7: ;#NM exception handler
|
2007-04-18 10:37:14 +04:00
|
|
|
save_ring3_context
|
|
|
|
clts
|
|
|
|
mov ax, app_data ;
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
|
|
|
|
mov ebx, [fpu_owner]
|
|
|
|
cmp ebx, [CURRENT_TASK]
|
|
|
|
je .exit
|
|
|
|
|
|
|
|
shl ebx, 8
|
|
|
|
mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state]
|
|
|
|
bt [cpu_caps], CAPS_SSE
|
|
|
|
jnc .no_SSE
|
|
|
|
|
|
|
|
fxsave [eax]
|
|
|
|
mov ebx, [CURRENT_TASK]
|
|
|
|
mov [fpu_owner], ebx
|
|
|
|
shl ebx, 8
|
|
|
|
mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state]
|
|
|
|
fxrstor [eax]
|
2006-11-20 10:06:00 +03:00
|
|
|
.exit:
|
2007-04-18 10:37:14 +04:00
|
|
|
restore_ring3_context
|
|
|
|
iret
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
.no_SSE:
|
2007-04-18 10:37:14 +04:00
|
|
|
fnsave [eax]
|
|
|
|
mov ebx, [CURRENT_TASK]
|
|
|
|
mov [fpu_owner], ebx
|
|
|
|
shl ebx, 8
|
|
|
|
mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state]
|
|
|
|
frstor [eax]
|
|
|
|
restore_ring3_context
|
|
|
|
iret
|
2006-11-20 10:06:00 +03:00
|
|
|
|
|
|
|
iglobal
|
|
|
|
fpu_owner dd 1
|
|
|
|
endg
|
|
|
|
|
|
|
|
reg_eip equ ebp+4
|
|
|
|
reg_cs equ ebp+8
|
|
|
|
reg_eflags equ ebp+12
|
|
|
|
reg_esp equ ebp+16
|
|
|
|
reg_ss equ ebp+20
|
|
|
|
|
|
|
|
align 4
|
|
|
|
except_16: ;fpu native exceptions handler
|
|
|
|
push ebp
|
|
|
|
mov ebp, esp
|
|
|
|
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov ebx, [CURRENT_TASK]
|
2006-11-20 10:06:00 +03:00
|
|
|
shl ebx, 8
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov eax, [ebx+SLOT_BASE+APPDATA.fpu_handler]
|
2006-11-20 10:06:00 +03:00
|
|
|
test eax, eax
|
|
|
|
jz .default
|
|
|
|
|
|
|
|
mov ecx, [reg_eip]
|
|
|
|
mov edx, [reg_esp]
|
|
|
|
sub edx, 4
|
2007-04-18 10:37:14 +04:00
|
|
|
mov [edx], ecx
|
2006-11-20 10:06:00 +03:00
|
|
|
mov [reg_esp], edx
|
|
|
|
mov dword [reg_eip], eax
|
|
|
|
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
|
|
|
|
leave
|
|
|
|
iretd
|
|
|
|
|
|
|
|
.default:
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
leave
|
|
|
|
|
|
|
|
save_ring3_context ;debugger support
|
|
|
|
|
|
|
|
mov bl, 16
|
|
|
|
jmp exc_c
|
|
|
|
|
|
|
|
align 4
|
|
|
|
except_19: ;sse exceptions handler
|
|
|
|
push ebp
|
|
|
|
mov ebp, esp
|
|
|
|
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov ebx, [current_slot]
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2007-04-18 10:37:14 +04:00
|
|
|
mov eax, [ebx+APPDATA.sse_handler]
|
2006-11-20 10:06:00 +03:00
|
|
|
test eax, eax
|
|
|
|
jz .default
|
|
|
|
|
|
|
|
mov ecx, [reg_eip]
|
|
|
|
mov edx, [reg_esp]
|
|
|
|
sub edx, 4
|
2007-04-18 10:37:14 +04:00
|
|
|
mov [edx], ecx
|
2006-11-20 10:06:00 +03:00
|
|
|
mov [reg_esp], edx
|
|
|
|
mov dword [reg_eip], eax
|
|
|
|
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
|
|
|
|
leave
|
|
|
|
iretd
|
|
|
|
|
|
|
|
.default:
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
leave
|
|
|
|
|
|
|
|
save_ring3_context ;debugger support
|
|
|
|
|
|
|
|
mov bl, 19
|
|
|
|
jmp exc_c
|
|
|
|
|
|
|
|
restore reg_eip
|
|
|
|
restore reg_cs
|
|
|
|
restore reg_eflags
|
|
|
|
restore reg_esp
|
|
|
|
restore reg_ss
|
|
|
|
|
|
|
|
|