diff --git a/kernel/inc/platform/interrupts.h b/kernel/inc/platform/interrupts.h index 02fe10c..092ba5f 100644 --- a/kernel/inc/platform/interrupts.h +++ b/kernel/inc/platform/interrupts.h @@ -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 (); diff --git a/kernel/inc/utils/core.h b/kernel/inc/utils/core.h index 36cdf59..983a65e 100644 --- a/kernel/inc/utils/core.h +++ b/kernel/inc/utils/core.h @@ -25,12 +25,13 @@ #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"); +#define CORE_INTERRUPTS_ENABLE asm("sti"); +#define CORE_INTERRUPTS_DISABLE asm("cli"); #endif //NOX_CORE_H diff --git a/kernel/src/drivers/graphics/renderer.c b/kernel/src/drivers/graphics/renderer.c index 6a4ed35..2dda84e 100644 --- a/kernel/src/drivers/graphics/renderer.c +++ b/kernel/src/drivers/graphics/renderer.c @@ -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); diff --git a/kernel/src/mm/page_frame.c b/kernel/src/mm/page_frame.c index 125171d..7da2270 100644 --- a/kernel/src/mm/page_frame.c +++ b/kernel/src/mm/page_frame.c @@ -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) { diff --git a/kernel/src/platform/interrupts.c b/kernel/src/platform/interrupts.c index 12f3a5a..3735f52 100644 --- a/kernel/src/platform/interrupts.c +++ b/kernel/src/platform/interrupts.c @@ -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; +} +