Boot framework rework (#45)
[lunaix-os.git] / lunaix-os / kernel / debug / trace.c
index 66e5505e2bc97a92d6c022beecbbe57391be9112..a2459bd64d00f4a8407af62733d1462c52e95b7a 100644 (file)
@@ -3,6 +3,7 @@
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 #include <lunaix/trace.h>
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 #include <lunaix/trace.h>
+#include <lunaix/sections.h>
 
 #include <sys/abi.h>
 #include <sys/mm/mm_defs.h>
 
 #include <sys/abi.h>
 #include <sys/mm/mm_defs.h>
@@ -14,8 +15,7 @@
 
 LOG_MODULE("TRACE")
 
 
 LOG_MODULE("TRACE")
 
-weak struct ksyms __lunaix_ksymtable[] = { };
-extern struct ksyms __lunaix_ksymtable[];
+extern_autogen(ksymtable);
 
 static struct trace_context trace_ctx;
 
 
 static struct trace_context trace_ctx;
 
@@ -33,7 +33,7 @@ trace_log(const char* fmt, ...)
 void
 trace_modksyms_init(struct boot_handoff* bhctx)
 {
 void
 trace_modksyms_init(struct boot_handoff* bhctx)
 {
-    trace_ctx.ksym_table = __lunaix_ksymtable;
+    trace_ctx.ksym_table = autogen(struct ksyms, ksymtable);
 }
 
 struct ksym_entry*
 }
 
 struct ksym_entry*
@@ -71,14 +71,14 @@ static char*
 ksym_getstr(struct ksym_entry* sym)
 {
     if (!sym) {
 ksym_getstr(struct ksym_entry* sym)
 {
     if (!sym) {
-        return "???";
+        return NULL;
     }
 
     return sym->label;
 }
 
 static inline bool valid_fp(ptr_t ptr) {
     }
 
     return sym->label;
 }
 
 static inline bool valid_fp(ptr_t ptr) {
-    ptr_t start = ROUNDUP(current_thread->kstack - KSTACK_SIZE, MEM_PAGE);
+    ptr_t start = ROUNDUP(current_thread->kstack - KSTACK_SIZE, PAGE_SIZE);
 
     return (start < ptr && ptr < current_thread->kstack) 
            || arch_valid_fp(ptr);
 
     return (start < ptr && ptr < current_thread->kstack) 
            || arch_valid_fp(ptr);
@@ -121,10 +121,10 @@ trace_walkback(struct trace_record* tb_buffer,
 static inline void
 trace_print_code_entry(ptr_t sym_pc, ptr_t inst_pc, char* sym)
 {
 static inline void
 trace_print_code_entry(ptr_t sym_pc, ptr_t inst_pc, char* sym)
 {
-    if (sym_pc) {
+    if (sym) {
         trace_log("%s+%p", sym, inst_pc - sym_pc);
     } else {
         trace_log("%s+%p", sym, inst_pc - sym_pc);
     } else {
-        trace_log("%s [%p]", sym, sym_pc);
+        trace_log("??? [%p]", inst_pc);
     }
 }
 
     }
 }
 
@@ -161,7 +161,7 @@ static void
 trace_printswctx(const struct hart_state* hstate, bool from_usr, bool to_usr)
 {
 
 trace_printswctx(const struct hart_state* hstate, bool from_usr, bool to_usr)
 {
 
-    struct ksym_entry* sym = trace_sym_lookup(hstate->execp->eip);
+    struct ksym_entry* sym = trace_sym_lookup(hart_pc(hstate));
 
     trace_log("^^^^^ --- %s", to_usr ? "user" : "kernel");
     trace_print_transistion_short(hstate);
 
     trace_log("^^^^^ --- %s", to_usr ? "user" : "kernel");
     trace_print_transistion_short(hstate);