From 0262236d2cd194dc0c81d68ad510c76240cb5ee8 Mon Sep 17 00:00:00 2001 From: souldbminersmwc Date: Wed, 26 Aug 2026 15:22:10 -0400 Subject: [PATCH] bpmpfw: system panic on panic --- Source/hoc-clk/bpmpfw/source/main.cpp | 13 ++++------ Source/hoc-clk/bpmpfw/source/start.s | 35 ++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Source/hoc-clk/bpmpfw/source/main.cpp b/Source/hoc-clk/bpmpfw/source/main.cpp index 43e74416..f4203f96 100644 --- a/Source/hoc-clk/bpmpfw/source/main.cpp +++ b/Source/hoc-clk/bpmpfw/source/main.cpp @@ -27,6 +27,8 @@ #include +extern "C" [[noreturn]] void _panic_reboot(); + namespace { HocClkBpmpSharedInfo &SharedInfo() { @@ -82,12 +84,7 @@ extern "C" void main() { MainLoop(info); printf("[hoc-bpmpfw]: PANIC\n"); - - /* Clear the magic so sysmodule knows of a panic */ - info.magic = 0x0; - - /* Give a panic code */ - info.status = ~0; - for(;;) - ; + + /* Kill execution */ + _panic_reboot(); } diff --git a/Source/hoc-clk/bpmpfw/source/start.s b/Source/hoc-clk/bpmpfw/source/start.s index 83f2e136..8c5c758f 100644 --- a/Source/hoc-clk/bpmpfw/source/start.s +++ b/Source/hoc-clk/bpmpfw/source/start.s @@ -68,17 +68,50 @@ _panic: 7: ldrb r1, [r3], #1 cmp r1, #0 - beq _panic_hang + beq 9f 8: ldr r2, [r0, #0x14] /* UART_LSR */ tst r2, #0x20 /* UART_LSR_THRE */ beq 8b str r1, [r0] b 7b +9: + ldr r2, [r0, #0x14] /* UART_LSR */ + tst r2, #0x40 /* UART_LSR_TMTY */ + beq 9b + b _panic_reboot _panic_msg: .asciz "[bpmpfw] PANIC\n" .align 2 +.global _panic_reboot +_panic_reboot: + ldr r0, =0x7000EC40 /* PMC_BASE + APBDEV_PMC_SCRATCH200 */ + ldr r1, =0xF8F00000 /* Panic code. */ + str r1, [r0] + + ldr r4, =0x60005000 /* TMR_BASE */ + + /* Write the magic */ + ldr r1, =0xC45A + str r1, [r4, #0x18C] + + /* Disable the counters */ + mov r1, #0x2 + str r1, [r4, #0x188] + + /* Start periodic timer */ + ldr r1, =0xC0000000 + str r1, [r4, #0x080] + + /* Set reboot source to the timer we started */ + ldr r1, =0x8019 + str r1, [r4, #0x180] + + /* Enable the counters */ + mov r1, #0x1 + str r1, [r4, #0x188] + _panic_hang: b _panic_hang