diff --git a/x64/src/common/inc/kernel/ke/s_intr.h b/x64/src/common/inc/kernel/ke/s_intr.h index 34c7955..e3acfba 100644 --- a/x64/src/common/inc/kernel/ke/s_intr.h +++ b/x64/src/common/inc/kernel/ke/s_intr.h @@ -40,7 +40,11 @@ extern void KABI hal_set_timer_timeout(uint64_t millis); extern void KABI hal_halt_cpu(); -extern uint32_t KABI hal_get_current_core(); +extern int32_t KABI hal_get_current_core(); + +extern void KABI hal_set_irql(irql_t irql); + +extern irql_t KABI hal_get_irql(); extern void KABI hal_issue_interrupt(uint32_t core_id, uint32_t vector); diff --git a/x64/src/hal/boot.asm b/x64/src/hal/boot.asm index 5959847..57f6db7 100644 --- a/x64/src/hal/boot.asm +++ b/x64/src/hal/boot.asm @@ -2,7 +2,7 @@ ; Distributed under GPL license ; See COPYING under root for details -%include "hal_addr.inc" +%include "addr.inc" MULTIBOOT_TAG_ALIGNMENT equ 8 MULTIBOOT_HEADER_ALIGNMENT equ 8 diff --git a/x64/src/hal/hal_k_impl.c b/x64/src/hal/hal_k_impl.c index 3af870f..b65fff0 100644 --- a/x64/src/hal/hal_k_impl.c +++ b/x64/src/hal/hal_k_impl.c @@ -1,5 +1,5 @@ #include "intr.h" -#include "hal_arch.h" +#include "arch.h" #include "s_atomic.h" #include "s_boot.h" #include "s_context.h" @@ -28,11 +28,6 @@ irql_t KABI ke_set_irql(irql_t irql) return old_irql; } -irql_t KABI ke_get_irql() -{ - return (irql_t)hal_read_cr8(); -} - void KABI ke_halt_cpu() { hal_halt_cpu(); diff --git a/x64/src/hal/inc/hal_addr.inc b/x64/src/hal/inc/addr.inc similarity index 100% rename from x64/src/hal/inc/hal_addr.inc rename to x64/src/hal/inc/addr.inc diff --git a/x64/src/hal/inc/hal_arch.h b/x64/src/hal/inc/arch.h similarity index 100% rename from x64/src/hal/inc/hal_arch.h rename to x64/src/hal/inc/arch.h diff --git a/x64/src/hal/inc/hal_multiboot.h b/x64/src/hal/inc/multiboot.h similarity index 100% rename from x64/src/hal/inc/hal_multiboot.h rename to x64/src/hal/inc/multiboot.h diff --git a/x64/src/hal/init.c b/x64/src/hal/init.c index 6517c9c..319a2e9 100644 --- a/x64/src/hal/init.c +++ b/x64/src/hal/init.c @@ -6,14 +6,14 @@ #include "print.h" #include "mem.h" #include "intr.h" -#include "hal_arch.h" +#include "arch.h" #include "sxtdlib.h" #include "s_boot.h" extern char HAL_KERNEL_START_VADDR[]; extern char HAL_KERNEL_END_VADDR[]; -static void KABI _hal_obtain_cpu_info(boot_info_t *hal_info) +static void KABI halp_obtain_cpu_info(boot_info_t *hal_info) { if(hal_info == NULL) return; @@ -42,7 +42,7 @@ void KABI hal_main(void *m_info) boot_info->krnl_end = (uint64_t)HAL_KERNEL_END_VADDR; // obtain cpu info - _hal_obtain_cpu_info(boot_info); + halp_obtain_cpu_info(boot_info); // init interrupt if(hal_interrupt_init() != 0) diff --git a/x64/src/hal/intr.c b/x64/src/hal/intr.c index 380aa1f..bd0f80f 100644 --- a/x64/src/hal/intr.c +++ b/x64/src/hal/intr.c @@ -3,7 +3,7 @@ * See COPYING under root for details */ -#include "hal_arch.h" +#include "arch.h" #include "intr.h" #include "print.h" #include "mem.h" @@ -135,7 +135,7 @@ void KABI hal_exception_dispatcher(uint64_t exc_vec, hal_intr_context_t* context return; } -static void KABI _hal_populate_idt() +static void KABI halp_populate_idt() { hal_set_interrupt_handler(0, hal_interrupt_handler_0); hal_set_interrupt_handler(1, hal_interrupt_handler_1); @@ -426,7 +426,7 @@ int32_t KABI hal_interrupt_init(void) } // hook asm interrupt handlers - _hal_populate_idt(); + halp_populate_idt(); hal_flush_idt(&_idt_ptrs[coreid]); diff --git a/x64/src/hal/mem.c b/x64/src/hal/mem.c index fe3ea7c..0c12942 100644 --- a/x64/src/hal/mem.c +++ b/x64/src/hal/mem.c @@ -6,7 +6,7 @@ #include "g_type.h" #include "mem.h" #include "salloc.h" -#include "hal_arch.h" +#include "arch.h" #include "intr.h" static uint8_t _gdts[HAL_CORE_COUNT][GDT_ENTRY_NUM * GDT_ENTRY_SIZE]; diff --git a/x64/src/hal/print.c b/x64/src/hal/print.c index 5c0dcf9..aebdef6 100644 --- a/x64/src/hal/print.c +++ b/x64/src/hal/print.c @@ -9,18 +9,18 @@ static uint64_t text_pos; -void KABI hal_print_init() +static void KABI hal_print_init() { text_pos = 0; } -void KABI _hal_print_scroll() +static void KABI halp_print_scroll() { lb_mem_move((void *) (0xb8000 + get_pos(1, 0) * 2), (void *) (0xb8000 + get_pos(0, 0) * 2), (80 * 24) * 2); return; } -void KABI _hal_print_str(char const *str) +static void KABI halp_print_str(char const *str) { if(str == NULL) return; @@ -32,7 +32,7 @@ void KABI _hal_print_str(char const *str) if(text_pos > 80 * 25 - 1) { //can't hold - _hal_print_scroll(); + halp_print_scroll(); lb_mem_set((void *) (0xb8000 + 80 * 24 * 2), 0, 80 * 2); // clear last row text_pos = 80 * 24; } @@ -43,7 +43,7 @@ void KABI _hal_print_str(char const *str) if (text_pos > 80 * 25 - 1) { //can't hold - _hal_print_scroll(); + halp_print_scroll(); text_pos = 80 * 24; } *((char*)(0xb8000) + text_pos*2) = *str; @@ -55,7 +55,7 @@ void KABI _hal_print_str(char const *str) return; } -void KABI _hal_print_uint(uint64_t number) +static void KABI halp_print_uint(uint64_t number) { char arr[21]; // do not need to initialize arr[20] = 0; //zero-terminated @@ -70,11 +70,11 @@ void KABI _hal_print_uint(uint64_t number) if (number == 0) break; } - _hal_print_str(&(arr[index + 1])); + halp_print_str(&(arr[index + 1])); return; } -void KABI _hal_print_int(int64_t number) +static void KABI halp_print_int(int64_t number) { char arr[21]; // do not need to initialize arr[20] = 0; //zero-terminated @@ -99,11 +99,11 @@ void KABI _hal_print_int(int64_t number) { arr[index--] = '-'; } - _hal_print_str(&(arr[index + 1])); + halp_print_str(&(arr[index + 1])); return; } -void KABI _hal_print_hex(uint64_t number, uint64_t capital) +static void KABI halp_print_hex(uint64_t number, uint64_t capital) { char const lookup_table_cap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; char const lookup_table[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; @@ -121,7 +121,7 @@ void KABI _hal_print_hex(uint64_t number, uint64_t capital) if (number == 0) break; } - _hal_print_str(&(arr[index + 1])); + halp_print_str(&(arr[index + 1])); return; } @@ -146,7 +146,7 @@ void KABI hal_printf(char const *format, ...) if (*format != '%') { buf[0] = *format; - _hal_print_str(buf); + halp_print_str(buf); continue; } format++; @@ -154,36 +154,36 @@ void KABI hal_printf(char const *format, ...) { case 'd': d = va_arg(args, int64_t); - _hal_print_int(d); + halp_print_int(d); break; case 'u': u = va_arg(args, uint64_t); - _hal_print_uint(u); + halp_print_uint(u); break; case 's': s = va_arg(args, char *); - _hal_print_str(s); + halp_print_str(s); break; case 'c': c = va_arg(args, int64_t); buf[0] = c; - _hal_print_str(buf); + halp_print_str(buf); break; case 'x': u = va_arg(args, uint64_t); - _hal_print_hex(u, 0); + halp_print_hex(u, 0); break; case 'X': u = va_arg(args, uint64_t); - _hal_print_hex(u, 1); + halp_print_hex(u, 1); break; case '%': buf[0] = '%'; - _hal_print_str(buf); + halp_print_str(buf); break; default: buf[0] = '%'; - _hal_print_str(buf); + halp_print_str(buf); format--; break; } diff --git a/x64/src/kernel/ke/inc/intr.h b/x64/src/kernel/ke/inc/intr.h index 94080fe..48f2f34 100644 --- a/x64/src/kernel/ke/inc/intr.h +++ b/x64/src/kernel/ke/inc/intr.h @@ -9,4 +9,8 @@ irql_t KABI ke_raise_irql(irql_t irql); irql_t KABI ke_lower_irql(irql_t irql); +int KABI ke_get_current_core(); + +irql_t KABI ke_get_irql(); + #endif \ No newline at end of file diff --git a/x64/src/kernel/ke/intr.c b/x64/src/kernel/ke/intr.c index d0f2f42..e614744 100644 --- a/x64/src/kernel/ke/intr.c +++ b/x64/src/kernel/ke/intr.c @@ -4,11 +4,22 @@ irql_t KABI ke_raise_irql(irql_t irql) { ke_assert(ke_get_irql() <= irql); - return ke_set_irql(irql); + return hal_set_irql(irql); } irql_t KABI ke_lower_irql(irql_t irql) { - ke_assert(ke_get_irql() >= irql); - return ke_set_irql(irql); + irql_t old_irql = ke_get_irql(); + ke_assert(old_irql >= irql); + return hal_set_irql(irql); +} + +irql_t KABI ke_get_irql() +{ + return hal_get_irql(); +} + +int KABI ke_get_current_core() +{ + return hal_get_current_core(); } \ No newline at end of file