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:
parent
b3e16068ef
commit
f5deb1048a
@ -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();
|
||||
}
|
@ -30,4 +30,30 @@ void Interrupts::return_from_handler(Context* context)
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user