2002-04-30 19:23:44 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by wavey@wavey.org
|
2008-05-18 16:21:52 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-04-30 19:23:44 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-09-12 10:34:27 +00:00
|
|
|
#include "config.h"
|
2002-04-30 19:23:44 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2002-11-12 09:04:06 +00:00
|
|
|
#include <string.h>
|
2002-04-30 19:23:44 +00:00
|
|
|
#include "panic.h"
|
2002-05-02 14:05:51 +00:00
|
|
|
#include "lcd.h"
|
2002-09-12 13:33:59 +00:00
|
|
|
#include "font.h"
|
2002-04-30 19:23:44 +00:00
|
|
|
#include "debug.h"
|
2002-11-12 09:04:06 +00:00
|
|
|
#include "led.h"
|
2005-09-12 10:34:27 +00:00
|
|
|
#include "power.h"
|
|
|
|
#include "system.h"
|
2014-01-05 21:20:26 +00:00
|
|
|
#include "logf.h"
|
2002-04-30 19:23:44 +00:00
|
|
|
|
2022-05-16 13:33:26 +00:00
|
|
|
#ifdef HAVE_RB_BACKTRACE
|
2012-01-25 08:57:59 +00:00
|
|
|
#include "gcc_extensions.h"
|
2022-05-16 13:33:26 +00:00
|
|
|
#include "backtrace.h"
|
2012-01-25 08:57:59 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
static char panic_buf[128];
|
2010-03-03 02:36:51 +00:00
|
|
|
#define LINECHARS (LCD_WIDTH/SYSFONT_WIDTH) - 2
|
2002-04-30 19:23:44 +00:00
|
|
|
|
2012-01-25 08:57:59 +00:00
|
|
|
#if defined(CPU_ARM)
|
|
|
|
void panicf_f( const char *fmt, ...);
|
|
|
|
|
|
|
|
/* we wrap panicf() here with naked function to catch SP value */
|
2014-08-25 17:55:16 +00:00
|
|
|
void __attribute__((naked)) panicf( const char *fmt, ...)
|
2012-01-25 08:57:59 +00:00
|
|
|
{
|
|
|
|
(void)fmt;
|
|
|
|
asm volatile ("mov r4, sp \n"
|
|
|
|
"b panicf_f \n"
|
|
|
|
);
|
2014-08-25 17:55:16 +00:00
|
|
|
while (1);
|
2012-01-25 08:57:59 +00:00
|
|
|
}
|
|
|
|
|
2002-04-30 19:23:44 +00:00
|
|
|
/*
|
|
|
|
* "Dude. This is pretty fucked-up, right here."
|
|
|
|
*/
|
2012-01-25 08:57:59 +00:00
|
|
|
void panicf_f( const char *fmt, ...)
|
|
|
|
{
|
|
|
|
int sp;
|
|
|
|
|
|
|
|
asm volatile ("mov %[SP],r4 \n"
|
|
|
|
: [SP] "=r" (sp)
|
|
|
|
);
|
|
|
|
|
|
|
|
int pc = (int)__builtin_return_address(0);
|
2022-05-16 13:33:26 +00:00
|
|
|
#elif defined(BACKTRACE_MIPSUNWINDER)
|
|
|
|
void panicf( const char *fmt, ... )
|
|
|
|
{
|
|
|
|
/* NOTE: these are obtained by the backtrace lib */
|
|
|
|
const int pc = 0;
|
|
|
|
const int sp = 0;
|
2012-01-25 08:57:59 +00:00
|
|
|
#else
|
2004-08-16 23:37:23 +00:00
|
|
|
void panicf( const char *fmt, ...)
|
2002-04-30 19:23:44 +00:00
|
|
|
{
|
2012-01-25 08:57:59 +00:00
|
|
|
#endif
|
2002-04-30 19:23:44 +00:00
|
|
|
va_list ap;
|
2002-05-05 17:51:23 +00:00
|
|
|
|
2010-06-21 16:53:00 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
2002-05-05 17:51:23 +00:00
|
|
|
/* Disable interrupts */
|
2007-05-12 05:20:04 +00:00
|
|
|
#ifdef CPU_ARM
|
2009-01-08 10:15:32 +00:00
|
|
|
disable_interrupt(IRQ_FIQ_STATUS);
|
|
|
|
#else
|
2007-05-12 05:20:04 +00:00
|
|
|
set_irq_level(DISABLE_INTERRUPTS);
|
2009-01-08 10:15:32 +00:00
|
|
|
#endif
|
2007-05-12 05:20:04 +00:00
|
|
|
#endif /* SIMULATOR */
|
|
|
|
|
2002-04-30 19:23:44 +00:00
|
|
|
va_start( ap, fmt );
|
2002-05-02 11:44:15 +00:00
|
|
|
vsnprintf( panic_buf, sizeof(panic_buf), fmt, ap );
|
2002-04-30 19:23:44 +00:00
|
|
|
va_end( ap );
|
|
|
|
|
2012-03-29 06:11:52 +00:00
|
|
|
lcd_set_viewport(NULL);
|
|
|
|
|
2009-08-10 20:27:03 +00:00
|
|
|
int y = 1;
|
|
|
|
|
2009-08-10 20:36:34 +00:00
|
|
|
#if LCD_DEPTH > 1
|
2009-08-10 20:27:03 +00:00
|
|
|
lcd_set_backdrop(NULL);
|
2009-11-14 11:27:41 +00:00
|
|
|
lcd_set_drawmode(DRMODE_SOLID);
|
2009-08-10 20:27:03 +00:00
|
|
|
lcd_set_foreground(LCD_BLACK);
|
|
|
|
lcd_set_background(LCD_WHITE);
|
|
|
|
#endif
|
|
|
|
|
2002-05-05 11:17:10 +00:00
|
|
|
lcd_clear_display();
|
2002-09-24 18:04:15 +00:00
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
2009-08-10 20:27:03 +00:00
|
|
|
lcd_puts(1, y++, (unsigned char *)"*PANIC*");
|
2002-11-12 09:04:06 +00:00
|
|
|
{
|
|
|
|
/* wrap panic line */
|
2009-08-10 20:27:03 +00:00
|
|
|
int i, len = strlen(panic_buf);
|
2009-01-08 10:15:32 +00:00
|
|
|
for (i=0; i<len; i+=LINECHARS) {
|
|
|
|
unsigned char c = panic_buf[i+LINECHARS];
|
|
|
|
panic_buf[i+LINECHARS] = 0;
|
2009-08-10 20:27:03 +00:00
|
|
|
lcd_puts(1, y++, (unsigned char *)panic_buf+i);
|
2009-01-08 10:15:32 +00:00
|
|
|
panic_buf[i+LINECHARS] = c;
|
2002-11-12 09:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-25 08:57:59 +00:00
|
|
|
|
2018-08-07 01:52:11 +00:00
|
|
|
#if defined(HAVE_RB_BACKTRACE)
|
2017-02-23 10:33:19 +00:00
|
|
|
rb_backtrace(pc, sp, &y);
|
2012-01-25 08:57:59 +00:00
|
|
|
#endif
|
2014-01-05 21:20:26 +00:00
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
|
|
|
logf_panic_dump(&y);
|
|
|
|
#endif
|
2009-07-25 18:23:06 +00:00
|
|
|
|
2007-04-06 22:55:00 +00:00
|
|
|
lcd_update();
|
2008-08-13 21:38:33 +00:00
|
|
|
DEBUGF("%s", panic_buf);
|
2005-09-12 10:34:27 +00:00
|
|
|
|
2017-01-21 13:04:43 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
if (cpu_boost_lock())
|
|
|
|
{
|
|
|
|
set_cpu_frequency(0);
|
|
|
|
cpu_boost_unlock();
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
|
2005-09-12 10:34:27 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_ATA_POWER_OFF
|
|
|
|
ide_power_enable(false);
|
|
|
|
#endif
|
|
|
|
|
2009-01-08 10:15:32 +00:00
|
|
|
system_exception_wait(); /* if this returns, try to reboot */
|
|
|
|
system_reboot();
|
|
|
|
while (1); /* halt */
|
2002-04-30 19:23:44 +00:00
|
|
|
}
|