root/Whitix/trunk/kernel/panic.c

Revision 1980, 2.7 KB (checked in by mwhitworth, 3 years ago)

Add KeAssertFail function, used by the assertion macros.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#include <assert.h>
20#include <module.h>
21#include <panic.h>
22#include <i386/i386.h>
23#include <i386/process.h>
24#include <console.h>
25#include <print.h>
26
27/***********************************************************************
28 *
29 * FUNCTION: KernelPanic
30 *
31 * DESCRIPTION: Halts the machine. Called in the *worst* cases, when an
32 *                              unrecoverable event occurs. CPU faults are dealt with
33 *                              differently.
34 *
35 * PARAMETERS: message - debug message to print.
36 *
37 ***********************************************************************/
38
39void KernelPanic(char* message)
40{
41        KePrint(KERN_CRITICAL "KERNEL PANIC\n");
42        KePrint(KERN_CRITICAL "An unrecoverable error has occured. Please restart your computer."
43        " If the error occurs again, contact the developers, giving the information on this screen.\n");
44        KePrint(KERN_CRITICAL "REASON: %s\n", message);
45               
46        ThrArchPrintCurrStack();
47       
48        MachineHalt();
49}
50
51/***********************************************************************
52 *
53 * FUNCTION: KeAssertFail
54 *
55 * DESCRIPTION: This function is called if we are in a debug build and
56 *                              a test in KeAssert or KeAssertEx fails.
57 *
58 * PARAMETERS: message - debug message to print.
59 *                         cond - condition that should hold true.
60 *                         file - name of the file when the KeAssert occurred.
61 *                         line - line number that the test failed on.
62 *
63 ***********************************************************************/
64
65/* TODO: Should only enable this function in a debug build? */
66
67void KeAssertFail(char* message, char* cond, char* file, int line)
68{
69        if (message == NULL)
70                message = "<no message>";
71       
72        KePrint(KERN_CRITICAL "\n=========================================================\n");
73        KePrint(KERN_CRITICAL "= DEBUG ASSERTION FAILURE\n");
74        KePrint(KERN_CRITICAL "= (%s) test = %s at %s, line %d\n", message, cond, file, line);
75        KePrint(KERN_CRITICAL "==========================================================");
76       
77        MachineHalt();
78}
79
80/* Exports to module code. */
81SYMBOL_EXPORT(KernelPanic);
82SYMBOL_EXPORT(KeAssertFail);
Note: See TracBrowser for help on using the browser.