Uso di funzionalità del processore estese nei driver windows
Ultimo aggiornamento
- Luglio 2016
I driver Windows per sistemi x86 e x64 che usano funzionalità del processore esteso devono eseguire il wrapping dei calcoli a virgola mobile tra le chiamate a KeSaveExtendedProcessorState e KeRestoreExtendedProcessorState per evitare errori nelle applicazioni simultanee che potrebbero usare i registri.
Registri MMX/x87 legacy
Questi registri corrispondono alla maschera di XSTATE_MASK_LEGACY_FLOATING_POINT e non sono disponibili per i driver per i sistemi x64. Per altre informazioni su questi registri, vedere Using Floating Point in a WDM Driver .For more information on these registers see Using Floating Point in a WDM Driver.
Registri SSE
Questi registri corrispondono al flag XSTATE_MASK_LEGACY_SSE e vengono usati dal compilatore x64 per le operazioni a virgola mobile. I driver per i sistemi x86 che usano questi registri devono salvarli prima di usarli passando il flag XSTATE_MASK_LEGACY o XSTATE_MASK_LEGACY_SSE nella chiamata KeSaveExtendedProcessorState e, al termine, ripristinarli con KeRestoreExtendedProcessorState. Questo non è necessario nei sistemi x64, ma non dannoso. Per altre informazioni su questi registri, vedere Uso del virgola mobile in un driver WDM.
Registri AVX
Questi registri corrispondono alle maschere XSTATE_MASK_GSSE o XSTATE_MASK_AVX. Nuovi processori x86, ad esempio il processore Intel Sandy Bridge (in precedenza Gesher), supportano le istruzioni AVX e il set di registrazione (YMM0-YMM15). In Windows 7 con Service Pack 1 (SP1), Windows Server 2008 R2 e versioni più recenti di Windows, sia le versioni x86 che x64 del sistema operativo mantengono i registri AVX tra i commutatori thread (e processo). Per usare i registri AVX in modalità kernel, i driver (x86 e x64) devono salvare e ripristinare in modo esplicito i registri AVX. I registri AVX non possono essere usati in una routine del servizio di interruzione e le eccezioni aritmetiche vengono disattivate per impostazione predefinita.
include ksamd64.inc
subttl "Set YMM State."
;++
;
; Routine Description:
;
; This routine loads the first four YMM registers with the state supplied.
;
; Arguments;
;
; rcx - Supplies a pointer to the values we want to load.
;
; Return Value:
;
; None
;
;--
LEAF_ENTRY SetYmmValues, _TEXT$00
vmovdqa ymm0, ymmword ptr[rcx + 0]
vmovdqa ymm1, ymmword ptr[rcx + 32]
vmovdqa ymm2, ymmword ptr[rcx + 64]
vmovdqa ymm3, ymmword ptr[rcx + 96]
ret
LEAF_END SetYmmValues, _TEXT$00
end
typedef DECLSPEC_ALIGN(32) struct _YMM_REGISTERS {
ULONG64 Ymm4Registers[16];
} YMM_REGISTERS, *PYMM_REGISTERS;
VOID
FASTCALL
SetYmmValues(
__in PYMM_REGISTERS YmmRegisterValues
);
NTSTATUS
DriverEntry (
__in PDRIVER_OBJECT DriverObject,
__in PUNICODE_STRING RegistryPath
)
{
NTSTATUS Status;
XSTATE_SAVE SaveState;
ULONG64 EnabledFeatures;
//
// Load the first 4 YMM registers as 4 vectors of 4 64-bit integers.
//
YMM_REGISTERS RegisterValues = { 0, 1, 2, 3, // YMM0
4, 5, 6, 7, // YMM1
8, 9, 10, 11, // YMM2
12, 13, 14, 15 }; // YMM3
//
// Check to see if AVX is available. Bail if it is not.
//
EnabledFeatures = RtlGetEnabledExtendedFeatures(-1);
if ((EnabledFeatures & XSTATE_MASK_GSSE) == 0) {
Status = STATUS_FAILED_DRIVER_ENTRY;
goto exit;
}
Status = KeSaveExtendedProcessorState(XSTATE_MASK_GSSE, &SaveState);
if (!NT_SUCCESS(Status)) {
goto exit;
}
__try {
SetYmmValues(&RegisterValues);
}
__finally {
KeRestoreExtendedProcessorState(&SaveState);
}
exit:
return Status;
}
Argomenti correlati
KeSaveExtendedProcessorState
KeRestoreExtendedProcessorState
Uso della virgola mobile in un driver WDM