revert FpuSave/FpuRestore to old implementations because existing drivers don't know about AVX, provide alternate exports AvxSaveSize/AvxSave/AvxRestore

git-svn-id: svn://kolibrios.org@7168 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
CleverMouse 2018-02-27 16:27:26 +00:00
parent 804abbc020
commit 4286d7bac3
2 changed files with 122 additions and 17 deletions

View File

@ -91,6 +91,9 @@ __exports:
srv_handler, 'ServiceHandler', \ srv_handler, 'ServiceHandler', \
fpu_save, 'FpuSave', \ fpu_save, 'FpuSave', \
fpu_restore, 'FpuRestore', \ fpu_restore, 'FpuRestore', \
avx_save_size, 'AvxSaveSize', \
avx_save, 'AvxSave', \
avx_restore, 'AvxRestore', \
r_f_port_area, 'ReservePortArea', \ r_f_port_area, 'ReservePortArea', \
boot_log, 'Boot_Log', \ boot_log, 'Boot_Log', \
\ \

View File

@ -12,7 +12,7 @@ init_fpu:
clts clts
fninit fninit
bt [cpu_caps+(CAPS_XSAVE/8)], CAPS_XSAVE mod 8 bt [cpu_caps+(CAPS_XSAVE/32)], CAPS_XSAVE mod 32
jnc .no_xsave jnc .no_xsave
mov ecx, cr4 mov ecx, cr4
@ -136,7 +136,7 @@ init_avx512:
ret ret
; param ; param
; eax= 512 bytes memory area ; eax= 512 bytes memory area aligned on a 16-byte boundary
align 4 align 4
fpu_save: fpu_save:
@ -155,6 +155,53 @@ fpu_save:
cmp ecx, esi cmp ecx, esi
jne .save jne .save
call save_fpu_context
jmp .exit
.save:
mov [fpu_owner], esi
shl ecx, 8
mov eax, [ecx+SLOT_BASE+APPDATA.fpu_state]
call save_context
; first 512 bytes of XSAVE area have the same format as FXSAVE
shl esi, 8
mov esi, [esi+SLOT_BASE+APPDATA.fpu_state]
mov ecx, 512/4
cld
rep movsd
fninit
.exit:
popfd
pop edi
pop esi
pop ecx
ret
avx_save_size:
mov eax, [xsave_area_size]
ret
; param
; eax= avx_save_size() bytes memory area aligned on a 64-byte boundary
avx_save:
push ecx
push esi
push edi
pushfd
cli
clts
mov edi, eax
mov ecx, [fpu_owner]
mov esi, [CURRENT_TASK]
cmp ecx, esi
jne .save
call save_context call save_context
jmp .exit jmp .exit
.save: .save:
@ -167,8 +214,9 @@ fpu_save:
shl esi, 8 shl esi, 8
mov esi, [esi+SLOT_BASE+APPDATA.fpu_state] mov esi, [esi+SLOT_BASE+APPDATA.fpu_state]
mov ecx, 512/4 mov ecx, [xsave_area_size]
cld add ecx, 3
shr ecx, 2
rep movsd rep movsd
fninit fninit
.exit: .exit:
@ -180,20 +228,20 @@ fpu_save:
align 4 align 4
save_context: save_context:
bt [cpu_caps+(CAPS_OSXSAVE/8)], CAPS_OSXSAVE mod 8 bt [cpu_caps+(CAPS_OSXSAVE/32)], CAPS_OSXSAVE mod 32
jnc .no_xsave jnc save_fpu_context
xsave [eax] xsave [eax]
ret ret
.no_xsave: save_fpu_context:
bt [cpu_caps], CAPS_SSE bt [cpu_caps], CAPS_SSE
jnc .no_SSE jnc .no_SSE
fxsave [eax] fxsave [eax]
ret ret
.no_SSE: .no_SSE:
fnsave [eax] fnsave [eax]
ret ret
align 4 align 4
fpu_restore: fpu_restore:
push ecx push ecx
@ -210,14 +258,6 @@ fpu_restore:
jne .copy jne .copy
clts clts
bt [cpu_caps+(CAPS_OSXSAVE/8)], CAPS_OSXSAVE mod 8
jnc .no_xsave
xrstor [esi]
popfd
pop esi
pop ecx
ret
.no_xsave:
bt [cpu_caps], CAPS_SSE bt [cpu_caps], CAPS_SSE
jnc .no_SSE jnc .no_SSE
@ -244,6 +284,57 @@ fpu_restore:
pop ecx pop ecx
ret ret
avx_restore:
push ecx
push esi
mov esi, eax
pushfd
cli
mov ecx, [fpu_owner]
mov eax, [CURRENT_TASK]
cmp ecx, eax
jne .copy
clts
bt [cpu_caps+(CAPS_OSXSAVE/32)], CAPS_OSXSAVE mod 32
jnc .no_xsave
xrstor [esi]
popfd
pop esi
pop ecx
ret
.no_xsave:
bt [cpu_caps], CAPS_SSE
jnc .no_SSE
fxrstor [esi]
popfd
pop esi
pop ecx
ret
.no_SSE:
fnclex ;fix possible problems
frstor [esi]
popfd
pop esi
pop ecx
ret
.copy:
shl eax, 8
mov edi, [eax+SLOT_BASE+APPDATA.fpu_state]
mov ecx, [xsave_area_size]
add ecx, 3
shr ecx, 2
cld
rep movsd
popfd
pop esi
pop ecx
ret
align 4 align 4
except_7: ;#NM exception handler except_7: ;#NM exception handler
save_ring3_context save_ring3_context
@ -258,6 +349,18 @@ except_7: ;#NM exception handler
shl ebx, 8 shl ebx, 8
mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state] mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state]
bt [cpu_caps+(CAPS_OSXSAVE/32)], CAPS_OSXSAVE mod 32
jnc .no_xsave
xsave [eax]
mov ebx, [CURRENT_TASK]
mov [fpu_owner], ebx
shl ebx, 8
mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state]
xrstor [eax]
.exit:
restore_ring3_context
iret
.no_xsave:
bt [cpu_caps], CAPS_SSE bt [cpu_caps], CAPS_SSE
jnc .no_SSE jnc .no_SSE
@ -267,7 +370,6 @@ except_7: ;#NM exception handler
shl ebx, 8 shl ebx, 8
mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state] mov eax, [ebx+SLOT_BASE+APPDATA.fpu_state]
fxrstor [eax] fxrstor [eax]
.exit:
restore_ring3_context restore_ring3_context
iret iret