feat: kernel stack tracing
authorMinep <lunaixsky@qq.com>
Sun, 20 Aug 2023 16:14:13 +0000 (17:14 +0100)
committerMinep <lunaixsky@qq.com>
Sun, 20 Aug 2023 16:21:07 +0000 (17:21 +0100)
refactor: move cpu.h to arch specific

20 files changed:
lunaix-os/GRUB_TEMPLATE
lunaix-os/arch/i386/exceptions/interrupt.S
lunaix-os/arch/i386/exceptions/interrupts.c
lunaix-os/arch/i386/exceptions/intr_routines.c
lunaix-os/arch/i386/hal/apic.c
lunaix-os/arch/i386/hal/cpu.c
lunaix-os/arch/i386/includes/sys/cpu.h [new file with mode: 0644]
lunaix-os/arch/i386/includes/sys/interrupts.h
lunaix-os/arch/i386/mm/pfault.c
lunaix-os/includes/hal/cpu.h [deleted file]
lunaix-os/includes/lunaix/trace.h
lunaix-os/kernel/block/blkio.c
lunaix-os/kernel/boot_helper.c
lunaix-os/kernel/debug/trace.c
lunaix-os/kernel/mm/vmm.c
lunaix-os/kernel/peripheral/ps2kbd.c
lunaix-os/kernel/peripheral/serial.c
lunaix-os/kernel/process/sched.c
lunaix-os/scripts/syms_export.py
lunaix-os/usr/libc/arch/i386/crt0.S

index 7d5fd86c5a0f67467a140480b70423a38f60dca7..176f426af4d82f5784e0de03e9bb548b5879ed30 100644 (file)
@@ -3,5 +3,5 @@ timeout=0
 
 menuentry "$_OS_NAME" {
        multiboot /boot/kernel.bin
 
 menuentry "$_OS_NAME" {
        multiboot /boot/kernel.bin
-       module /boot/modksyms modksyms
+       module --nounzip /boot/modksyms modksyms
 }
\ No newline at end of file
 }
\ No newline at end of file
index e5a125fde8edf54018d887bf59f696cdc666305a..c61e6a60a65f75925edf9f2eee5874b5246a1d4f 100644 (file)
@@ -33,6 +33,7 @@
 */
 
 .section .text
 */
 
 .section .text
+    .type interrupt_wrapper, @function
     .global interrupt_wrapper
     interrupt_wrapper:
         cld
     .global interrupt_wrapper
     interrupt_wrapper:
         cld
@@ -90,6 +91,7 @@
         subl $16, %esp
         movl %eax, (%esp)
 
         subl $16, %esp
         movl %eax, (%esp)
 
+        xorl %ebp, %ebp     # marks the boundary of stack walking
         call intr_handler
 
         movl (%esp), %eax
         call intr_handler
 
         movl (%esp), %eax
 
         iret
 
 
         iret
 
+    .type switch_to, @function
     .global switch_to
     switch_to:
         # 约定
     .global switch_to
     switch_to:
         # 约定
         movl proc_intr_ctx(%ebx), %eax
         jmp soft_iret
 
         movl proc_intr_ctx(%ebx), %eax
         jmp soft_iret
 
+    .type handle_signal, @function 
     .global handle_signal
     handle_signal:
         # 注意1:任何对proc_sig的布局改动,都须及时的保证这里的一致性!
     .global handle_signal
     handle_signal:
         # 注意1:任何对proc_sig的布局改动,都须及时的保证这里的一致性!
index adde97346a45627b399b7597f44c58d08462ae56..c45f961018d8199e565536d6ccf07878b34647c8 100644 (file)
@@ -1,7 +1,7 @@
 #include <sys/interrupts.h>
 #include <sys/x86_isa.h>
 
 #include <sys/interrupts.h>
 #include <sys/x86_isa.h>
 
-#include <hal/cpu.h>
+#include <sys/cpu.h>
 #include <hal/intc.h>
 
 #include <lunaix/isrm.h>
 #include <hal/intc.h>
 
 #include <lunaix/isrm.h>
index 6571f9a63219b9b4ee2b91fae10f1a380891890c..100df0ba2f84628321c4bb67031e98a6ca4d3807 100644 (file)
@@ -6,6 +6,7 @@
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 #include <lunaix/sched.h>
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
+#include <lunaix/trace.h>
 #include <lunaix/tty/tty.h>
 
 #include <klibc/stdio.h>
 #include <lunaix/tty/tty.h>
 
 #include <klibc/stdio.h>
@@ -23,47 +24,42 @@ extern u32_t debug_resv;
 void
 __print_panic_msg(const char* msg, const isr_param* param)
 {
 void
 __print_panic_msg(const char* msg, const isr_param* param)
 {
-    volatile struct exec_param* execp = param->execp;
-
-    kprint_panic("  INT %u: (%x) [%p: %p] %s",
-                 execp->vector,
-                 execp->err_code,
-                 execp->cs,
-                 execp->eip,
-                 msg);
+    kprintf(KERROR "panic: %s\n", msg);
+    trace_printstack_isr(param);
 }
 
 void
 intr_routine_divide_zero(const isr_param* param)
 {
 }
 
 void
 intr_routine_divide_zero(const isr_param* param)
 {
+    __print_panic_msg("div zero", param);
+
     console_flush();
     console_flush();
-    __print_panic_msg("Divide by zero!", param);
     spin();
 }
 
 void
 intr_routine_general_protection(const isr_param* param)
 {
     spin();
 }
 
 void
 intr_routine_general_protection(const isr_param* param)
 {
-    kprintf(KERROR "Pid: %d\n", __current->pid);
-    kprintf(KERROR "Addr: %p\n", (&debug_resv)[0]);
-    kprintf(KERROR "Expected: %p\n", (&debug_resv)[1]);
+    __print_panic_msg("general protection", param);
+
     console_flush();
     console_flush();
-    __print_panic_msg("General Protection", param);
     spin();
 }
 
 void
 intr_routine_sys_panic(const isr_param* param)
 {
     spin();
 }
 
 void
 intr_routine_sys_panic(const isr_param* param)
 {
-    console_flush();
     __print_panic_msg((char*)(param->registers.edi), param);
     __print_panic_msg((char*)(param->registers.edi), param);
+
+    console_flush();
     spin();
 }
 
 void
 intr_routine_fallback(const isr_param* param)
 {
     spin();
 }
 
 void
 intr_routine_fallback(const isr_param* param)
 {
-    __print_panic_msg("Unknown Interrupt", param);
+    __print_panic_msg("unknown interrupt", param);
+
     console_flush();
     spin();
 }
     console_flush();
     spin();
 }
@@ -85,8 +81,10 @@ intr_routine_apic_error(const isr_param* param)
     u32_t error_reg = apic_read_reg(APIC_ESR);
     char buf[32];
     ksprintf(buf, "APIC error, ESR=0x%x", error_reg);
     u32_t error_reg = apic_read_reg(APIC_ESR);
     char buf[32];
     ksprintf(buf, "APIC error, ESR=0x%x", error_reg);
-    console_flush();
+
     __print_panic_msg(buf, param);
     __print_panic_msg(buf, param);
+
+    console_flush();
     spin();
 }
 
     spin();
 }
 
index bd53fc55888e7b172a8697c08cc4f77970443d66..4323ac8051ab8b10852b9163306b346d64d5fb9f 100644 (file)
@@ -9,7 +9,7 @@
  *
  */
 
  *
  */
 
-#include <hal/cpu.h>
+#include <sys/cpu.h>
 #include <hal/intc.h>
 
 #include <sys/apic.h>
 #include <hal/intc.h>
 
 #include <sys/apic.h>
index 2ca126ae17407a5b52a80d54d955bacfc914137d..00ba7f429fc56cccf1f566d2e474945ad1ed8a7d 100644 (file)
@@ -1,7 +1,7 @@
-#include <sys/vectors.h>
 #include <cpuid.h>
 #include <cpuid.h>
-#include <hal/cpu.h>
 #include <lunaix/types.h>
 #include <lunaix/types.h>
+#include <sys/cpu.h>
+#include <sys/vectors.h>
 
 #define BRAND_LEAF 0x80000000UL
 
 
 #define BRAND_LEAF 0x80000000UL
 
@@ -46,68 +46,20 @@ cpu_get_id(char* id_out)
     id_out[48] = '\0';
 }
 
     id_out[48] = '\0';
 }
 
-u32_t
-cpu_ldstate()
-{
-    ptr_t val;
-    asm volatile("pushf\n"
-                 "popl %0\n"
-                 : "=r"(val)::);
-    return val;
-}
-
-u32_t
-cpu_ldconfig()
-{
-    ptr_t val;
-    asm volatile("movl %%cr0,%0" : "=r"(val));
-    return val;
-}
-
-void
-cpu_chconfig(u32_t val)
-{
-    asm("mov %0, %%cr0" ::"r"(val));
-}
-
-u32_t
-cpu_ldvmspace()
-{
-    ptr_t val;
-    asm volatile("movl %%cr3,%0" : "=r"(val));
-    return val;
-}
-
-void
-cpu_chvmspace(u32_t val)
-{
-    asm("mov %0, %%cr3" ::"r"(val));
-}
-
-void
-cpu_flush_page(ptr_t va)
-{
-    asm volatile("invlpg (%0)" ::"r"(va) : "memory");
-}
-
 void
 void
-cpu_flush_vmspace()
+cpu_rdmsr(u32_t msr_idx, u32_t* reg_high, u32_t* reg_low)
 {
 {
-    asm("movl %%cr3, %%eax\n"
-        "movl %%eax, %%cr3" ::
-          : "eax");
-}
+    u32_t h = 0, l = 0;
+    asm volatile("rdmsr" : "=d"(h), "=a"(l) : "c"(msr_idx));
 
 
-void
-cpu_enable_interrupt()
-{
-    asm volatile("sti");
+    *reg_high = h;
+    *reg_low = l;
 }
 
 void
 }
 
 void
-cpu_disable_interrupt()
+cpu_wrmsr(u32_t msr_idx, u32_t reg_high, u32_t reg_low)
 {
 {
-    asm volatile("cli");
+    asm volatile("wrmsr" : : "d"(reg_high), "a"(reg_low), "c"(msr_idx));
 }
 
 void
 }
 
 void
@@ -121,33 +73,3 @@ cpu_trap_panic(char* message)
 {
     asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(message));
 }
 {
     asm("int %0" ::"i"(LUNAIX_SYS_PANIC), "D"(message));
 }
-
-void
-cpu_wait()
-{
-    asm("hlt");
-}
-
-ptr_t
-cpu_ldeaddr()
-{
-    ptr_t val;
-    asm volatile("movl %%cr2,%0" : "=r"(val));
-    return val;
-}
-
-void
-cpu_rdmsr(u32_t msr_idx, u32_t* reg_high, u32_t* reg_low)
-{
-    u32_t h = 0, l = 0;
-    asm volatile("rdmsr" : "=d"(h), "=a"(l) : "c"(msr_idx));
-
-    *reg_high = h;
-    *reg_low = l;
-}
-
-void
-cpu_wrmsr(u32_t msr_idx, u32_t reg_high, u32_t reg_low)
-{
-    asm volatile("wrmsr" : : "d"(reg_high), "a"(reg_low), "c"(msr_idx));
-}
\ No newline at end of file
diff --git a/lunaix-os/arch/i386/includes/sys/cpu.h b/lunaix-os/arch/i386/includes/sys/cpu.h
new file mode 100644 (file)
index 0000000..3289522
--- /dev/null
@@ -0,0 +1,136 @@
+#ifndef __LUNAIX_CPU_H
+#define __LUNAIX_CPU_H
+
+#include <lunaix/types.h>
+
+/**
+ * @brief Get processor ID string
+ *
+ * @param id_out
+ */
+void
+cpu_get_id(char* id_out);
+
+void
+cpu_trap_sched();
+
+void
+cpu_trap_panic(char* message);
+
+static inline ptr_t
+cpu_get_fp()
+{
+    ptr_t val;
+    asm("movl %%ebp, %0" : "=r"(val)::);
+    return val;
+}
+
+/**
+ * @brief Load current processor state
+ *
+ * @return u32_t
+ */
+static inline u32_t
+cpu_ldstate()
+{
+    ptr_t val;
+    asm volatile("pushf\n"
+                 "popl %0\n"
+                 : "=r"(val)::);
+    return val;
+}
+
+/**
+ * @brief Load current processor config
+ *
+ * @return u32_t
+ */
+static inline u32_t
+cpu_ldconfig()
+{
+    ptr_t val;
+    asm volatile("movl %%cr0,%0" : "=r"(val));
+    return val;
+}
+
+/**
+ * @brief Change current processor state
+ *
+ * @return u32_t
+ */
+static inline void
+cpu_chconfig(u32_t val)
+{
+    asm("mov %0, %%cr0" ::"r"(val));
+}
+
+/**
+ * @brief Load current virtual memory space
+ *
+ * @return u32_t
+ */
+static inline u32_t
+cpu_ldvmspace()
+{
+    ptr_t val;
+    asm volatile("movl %%cr3,%0" : "=r"(val));
+    return val;
+}
+
+/**
+ * @brief Change current virtual memory space
+ *
+ * @return u32_t
+ */
+static inline void
+cpu_chvmspace(u32_t val)
+{
+    asm("mov %0, %%cr3" ::"r"(val));
+}
+
+/**
+ * @brief Flush TLB
+ *
+ * @return u32_t
+ */
+static inline void
+cpu_flush_page(ptr_t va)
+{
+    asm volatile("invlpg (%0)" ::"r"(va) : "memory");
+}
+
+static inline void
+cpu_flush_vmspace()
+{
+    asm("movl %%cr3, %%eax\n"
+        "movl %%eax, %%cr3" ::
+          : "eax");
+}
+
+static inline void
+cpu_enable_interrupt()
+{
+    asm volatile("sti");
+}
+
+static inline void
+cpu_disable_interrupt()
+{
+    asm volatile("cli");
+}
+
+static inline void
+cpu_wait()
+{
+    asm("hlt");
+}
+
+static inline ptr_t
+cpu_ldeaddr()
+{
+    ptr_t val;
+    asm volatile("movl %%cr2,%0" : "=r"(val));
+    return val;
+}
+
+#endif /* __LUNAIX_CPU_H */
index 003a2cd96bcda75b10933814b0a64ad40fe4227c..f1b7bf93aec373fde938947ba5eb9512600f3c42 100644 (file)
@@ -4,7 +4,10 @@
 #include "vectors.h"
 
 #ifndef __ASM__
 #include "vectors.h"
 
 #ifndef __ASM__
-#include <hal/cpu.h>
+#include <sys/cpu.h>
+
+#define saved_fp(isrm) ((isrm)->registers.ebp)
+#define uspace_context(isrm) (((isrm)->execp->cs) == 0x8)
 
 struct exec_param;
 
 
 struct exec_param;
 
index 4c28a955eea1e9465cbf5c145a160c987554399e..b028d844d9d64b4ee72a3b2d8faa111ec981e7e5 100644 (file)
@@ -7,6 +7,8 @@
 #include <lunaix/signal.h>
 #include <lunaix/status.h>
 #include <lunaix/syslog.h>
 #include <lunaix/signal.h>
 #include <lunaix/status.h>
 #include <lunaix/syslog.h>
+#include <lunaix/trace.h>
+
 #include <sys/interrupts.h>
 
 #include <klibc/string.h>
 #include <sys/interrupts.h>
 
 #include <klibc/string.h>
@@ -159,6 +161,8 @@ segv_term:
 
     sigset_add(__current->sigctx.sig_pending, _SIGSEGV);
 
 
     sigset_add(__current->sigctx.sig_pending, _SIGSEGV);
 
+    trace_printstack_isr(param);
+
     schedule();
     // should not reach
     while (1)
     schedule();
     // should not reach
     while (1)
diff --git a/lunaix-os/includes/hal/cpu.h b/lunaix-os/includes/hal/cpu.h
deleted file mode 100644 (file)
index c68bb95..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-#ifndef __LUNAIX_CPU_H
-#define __LUNAIX_CPU_H
-
-#include <lunaix/types.h>
-
-/**
- * @brief Get processor ID string
- *
- * @param id_out
- */
-void
-cpu_get_id(char* id_out);
-
-/**
- * @brief Load current processor state
- *
- * @return u32_t
- */
-u32_t
-cpu_ldstate();
-
-/**
- * @brief Load current processor config
- *
- * @return u32_t
- */
-u32_t
-cpu_ldconfig();
-
-/**
- * @brief Change current processor state
- *
- * @return u32_t
- */
-void
-cpu_chconfig(u32_t val);
-
-/**
- * @brief Load current virtual memory space
- *
- * @return u32_t
- */
-u32_t
-cpu_ldvmspace();
-
-/**
- * @brief Change current virtual memory space
- *
- * @return u32_t
- */
-void
-cpu_chvmspace(u32_t val);
-
-/**
- * @brief Flush TLB
- *
- * @return u32_t
- */
-void
-cpu_flush_page(ptr_t va);
-
-void
-cpu_flush_vmspace();
-
-void
-cpu_enable_interrupt();
-
-void
-cpu_disable_interrupt();
-
-void
-cpu_trap_sched();
-
-void
-cpu_trap_panic(char* message);
-
-void
-cpu_wait();
-
-ptr_t
-cpu_ldeaddr();
-
-#endif /* __LUNAIX_CPU_H */
index 80cf5f33ce09de2cead253cc10b17f8970f9ab74..4fbddd93d6bee23b4f9e374912efc15ab7ee9c8a 100644 (file)
@@ -2,6 +2,7 @@
 #define __LUNAIX_TRACE_H
 
 #include <lunaix/boot_generic.h>
 #define __LUNAIX_TRACE_H
 
 #include <lunaix/boot_generic.h>
+#include <sys/interrupts.h>
 
 struct ksym_entry
 {
 
 struct ksym_entry
 {
@@ -9,6 +10,12 @@ struct ksym_entry
     u32_t label_off;
 };
 
     u32_t label_off;
 };
 
+struct trace_record
+{
+    ptr_t pc;
+    char* symbol;
+};
+
 struct ksyms
 {
     u32_t ksym_count;
 struct ksyms
 {
     u32_t ksym_count;
@@ -27,7 +34,19 @@ trace_modksyms_init(struct boot_handoff* bhctx);
 struct ksym_entry*
 trace_sym_lookup(ptr_t pc);
 
 struct ksym_entry*
 trace_sym_lookup(ptr_t pc);
 
+int
+trace_walkback(struct trace_record* tb_buffer,
+               ptr_t fp,
+               int limit,
+               ptr_t* last_fp);
+
+void
+trace_printstack_of(ptr_t fp);
+
+void
+trace_printstack_isr(const isr_param* isrm);
+
 void
 void
-trace_walkback(ptr_t fp);
+trace_printstack();
 
 #endif /* __LUNAIX_TRACE_H */
 
 #endif /* __LUNAIX_TRACE_H */
index 0427622d9af4dcaf8cbbf0b2f73286feda0834a4..9fcd670e350286b28a1a251eaf8503f7498650c6 100644 (file)
@@ -2,7 +2,7 @@
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/valloc.h>
 
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/valloc.h>
 
-#include <hal/cpu.h>
+#include <sys/cpu.h>
 
 static struct cake_pile* blkio_reqpile;
 
 
 static struct cake_pile* blkio_reqpile;
 
index fa87bff5fae8777df9e121dbc998c85eacd74065..1383f60af7290181a01d8524b9485810c0201fcc 100644 (file)
@@ -32,6 +32,15 @@ boot_begin(struct boot_handoff* bhctx)
             vmm_set_mapping(VMS_SELF, pa, pa, PG_PREM_RW, VMAP_IGNORE);
         }
     }
             vmm_set_mapping(VMS_SELF, pa, pa, PG_PREM_RW, VMAP_IGNORE);
         }
     }
+
+    /* Reserve region for all loaded modules */
+    for (size_t i = 0; i < bhctx->mods.mods_num; i++) {
+        struct boot_modent* mod = &bhctx->mods.entries[i];
+        pmm_mark_chunk_occupied(KERNEL_PID,
+                                PN(mod->start),
+                                CEIL(mod->end - mod->start, PG_SIZE_BITS),
+                                PP_FGLOCKED);
+    }
 }
 
 extern u8_t __kexec_boot_end; /* link/linker.ld */
 }
 
 extern u8_t __kexec_boot_end; /* link/linker.ld */
index c08a6f726e7a8c267308b04d5efdeaacb4341819..a3553f104925466ff5ffb0b25034696a63a65d0e 100644 (file)
@@ -1,10 +1,19 @@
 #include <lunaix/mm/mmio.h>
 #include <lunaix/mm/page.h>
 #include <lunaix/mm/mmio.h>
 #include <lunaix/mm/page.h>
+#include <lunaix/process.h>
 #include <lunaix/spike.h>
 #include <lunaix/spike.h>
+#include <lunaix/syslog.h>
 #include <lunaix/trace.h>
 
 #include <lunaix/trace.h>
 
+#include <sys/cpu.h>
+#include <sys/mm/mempart.h>
+
 #include <klibc/string.h>
 
 #include <klibc/string.h>
 
+#define NB_TRACEBACK 16
+
+LOG_MODULE("TRACE")
+
 static struct trace_context trace_ctx;
 
 void
 static struct trace_context trace_ctx;
 
 void
@@ -26,12 +35,137 @@ trace_modksyms_init(struct boot_handoff* bhctx)
 }
 
 struct ksym_entry*
 }
 
 struct ksym_entry*
-trace_sym_lookup(ptr_t pc)
+trace_sym_lookup(ptr_t addr)
+{
+    int c = trace_ctx.ksym_table->ksym_count;
+    struct ksym_entry* ksent = trace_ctx.ksym_table->syms;
+
+    int i = c - 1, j = 0, m = 0;
+
+    if (addr > ksent[i].pc || addr < ksent[j].pc || addr < KERNEL_EXEC) {
+        return NULL;
+    }
+
+    while (i - j != 1) {
+        m = (i + j) / 2;
+        if (ksent[m].pc > addr) {
+            i = m;
+        } else if (ksent[m].pc < addr) {
+            j = m;
+        } else {
+            break;
+        }
+    }
+
+    struct ksym_entry* result = &ksent[MIN(i, j)];
+    if (result->pc > addr) {
+        return NULL;
+    }
+
+    return result;
+}
+
+static char*
+ksym_getstr(struct ksym_entry* sym)
+{
+    if (!sym) {
+        return "???";
+    }
+
+    return (char*)((ptr_t)trace_ctx.ksym_table +
+                   trace_ctx.ksym_table->ksym_label_off + sym->label_off);
+}
+
+int
+trace_walkback(struct trace_record* tb_buffer,
+               ptr_t fp,
+               int limit,
+               ptr_t* last_fp)
+{
+    ptr_t* frame = (ptr_t*)fp;
+    struct ksym_entry* current = NULL;
+    int i = 0;
+
+    while (frame && i < limit) {
+        ptr_t pc = *(frame + 1);
+
+        current = trace_sym_lookup(pc);
+        tb_buffer[i] = (struct trace_record){ .pc = current ? current->pc : pc,
+                                              .symbol = ksym_getstr(current) };
+
+        frame = (ptr_t*)*frame;
+        i++;
+    }
+
+    if (last_fp) {
+        *last_fp = (ptr_t)frame;
+    }
+
+    return i;
+}
+
+void
+trace_printstack_of(ptr_t fp)
+{
+    struct trace_record tbs[NB_TRACEBACK];
+
+    int n = trace_walkback(tbs, fp, NB_TRACEBACK, &fp);
+
+    if (fp) {
+        kprintf(KDEBUG "...<truncated>\n");
+    }
+
+    for (int i = 0; i < n; i++) {
+        kprintf(KDEBUG "%p: %s\n", tbs[i].pc, tbs[i].symbol);
+    }
+}
+
+void
+trace_printstack()
 {
 {
-    return NULL;
+    trace_printstack_of(cpu_get_fp());
 }
 
 void
 }
 
 void
-trace_walkback(ptr_t fp)
+trace_printswctx(const isr_param* p, char* direction)
 {
 {
+
+    struct ksym_entry* sym = trace_sym_lookup(p->execp->eip);
+
+    kprintf(
+      KDEBUG ">> (sw:%s) iv:%d, errno:%p <<\n", direction, p->execp->vector);
+    kprintf(KDEBUG "%p:%s\n", p->execp->eip, ksym_getstr(sym));
+}
+
+void
+trace_printstack_isr(const isr_param* isrm)
+{
+    isr_param* p = isrm;
+    ptr_t fp = cpu_get_fp();
+    int prev_fromusr = uspace_context(p);
+
+    kprintf(KDEBUG "\n");
+    kprintf(KDEBUG "stack trace (pid=%d)\n", __current->pid);
+
+    trace_printstack_of(fp);
+
+    while (p) {
+        if (!prev_fromusr) {
+            if (uspace_context(p)) {
+                trace_printswctx(p, "s/u");
+            } else {
+                trace_printswctx(p, "s/s");
+            }
+        } else {
+            trace_printswctx(p, "u/s");
+        }
+
+        fp = saved_fp(p);
+        trace_printstack_of(fp);
+
+        prev_fromusr = uspace_context(p);
+
+        p = p->execp->saved_prev_ctx;
+    }
+    kprintf(KDEBUG "\n");
 }
\ No newline at end of file
 }
\ No newline at end of file
index 5a868d41734ce9b3aba898cd49c5c9b87764a8a0..c3ba8142c4b0a3f9139166781f5a6bc33f14ff3c 100644 (file)
@@ -1,4 +1,4 @@
-#include <hal/cpu.h>
+#include <sys/cpu.h>
 #include <klibc/string.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/mm/vmm.h>
 #include <klibc/string.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/mm/vmm.h>
index fc55ece27f8a9cfee1236f4df9c1e6966594e7c4..6690faf22024f49d9583b9f015b7779073c8a382 100644 (file)
@@ -6,7 +6,7 @@
 #include <lunaix/syslog.h>
 #include <lunaix/timer.h>
 
 #include <lunaix/syslog.h>
 #include <lunaix/timer.h>
 
-#include <hal/cpu.h>
+#include <sys/cpu.h>
 #include <hal/intc.h>
 
 #include <klibc/string.h>
 #include <hal/intc.h>
 
 #include <klibc/string.h>
index 516d569c088fe03836b57c33201ac2369dc74e12..8cdced6373b2f9525d9cb8ea0823ee28c07ab81c 100644 (file)
@@ -1,4 +1,4 @@
-#include <hal/cpu.h>
+#include <sys/cpu.h>
 #include <lunaix/peripheral/serial.h>
 #include <lunaix/syslog.h>
 #include <sys/port_io.h>
 #include <lunaix/peripheral/serial.h>
 #include <lunaix/syslog.h>
 #include <sys/port_io.h>
index 82c73c0ee6d4a3d26cce6b93516bc4f807042417..31a94ee08f3ce7f8fe6be03d0b81084cf7b4a7e4 100644 (file)
@@ -2,7 +2,7 @@
 #include <sys/interrupts.h>
 #include <sys/mm/mempart.h>
 
 #include <sys/interrupts.h>
 #include <sys/mm/mempart.h>
 
-#include <hal/cpu.h>
+#include <sys/cpu.h>
 #include <hal/intc.h>
 
 #include <lunaix/fs/taskfs.h>
 #include <hal/intc.h>
 
 #include <lunaix/fs/taskfs.h>
index af5d90118637cda9a482146ee84b7bb2f34332c8..7edbfcb7838f45d8d6181cce4bdd52f7b70a7dd7 100644 (file)
@@ -4,7 +4,7 @@ import re
 
 sym_line = re.compile(r"^(?P<addr>[0-9a-f]+)\s[a-z]\s+F\s+\.[a-z._]+\s+[0-9a-f]+(?P<label>.+)$")
 
 
 sym_line = re.compile(r"^(?P<addr>[0-9a-f]+)\s[a-z]\s+F\s+\.[a-z._]+\s+[0-9a-f]+(?P<label>.+)$")
 
-def main(kbin, sym_out, endianness='little', bits=32):
+def main(kbin, sym_out, endianness='little', bits=32, just_print=False):
     assert bits >= 32
     assert (1 << int(math.log2(bits))) == bits
 
     assert bits >= 32
     assert (1 << int(math.log2(bits))) == bits
 
@@ -35,6 +35,11 @@ def main(kbin, sym_out, endianness='little', bits=32):
         functions.append((addr, label))
 
     functions = sorted(functions, key=lambda x: x[0])
         functions.append((addr, label))
 
     functions = sorted(functions, key=lambda x: x[0])
+
+    if just_print:
+        for (a, l) in functions:
+            print(hex(a), ":", l)
+        return
     
     # struct {
     #   ptr_t addr;
     
     # struct {
     #   ptr_t addr;
@@ -79,8 +84,9 @@ if __name__ == "__main__":
     parser.add_argument('-o', '--outfile', required=True)
     parser.add_argument('--bits', default=32)
     parser.add_argument('--order', default='little')
     parser.add_argument('-o', '--outfile', required=True)
     parser.add_argument('--bits', default=32)
     parser.add_argument('--order', default='little')
+    parser.add_argument('-p', '--just-print', action='store_true')
 
     args = parser.parse_args()
 
 
     args = parser.parse_args()
 
-    main(args.elf_exec, args.outfile, endianness=args.order, bits=int(args.bits))
+    main(args.elf_exec, args.outfile, endianness=args.order, bits=int(args.bits), just_print=args.just_print)
 
 
index eec9ee9e0e435c00cee3ba94a1141c79fe1f9f23..a449ac3547829fe84bede17edb319e43eb920c7f 100644 (file)
@@ -8,8 +8,9 @@
 
 .section .text
     .global _start
 
 .section .text
     .global _start
-    _start:        
+    _start:      
         xorl %eax, %eax
         xorl %eax, %eax
+        xorl %ebp, %ebp
         fninit
         call main
         
         fninit
         call main