[06737a0] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Jakub Jermar
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup genericdebug
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <panic.h>
|
---|
| 36 | #include <print.h>
|
---|
| 37 | #include <stacktrace.h>
|
---|
| 38 | #include <func.h>
|
---|
| 39 | #include <typedefs.h>
|
---|
| 40 | #include <mm/as.h>
|
---|
| 41 | #include <stdarg.h>
|
---|
| 42 | #include <interrupt.h>
|
---|
| 43 |
|
---|
| 44 | void panic_common(panic_category_t cat, istate_t *istate, int access,
|
---|
| 45 | uintptr_t address, const char *fmt, ...)
|
---|
| 46 | {
|
---|
| 47 | va_list args;
|
---|
| 48 |
|
---|
| 49 | silent = false;
|
---|
| 50 |
|
---|
[7c31d20] | 51 | printf("\nKERNEL PANIC ");
|
---|
| 52 | if (CPU)
|
---|
| 53 | printf("ON cpu%d ", CPU->id);
|
---|
| 54 | printf("DUE TO ");
|
---|
| 55 |
|
---|
[06737a0] | 56 | va_start(args, fmt);
|
---|
| 57 | if (cat == PANIC_ASSERT) {
|
---|
| 58 | printf("A FAILED ASSERTION:\n");
|
---|
| 59 | vprintf(fmt, args);
|
---|
| 60 | printf("\n");
|
---|
| 61 | } else if (cat == PANIC_BADTRAP) {
|
---|
| 62 | printf("BAD TRAP %ld.\n", address);
|
---|
| 63 | } else if (cat == PANIC_MEMTRAP) {
|
---|
| 64 | printf("A BAD MEMORY ACCESS WHILE ");
|
---|
| 65 | if (access == PF_ACCESS_READ)
|
---|
| 66 | printf("LOADING FROM");
|
---|
| 67 | else if (access == PF_ACCESS_WRITE)
|
---|
| 68 | printf("STORING TO");
|
---|
| 69 | else if (access == PF_ACCESS_EXEC)
|
---|
| 70 | printf("BRANCHING TO");
|
---|
| 71 | else
|
---|
| 72 | printf("REFERENCING");
|
---|
| 73 | printf(" ADDRESS %p.\n", address);
|
---|
| 74 | } else {
|
---|
| 75 | printf("THE FOLLOWING REASON:\n");
|
---|
| 76 | vprintf(fmt, args);
|
---|
| 77 | }
|
---|
| 78 | va_end(args);
|
---|
| 79 |
|
---|
| 80 | printf("\n");
|
---|
| 81 |
|
---|
| 82 | if (istate) {
|
---|
[22a28a69] | 83 | istate_decode(istate);
|
---|
[06737a0] | 84 | printf("\n");
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | stack_trace();
|
---|
| 88 | halt();
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /** @}
|
---|
| 92 | */
|
---|