43 lines
1.1 KiB
C
43 lines
1.1 KiB
C
// HAL processor control exports. This file owns interrupt masking and processor halt instructions.
|
|
|
|
#include <stdint.h>
|
|
#include <intrin.h>
|
|
#include <ntlite/ddi/hal_api.h>
|
|
#pragma intrinsic(_disable)
|
|
#pragma intrinsic(_enable)
|
|
|
|
// Masks interrupts and returns the previous RFLAGS value.
|
|
__declspec(dllexport) uintptr_t HalDisableInterrupts(void) {
|
|
uintptr_t flags = __readeflags();
|
|
_disable();
|
|
return flags;
|
|
}
|
|
|
|
// Restores a previously saved RFLAGS value.
|
|
__declspec(dllexport) void HalRestoreInterrupts(uintptr_t flags) {
|
|
__writeeflags(flags);
|
|
}
|
|
|
|
// Enables maskable interrupts.
|
|
__declspec(dllexport) void HalEnableInterrupts(void) {
|
|
_enable();
|
|
}
|
|
|
|
// Enables interrupts and halts until an interrupt arrives.
|
|
__declspec(dllexport) void HalWaitForInterrupt(void) {
|
|
_enable();
|
|
__halt();
|
|
}
|
|
|
|
// Halts once without changing interrupt state.
|
|
__declspec(dllexport) void HalHalt(void) {
|
|
__halt();
|
|
}
|
|
|
|
// Masks interrupts and permanently stops the current processor.
|
|
__declspec(dllexport) _Noreturn void HalStopProcessor(void) {
|
|
_disable();
|
|
for (;;)
|
|
__halt();
|
|
}
|