[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 |
|
---|
[7e752b2] | 44 | #define BANNER_LEFT "######>"
|
---|
| 45 | #define BANNER_RIGHT "<######"
|
---|
| 46 |
|
---|
[06737a0] | 47 | void panic_common(panic_category_t cat, istate_t *istate, int access,
|
---|
| 48 | uintptr_t address, const char *fmt, ...)
|
---|
| 49 | {
|
---|
[b366a6f4] | 50 | console_override = true;
|
---|
[7e752b2] | 51 |
|
---|
| 52 | printf("\n%s Kernel panic ", BANNER_LEFT);
|
---|
[7c31d20] | 53 | if (CPU)
|
---|
[7e752b2] | 54 | printf("on cpu%u ", CPU->id);
|
---|
| 55 | printf("due to ");
|
---|
| 56 |
|
---|
[b366a6f4] | 57 | va_list args;
|
---|
[06737a0] | 58 | va_start(args, fmt);
|
---|
| 59 | if (cat == PANIC_ASSERT) {
|
---|
[7e752b2] | 60 | printf("a failed assertion: %s\n", BANNER_RIGHT);
|
---|
[06737a0] | 61 | vprintf(fmt, args);
|
---|
| 62 | printf("\n");
|
---|
| 63 | } else if (cat == PANIC_BADTRAP) {
|
---|
[7e752b2] | 64 | printf("bad trap %" PRIun ". %s\n", address,
|
---|
| 65 | BANNER_RIGHT);
|
---|
[d5a1c73] | 66 | if (fmt) {
|
---|
| 67 | vprintf(fmt, args);
|
---|
| 68 | printf("\n");
|
---|
| 69 | }
|
---|
[06737a0] | 70 | } else if (cat == PANIC_MEMTRAP) {
|
---|
[7e752b2] | 71 | printf("a bad memory access while ");
|
---|
[06737a0] | 72 | if (access == PF_ACCESS_READ)
|
---|
[7e752b2] | 73 | printf("loading from");
|
---|
[06737a0] | 74 | else if (access == PF_ACCESS_WRITE)
|
---|
[7e752b2] | 75 | printf("storing to");
|
---|
[06737a0] | 76 | else if (access == PF_ACCESS_EXEC)
|
---|
[7e752b2] | 77 | printf("branching to");
|
---|
[06737a0] | 78 | else
|
---|
[7e752b2] | 79 | printf("referencing");
|
---|
| 80 | printf(" address %p. %s\n", (void *) address,
|
---|
| 81 | BANNER_RIGHT);
|
---|
[d5a1c73] | 82 | if (fmt) {
|
---|
| 83 | vprintf(fmt, args);
|
---|
| 84 | printf("\n");
|
---|
| 85 | }
|
---|
[06737a0] | 86 | } else {
|
---|
[7e752b2] | 87 | printf("the following reason: %s\n",
|
---|
| 88 | BANNER_RIGHT);
|
---|
[06737a0] | 89 | vprintf(fmt, args);
|
---|
[e9a6b29] | 90 | printf("\n");
|
---|
[06737a0] | 91 | }
|
---|
| 92 | va_end(args);
|
---|
[7e752b2] | 93 |
|
---|
[06737a0] | 94 | printf("\n");
|
---|
[7e752b2] | 95 |
|
---|
[473d5d2] | 96 | printf("THE=%p: ", THE);
|
---|
[1182d79] | 97 | if (THE != NULL) {
|
---|
[b1c57a8] | 98 | printf("pe=%" PRIun " thread=%p task=%p cpu=%p as=%p"
|
---|
[1066041] | 99 | " magic=%#" PRIx32 "\n", THE->preemption,
|
---|
[a6d8726] | 100 | THE->thread, THE->task, THE->cpu, THE->as, THE->magic);
|
---|
[adec6a29] | 101 |
|
---|
| 102 | if (THE->thread != NULL)
|
---|
| 103 | printf("thread=\"%s\"\n", THE->thread->name);
|
---|
| 104 |
|
---|
| 105 | if (THE->task != NULL)
|
---|
| 106 | printf("task=\"%s\"\n", THE->task->name);
|
---|
[473d5d2] | 107 | } else
|
---|
| 108 | printf("invalid\n");
|
---|
[1182d79] | 109 |
|
---|
[06737a0] | 110 | if (istate) {
|
---|
[22a28a69] | 111 | istate_decode(istate);
|
---|
[06737a0] | 112 | printf("\n");
|
---|
| 113 | }
|
---|
[7e752b2] | 114 |
|
---|
[06737a0] | 115 | stack_trace();
|
---|
| 116 | halt();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /** @}
|
---|
| 120 | */
|
---|