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"
2 theseven 26
#include "console.h"
15 theseven 27
#include "format.h"
28
#include "thread.h"
29
#include "contextswitch.h"
2 theseven 30
 
31
 
704 theseven 32
void handle_panic(enum panic_severity severity, uint32_t mode)
2 theseven 33
{
704 theseven 34
    if (severity == PANIC_FATAL) panic_fatal(mode);
429 theseven 35
    struct scheduler_thread* t;
249 theseven 36
    if (severity == PANIC_KILLUSERTHREADS)
50 theseven 37
    {
249 theseven 38
        int i;
429 theseven 39
        for (t = head_thread; t; t = t->thread_next)
40
            if (t->type == USER_THREAD)
41
                t->state = THREAD_SUSPENDED;
50 theseven 42
    }
249 theseven 43
    current_thread->state = THREAD_DEFUNCT_ACK;
44
    current_thread->block_type = THREAD_DEFUNCT_PANIC;
45
    leave_critical_section(mode);
704 theseven 46
    panic_recover(mode);
2 theseven 47
}
48
 
14 theseven 49
void panic(enum panic_severity severity, const char* string)
2 theseven 50
{
704 theseven 51
    uint32_t mode = enter_critical_section();
52
    csputs(CONSOLE_PANIC, "\n*PANIC*\n");
53
    csputs(CONSOLE_PANIC, string);
54
    csputc(CONSOLE_PANIC, '\n');
55
    csflush(CONSOLE_PANIC);
56
    handle_panic(severity, mode);
2 theseven 57
}
58
 
14 theseven 59
void panicf(enum panic_severity severity, const char* string, ...)
2 theseven 60
{
15 theseven 61
    va_list ap;
704 theseven 62
    uint32_t mode = enter_critical_section();
63
    csputs(CONSOLE_PANIC, "\n*PANIC*\n");
64
    va_start(ap, string);
65
    csvprintf(CONSOLE_PANIC, string, ap);
66
    va_end(ap);
67
    csputc(CONSOLE_PANIC, '\n');
68
    csflush(CONSOLE_PANIC);
69
    handle_panic(severity, mode);
2 theseven 70
}
71
 
72
void __div0()
73
{
15 theseven 74
    panic(PANIC_KILLTHREAD, "Division by zero!");
2 theseven 75
}