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 lcd_set_viewport(NULL
);
87 #ifdef HAVE_LCD_CHARCELLS
88 lcd_double_height(false);
89 lcd_puts(0, 0, "*PANIC*");
90 lcd_puts(0, 1, panic_buf
);
91 #elif defined(HAVE_LCD_BITMAP)
95 lcd_set_backdrop(NULL
);
96 lcd_set_drawmode(DRMODE_SOLID
);
97 lcd_set_foreground(LCD_BLACK
);
98 lcd_set_background(LCD_WHITE
);
102 lcd_setfont(FONT_SYSFIXED
);
103 lcd_puts(1, y
++, (unsigned char *)"*PANIC*");
105 /* wrap panic line */
106 int i
, len
= strlen(panic_buf
);
107 for (i
=0; i
<len
; i
+=LINECHARS
) {
108 unsigned char c
= panic_buf
[i
+LINECHARS
];
109 panic_buf
[i
+LINECHARS
] = 0;
110 lcd_puts(1, y
++, (unsigned char *)panic_buf
+i
);
111 panic_buf
[i
+LINECHARS
] = c
;
116 backtrace(pc
, sp
, &y
);
123 DEBUGF("%s", panic_buf
);
125 set_cpu_frequency(0);
127 #ifdef HAVE_ATA_POWER_OFF
128 ide_power_enable(false);
131 system_exception_wait(); /* if this returns, try to reboot */
133 while (1); /* halt */