diff --git a/arm/crash.cc b/arm/crash.cc index daeda06..4f40894 100644 --- a/arm/crash.cc +++ b/arm/crash.cc @@ -3,6 +3,7 @@ #include "gpio.h" #include "itoa.h" #include "sleep.h" +#include "trace.h" #include "uart.h" extern "C" uint32_t _initial_stack_pointer, _text_begin, _text_end; @@ -80,6 +81,8 @@ void CrashHandler(Armv6mRegs* regs) { UartWriteCrash("- Stack trace:\r\n"); StackTrace(reinterpret_cast(regs->sp)); + tracing::dump(); + while (1) { gpio0->data = 0x55; sleep(100); diff --git a/arm/main.cc b/arm/main.cc index 5b22ef2..815073d 100644 --- a/arm/main.cc +++ b/arm/main.cc @@ -18,10 +18,7 @@ void Uart0Isr() { HandleUartIsr(); } -void Timer0Isr() { - tracing::dump(); - __builtin_trap(); -} +void Timer0Isr() { __builtin_trap(); } void SetupUart() { InitUarts(); diff --git a/arm/stdlib.cc b/arm/stdlib.cc index 1c2c44f..fe1a9e2 100644 --- a/arm/stdlib.cc +++ b/arm/stdlib.cc @@ -7,14 +7,19 @@ #include "timer.h" #include "uart.h" +#ifndef SBRK_STATS +#define SBRK_STATS 0 +#endif + extern unsigned char _heap_begin, _heap_end; namespace { +[[maybe_unused]] void LogStats(unsigned char* heap) { char number[] = "00000000\r\n"; - UartWriteBlocking("Program break now at 0x"); + UartWriteCrash("Program break now at 0x"); itoa(reinterpret_cast(heap), number); - UartWriteBlocking(number); + UartWriteCrash(number); } } // namespace @@ -22,11 +27,13 @@ extern "C" void* _sbrk(int increment) { static unsigned char* heap = &_heap_begin; unsigned char* prev_heap = heap; if (heap + increment >= &_heap_end) { - UartWriteBlocking("Heap overflow!\r\n"); + UartWriteCrash("Heap overflow!\r\n"); return reinterpret_cast(-1); } heap += increment; +#if SBRK_STATS LogStats(heap); +#endif return prev_heap; }