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