[db3341e] | 1 | /*
|
---|
| 2 | * Copyright (C) 2001-2004 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 | #include <arch/interrupt.h>
|
---|
| 30 | #include <print.h>
|
---|
| 31 | #include <debug.h>
|
---|
| 32 | #include <panic.h>
|
---|
| 33 | #include <arch/i8259.h>
|
---|
| 34 | #include <func.h>
|
---|
| 35 | #include <cpu.h>
|
---|
| 36 | #include <arch/asm.h>
|
---|
| 37 | #include <mm/tlb.h>
|
---|
[20d50a1] | 38 | #include <mm/as.h>
|
---|
[db3341e] | 39 | #include <arch.h>
|
---|
[ab08b42] | 40 | #include <symtab.h>
|
---|
[3396f59] | 41 | #include <arch/asm.h>
|
---|
[b49f4ae] | 42 | #include <proc/scheduler.h>
|
---|
[1084a784] | 43 | #include <proc/thread.h>
|
---|
[8ec9bae] | 44 |
|
---|
[25d7709] | 45 | static void print_info_errcode(int n, istate_t *istate)
|
---|
[8ec9bae] | 46 | {
|
---|
| 47 | char *symbol;
|
---|
[25d7709] | 48 | __u64 *x = &istate->stack[0];
|
---|
[8ec9bae] | 49 |
|
---|
| 50 | if (!(symbol=get_symtab_entry(x[1])))
|
---|
| 51 | symbol = "";
|
---|
| 52 |
|
---|
| 53 | printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__);
|
---|
[25d7709] | 54 | printf("%%rip: %Q (%s)\n",istate->stack[1],symbol);
|
---|
| 55 | printf("ERROR_WORD=%Q\n", istate->stack[0]);
|
---|
| 56 | printf("%%rcs=%Q,flags=%Q, %%cr0=%Q\n", istate->stack[2],
|
---|
| 57 | istate->stack[3],read_cr0());
|
---|
| 58 | printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",istate->rax,istate->rbx,istate->rcx);
|
---|
| 59 | printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",istate->rdx,istate->rsi,istate->rdi);
|
---|
| 60 | printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",istate->r8,istate->r9,istate->r10);
|
---|
| 61 | printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",istate->r11,istate->r12,istate->r13);
|
---|
| 62 | printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",istate->r14,istate->r15,&istate->stack[0]);
|
---|
| 63 | printf("%%rbp=%Q\n",istate->rbp);
|
---|
[8ec9bae] | 64 | printf("stack: %Q, %Q, %Q\n", x[5], x[6], x[7]);
|
---|
| 65 | printf(" %Q, %Q, %Q\n", x[8], x[9], x[10]);
|
---|
| 66 | printf(" %Q, %Q, %Q\n", x[11], x[12], x[13]);
|
---|
| 67 | printf(" %Q, %Q, %Q\n", x[14], x[15], x[16]);
|
---|
| 68 | }
|
---|
[db3341e] | 69 |
|
---|
| 70 | /*
|
---|
| 71 | * Interrupt and exception dispatching.
|
---|
| 72 | */
|
---|
| 73 |
|
---|
| 74 | void (* disable_irqs_function)(__u16 irqmask) = NULL;
|
---|
| 75 | void (* enable_irqs_function)(__u16 irqmask) = NULL;
|
---|
| 76 | void (* eoi_function)(void) = NULL;
|
---|
| 77 |
|
---|
[25d7709] | 78 | void null_interrupt(int n, istate_t *istate)
|
---|
[db3341e] | 79 | {
|
---|
[3396f59] | 80 | printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__); \
|
---|
[25d7709] | 81 | printf("stack: %X, %X, %X, %X\n", istate->stack[0], istate->stack[1],
|
---|
| 82 | istate->stack[2], istate->stack[3]);
|
---|
[db3341e] | 83 | panic("unserviced interrupt\n");
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[25d7709] | 86 | void gp_fault(int n, istate_t *istate)
|
---|
[db3341e] | 87 | {
|
---|
[25d7709] | 88 | print_info_errcode(n, istate);
|
---|
[db3341e] | 89 | panic("general protection fault\n");
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[25d7709] | 92 | void ss_fault(int n, istate_t *istate)
|
---|
[db3341e] | 93 | {
|
---|
[25d7709] | 94 | print_info_errcode(n, istate);
|
---|
[db3341e] | 95 | panic("stack fault\n");
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
[25d7709] | 99 | void nm_fault(int n, istate_t *istate)
|
---|
[db3341e] | 100 | {
|
---|
[5f85c91] | 101 | #ifdef CONFIG_FPU_LAZY
|
---|
[b49f4ae] | 102 | scheduler_fpu_lazy_request();
|
---|
| 103 | #else
|
---|
| 104 | panic("fpu fault");
|
---|
| 105 | #endif
|
---|
[db3341e] | 106 | }
|
---|
| 107 |
|
---|
[25d7709] | 108 | void page_fault(int n, istate_t *istate)
|
---|
[db3341e] | 109 | {
|
---|
[20d50a1] | 110 | __address page;
|
---|
| 111 |
|
---|
| 112 | page = read_cr2();
|
---|
| 113 | if (!as_page_fault(page)) {
|
---|
[25d7709] | 114 | print_info_errcode(n, istate);
|
---|
[20d50a1] | 115 | printf("Page fault address: %Q\n", page);
|
---|
| 116 | panic("page fault\n");
|
---|
| 117 | }
|
---|
[db3341e] | 118 | }
|
---|
| 119 |
|
---|
[25d7709] | 120 | void tlb_shootdown_ipi(int n, istate_t *istate)
|
---|
[db3341e] | 121 | {
|
---|
| 122 | trap_virtual_eoi();
|
---|
| 123 | tlb_shootdown_ipi_recv();
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | void trap_virtual_enable_irqs(__u16 irqmask)
|
---|
| 127 | {
|
---|
| 128 | if (enable_irqs_function)
|
---|
| 129 | enable_irqs_function(irqmask);
|
---|
| 130 | else
|
---|
| 131 | panic("no enable_irqs_function\n");
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | void trap_virtual_disable_irqs(__u16 irqmask)
|
---|
| 135 | {
|
---|
| 136 | if (disable_irqs_function)
|
---|
| 137 | disable_irqs_function(irqmask);
|
---|
| 138 | else
|
---|
| 139 | panic("no disable_irqs_function\n");
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | void trap_virtual_eoi(void)
|
---|
| 143 | {
|
---|
| 144 | if (eoi_function)
|
---|
| 145 | eoi_function();
|
---|
| 146 | else
|
---|
| 147 | panic("no eoi_function\n");
|
---|
| 148 |
|
---|
| 149 | }
|
---|