[a7fdfe1] | 1 | /*
|
---|
[973be64e] | 2 | * Copyright (C) 2005 Ondrej Palkovsky
|
---|
[a7fdfe1] | 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 |
|
---|
[973be64e] | 29 | #include <interrupt.h>
|
---|
| 30 | #include <debug.h>
|
---|
[aace6624] | 31 | #include <console/kconsole.h>
|
---|
| 32 | #include <console/console.h>
|
---|
| 33 | #include <console/chardev.h>
|
---|
| 34 | #include <panic.h>
|
---|
| 35 | #include <print.h>
|
---|
| 36 | #include <symtab.h>
|
---|
[a7fdfe1] | 37 |
|
---|
[973be64e] | 38 | static struct {
|
---|
[aace6624] | 39 | const char *name;
|
---|
[973be64e] | 40 | iroutine f;
|
---|
[aace6624] | 41 | } exc_table[IVT_ITEMS];
|
---|
[a7fdfe1] | 42 |
|
---|
[dc747e3] | 43 | SPINLOCK_INITIALIZE(exctbl_lock);
|
---|
[aace6624] | 44 |
|
---|
| 45 | /** Register exception handler
|
---|
| 46 | *
|
---|
| 47 | * @param n Exception number
|
---|
| 48 | * @param name Description
|
---|
| 49 | * @param f Exception handler
|
---|
| 50 | */
|
---|
| 51 | iroutine exc_register(int n, const char *name, iroutine f)
|
---|
[973be64e] | 52 | {
|
---|
| 53 | ASSERT(n < IVT_ITEMS);
|
---|
| 54 |
|
---|
| 55 | iroutine old;
|
---|
| 56 |
|
---|
[aace6624] | 57 | spinlock_lock(&exctbl_lock);
|
---|
| 58 |
|
---|
| 59 | old = exc_table[n].f;
|
---|
| 60 | exc_table[n].f = f;
|
---|
| 61 | exc_table[n].name = name;
|
---|
| 62 |
|
---|
| 63 | spinlock_unlock(&exctbl_lock);
|
---|
| 64 |
|
---|
[973be64e] | 65 | return old;
|
---|
| 66 | }
|
---|
[a7fdfe1] | 67 |
|
---|
[aace6624] | 68 | /** Dispatch exception according to exception table
|
---|
| 69 | *
|
---|
[973be64e] | 70 | * Called directly from the assembler code.
|
---|
| 71 | * CPU is interrupts_disable()'d.
|
---|
| 72 | */
|
---|
| 73 | void exc_dispatch(int n, void *stack)
|
---|
| 74 | {
|
---|
| 75 | ASSERT(n < IVT_ITEMS);
|
---|
| 76 |
|
---|
[39494010] | 77 | exc_table[n].f(n + IVT_FIRST, stack);
|
---|
[aace6624] | 78 | }
|
---|
| 79 |
|
---|
| 80 | /** Default 'null' exception handler */
|
---|
| 81 | static void exc_undef(int n, void *stack)
|
---|
| 82 | {
|
---|
| 83 | panic("Unhandled exception %d.", n);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[39494010] | 86 | /** kconsole cmd - print all exceptions */
|
---|
[aace6624] | 87 | static int exc_print_cmd(cmd_arg_t *argv)
|
---|
| 88 | {
|
---|
| 89 | int i;
|
---|
| 90 | char *symbol;
|
---|
| 91 |
|
---|
| 92 | spinlock_lock(&exctbl_lock);
|
---|
[6e716a59] | 93 | printf("Exc Description Handler\n");
|
---|
[aace6624] | 94 | for (i=0; i < IVT_ITEMS; i++) {
|
---|
| 95 | symbol = get_symtab_entry((__native)exc_table[i].f);
|
---|
| 96 | if (!symbol)
|
---|
| 97 | symbol = "not found";
|
---|
[39494010] | 98 | printf("%d %s 0x%p(%s)\n", i + IVT_FIRST, exc_table[i].name,
|
---|
[aace6624] | 99 | exc_table[i].f,symbol);
|
---|
| 100 | if (!((i+1) % 20)) {
|
---|
| 101 | printf("Press any key to continue.");
|
---|
[402fc8bf] | 102 | spinlock_unlock(&exctbl_lock);
|
---|
[aace6624] | 103 | getc(stdin);
|
---|
[402fc8bf] | 104 | spinlock_lock(&exctbl_lock);
|
---|
[aace6624] | 105 | printf("\n");
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | spinlock_unlock(&exctbl_lock);
|
---|
| 109 |
|
---|
| 110 | return 1;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | static cmd_info_t exc_info = {
|
---|
[a3ac9a7] | 114 | .name = "pexc",
|
---|
[adb2ebf8] | 115 | .description = "Print exception table.",
|
---|
[aace6624] | 116 | .func = exc_print_cmd,
|
---|
| 117 | .help = NULL,
|
---|
| 118 | .argc = 0,
|
---|
| 119 | .argv = NULL
|
---|
| 120 | };
|
---|
| 121 |
|
---|
| 122 | /** Initialize generic exception handling support */
|
---|
| 123 | void exc_init(void)
|
---|
| 124 | {
|
---|
| 125 | int i;
|
---|
| 126 |
|
---|
| 127 | for (i=0;i < IVT_ITEMS; i++)
|
---|
| 128 | exc_register(i, "undef", exc_undef);
|
---|
| 129 |
|
---|
| 130 | spinlock_initialize(&exc_info.lock, "kconsole_excinfo");
|
---|
| 131 | link_initialize(&exc_info.link);
|
---|
| 132 | if (!cmd_register(&exc_info))
|
---|
| 133 | panic("could not register command %s\n", exc_info.name);
|
---|
[973be64e] | 134 | }
|
---|
[aace6624] | 135 |
|
---|