Add a is_in_handler function to validate being in an interrupt handler
This commit is contained in:
parent
3a796eb64c
commit
d0d2d4381c
@ -1,7 +1,11 @@
|
||||
#pragma once
|
||||
#include "interrupts/SavedContext.h"
|
||||
|
||||
namespace Interrupts
|
||||
{
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
bool is_in_handler();
|
||||
void return_from_handler(SavedContext* context);
|
||||
}
|
@ -37,6 +37,12 @@ unused:
|
||||
|
||||
extern common_handler
|
||||
|
||||
section .bss
|
||||
global __is_in_interrupt_handler
|
||||
__is_in_interrupt_handler:
|
||||
resb 1
|
||||
|
||||
section .text
|
||||
global asm_common
|
||||
asm_common:
|
||||
cld
|
||||
@ -66,12 +72,18 @@ asm_common:
|
||||
mov r8, cr2
|
||||
push r8
|
||||
|
||||
mov BYTE [__is_in_interrupt_handler], 1
|
||||
|
||||
mov rdi, rsp
|
||||
|
||||
call common_handler
|
||||
|
||||
global _asm_interrupt_exit
|
||||
_asm_interrupt_exit:
|
||||
add rsp, 8
|
||||
|
||||
mov BYTE [__is_in_interrupt_handler], 0
|
||||
|
||||
pop r8
|
||||
mov ds, r8
|
||||
mov es, r8
|
||||
|
@ -8,4 +8,18 @@ void Interrupts::disable()
|
||||
void Interrupts::enable()
|
||||
{
|
||||
asm volatile("sti");
|
||||
}
|
||||
|
||||
extern char __is_in_interrupt_handler;
|
||||
bool Interrupts::is_in_handler()
|
||||
{
|
||||
return __is_in_interrupt_handler;
|
||||
}
|
||||
|
||||
void Interrupts::return_from_handler(SavedContext* context)
|
||||
{
|
||||
asm volatile("mov %0, %%rsp\n"
|
||||
"jmp _asm_interrupt_exit"
|
||||
:
|
||||
: "r"(context));
|
||||
}
|
Loading…
Reference in New Issue
Block a user