Make backup dialog modal.
[maemo-rb.git] / firmware / panic.c
blob0d49847a193b34aa139c3c6bae5f178b6a2e1af1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
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"
34 #if defined(CPU_ARM)
35 #include "gcc_extensions.h"
36 #include <backtrace.h>
37 #endif
39 static char panic_buf[128];
40 #define LINECHARS (LCD_WIDTH/SYSFONT_WIDTH) - 2
42 #if defined(CPU_ARM)
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, ...)
48 (void)fmt;
49 asm volatile ("mov r4, sp \n"
50 "b panicf_f \n"
55 * "Dude. This is pretty fucked-up, right here."
57 void panicf_f( const char *fmt, ...)
59 int sp;
61 asm volatile ("mov %[SP],r4 \n"
62 : [SP] "=r" (sp)
65 int pc = (int)__builtin_return_address(0);
66 #else
67 void panicf( const char *fmt, ...)
69 #endif
70 va_list ap;
72 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
73 /* Disable interrupts */
74 #ifdef CPU_ARM
75 disable_interrupt(IRQ_FIQ_STATUS);
76 #else
77 set_irq_level(DISABLE_INTERRUPTS);
78 #endif
79 #endif /* SIMULATOR */
81 va_start( ap, fmt );
82 vsnprintf( panic_buf, sizeof(panic_buf), fmt, ap );
83 va_end( 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)
92 int y = 1;
94 #if LCD_DEPTH > 1
95 lcd_set_backdrop(NULL);
96 lcd_set_drawmode(DRMODE_SOLID);
97 lcd_set_foreground(LCD_BLACK);
98 lcd_set_background(LCD_WHITE);
99 #endif
101 lcd_clear_display();
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;
115 #if defined(CPU_ARM)
116 backtrace(pc, sp, &y);
117 #endif
118 #else
119 /* no LCD */
120 #endif
122 lcd_update();
123 DEBUGF("%s", panic_buf);
125 set_cpu_frequency(0);
127 #ifdef HAVE_ATA_POWER_OFF
128 ide_power_enable(false);
129 #endif
131 system_exception_wait(); /* if this returns, try to reboot */
132 system_reboot();
133 while (1); /* halt */