Add a is_in_handler function to validate being in an interrupt handler

This commit is contained in:
apio 2022-09-20 17:16:07 +02:00
parent 3a796eb64c
commit d0d2d4381c
3 changed files with 30 additions and 0 deletions

View File

@ -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);
} }

View File

@ -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

View File

@ -8,4 +8,18 @@ void Interrupts::disable()
void Interrupts::enable() 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));
} }