Subversion Repositories freemyipod

Rev

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
{
50 theseven 40
    int i;
41
    if (severity == PANIC_KILLTHREAD) thread_exit();
42
    else
43
    {
44
        uint32_t mode = enter_critical_section();
45
        for (i = 0; i < MAX_THREADS; i++)
46
            if (scheduler_threads[i].type == USER_THREAD)
47
                scheduler_threads[i].state = THREAD_SUSPENDED;
48
        current_thread->state = THREAD_DEFUNCT_ACK;
49
        current_thread->block_type = THREAD_DEFUNCT_PANIC;
50
        leave_critical_section(mode);
51
        context_switch();
52
    }
2 theseven 53
}
54
 
14 theseven 55
void panic(enum panic_severity severity, const char* string)
2 theseven 56
{
15 theseven 57
    if (severity == PANIC_FATAL)
58
    {
59
        enter_critical_section();
60
        while (!displaylcd_safe());
61
        lcdconsole_puts_noblit("\n*PANIC*\n", 0, -1);
62
        lcdconsole_puts_noblit(string, 0, -1);
63
        lcdconsole_puts_noblit("\n", 0, -1);
64
        lcdconsole_update();
65
        hang();
66
    }
67
    else
68
    {
69
        cputs(1, "\n*PANIC*\n");
70
        cputs(1, string);
71
        cputc(1, '\n');
72
        handle_panic(severity);
73
    }
2 theseven 74
}
75
 
15 theseven 76
static int pprfunc(void* ptr, unsigned char letter)
77
{
78
    lcdconsole_putc_noblit(letter, 0, -1);
79
    return true;
80
}
81
 
14 theseven 82
void panicf(enum panic_severity severity, const char* string, ...)
2 theseven 83
{
15 theseven 84
    va_list ap;
85
    if (severity == PANIC_FATAL)
86
    {
87
        enter_critical_section();
88
        while (!displaylcd_safe());
89
        lcdconsole_puts_noblit("\n*PANIC*\n", 0, -1);
90
        va_start(ap, string);
91
        format(pprfunc, NULL, string, ap);
92
        va_end(ap);
93
        lcdconsole_puts_noblit("\n", 0, -1);
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
}