A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by wavey@wavey.org
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include <stdio.h>
24#include <stdarg.h>
25#include <string.h>
26#include "panic.h"
27#include "lcd.h"
28#include "font.h"
29#include "debug.h"
30#include "led.h"
31#include "power.h"
32#include "system.h"
33#include "logf.h"
34#include "rbversion.h"
35
36#ifdef HAVE_RB_BACKTRACE
37#include "gcc_extensions.h"
38#include "backtrace.h"
39#endif
40
41#if (defined(CPU_MIPS) && (CONFIG_PLATFORM & PLATFORM_NATIVE))
42/* TODO: see comment above exception_dump in system-mips.c */
43char panic_buf[128];
44#else
45static char panic_buf[128];
46#endif
47
48#define LINECHARS (LCD_WIDTH/SYSFONT_WIDTH) - 2
49
50#if defined(CPU_ARM) && defined(HAVE_RB_BACKTRACE)
51void panicf_f( const char *fmt, ...) USED_ATTR;
52
53/* we wrap panicf() here with naked function to catch SP value */
54void __attribute__((naked)) panicf( const char *fmt, ...)
55{
56 (void)fmt;
57 asm volatile ("mov r4, sp \n"
58 "b panicf_f \n"
59 );
60 while (1);
61}
62
63/*
64 * "Dude. This is pretty fucked-up, right here."
65 */
66void panicf_f( const char *fmt, ...)
67{
68 int sp;
69
70 asm volatile ("mov %[SP],r4 \n"
71 : [SP] "=r" (sp)
72 );
73
74 int pc = (int)__builtin_return_address(0);
75#elif defined(BACKTRACE_MIPSUNWINDER)
76void panicf( const char *fmt, ... )
77{
78 /* NOTE: these are obtained by the backtrace lib */
79 const int pc = 0;
80 const int sp = 0;
81#else
82void panicf( const char *fmt, ...)
83{
84#endif
85 va_list ap;
86
87#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
88 /* Disable interrupts */
89#if defined(CPU_ARM_CLASSIC)
90 disable_interrupt(IRQ_FIQ_STATUS);
91#else
92 set_irq_level(DISABLE_INTERRUPTS);
93#endif
94#endif /* SIMULATOR */
95
96 va_start( ap, fmt );
97 vsnprintf( panic_buf, sizeof(panic_buf), fmt, ap );
98 va_end( ap );
99
100 lcd_set_viewport(NULL);
101
102 int y = 1;
103
104#if LCD_DEPTH > 1
105 lcd_set_backdrop(NULL);
106 lcd_set_drawinfo(DRMODE_SOLID, LCD_BLACK, LCD_WHITE);
107#endif
108
109 lcd_clear_display();
110 lcd_setfont(FONT_SYSFIXED);
111 lcd_puts(1, y++, (unsigned char *) "*PANIC* (" RBVERSION ")");
112 {
113 /* wrap panic line */
114 int i, len = strlen(panic_buf);
115 for (i=0; i<len; i+=LINECHARS) {
116 unsigned char c = panic_buf[i+LINECHARS];
117 panic_buf[i+LINECHARS] = 0;
118 lcd_puts(1, y++, (unsigned char *)panic_buf+i);
119 panic_buf[i+LINECHARS] = c;
120 }
121 }
122
123#if defined(HAVE_RB_BACKTRACE)
124 rb_backtrace(pc, sp, &y);
125#endif
126#ifdef ROCKBOX_HAS_LOGF
127 logf_panic_dump(&y);
128#endif
129
130 lcd_update();
131 DEBUGF("%s", panic_buf);
132
133#ifdef HAVE_ADJUSTABLE_CPU_FREQ
134 if (cpu_boost_lock())
135 {
136 set_cpu_frequency(0);
137 cpu_boost_unlock();
138 }
139#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
140
141#ifdef HAVE_ATA_POWER_OFF
142 ide_power_enable(false);
143#endif
144
145 system_exception_wait(); /* if this returns, try to reboot */
146 system_reboot();
147 while (1); /* halt */
148}