fix (core): made CORE_HALT_WHILE interruptable while interrupt handlers

This commit is contained in:
antifallobst 2023-03-04 17:23:12 +01:00
parent ebe10b359d
commit 9d5ba72228
5 changed files with 25 additions and 12 deletions

View File

@ -83,6 +83,7 @@ typedef struct {
} idt_descriptor_entry_T;
extern idt_register_T g_idt_register;
extern uint8_t g_handling_interrupt;
void idt_init ();
void pic_init ();

View File

@ -25,10 +25,11 @@
#define NOX_CORE_H
#include "utils/logger.h"
#include "platform/interrupts.h"
#define CORE_HALT_WHILE(a) while(a) { asm("hlt"); }
#define CORE_HALT_FOREVER log(LOG_WARNING, "!=====[ HALTING SYSTEM ]=====!");\
while(1) { asm("hlt"); }
#define CORE_INTERRUPTABLE_HALT_WHILE(a) while(!g_handling_interrupt && a) { asm("hlt"); }
#define CORE_HALT_WHILE(a) while(!g_handling_interrupt && a) { asm("hlt"); }
#define CORE_HALT_FOREVER log(LOG_WARNING, "!=====[ HALTING SYSTEM ]=====!"); while(1) { asm("hlt"); }
#define CORE_INTERRUPTS_ENABLE asm("sti");
#define CORE_INTERRUPTS_DISABLE asm("cli");

View File

@ -109,7 +109,7 @@ void graphics_buffer_draw_char(graphics_buffer_T* graphics_buffer, uint32_t x, u
}
position_T graphics_buffer_draw_string(graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, string_t string) {
CORE_HALT_WHILE(graphics_buffer->blocked)
CORE_INTERRUPTABLE_HALT_WHILE(graphics_buffer->blocked)
graphics_buffer->blocked = true;
position_T pos = (position_T){x, y};
@ -203,7 +203,7 @@ void graphics_renderer_update_graphics_buffer(graphics_buffer_T* graphics_buffer
}
void graphics_renderer_update() {
CORE_HALT_WHILE(g_renderer.blocked)
CORE_INTERRUPTABLE_HALT_WHILE(g_renderer.blocked)
g_renderer.blocked = true;
memory_set(g_renderer.back_buffer, 0, g_renderer.buffer_size);

View File

@ -30,7 +30,7 @@
page_frame_manager_T g_page_frame_manager;
void pframe_reserve(void* address) {
CORE_HALT_WHILE(g_page_frame_manager.blocked)
CORE_INTERRUPTABLE_HALT_WHILE(g_page_frame_manager.blocked)
g_page_frame_manager.blocked = true;
uint64_t index = (uint64_t)address / PFRAME_SIZE;
@ -55,7 +55,7 @@ void pframe_reserve_multi(void* address, uint32_t n) {
}
void pframe_unreserve(void* address) {
CORE_HALT_WHILE(g_page_frame_manager.blocked)
CORE_INTERRUPTABLE_HALT_WHILE(g_page_frame_manager.blocked)
g_page_frame_manager.blocked = true;
uint64_t index = (uint64_t)address / PFRAME_SIZE;
@ -104,7 +104,7 @@ void pframe_lock_multi(void* address, uint32_t n) {
}
void pframe_free(void* address) {
CORE_HALT_WHILE(g_page_frame_manager.blocked)
CORE_INTERRUPTABLE_HALT_WHILE(g_page_frame_manager.blocked)
g_page_frame_manager.blocked = true;
uint64_t index = (uint64_t)address / PFRAME_SIZE;
@ -133,7 +133,7 @@ void pframe_free_multi(void* address, uint32_t n) {
}
void* pframe_request() {
CORE_HALT_WHILE(g_page_frame_manager.blocked)
CORE_INTERRUPTABLE_HALT_WHILE(g_page_frame_manager.blocked)
g_page_frame_manager.blocked = true;
while (g_page_frame_manager.page_bitmap_index < g_page_frame_manager.page_bitmap.size * 8) {

View File

@ -32,6 +32,7 @@
#include "proc/scheduler.h"
idt_register_T g_idt_register;
uint8_t g_handling_interrupt;
extern void idt_load(idt_register_T* idt_register);
@ -255,7 +256,7 @@ cpu_state_T* irq_handle(cpu_state_T* state, pic_irq_E irq) {
return return_state;
}
cpu_state_T* interrupts_handle(cpu_state_T* state) {
cpu_state_T* interrupts_handle_stage_2(cpu_state_T* state) {
if (state->interrupt_id < EXCEPTIONS_ENUM_END) {
return exception_handle(state);
}
@ -273,3 +274,13 @@ cpu_state_T* interrupts_handle(cpu_state_T* state) {
return state;
}
cpu_state_T* interrupts_handle(cpu_state_T* state) {
g_handling_interrupt++;
state = interrupts_handle_stage_2(state);
g_handling_interrupt--;
return state;
}