Aurelien Jarno | 7b9cbad | 2010-03-14 23:30:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QEMU MIPS interrupt support |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to deal |
| 6 | * in the Software without restriction, including without limitation the rights |
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | * copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | * THE SOFTWARE. |
| 21 | */ |
| 22 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 23 | #include "hw.h" |
Blue Swirl | b970ea8 | 2010-03-27 07:26:16 +0000 | [diff] [blame] | 24 | #include "mips_cpudevs.h" |
ths | 4de9b24 | 2007-01-24 01:47:51 +0000 | [diff] [blame] | 25 | #include "cpu.h" |
| 26 | |
pbrook | d537cf6 | 2007-04-07 18:14:41 +0000 | [diff] [blame] | 27 | static void cpu_mips_irq_request(void *opaque, int irq, int level) |
ths | 4de9b24 | 2007-01-24 01:47:51 +0000 | [diff] [blame] | 28 | { |
Andreas Färber | 61c56c8 | 2012-03-14 01:38:23 +0100 | [diff] [blame] | 29 | CPUMIPSState *env = (CPUMIPSState *)opaque; |
ths | 4de9b24 | 2007-01-24 01:47:51 +0000 | [diff] [blame] | 30 | |
ths | 39d51eb | 2007-03-18 12:43:40 +0000 | [diff] [blame] | 31 | if (irq < 0 || irq > 7) |
ths | 4de9b24 | 2007-01-24 01:47:51 +0000 | [diff] [blame] | 32 | return; |
| 33 | |
ths | 4de9b24 | 2007-01-24 01:47:51 +0000 | [diff] [blame] | 34 | if (level) { |
ths | 39d51eb | 2007-03-18 12:43:40 +0000 | [diff] [blame] | 35 | env->CP0_Cause |= 1 << (irq + CP0Ca_IP); |
ths | 4de9b24 | 2007-01-24 01:47:51 +0000 | [diff] [blame] | 36 | } else { |
ths | a4bc3af | 2007-03-31 16:54:14 +0000 | [diff] [blame] | 37 | env->CP0_Cause &= ~(1 << (irq + CP0Ca_IP)); |
ths | 4de9b24 | 2007-01-24 01:47:51 +0000 | [diff] [blame] | 38 | } |
Edgar E. Iglesias | 3638831 | 2010-07-24 13:40:05 +0200 | [diff] [blame] | 39 | |
| 40 | if (env->CP0_Cause & CP0Ca_IP_mask) { |
| 41 | cpu_interrupt(env, CPU_INTERRUPT_HARD); |
| 42 | } else { |
| 43 | cpu_reset_interrupt(env, CPU_INTERRUPT_HARD); |
| 44 | } |
ths | 4de9b24 | 2007-01-24 01:47:51 +0000 | [diff] [blame] | 45 | } |
pbrook | d537cf6 | 2007-04-07 18:14:41 +0000 | [diff] [blame] | 46 | |
Andreas Färber | 61c56c8 | 2012-03-14 01:38:23 +0100 | [diff] [blame] | 47 | void cpu_mips_irq_init_cpu(CPUMIPSState *env) |
pbrook | d537cf6 | 2007-04-07 18:14:41 +0000 | [diff] [blame] | 48 | { |
| 49 | qemu_irq *qi; |
| 50 | int i; |
| 51 | |
| 52 | qi = qemu_allocate_irqs(cpu_mips_irq_request, env, 8); |
| 53 | for (i = 0; i < 8; i++) { |
| 54 | env->irq[i] = qi[i]; |
| 55 | } |
| 56 | } |
Aurelien Jarno | 5dc5d9f | 2010-07-25 16:51:29 +0200 | [diff] [blame] | 57 | |
Andreas Färber | 61c56c8 | 2012-03-14 01:38:23 +0100 | [diff] [blame] | 58 | void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level) |
Aurelien Jarno | 5dc5d9f | 2010-07-25 16:51:29 +0200 | [diff] [blame] | 59 | { |
| 60 | if (irq < 0 || irq > 2) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | qemu_set_irq(env->irq[irq], level); |
| 65 | } |