Kernel: Add functions to push and pop the interrupt state

This can be useful when you want to disable interrupts, but then only enable them back if they were previously enabled.
This commit is contained in:
apio 2022-10-12 12:58:56 +02:00
parent b3e16068ef
commit f5deb1048a
2 changed files with 30 additions and 0 deletions

View File

@ -10,4 +10,8 @@ namespace Interrupts
void return_from_handler(Context* context);
bool are_enabled();
bool were_enabled();
void push_and_disable();
void push_and_enable();
void pop();
}

View File

@ -31,3 +31,29 @@ bool Interrupts::are_enabled()
{
return (Utilities::get_rflags() & 0x200) > 0;
}
static bool saved_interrupt_state;
void Interrupts::push_and_disable()
{
saved_interrupt_state = are_enabled();
disable();
}
void Interrupts::push_and_enable()
{
saved_interrupt_state = are_enabled();
enable();
}
void Interrupts::pop()
{
if (saved_interrupt_state && !are_enabled()) enable();
else if (!saved_interrupt_state && are_enabled())
disable();
}
bool Interrupts::were_enabled()
{
return saved_interrupt_state;
}