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