Skip to content

Commit

Permalink
Добавлена трассировка стека
Browse files Browse the repository at this point in the history
  • Loading branch information
0Nera committed Feb 1, 2024
1 parent ba1047a commit 84e5169
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 987
#define VERSION_BUILD 999
17 changes: 17 additions & 0 deletions kernel/cpu/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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");
}
Expand Down
3 changes: 2 additions & 1 deletion kernel/cpu/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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( ) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions kernel/mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 3 additions & 9 deletions kernel/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ void finally( ) {

void dummy( ) {
LOG("Поток %u\n", dum++);
task_del(current_task->id);
task_del_current( );
for (;;) { asm volatile("hlt"); }
}

// Точка входа
Expand All @@ -39,6 +40,7 @@ void _start( ) {
arch_init( );
pit_init( );
task_init( );
task_f_init = 1;
mod_init( );

LOG("\t\t\t\t *** Базовая Модульная Платформа Операционных Систем "
Expand All @@ -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"); }
Expand Down
10 changes: 1 addition & 9 deletions modules/imfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
};
}
1 change: 1 addition & 0 deletions modules/ios/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 84e5169

Please sign in to comment.