source: mainline/kernel/generic/src/debug/panic.c@ 7e752b2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7e752b2 was 7e752b2, checked in by Martin Decky <martin@…>, 15 years ago
  • correct printf() formatting strings and corresponding arguments
  • minor cstyle changes and other small fixes
  • Property mode set to 100644
File size: 2.9 KB
Line 
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#define BANNER_LEFT "######>"
45#define BANNER_RIGHT "<######"
46
47void panic_common(panic_category_t cat, istate_t *istate, int access,
48 uintptr_t address, const char *fmt, ...)
49{
50 va_list args;
51
52 silent = false;
53
54 printf("\n%s Kernel panic ", BANNER_LEFT);
55 if (CPU)
56 printf("on cpu%u ", CPU->id);
57 printf("due to ");
58
59 va_start(args, fmt);
60 if (cat == PANIC_ASSERT) {
61 printf("a failed assertion: %s\n", BANNER_RIGHT);
62 vprintf(fmt, args);
63 printf("\n");
64 } else if (cat == PANIC_BADTRAP) {
65 printf("bad trap %" PRIun ". %s\n", address,
66 BANNER_RIGHT);
67 if (fmt) {
68 vprintf(fmt, args);
69 printf("\n");
70 }
71 } else if (cat == PANIC_MEMTRAP) {
72 printf("a bad memory access while ");
73 if (access == PF_ACCESS_READ)
74 printf("loading from");
75 else if (access == PF_ACCESS_WRITE)
76 printf("storing to");
77 else if (access == PF_ACCESS_EXEC)
78 printf("branching to");
79 else
80 printf("referencing");
81 printf(" address %p. %s\n", (void *) address,
82 BANNER_RIGHT);
83 if (fmt) {
84 vprintf(fmt, args);
85 printf("\n");
86 }
87 } else {
88 printf("the following reason: %s\n",
89 BANNER_RIGHT);
90 vprintf(fmt, args);
91 printf("\n");
92 }
93 va_end(args);
94
95 printf("\n");
96
97 if (istate) {
98 istate_decode(istate);
99 printf("\n");
100 }
101
102 stack_trace();
103 halt();
104}
105
106/** @}
107 */
Note: See TracBrowser for help on using the repository browser.