[dbd1059] | 1 | /*
|
---|
| 2 | * Copyright (C) 2005 Jakub Jermar
|
---|
[e2ec980f] | 3 | * Copyright (C) 2005 Jakub Vana
|
---|
[dbd1059] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
[b45c443] | 28 | */
|
---|
| 29 |
|
---|
[b6529ae] | 30 | /** @addtogroup ia64interrupt
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
[dbd1059] | 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <arch/interrupt.h>
|
---|
[de57e060] | 37 | #include <interrupt.h>
|
---|
| 38 | #include <ddi/irq.h>
|
---|
[dbd1059] | 39 | #include <panic.h>
|
---|
[05d9dd89] | 40 | #include <print.h>
|
---|
[de57e060] | 41 | #include <symtab.h>
|
---|
| 42 | #include <debug.h>
|
---|
[72f5866d] | 43 | #include <console/console.h>
|
---|
[dbd1059] | 44 | #include <arch/types.h>
|
---|
| 45 | #include <arch/asm.h>
|
---|
| 46 | #include <arch/barrier.h>
|
---|
[0259524] | 47 | #include <arch/register.h>
|
---|
[05d9dd89] | 48 | #include <arch.h>
|
---|
[901122b] | 49 | #include <syscall/syscall.h>
|
---|
| 50 | #include <print.h>
|
---|
[9e1c942] | 51 | #include <proc/scheduler.h>
|
---|
[953b0f33] | 52 | #include <ipc/sysipc.h>
|
---|
[d0c5901] | 53 | #include <ipc/irq.h>
|
---|
| 54 | #include <ipc/ipc.h>
|
---|
[de57e060] | 55 | #include <synch/spinlock.h>
|
---|
[dbd1059] | 56 |
|
---|
[e2ec980f] | 57 | #define VECTORS_64_BUNDLE 20
|
---|
| 58 | #define VECTORS_16_BUNDLE 48
|
---|
| 59 | #define VECTORS_16_BUNDLE_START 0x5000
|
---|
| 60 | #define VECTOR_MAX 0x7f00
|
---|
| 61 |
|
---|
| 62 | #define BUNDLE_SIZE 16
|
---|
| 63 |
|
---|
| 64 | char *vector_names_64_bundle[VECTORS_64_BUNDLE] = {
|
---|
| 65 | "VHPT Translation vector",
|
---|
| 66 | "Instruction TLB vector",
|
---|
| 67 | "Data TLB vector",
|
---|
| 68 | "Alternate Instruction TLB vector",
|
---|
| 69 | "Alternate Data TLB vector",
|
---|
| 70 | "Data Nested TLB vector",
|
---|
| 71 | "Instruction Key Miss vector",
|
---|
| 72 | "Data Key Miss vector",
|
---|
| 73 | "Dirty-Bit vector",
|
---|
| 74 | "Instruction Access-Bit vector",
|
---|
| 75 | "Data Access-Bit vector"
|
---|
| 76 | "Break Instruction vector",
|
---|
| 77 | "External Interrupt vector"
|
---|
| 78 | "Reserved",
|
---|
| 79 | "Reserved",
|
---|
| 80 | "Reserved",
|
---|
| 81 | "Reserved",
|
---|
| 82 | "Reserved",
|
---|
| 83 | "Reserved",
|
---|
| 84 | "Reserved"
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | char *vector_names_16_bundle[VECTORS_16_BUNDLE] = {
|
---|
| 88 | "Page Not Present vector",
|
---|
| 89 | "Key Permission vector",
|
---|
| 90 | "Instruction Access rights vector",
|
---|
| 91 | "Data Access Rights vector",
|
---|
| 92 | "General Exception vector",
|
---|
| 93 | "Disabled FP-Register vector",
|
---|
| 94 | "NaT Consumption vector",
|
---|
| 95 | "Speculation vector",
|
---|
| 96 | "Reserved",
|
---|
| 97 | "Debug vector",
|
---|
| 98 | "Unaligned Reference vector",
|
---|
| 99 | "Unsupported Data Reference vector",
|
---|
| 100 | "Floating-point Fault vector",
|
---|
| 101 | "Floating-point Trap vector",
|
---|
| 102 | "Lower-Privilege Transfer Trap vector",
|
---|
| 103 | "Taken Branch Trap vector",
|
---|
[66eb2c8] | 104 | "Single Step Trap vector",
|
---|
[e2ec980f] | 105 | "Reserved",
|
---|
| 106 | "Reserved",
|
---|
| 107 | "Reserved",
|
---|
| 108 | "Reserved",
|
---|
| 109 | "Reserved",
|
---|
| 110 | "Reserved",
|
---|
| 111 | "Reserved",
|
---|
| 112 | "Reserved",
|
---|
| 113 | "IA-32 Exception vector",
|
---|
| 114 | "IA-32 Intercept vector",
|
---|
| 115 | "IA-32 Interrupt vector",
|
---|
| 116 | "Reserved",
|
---|
| 117 | "Reserved",
|
---|
| 118 | "Reserved"
|
---|
| 119 | };
|
---|
| 120 |
|
---|
[7f1c620] | 121 | static char *vector_to_string(uint16_t vector);
|
---|
[25d7709] | 122 | static void dump_interrupted_context(istate_t *istate);
|
---|
[e2ec980f] | 123 |
|
---|
[7f1c620] | 124 | char *vector_to_string(uint16_t vector)
|
---|
[e2ec980f] | 125 | {
|
---|
| 126 | ASSERT(vector <= VECTOR_MAX);
|
---|
| 127 |
|
---|
| 128 | if (vector >= VECTORS_16_BUNDLE_START)
|
---|
| 129 | return vector_names_16_bundle[(vector-VECTORS_16_BUNDLE_START)/(16*BUNDLE_SIZE)];
|
---|
| 130 | else
|
---|
| 131 | return vector_names_64_bundle[vector/(64*BUNDLE_SIZE)];
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[25d7709] | 134 | void dump_interrupted_context(istate_t *istate)
|
---|
[e2ec980f] | 135 | {
|
---|
| 136 | char *ifa, *iipa, *iip;
|
---|
| 137 |
|
---|
[25d7709] | 138 | ifa = get_symtab_entry(istate->cr_ifa);
|
---|
| 139 | iipa = get_symtab_entry(istate->cr_iipa);
|
---|
| 140 | iip = get_symtab_entry(istate->cr_iip);
|
---|
[e2ec980f] | 141 |
|
---|
| 142 | putchar('\n');
|
---|
[2ccd275] | 143 | printf("Interrupted context dump:\n");
|
---|
[cf85e24c] | 144 | printf("ar.bsp=%p\tar.bspstore=%p\n", istate->ar_bsp, istate->ar_bspstore);
|
---|
[d0c5901] | 145 | printf("ar.rnat=%#018llx\tar.rsc=%#018llx\n", istate->ar_rnat, istate->ar_rsc);
|
---|
| 146 | printf("ar.ifs=%#018llx\tar.pfs=%#018llx\n", istate->ar_ifs, istate->ar_pfs);
|
---|
| 147 | printf("cr.isr=%#018llx\tcr.ipsr=%#018llx\t\n", istate->cr_isr.value, istate->cr_ipsr);
|
---|
[e2ec980f] | 148 |
|
---|
[d0c5901] | 149 | printf("cr.iip=%#018llx, #%d\t(%s)\n", istate->cr_iip, istate->cr_isr.ei, iip);
|
---|
| 150 | printf("cr.iipa=%#018llx\t(%s)\n", istate->cr_iipa, iipa);
|
---|
| 151 | printf("cr.ifa=%#018llx\t(%s)\n", istate->cr_ifa, ifa);
|
---|
[e2ec980f] | 152 | }
|
---|
| 153 |
|
---|
[7f1c620] | 154 | void general_exception(uint64_t vector, istate_t *istate)
|
---|
[e2ec980f] | 155 | {
|
---|
[2ccd275] | 156 | char *desc = "";
|
---|
| 157 |
|
---|
[25d7709] | 158 | switch (istate->cr_isr.ge_code) {
|
---|
[6eabb6e6] | 159 | case GE_ILLEGALOP:
|
---|
[2ccd275] | 160 | desc = "Illegal Operation fault";
|
---|
| 161 | break;
|
---|
[6eabb6e6] | 162 | case GE_PRIVOP:
|
---|
[2ccd275] | 163 | desc = "Privileged Operation fault";
|
---|
| 164 | break;
|
---|
[6eabb6e6] | 165 | case GE_PRIVREG:
|
---|
[2ccd275] | 166 | desc = "Privileged Register fault";
|
---|
| 167 | break;
|
---|
[6eabb6e6] | 168 | case GE_RESREGFLD:
|
---|
[2ccd275] | 169 | desc = "Reserved Register/Field fault";
|
---|
| 170 | break;
|
---|
[6eabb6e6] | 171 | case GE_DISBLDISTRAN:
|
---|
[2ccd275] | 172 | desc = "Disabled Instruction Set Transition fault";
|
---|
| 173 | break;
|
---|
[6eabb6e6] | 174 | case GE_ILLEGALDEP:
|
---|
[2ccd275] | 175 | desc = "Illegal Dependency fault";
|
---|
| 176 | break;
|
---|
[6eabb6e6] | 177 | default:
|
---|
| 178 | desc = "unknown";
|
---|
[2ccd275] | 179 | break;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[874621f] | 182 | fault_if_from_uspace(istate, "General Exception (%s)", desc);
|
---|
| 183 |
|
---|
| 184 | dump_interrupted_context(istate);
|
---|
[2ccd275] | 185 | panic("General Exception (%s)\n", desc);
|
---|
[e2ec980f] | 186 | }
|
---|
| 187 |
|
---|
[7f1c620] | 188 | void disabled_fp_register(uint64_t vector, istate_t *istate)
|
---|
[9e1c942] | 189 | {
|
---|
[41fa6f2] | 190 | #ifdef CONFIG_FPU_LAZY
|
---|
[9e1c942] | 191 | scheduler_fpu_lazy_request();
|
---|
[41fa6f2] | 192 | #else
|
---|
[7f1c620] | 193 | fault_if_from_uspace(istate, "Interruption: %#hx (%s)", (uint16_t) vector, vector_to_string(vector));
|
---|
[41fa6f2] | 194 | dump_interrupted_context(istate);
|
---|
[7f1c620] | 195 | panic("Interruption: %#hx (%s)\n", (uint16_t) vector, vector_to_string(vector));
|
---|
[9e1c942] | 196 | #endif
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[7f1c620] | 199 | void nop_handler(uint64_t vector, istate_t *istate)
|
---|
[9e1c942] | 200 | {
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[901122b] | 203 | /** Handle syscall. */
|
---|
[7f1c620] | 204 | int break_instruction(uint64_t vector, istate_t *istate)
|
---|
[e2ec980f] | 205 | {
|
---|
[901122b] | 206 | /*
|
---|
| 207 | * Move to next instruction after BREAK.
|
---|
| 208 | */
|
---|
[25d7709] | 209 | if (istate->cr_ipsr.ri == 2) {
|
---|
| 210 | istate->cr_ipsr.ri = 0;
|
---|
| 211 | istate->cr_iip += 16;
|
---|
[901122b] | 212 | } else {
|
---|
[25d7709] | 213 | istate->cr_ipsr.ri++;
|
---|
[901122b] | 214 | }
|
---|
| 215 |
|
---|
[06e1e95] | 216 | return syscall_handler(istate->in0, istate->in1, istate->in2, istate->in3, istate->in4);
|
---|
[e2ec980f] | 217 | }
|
---|
| 218 |
|
---|
[7f1c620] | 219 | void universal_handler(uint64_t vector, istate_t *istate)
|
---|
[e2ec980f] | 220 | {
|
---|
[7f1c620] | 221 | fault_if_from_uspace(istate,"Interruption: %#hx (%s)\n",(uint16_t) vector, vector_to_string(vector));
|
---|
[25d7709] | 222 | dump_interrupted_context(istate);
|
---|
[7f1c620] | 223 | panic("Interruption: %#hx (%s)\n", (uint16_t) vector, vector_to_string(vector));
|
---|
[e2ec980f] | 224 | }
|
---|
| 225 |
|
---|
[7f1c620] | 226 | void external_interrupt(uint64_t vector, istate_t *istate)
|
---|
[dbd1059] | 227 | {
|
---|
[de57e060] | 228 | irq_t *irq;
|
---|
[05d9dd89] | 229 | cr_ivr_t ivr;
|
---|
[dbd1059] | 230 |
|
---|
[05d9dd89] | 231 | ivr.value = ivr_read();
|
---|
[dbd1059] | 232 | srlz_d();
|
---|
[83817ea] | 233 |
|
---|
[de57e060] | 234 | irq = irq_dispatch_and_lock(ivr.vector);
|
---|
| 235 | if (irq) {
|
---|
| 236 | irq->handler(irq, irq->arg);
|
---|
| 237 | spinlock_unlock(&irq->lock);
|
---|
| 238 | } else {
|
---|
| 239 | switch (ivr.vector) {
|
---|
| 240 | case INTERRUPT_SPURIOUS:
|
---|
| 241 | #ifdef CONFIG_DEBUG
|
---|
| 242 | printf("cpu%d: spurious interrupt\n", CPU->id);
|
---|
| 243 | #endif
|
---|
| 244 | break;
|
---|
[953b0f33] | 245 |
|
---|
[de57e060] | 246 | default:
|
---|
| 247 | panic("\nUnhandled External Interrupt Vector %d\n", ivr.vector);
|
---|
| 248 | break;
|
---|
| 249 | }
|
---|
[d0c5901] | 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
[3222efd] | 253 | /** @}
|
---|
[b45c443] | 254 | */
|
---|