1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by wavey@wavey.org
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
35 #include "gcc_extensions.h"
36 #include <backtrace.h>
39 static char panic_buf
[128];
40 #define LINECHARS (LCD_WIDTH/SYSFONT_WIDTH) - 2
43 void panicf_f( const char *fmt
, ...);
45 /* we wrap panicf() here with naked function to catch SP value */
46 void panicf( const char *fmt
, ...)
49 asm volatile ("mov r4, sp \n"
55 * "Dude. This is pretty fucked-up, right here."
57 void panicf_f( const char *fmt
, ...)
61 asm volatile ("mov %[SP],r4 \n"
65 int pc
= (int)__builtin_return_address(0);
67 void panicf( const char *fmt
, ...)
72 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
73 /* Disable interrupts */
75 disable_interrupt(IRQ_FIQ_STATUS
);
77 set_irq_level(DISABLE_INTERRUPTS
);
79 #endif /* SIMULATOR */
82 vsnprintf( panic_buf
, sizeof(panic_buf
), fmt
, ap
);
85 #ifdef HAVE_LCD_CHARCELLS
86 lcd_double_height(false);
87 lcd_puts(0, 0, "*PANIC*");
88 lcd_puts(0, 1, panic_buf
);
89 #elif defined(HAVE_LCD_BITMAP)
93 lcd_set_backdrop(NULL
);
94 lcd_set_drawmode(DRMODE_SOLID
);
95 lcd_set_foreground(LCD_BLACK
);
96 lcd_set_background(LCD_WHITE
);
100 lcd_setfont(FONT_SYSFIXED
);
101 lcd_set_viewport(NULL
);
102 lcd_puts(1, y
++, (unsigned char *)"*PANIC*");
104 /* wrap panic line */
105 int i
, len
= strlen(panic_buf
);
106 for (i
=0; i
<len
; i
+=LINECHARS
) {
107 unsigned char c
= panic_buf
[i
+LINECHARS
];
108 panic_buf
[i
+LINECHARS
] = 0;
109 lcd_puts(1, y
++, (unsigned char *)panic_buf
+i
);
110 panic_buf
[i
+LINECHARS
] = c
;
115 backtrace(pc
, sp
, &y
);
122 DEBUGF("%s", panic_buf
);
124 set_cpu_frequency(0);
126 #ifdef HAVE_ATA_POWER_OFF
127 ide_power_enable(false);
130 system_exception_wait(); /* if this returns, try to reboot */
132 while (1); /* halt */