From 84e5169bff5f8ffea066d30fc20f629958e828c3 Mon Sep 17 00:00:00 2001 From: Aren Elchinyan Date: Thu, 1 Feb 2024 11:12:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=82=D1=80=D0=B0=D1=81=D1=81=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D1=81=D1=82=D0=B5=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/version.h | 2 +- kernel/cpu/idt.c | 17 +++++++++++++++++ kernel/cpu/task.c | 3 ++- kernel/mem.c | 2 +- kernel/mod.c | 12 ++++++++++-- kernel/start.c | 12 +++--------- modules/imfs/main.c | 10 +--------- modules/ios/main.c | 1 + 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/include/version.h b/include/version.h index 8a91815..5fcd4c4 100644 --- a/include/version.h +++ b/include/version.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 1 -#define VERSION_BUILD 987 +#define VERSION_BUILD 999 diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c index 9b3f564..6ad5a21 100644 --- a/kernel/cpu/idt.c +++ b/kernel/cpu/idt.c @@ -16,6 +16,13 @@ extern task_t *current_task; +struct stack_frame { + struct stack_frame *rbp; + uint64_t rip; +} __attribute__((packed)); + +typedef struct stack_frame stack_frame_t; + static inline void idt_load( ) { asm volatile("lidt %0" : : "m"(idtr)); } @@ -65,6 +72,16 @@ static void exception_handler(struct frame state) { t = t->next; } + stack_frame_t *stk; + stk = state.rbp; + + LOG("Трассировка стека:\n"); + + for (uint64_t i = 0; stk && i < 4; i++) { + LOG(" 0x%x\n", stk->rip); + stk = stk->rbp; + } + asm volatile("cli"); asm volatile("hlt"); } diff --git a/kernel/cpu/task.c b/kernel/cpu/task.c index b540a46..efda6cb 100644 --- a/kernel/cpu/task.c +++ b/kernel/cpu/task.c @@ -96,6 +96,7 @@ void task_del(uint64_t id) { } } + LOG("Удаление потока ID: %u, %s\n", current_task->id, current_task->id_str); task_t *prev = task->last; task_t *next = task->next; @@ -123,7 +124,7 @@ void task_del_current( ) { mem_free(current_task); current_task = next; - task_switch( ); + if (full_init) { task_switch( ); } } void task_after_init( ) { diff --git a/kernel/mem.c b/kernel/mem.c index c3c0fc9..0899015 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -222,7 +222,7 @@ static void *alloc_align(size_t size, size_t alignment) { second->free = 0; second->task_id = 0; - if (full_init) { second->task_id = current_task->id; } + if (task_f_init) { second->task_id = current_task->id; } if (curr != second) { curr->next = second; diff --git a/kernel/mod.c b/kernel/mod.c index 6ec17cb..407e0eb 100644 --- a/kernel/mod.c +++ b/kernel/mod.c @@ -62,7 +62,7 @@ void mod_after_init( ) { for (uint64_t i = 0; i < modules_count; i++) { if (module_list[i].after_init != 0) { LOG("%s.after_init( );\n", module_list[i].name); - task_new_thread(module_list[i].after_init); + task_new_thread(module_list[i].after_init, module_list[i].name); } } } @@ -136,15 +136,23 @@ void mod_init( ) { sys_install(&main_env); - module_info_t ret = module_init(&main_env); + uint64_t id = task_new_thread(1, module_list[i].name); + module_info_t ret = module_init(&main_env); LOG("\t->%s\n", ret.message); + + task_del(id); + module_list[modules_count].name = ret.name; module_list[modules_count].message = ret.message; module_list[modules_count].data_size = ret.data_size; module_list[modules_count].get_func = ret.get_func; module_list[modules_count].after_init = ret.after_init; + if (module_list[modules_count].after_init) { + task_new_thread(module_list[modules_count].after_init, module_list[modules_count].name); + } + if (ret.data_size != 0) { module_list[modules_count].data = ret.data; } if (ret.irq != 0) { diff --git a/kernel/start.c b/kernel/start.c index a44bf5a..12b84e1 100644 --- a/kernel/start.c +++ b/kernel/start.c @@ -25,7 +25,8 @@ void finally( ) { void dummy( ) { LOG("Поток %u\n", dum++); - task_del(current_task->id); + task_del_current( ); + for (;;) { asm volatile("hlt"); } } // Точка входа @@ -39,6 +40,7 @@ void _start( ) { arch_init( ); pit_init( ); task_init( ); + task_f_init = 1; mod_init( ); LOG("\t\t\t\t *** Базовая Модульная Платформа Операционных Систем " @@ -53,17 +55,9 @@ void _start( ) { task_new_thread(finally, "fin"); full_init = 1; - task_f_init = 1; task_after_init( ); - for (uint64_t i = 0; i < 6; i++) { - char *buf = mem_alloc(32); - tool_strcpy(buf, "dum"); - tool_uint_to_str(i, 10, buf + 3); - task_new_thread(dummy, buf); - } - asm volatile("sti"); for (;;) { asm volatile("hlt"); } diff --git a/modules/imfs/main.c b/modules/imfs/main.c index 1cb316d..bb732fb 100644 --- a/modules/imfs/main.c +++ b/modules/imfs/main.c @@ -142,14 +142,6 @@ void print_folder_contents(folder_t *folder, size_t depth) { } } -static void main( ) { - uint64_t *mod_count = alloc(sizeof(uint64_t)); - module_info_t *mod_list = mod_list_get(mod_count); - fb_printf("Модулей: %u\n", *mod_count); - free(mod_count); - delete_thread( ); -} - module_info_t __attribute__((section(".minit"))) init(env_t *env) { init_env(env); create_folder("", NULL); @@ -173,6 +165,6 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) { .irq = 0, .irq_handler = 0, .get_func = 0, - .after_init = main + .after_init = 0 }; } diff --git a/modules/ios/main.c b/modules/ios/main.c index 51a4948..207a935 100644 --- a/modules/ios/main.c +++ b/modules/ios/main.c @@ -15,6 +15,7 @@ static void main( ) { if (app_list == NULL) { fb_printf("Ошибка выделения памяти для app_list!\n"); delete_thread( ); + for (;;) { asm volatile("hlt"); } } app_count = 0;