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
//
427 farthen 6
//    This file is part of emCORE.
2 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
2 theseven 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
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
2 theseven 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
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
2 theseven 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
 
14 theseven 34
void handle_panic(enum panic_severity severity)
2 theseven 35
{
429 theseven 36
    struct scheduler_thread* t;
249 theseven 37
    uint32_t mode = enter_critical_section();
38
    if (severity == PANIC_KILLUSERTHREADS)
50 theseven 39
    {
249 theseven 40
        int i;
429 theseven 41
        for (t = head_thread; t; t = t->thread_next)
42
            if (t->type == USER_THREAD)
43
                t->state = THREAD_SUSPENDED;
50 theseven 44
    }
249 theseven 45
    current_thread->state = THREAD_DEFUNCT_ACK;
46
    current_thread->block_type = THREAD_DEFUNCT_PANIC;
47
    leave_critical_section(mode);
48
    context_switch();
2 theseven 49
}
50
 
14 theseven 51
void panic(enum panic_severity severity, const char* string)
2 theseven 52
{
15 theseven 53
    if (severity == PANIC_FATAL)
54
    {
55
        enter_critical_section();
56
        while (!displaylcd_safe());
257 theseven 57
        lcdconsole_puts_noblit("\n*PANIC*\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
58
        lcdconsole_puts_noblit(string, LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
59
        lcdconsole_puts_noblit("\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
15 theseven 60
        lcdconsole_update();
61
        hang();
62
    }
63
    else
64
    {
65
        cputs(1, "\n*PANIC*\n");
66
        cputs(1, string);
67
        cputc(1, '\n');
68
        handle_panic(severity);
69
    }
2 theseven 70
}
71
 
15 theseven 72
static int pprfunc(void* ptr, unsigned char letter)
73
{
257 theseven 74
    lcdconsole_putc_noblit(letter, LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
15 theseven 75
    return true;
76
}
77
 
14 theseven 78
void panicf(enum panic_severity severity, const char* string, ...)
2 theseven 79
{
15 theseven 80
    va_list ap;
81
    if (severity == PANIC_FATAL)
82
    {
83
        enter_critical_section();
84
        while (!displaylcd_safe());
257 theseven 85
        lcdconsole_puts_noblit("\n*PANIC*\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
15 theseven 86
        va_start(ap, string);
87
        format(pprfunc, NULL, string, ap);
88
        va_end(ap);
257 theseven 89
        lcdconsole_puts_noblit("\n", LCDCONSOLE_FGCOLOR, LCDCONSOLE_BGCOLOR);
15 theseven 90
        lcdconsole_update();
91
        hang();
92
    }
93
    else
94
    {
95
        cputs(1, "\n*PANIC*\n");
96
        va_start(ap, string);
97
        cvprintf(1, string, ap);
98
        va_end(ap);
99
        cputc(1, '\n');
100
        handle_panic(severity);
101
    }
2 theseven 102
}
103
 
104
void __div0()
105
{
15 theseven 106
    panic(PANIC_KILLTHREAD, "Division by zero!");
2 theseven 107
}