Добавлена трассировка стека

This commit is contained in:
Aren Elchinyan 2024-02-01 11:12:35 +03:00
parent ba1047a70d
commit 84e5169bff
8 changed files with 36 additions and 23 deletions

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 987
#define VERSION_BUILD 999

View File

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

View File

@ -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( ) {

View File

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

View File

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

View File

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

View File

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

View File

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