[3debedec] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Martin Decky
|
---|
[3debedec] | 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 |
|
---|
[10e0cee] | 29 | /** @addtogroup ppc32interrupt
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[f5e39a32] | 35 | #include <ddi/irq.h>
|
---|
[91d5ad6] | 36 | #include <interrupt.h>
|
---|
| 37 | #include <arch/interrupt.h>
|
---|
[d99c1d2] | 38 | #include <typedefs.h>
|
---|
[91d5ad6] | 39 | #include <arch.h>
|
---|
| 40 | #include <time/clock.h>
|
---|
[953b0f33] | 41 | #include <ipc/sysipc.h>
|
---|
[982f0fe] | 42 | #include <arch/drivers/pic.h>
|
---|
[10e0cee] | 43 | #include <arch/mm/tlb.h>
|
---|
[f5e39a32] | 44 | #include <print.h>
|
---|
[8965838e] | 45 |
|
---|
| 46 | void start_decrementer(void)
|
---|
| 47 | {
|
---|
| 48 | asm volatile (
|
---|
[ffe276f] | 49 | "mtdec %[dec]\n"
|
---|
| 50 | :: [dec] "r" (1000)
|
---|
[8965838e] | 51 | );
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[22a28a69] | 54 | void istate_decode(istate_t *istate)
|
---|
[5b8016d] | 55 | {
|
---|
| 56 | printf("r0 =%p\tr1 =%p\tr2 =%p\n", istate->r0, istate->sp, istate->r2);
|
---|
| 57 | printf("r3 =%p\tr4 =%p\tr5 =%p\n", istate->r3, istate->r4, istate->r5);
|
---|
| 58 | printf("r6 =%p\tr7 =%p\tr8 =%p\n", istate->r6, istate->r7, istate->r8);
|
---|
| 59 | printf("r9 =%p\tr10=%p\tr11=%p\n",
|
---|
| 60 | istate->r9, istate->r10, istate->r11);
|
---|
| 61 | printf("r12=%p\tr13=%p\tr14=%p\n",
|
---|
| 62 | istate->r12, istate->r13, istate->r14);
|
---|
| 63 | printf("r15=%p\tr16=%p\tr17=%p\n",
|
---|
| 64 | istate->r15, istate->r16, istate->r17);
|
---|
| 65 | printf("r18=%p\tr19=%p\tr20=%p\n",
|
---|
| 66 | istate->r18, istate->r19, istate->r20);
|
---|
| 67 | printf("r21=%p\tr22=%p\tr23=%p\n",
|
---|
| 68 | istate->r21, istate->r22, istate->r23);
|
---|
| 69 | printf("r24=%p\tr25=%p\tr26=%p\n",
|
---|
| 70 | istate->r24, istate->r25, istate->r26);
|
---|
| 71 | printf("r27=%p\tr28=%p\tr29=%p\n",
|
---|
| 72 | istate->r27, istate->r28, istate->r29);
|
---|
| 73 | printf("r30=%p\tr31=%p\n", istate->r30, istate->r31);
|
---|
| 74 | printf("cr =%p\tpc =%p\tlr =%p\n", istate->cr, istate->pc, istate->lr);
|
---|
| 75 | printf("ctr=%p\txer=%p\tdar=%p\n",
|
---|
| 76 | istate->ctr, istate->xer, istate->dar);
|
---|
| 77 | printf("srr1=%p\n", istate->srr1);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[ffe276f] | 80 | /** External interrupts handler
|
---|
| 81 | *
|
---|
| 82 | */
|
---|
[5954241] | 83 | static void exception_external(unsigned int n, istate_t *istate)
|
---|
[c782434] | 84 | {
|
---|
[ffe276f] | 85 | uint8_t inum;
|
---|
[f5e39a32] | 86 |
|
---|
[ffe276f] | 87 | while ((inum = pic_get_pending()) != 255) {
|
---|
[f5e39a32] | 88 | irq_t *irq = irq_dispatch_and_lock(inum);
|
---|
| 89 | if (irq) {
|
---|
| 90 | /*
|
---|
| 91 | * The IRQ handler was found.
|
---|
| 92 | */
|
---|
[7bcfbbc] | 93 |
|
---|
| 94 | if (irq->preack) {
|
---|
| 95 | /* Acknowledge the interrupt before processing */
|
---|
[c2417bc] | 96 | if (irq->cir)
|
---|
| 97 | irq->cir(irq->cir_arg, irq->inr);
|
---|
[7bcfbbc] | 98 | }
|
---|
| 99 |
|
---|
[6cd9aa6] | 100 | irq->handler(irq);
|
---|
[c2417bc] | 101 |
|
---|
| 102 | if (!irq->preack) {
|
---|
| 103 | if (irq->cir)
|
---|
| 104 | irq->cir(irq->cir_arg, irq->inr);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[ffe276f] | 107 | irq_spinlock_unlock(&irq->lock, false);
|
---|
[f5e39a32] | 108 | } else {
|
---|
| 109 | /*
|
---|
| 110 | * Spurious interrupt.
|
---|
| 111 | */
|
---|
| 112 | #ifdef CONFIG_DEBUG
|
---|
[ffe276f] | 113 | printf("cpu%" PRIs ": spurious interrupt (inum=%" PRIu8 ")\n",
|
---|
| 114 | CPU->id, inum);
|
---|
[f5e39a32] | 115 | #endif
|
---|
| 116 | }
|
---|
[c782434] | 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[5954241] | 120 | static void exception_decrementer(unsigned int n, istate_t *istate)
|
---|
[91d5ad6] | 121 | {
|
---|
[8965838e] | 122 | start_decrementer();
|
---|
[2425349] | 123 | clock();
|
---|
[91d5ad6] | 124 | }
|
---|
[3debedec] | 125 |
|
---|
[91d5ad6] | 126 | /* Initialize basic tables for exception dispatching */
|
---|
| 127 | void interrupt_init(void)
|
---|
| 128 | {
|
---|
[b3b7e14a] | 129 | exc_register(VECTOR_DATA_STORAGE, "data_storage", true,
|
---|
| 130 | pht_refill);
|
---|
| 131 | exc_register(VECTOR_INSTRUCTION_STORAGE, "instruction_storage", true,
|
---|
| 132 | pht_refill);
|
---|
| 133 | exc_register(VECTOR_EXTERNAL, "external", true,
|
---|
| 134 | exception_external);
|
---|
| 135 | exc_register(VECTOR_DECREMENTER, "timer", true,
|
---|
| 136 | exception_decrementer);
|
---|
[91d5ad6] | 137 | }
|
---|
[953b0f33] | 138 |
|
---|
[10e0cee] | 139 | /** @}
|
---|
[b45c443] | 140 | */
|
---|