Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
6
//    This file is part of emBIOS.
7
//
8
//    emBIOS is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emBIOS is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "global.h"
14 theseven 25
#include "panic.h"
15 theseven 26
#include "lcd.h"
27
#include "lcdconsole.h"
2 theseven 28
#include "console.h"
15 theseven 29
#include "format.h"
30
#include "thread.h"
31
#include "contextswitch.h"
2 theseven 32
 
33
 
50 theseven 34
extern struct scheduler_thread* scheduler_threads;
35
extern struct scheduler_thread* current_thread;
15 theseven 36
 
37
 
14 theseven 38
void handle_panic(enum panic_severity severity)
2 theseven 39
{
249 theseven 40
    uint32_t mode = enter_critical_section();
41
    if (severity == PANIC_KILLUSERTHREADS)
50 theseven 42
    {
249 theseven 43
        int i;
50 theseven 44
        for (i = 0; i < MAX_THREADS; i++)
45
            if (scheduler_threads[i].type == USER_THREAD)
46
                scheduler_threads[i].state = THREAD_SUSPENDED;
47
    }
249 theseven 48
    current_thread->state = THREAD_DEFUNCT_ACK;
49
    current_thread->block_type = THREAD_DEFUNCT_PANIC;
50
    leave_critical_section(mode);
51
    context_switch();
2 theseven 52
}
53
 
14 theseven 54
void panic(enum panic_severity severity, const char* string)
2 theseven 55
{
15 theseven 56
    if (severity == PANIC_FATAL)
57
    {
58
        enter_critical_section();
59
        while (!displaylcd_safe());
257 theseven 60
        lcdconsole_puts_noblit("\n*PANIC*\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
61
        lcdconsole_puts_noblit(string, LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
62
        lcdconsole_puts_noblit("\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
15 theseven 63
        lcdconsole_update();
64
        hang();
65
    }
66
    else
67
    {
68
        cputs(1, "\n*PANIC*\n");
69
        cputs(1, string);
70
        cputc(1, '\n');
71
        handle_panic(severity);
72
    }
2 theseven 73
}
74
 
15 theseven 75
static int pprfunc(void* ptr, unsigned char letter)
76
{
257 theseven 77
    lcdconsole_putc_noblit(letter, LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
15 theseven 78
    return true;
79
}
80
 
14 theseven 81
void panicf(enum panic_severity severity, const char* string, ...)
2 theseven 82
{
15 theseven 83
    va_list ap;
84
    if (severity == PANIC_FATAL)
85
    {
86
        enter_critical_section();
265 theseven 87
        while(1);
15 theseven 88
        while (!displaylcd_safe());
257 theseven 89
        lcdconsole_puts_noblit("\n*PANIC*\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
15 theseven 90
        va_start(ap, string);
91
        format(pprfunc, NULL, string, ap);
92
        va_end(ap);
257 theseven 93
        lcdconsole_puts_noblit("\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
15 theseven 94
        lcdconsole_update();
95
        hang();
96
    }
97
    else
98
    {
99
        cputs(1, "\n*PANIC*\n");
100
        va_start(ap, string);
101
        cvprintf(1, string, ap);
102
        va_end(ap);
103
        cputc(1, '\n');
104
        handle_panic(severity);
105
    }
2 theseven 106
}
107
 
108
void __div0()
109
{
15 theseven 110
    panic(PANIC_KILLTHREAD, "Division by zero!");
2 theseven 111
}