[dbd1059] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2005 Jakub Jermar
|
---|
| 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>
|
---|
[63e27ef] | 37 | #include <assert.h>
|
---|
[de57e060] | 38 | #include <interrupt.h>
|
---|
| 39 | #include <ddi/irq.h>
|
---|
[dbd1059] | 40 | #include <panic.h>
|
---|
[05d9dd89] | 41 | #include <print.h>
|
---|
[72f5866d] | 42 | #include <console/console.h>
|
---|
[d99c1d2] | 43 | #include <typedefs.h>
|
---|
[dbd1059] | 44 | #include <arch/asm.h>
|
---|
| 45 | #include <arch/barrier.h>
|
---|
[0259524] | 46 | #include <arch/register.h>
|
---|
[05d9dd89] | 47 | #include <arch.h>
|
---|
[901122b] | 48 | #include <syscall/syscall.h>
|
---|
| 49 | #include <print.h>
|
---|
[9e1c942] | 50 | #include <proc/scheduler.h>
|
---|
[953b0f33] | 51 | #include <ipc/sysipc.h>
|
---|
[d0c5901] | 52 | #include <ipc/irq.h>
|
---|
| 53 | #include <ipc/ipc.h>
|
---|
[de57e060] | 54 | #include <synch/spinlock.h>
|
---|
[7782030] | 55 | #include <mm/tlb.h>
|
---|
[9928240] | 56 | #include <arch/mm/tlb.h>
|
---|
[e2b762ec] | 57 | #include <symtab.h>
|
---|
[b60c582] | 58 | #include <putchar.h>
|
---|
[e2b762ec] | 59 |
|
---|
[da1bafb] | 60 | #define VECTORS_64_BUNDLE 20
|
---|
| 61 | #define VECTORS_16_BUNDLE 48
|
---|
[9928240] | 62 | #define VECTORS_16_BUNDLE_START 0x50
|
---|
[e2ec980f] | 63 |
|
---|
[9928240] | 64 | #define VECTOR_MAX 0x7f
|
---|
[e2ec980f] | 65 |
|
---|
[a000878c] | 66 | static const char *vector_names_64_bundle[VECTORS_64_BUNDLE] = {
|
---|
[e2ec980f] | 67 | "VHPT Translation vector",
|
---|
| 68 | "Instruction TLB vector",
|
---|
| 69 | "Data TLB vector",
|
---|
| 70 | "Alternate Instruction TLB vector",
|
---|
| 71 | "Alternate Data TLB vector",
|
---|
| 72 | "Data Nested TLB vector",
|
---|
| 73 | "Instruction Key Miss vector",
|
---|
| 74 | "Data Key Miss vector",
|
---|
| 75 | "Dirty-Bit vector",
|
---|
| 76 | "Instruction Access-Bit vector",
|
---|
| 77 | "Data Access-Bit vector"
|
---|
| 78 | "Break Instruction vector",
|
---|
| 79 | "External Interrupt vector"
|
---|
| 80 | "Reserved",
|
---|
| 81 | "Reserved",
|
---|
| 82 | "Reserved",
|
---|
| 83 | "Reserved",
|
---|
| 84 | "Reserved",
|
---|
| 85 | "Reserved",
|
---|
| 86 | "Reserved"
|
---|
| 87 | };
|
---|
| 88 |
|
---|
[a000878c] | 89 | static const char *vector_names_16_bundle[VECTORS_16_BUNDLE] = {
|
---|
[e2ec980f] | 90 | "Page Not Present vector",
|
---|
| 91 | "Key Permission vector",
|
---|
| 92 | "Instruction Access rights vector",
|
---|
| 93 | "Data Access Rights vector",
|
---|
| 94 | "General Exception vector",
|
---|
| 95 | "Disabled FP-Register vector",
|
---|
| 96 | "NaT Consumption vector",
|
---|
| 97 | "Speculation vector",
|
---|
| 98 | "Reserved",
|
---|
| 99 | "Debug vector",
|
---|
| 100 | "Unaligned Reference vector",
|
---|
| 101 | "Unsupported Data Reference vector",
|
---|
| 102 | "Floating-point Fault vector",
|
---|
| 103 | "Floating-point Trap vector",
|
---|
| 104 | "Lower-Privilege Transfer Trap vector",
|
---|
| 105 | "Taken Branch Trap vector",
|
---|
[66eb2c8] | 106 | "Single Step Trap vector",
|
---|
[e2ec980f] | 107 | "Reserved",
|
---|
| 108 | "Reserved",
|
---|
| 109 | "Reserved",
|
---|
| 110 | "Reserved",
|
---|
| 111 | "Reserved",
|
---|
| 112 | "Reserved",
|
---|
| 113 | "Reserved",
|
---|
| 114 | "Reserved",
|
---|
| 115 | "IA-32 Exception vector",
|
---|
| 116 | "IA-32 Intercept vector",
|
---|
| 117 | "IA-32 Interrupt vector",
|
---|
| 118 | "Reserved",
|
---|
| 119 | "Reserved",
|
---|
| 120 | "Reserved"
|
---|
| 121 | };
|
---|
| 122 |
|
---|
[9928240] | 123 | static const char *vector_to_string(unsigned int n)
|
---|
[e2ec980f] | 124 | {
|
---|
[63e27ef] | 125 | assert(n <= VECTOR_MAX);
|
---|
[e2ec980f] | 126 |
|
---|
[9928240] | 127 | if (n >= VECTORS_16_BUNDLE_START)
|
---|
| 128 | return vector_names_16_bundle[n - VECTORS_16_BUNDLE_START];
|
---|
[e2ec980f] | 129 | else
|
---|
[9928240] | 130 | return vector_names_64_bundle[n / 4];
|
---|
[e2ec980f] | 131 | }
|
---|
| 132 |
|
---|
[22a28a69] | 133 | void istate_decode(istate_t *istate)
|
---|
[e2ec980f] | 134 | {
|
---|
[7e752b2] | 135 | printf("ar.bsp=%p\tar.bspstore=%p\n",
|
---|
| 136 | (void *) istate->ar_bsp, (void *) istate->ar_bspstore);
|
---|
| 137 | printf("ar.rnat=%#0" PRIx64 "\tar.rsc=%#0" PRIx64 "\n",
|
---|
| 138 | istate->ar_rnat, istate->ar_rsc);
|
---|
| 139 | printf("ar.ifs=%#0" PRIx64 "\tar.pfs=%#0" PRIx64 "\n",
|
---|
| 140 | istate->ar_ifs, istate->ar_pfs);
|
---|
| 141 | printf("cr.isr=%#0" PRIx64 "\tcr.ipsr=%#0" PRIx64 "\n",
|
---|
| 142 | istate->cr_isr.value, istate->cr_ipsr.value);
|
---|
[e2ec980f] | 143 |
|
---|
[002fd5f] | 144 | printf("cr.iip=%#0" PRIxPTR ", #%u\t(%s)\n",
|
---|
[7e752b2] | 145 | istate->cr_iip, istate->cr_isr.ei,
|
---|
[da1bafb] | 146 | symtab_fmt_name_lookup(istate->cr_iip));
|
---|
[002fd5f] | 147 | printf("cr.iipa=%#0" PRIxPTR "\t(%s)\n", istate->cr_iipa,
|
---|
[da1bafb] | 148 | symtab_fmt_name_lookup(istate->cr_iipa));
|
---|
[002fd5f] | 149 | printf("cr.ifa=%#0" PRIxPTR "\t(%s)\n", istate->cr_ifa,
|
---|
[da1bafb] | 150 | symtab_fmt_name_lookup(istate->cr_ifa));
|
---|
[e2ec980f] | 151 | }
|
---|
| 152 |
|
---|
[9928240] | 153 | void general_exception(unsigned int n, istate_t *istate)
|
---|
[e2ec980f] | 154 | {
|
---|
[a000878c] | 155 | const char *desc;
|
---|
| 156 |
|
---|
[25d7709] | 157 | switch (istate->cr_isr.ge_code) {
|
---|
[6eabb6e6] | 158 | case GE_ILLEGALOP:
|
---|
[2ccd275] | 159 | desc = "Illegal Operation fault";
|
---|
| 160 | break;
|
---|
[6eabb6e6] | 161 | case GE_PRIVOP:
|
---|
[2ccd275] | 162 | desc = "Privileged Operation fault";
|
---|
| 163 | break;
|
---|
[6eabb6e6] | 164 | case GE_PRIVREG:
|
---|
[2ccd275] | 165 | desc = "Privileged Register fault";
|
---|
| 166 | break;
|
---|
[6eabb6e6] | 167 | case GE_RESREGFLD:
|
---|
[2ccd275] | 168 | desc = "Reserved Register/Field fault";
|
---|
| 169 | break;
|
---|
[6eabb6e6] | 170 | case GE_DISBLDISTRAN:
|
---|
[2ccd275] | 171 | desc = "Disabled Instruction Set Transition fault";
|
---|
| 172 | break;
|
---|
[6eabb6e6] | 173 | case GE_ILLEGALDEP:
|
---|
[2ccd275] | 174 | desc = "Illegal Dependency fault";
|
---|
| 175 | break;
|
---|
[6eabb6e6] | 176 | default:
|
---|
| 177 | desc = "unknown";
|
---|
[2ccd275] | 178 | break;
|
---|
| 179 | }
|
---|
[a000878c] | 180 |
|
---|
[f651e80] | 181 | fault_if_from_uspace(istate, "General Exception (%s).", desc);
|
---|
[9928240] | 182 | panic_badtrap(istate, n, "General Exception (%s).", desc);
|
---|
[e2ec980f] | 183 | }
|
---|
| 184 |
|
---|
[9928240] | 185 | void disabled_fp_register(unsigned int n, istate_t *istate)
|
---|
[9e1c942] | 186 | {
|
---|
[6da1013f] | 187 | #ifdef CONFIG_FPU_LAZY
|
---|
| 188 | scheduler_fpu_lazy_request();
|
---|
[41fa6f2] | 189 | #else
|
---|
[f651e80] | 190 | fault_if_from_uspace(istate, "Interruption: %#hx (%s).",
|
---|
[9928240] | 191 | (uint16_t) n, vector_to_string(n));
|
---|
[38e5675b] | 192 | panic_badtrap(istate, vector, "Interruption: %#hx (%s).",
|
---|
[9928240] | 193 | (uint16_t) n, vector_to_string(n));
|
---|
[9e1c942] | 194 | #endif
|
---|
| 195 | }
|
---|
| 196 |
|
---|
[901122b] | 197 | /** Handle syscall. */
|
---|
[9928240] | 198 | sysarg_t break_instruction(unsigned int n, istate_t *istate)
|
---|
[e2ec980f] | 199 | {
|
---|
[416ef49] | 200 | sysarg_t ret;
|
---|
| 201 |
|
---|
[901122b] | 202 | /*
|
---|
| 203 | * Move to next instruction after BREAK.
|
---|
| 204 | */
|
---|
[25d7709] | 205 | if (istate->cr_ipsr.ri == 2) {
|
---|
| 206 | istate->cr_ipsr.ri = 0;
|
---|
| 207 | istate->cr_iip += 16;
|
---|
[901122b] | 208 | } else {
|
---|
[25d7709] | 209 | istate->cr_ipsr.ri++;
|
---|
[901122b] | 210 | }
|
---|
[da1bafb] | 211 |
|
---|
[416ef49] | 212 | interrupts_enable();
|
---|
| 213 | ret = syscall_handler(istate->in0, istate->in1, istate->in2,
|
---|
[1b03ed3] | 214 | istate->in3, istate->in4, istate->in5, istate->in6);
|
---|
[416ef49] | 215 | interrupts_disable();
|
---|
| 216 |
|
---|
| 217 | return ret;
|
---|
[e2ec980f] | 218 | }
|
---|
| 219 |
|
---|
[9928240] | 220 | void universal_handler(unsigned int n, istate_t *istate)
|
---|
[e2ec980f] | 221 | {
|
---|
[f651e80] | 222 | fault_if_from_uspace(istate, "Interruption: %#hx (%s).",
|
---|
[9928240] | 223 | n, vector_to_string(n));
|
---|
| 224 | panic_badtrap(istate, n, "Interruption: %#hx (%s).",
|
---|
| 225 | n, vector_to_string(n));
|
---|
[e2ec980f] | 226 | }
|
---|
| 227 |
|
---|
[323a5aaf] | 228 | static void end_of_local_irq(void)
|
---|
[7782030] | 229 | {
|
---|
[da1bafb] | 230 | asm volatile (
|
---|
[9928240] | 231 | "mov cr.eoi = r0 ;;"
|
---|
[da1bafb] | 232 | );
|
---|
[7782030] | 233 | }
|
---|
| 234 |
|
---|
[9928240] | 235 | void external_interrupt(unsigned int n, istate_t *istate)
|
---|
[dbd1059] | 236 | {
|
---|
[05d9dd89] | 237 | cr_ivr_t ivr;
|
---|
[dbd1059] | 238 |
|
---|
[05d9dd89] | 239 | ivr.value = ivr_read();
|
---|
[dbd1059] | 240 | srlz_d();
|
---|
[da1bafb] | 241 |
|
---|
| 242 | irq_t *irq;
|
---|
| 243 |
|
---|
[666773c] | 244 | switch (ivr.vector) {
|
---|
| 245 | case INTERRUPT_SPURIOUS:
|
---|
[de57e060] | 246 | #ifdef CONFIG_DEBUG
|
---|
[666773c] | 247 | printf("cpu%d: spurious interrupt\n", CPU->id);
|
---|
[de57e060] | 248 | #endif
|
---|
[666773c] | 249 | break;
|
---|
[da1bafb] | 250 |
|
---|
[7782030] | 251 | #ifdef CONFIG_SMP
|
---|
[666773c] | 252 | case VECTOR_TLB_SHOOTDOWN_IPI:
|
---|
| 253 | tlb_shootdown_ipi_recv();
|
---|
| 254 | end_of_local_irq();
|
---|
| 255 | break;
|
---|
[7782030] | 256 | #endif
|
---|
[da1bafb] | 257 |
|
---|
[666773c] | 258 | case INTERRUPT_TIMER:
|
---|
| 259 | irq = irq_dispatch_and_lock(ivr.vector);
|
---|
| 260 | if (irq) {
|
---|
[6cd9aa6] | 261 | irq->handler(irq);
|
---|
[da1bafb] | 262 | irq_spinlock_unlock(&irq->lock, false);
|
---|
[666773c] | 263 | } else {
|
---|
[f651e80] | 264 | panic("Unhandled Internal Timer Interrupt (%d).",
|
---|
[666773c] | 265 | ivr.vector);
|
---|
| 266 | }
|
---|
| 267 | break;
|
---|
| 268 | default:
|
---|
| 269 | irq = irq_dispatch_and_lock(ivr.vector);
|
---|
| 270 | if (irq) {
|
---|
| 271 | /*
|
---|
| 272 | * The IRQ handler was found.
|
---|
| 273 | */
|
---|
| 274 | if (irq->preack) {
|
---|
| 275 | /* Send EOI before processing the interrupt */
|
---|
| 276 | end_of_local_irq();
|
---|
| 277 | }
|
---|
[6cd9aa6] | 278 | irq->handler(irq);
|
---|
[666773c] | 279 | if (!irq->preack)
|
---|
| 280 | end_of_local_irq();
|
---|
[da1bafb] | 281 | irq_spinlock_unlock(&irq->lock, false);
|
---|
[666773c] | 282 | } else {
|
---|
| 283 | /*
|
---|
| 284 | * Unhandled interrupt.
|
---|
| 285 | */
|
---|
| 286 | end_of_local_irq();
|
---|
[323a5aaf] | 287 | #ifdef CONFIG_DEBUG
|
---|
[666773c] | 288 | printf("\nUnhandled External Interrupt Vector %d\n",
|
---|
| 289 | ivr.vector);
|
---|
[323a5aaf] | 290 | #endif
|
---|
[de57e060] | 291 | }
|
---|
[666773c] | 292 | break;
|
---|
| 293 | }
|
---|
[d0c5901] | 294 | }
|
---|
| 295 |
|
---|
[6da1013f] | 296 | void trap_virtual_enable_irqs(uint16_t irqmask)
|
---|
| 297 | {
|
---|
| 298 | }
|
---|
| 299 |
|
---|
[9928240] | 300 | void exception_init(void)
|
---|
| 301 | {
|
---|
| 302 | unsigned int i;
|
---|
| 303 |
|
---|
| 304 | for (i = 0; i < IVT_ITEMS; i++)
|
---|
| 305 | exc_register(i, "universal_handler", false, universal_handler);
|
---|
| 306 |
|
---|
| 307 | exc_register(EXC_ALT_ITLB_FAULT,
|
---|
| 308 | vector_to_string(EXC_ALT_ITLB_FAULT), true,
|
---|
| 309 | alternate_instruction_tlb_fault);
|
---|
| 310 | exc_register(EXC_ALT_DTLB_FAULT,
|
---|
| 311 | vector_to_string(EXC_ALT_DTLB_FAULT), true,
|
---|
| 312 | alternate_data_tlb_fault);
|
---|
| 313 | exc_register(EXC_NESTED_TLB_FAULT,
|
---|
| 314 | vector_to_string(EXC_NESTED_TLB_FAULT), false,
|
---|
| 315 | data_nested_tlb_fault);
|
---|
| 316 | exc_register(EXC_DATA_D_BIT_FAULT,
|
---|
| 317 | vector_to_string(EXC_DATA_D_BIT_FAULT), true,
|
---|
| 318 | data_dirty_bit_fault);
|
---|
| 319 | exc_register(EXC_INST_A_BIT_FAULT,
|
---|
| 320 | vector_to_string(EXC_INST_A_BIT_FAULT), true,
|
---|
| 321 | instruction_access_bit_fault);
|
---|
| 322 | exc_register(EXC_DATA_A_BIT_FAULT,
|
---|
| 323 | vector_to_string(EXC_DATA_A_BIT_FAULT), true,
|
---|
| 324 | data_access_bit_fault);
|
---|
| 325 | exc_register(EXC_EXT_INTERRUPT,
|
---|
| 326 | vector_to_string(EXC_EXT_INTERRUPT), true,
|
---|
| 327 | external_interrupt);
|
---|
| 328 |
|
---|
| 329 | exc_register(EXC_PAGE_NOT_PRESENT,
|
---|
| 330 | vector_to_string(EXC_PAGE_NOT_PRESENT), true,
|
---|
| 331 | page_not_present);
|
---|
| 332 | exc_register(EXC_DATA_AR_FAULT,
|
---|
| 333 | vector_to_string(EXC_DATA_AR_FAULT), true,
|
---|
| 334 | data_access_rights_fault);
|
---|
| 335 | exc_register(EXC_GENERAL_EXCEPTION,
|
---|
| 336 | vector_to_string(EXC_GENERAL_EXCEPTION), false,
|
---|
| 337 | general_exception);
|
---|
| 338 | exc_register(EXC_DISABLED_FP_REG,
|
---|
| 339 | vector_to_string(EXC_DISABLED_FP_REG), true,
|
---|
| 340 | disabled_fp_register);
|
---|
| 341 | }
|
---|
| 342 |
|
---|
[3222efd] | 343 | /** @}
|
---|
[b45c443] | 344 | */
|
---|