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 | |
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).
-rw-r--r-- | include/arch/arm/arch.h | 5 | ||||
-rw-r--r-- | include/arch/x86_64/arch.h | 1 | ||||
-rw-r--r-- | linker/linker_script.ld | 2 | ||||
-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 | ||||
-rw-r--r-- | tests/test_lib.c | 8 |
9 files changed, 32 insertions, 9 deletions
diff --git a/include/arch/arm/arch.h b/include/arch/arm/arch.h index 8bd47c2..bf96fae 100644 --- a/include/arch/arm/arch.h +++ b/include/arch/arm/arch.h @@ -10,6 +10,9 @@ #define enable_all_interrupts() \ asm volatile(" cpsie i ") +#define disable_all_interrupts() \ + asm volatile(" cpsid i ") + #define DMA1_BASE (0x40020000) #define DMA2_BASE (0x40020400) @@ -32,6 +35,8 @@ #define SPI1_BASE (0x40013000) #define SPI3_BASE (0x40003C00) +#define STACK_TOP (0x2000c000) + #include <stdint.h> #ifndef DRY_RUN _Static_assert(sizeof(void*) == sizeof(uint32_t), "Pointers must be 32 bits"); diff --git a/include/arch/x86_64/arch.h b/include/arch/x86_64/arch.h index a7ba776..62ef730 100644 --- a/include/arch/x86_64/arch.h +++ b/include/arch/x86_64/arch.h @@ -6,6 +6,7 @@ #define ARCH_PC #define enable_all_interrupts() do {} while(0) +#define disable_all_interrupts() do {} while(0) #define RCC_BASE (load_fake_rcc__()) diff --git a/linker/linker_script.ld b/linker/linker_script.ld index 909c8cb..8850182 100644 --- a/linker/linker_script.ld +++ b/linker/linker_script.ld @@ -54,7 +54,7 @@ SECTIONS *(.noinit); HEAP_START = .; - HEAP_STOP = 16k; + HEAP_STOP = LENGTH(sram1); } >sram1 AT>flash BSS_START = .; 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(;;); diff --git a/tests/test_lib.c b/tests/test_lib.c index e9361c4..118a863 100644 --- a/tests/test_lib.c +++ b/tests/test_lib.c @@ -6,16 +6,16 @@ TEST(lib, hexify) char buf[10]; hexify(0xaaaaaaaa, buf); - ASSERT_EQ_STR(buf, "AAAAAAAA"); + ASSERT_EQ_STR(buf, "aaaaaaaa"); hexify(0xdddddddd, buf); - ASSERT_EQ_STR(buf, "DDDDDDDD"); + ASSERT_EQ_STR(buf, "dddddddd"); hexify(0x02468ace, buf); - ASSERT_EQ_STR(buf, "02468ACE"); + ASSERT_EQ_STR(buf, "02468ace"); hexify(0xdeadbeef, buf); - ASSERT_EQ_STR(buf, "DEADBEEF"); + ASSERT_EQ_STR(buf, "deadbeef"); return 0; } |