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