diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2020-11-24 16:41:49 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2020-11-24 16:41:49 -0700 |
commit | c29e0323020e0f96932d0f9b09747d5b2e28e5a6 (patch) | |
tree | c6100f1a4702d14548f5b82d72afb85340711a68 /src | |
parent | 0c0f5c3d8397ba5168f0cd01b25ba70c238b36e0 (diff) | |
download | stm32l4-c29e0323020e0f96932d0f9b09747d5b2e28e5a6.tar.gz stm32l4-c29e0323020e0f96932d0f9b09747d5b2e28e5a6.tar.bz2 stm32l4-c29e0323020e0f96932d0f9b09747d5b2e28e5a6.zip |
Changes to painic. It now prints the stack at the time of failure (if logging is initialized).
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/stm32l4xxx/peripherals/irq.c | 4 | ||||
-rw-r--r-- | src/kern/lib.c | 2 | ||||
-rw-r--r-- | src/kern/log.c | 3 | ||||
-rw-r--r-- | src/kern/main.c | 7 | ||||
-rw-r--r-- | src/kern/panic.c | 9 |
5 files changed, 21 insertions, 4 deletions
diff --git a/src/arch/stm32l4xxx/peripherals/irq.c b/src/arch/stm32l4xxx/peripherals/irq.c index 7870a10..e79d8ae 100644 --- a/src/arch/stm32l4xxx/peripherals/irq.c +++ b/src/arch/stm32l4xxx/peripherals/irq.c @@ -22,14 +22,16 @@ void isr_simple_pin_on() set_gpio_pin_high(pin3); } +#ifdef ARCH_STM32L4 #define IRQ_RESERVED(n) 0, #define IRQ(name, uname_, n) name, const void* vectors[] __attribute__((section(".vectors"))) = { - (void*)0x2000c000, /* Top of stack at top of sram1. 48k */ + (void*)STACK_TOP, /* Top of stack at top of sram1. 48k */ #include "arch/stm32l4xxx/peripherals/isrs.inc" }; #undef IRQ_RESERVED #undef IRQ +#endif /* Encodes the provided number as a series of flashes on the on-board * LED. The flashes follow as such: diff --git a/src/kern/lib.c b/src/kern/lib.c index 3214b7c..24e1658 100644 --- a/src/kern/lib.c +++ b/src/kern/lib.c @@ -1,6 +1,6 @@ #include "kern/lib.h" -#define nybble_to_hex(n) ((n) < 10 ? 0x30 + (n) : ('A' + ((n)-10))) +#define nybble_to_hex(n) ((n) < 10 ? 0x30 + (n) : ('a' + ((n)-10))) void hexify(uint32_t v, char* into) { diff --git a/src/kern/log.c b/src/kern/log.c index c876759..3331249 100644 --- a/src/kern/log.c +++ b/src/kern/log.c @@ -5,6 +5,7 @@ #include "kern/common.h" #include "kern/gpio/gpio_manager.h" #include "kern/init.h" +#include "kern/delay.h" void setup_usart2(uint32_t baud_rate); @@ -37,7 +38,7 @@ void kvlogf(const char* fmt, va_list l) void kerr_vlogf(const char* fmt, va_list l) { klogf("\x1b[01;31m[ERROR] "); - usart_vprintf(&USART2, fmt, l); + kvlogf(fmt, l); klogf("\x1b[00m"); } diff --git a/src/kern/main.c b/src/kern/main.c index a6743d5..c85decb 100644 --- a/src/kern/main.c +++ b/src/kern/main.c @@ -4,6 +4,7 @@ #include "kern/log.h" #include "kern/panic.h" #include "kern/init.h" +#include "kern/mem.h" void on_systick() /* Overrides weak-symbol on_systick. */ { @@ -20,13 +21,17 @@ int main() klogf("Heap End : %p\n", &HEAP_STOP); /* Set the countdown to start from 10,000,0000. */ - SCB.strv_r = 10000000; + SCB.strv_r = 10000000 / 20; /* Enable interrupts. */ regset(SCB.stcs_r, scb_tickint, 1); /* Start the systick. */ regset(SCB.stcs_r, scb_enable, 1); + + void* hunk = kalloc(25); + kfree(hunk); + kfree(hunk); /* Invalid free. */ } #endif diff --git a/src/kern/panic.c b/src/kern/panic.c index 8708456..3e67b90 100644 --- a/src/kern/panic.c +++ b/src/kern/panic.c @@ -12,6 +12,8 @@ #ifdef ARCH_STM32L4 _Noreturn void panic(const char* fmt, ...) { + uint32_t base[0]; + disable_all_interrupts(); if (get_system_init_level() > INIT_LEVEL_2) { va_list l; @@ -19,6 +21,13 @@ _Noreturn void panic(const char* fmt, ...) kerr_logf("** Kernel Panic! **\n"); kerr_vlogf(fmt, l); + kerr_logf("** Stack:\n"); + + int i = 0; + for (; i < 20 && &base[i] != (void*)STACK_TOP; ++ i) { + kerr_logf(" (%p) %p\n", &base[i], base[i]); + } + set_system_clock_MHz(4); /* reduce power usage while we do nothing. */ for(;;); |