Bulgarian translation for the remaining strings.
[maemo-rb.git] / firmware / panic.c
blobcdefc5a0b868fcb912ef91dc3e45a7e4d296206c
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 #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)
90 int y = 1;
92 #if LCD_DEPTH > 1
93 lcd_set_backdrop(NULL);
94 lcd_set_drawmode(DRMODE_SOLID);
95 lcd_set_foreground(LCD_BLACK);
96 lcd_set_background(LCD_WHITE);
97 #endif
99 lcd_clear_display();
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;
114 #if defined(CPU_ARM)
115 backtrace(pc, sp, &y);
116 #endif
117 #else
118 /* no LCD */
119 #endif
121 lcd_update();
122 DEBUGF("%s", panic_buf);
124 set_cpu_frequency(0);
126 #ifdef HAVE_ATA_POWER_OFF
127 ide_power_enable(false);
128 #endif
130 system_exception_wait(); /* if this returns, try to reboot */
131 system_reboot();
132 while (1); /* halt */