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
|
#pragma once
|
||||||
|
#include "interrupts/SavedContext.h"
|
||||||
|
|
||||||
namespace Interrupts
|
namespace Interrupts
|
||||||
{
|
{
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
|
bool is_in_handler();
|
||||||
|
void return_from_handler(SavedContext* context);
|
||||||
}
|
}
|
@ -37,6 +37,12 @@ unused:
|
|||||||
|
|
||||||
extern common_handler
|
extern common_handler
|
||||||
|
|
||||||
|
section .bss
|
||||||
|
global __is_in_interrupt_handler
|
||||||
|
__is_in_interrupt_handler:
|
||||||
|
resb 1
|
||||||
|
|
||||||
|
section .text
|
||||||
global asm_common
|
global asm_common
|
||||||
asm_common:
|
asm_common:
|
||||||
cld
|
cld
|
||||||
@ -66,12 +72,18 @@ asm_common:
|
|||||||
mov r8, cr2
|
mov r8, cr2
|
||||||
push r8
|
push r8
|
||||||
|
|
||||||
|
mov BYTE [__is_in_interrupt_handler], 1
|
||||||
|
|
||||||
mov rdi, rsp
|
mov rdi, rsp
|
||||||
|
|
||||||
call common_handler
|
call common_handler
|
||||||
|
|
||||||
|
global _asm_interrupt_exit
|
||||||
|
_asm_interrupt_exit:
|
||||||
add rsp, 8
|
add rsp, 8
|
||||||
|
|
||||||
|
mov BYTE [__is_in_interrupt_handler], 0
|
||||||
|
|
||||||
pop r8
|
pop r8
|
||||||
mov ds, r8
|
mov ds, r8
|
||||||
mov es, r8
|
mov es, r8
|
||||||
|
@ -9,3 +9,17 @@ void Interrupts::enable()
|
|||||||
{
|
{
|
||||||
asm volatile("sti");
|
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