Statistics
| Branch: | Revision:

root / hw / mips_int.c @ 7b9cbadb

History | View | Annotate | Download (2.2 kB)

1 7b9cbadb Aurelien Jarno
/*
2 7b9cbadb Aurelien Jarno
 * QEMU MIPS interrupt support
3 7b9cbadb Aurelien Jarno
 *
4 7b9cbadb Aurelien Jarno
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 7b9cbadb Aurelien Jarno
 * of this software and associated documentation files (the "Software"), to deal
6 7b9cbadb Aurelien Jarno
 * in the Software without restriction, including without limitation the rights
7 7b9cbadb Aurelien Jarno
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 7b9cbadb Aurelien Jarno
 * copies of the Software, and to permit persons to whom the Software is
9 7b9cbadb Aurelien Jarno
 * furnished to do so, subject to the following conditions:
10 7b9cbadb Aurelien Jarno
 *
11 7b9cbadb Aurelien Jarno
 * The above copyright notice and this permission notice shall be included in
12 7b9cbadb Aurelien Jarno
 * all copies or substantial portions of the Software.
13 7b9cbadb Aurelien Jarno
 *
14 7b9cbadb Aurelien Jarno
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 7b9cbadb Aurelien Jarno
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 7b9cbadb Aurelien Jarno
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 7b9cbadb Aurelien Jarno
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 7b9cbadb Aurelien Jarno
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 7b9cbadb Aurelien Jarno
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 7b9cbadb Aurelien Jarno
 * THE SOFTWARE.
21 7b9cbadb Aurelien Jarno
 */
22 7b9cbadb Aurelien Jarno
23 87ecb68b pbrook
#include "hw.h"
24 87ecb68b pbrook
#include "mips.h"
25 4de9b249 ths
#include "cpu.h"
26 4de9b249 ths
27 4de9b249 ths
/* Raise IRQ to CPU if necessary. It must be called every time the active
28 4de9b249 ths
   IRQ may change */
29 4de9b249 ths
void cpu_mips_update_irq(CPUState *env)
30 4de9b249 ths
{
31 24c7b0e3 ths
    if ((env->CP0_Status & (1 << CP0St_IE)) &&
32 24c7b0e3 ths
        !(env->CP0_Status & (1 << CP0St_EXL)) &&
33 24c7b0e3 ths
        !(env->CP0_Status & (1 << CP0St_ERL)) &&
34 24c7b0e3 ths
        !(env->hflags & MIPS_HFLAG_DM)) {
35 24c7b0e3 ths
        if ((env->CP0_Status & env->CP0_Cause & CP0Ca_IP_mask) &&
36 24c7b0e3 ths
            !(env->interrupt_request & CPU_INTERRUPT_HARD)) {
37 4de9b249 ths
            cpu_interrupt(env, CPU_INTERRUPT_HARD);
38 4de9b249 ths
        }
39 24c7b0e3 ths
    } else
40 4de9b249 ths
        cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
41 4de9b249 ths
}
42 4de9b249 ths
43 d537cf6c pbrook
static void cpu_mips_irq_request(void *opaque, int irq, int level)
44 4de9b249 ths
{
45 39d51eb8 ths
    CPUState *env = (CPUState *)opaque;
46 4de9b249 ths
47 39d51eb8 ths
    if (irq < 0 || irq > 7)
48 4de9b249 ths
        return;
49 4de9b249 ths
50 4de9b249 ths
    if (level) {
51 39d51eb8 ths
        env->CP0_Cause |= 1 << (irq + CP0Ca_IP);
52 4de9b249 ths
    } else {
53 a4bc3afc ths
        env->CP0_Cause &= ~(1 << (irq + CP0Ca_IP));
54 4de9b249 ths
    }
55 4de9b249 ths
    cpu_mips_update_irq(env);
56 4de9b249 ths
}
57 d537cf6c pbrook
58 d537cf6c pbrook
void cpu_mips_irq_init_cpu(CPUState *env)
59 d537cf6c pbrook
{
60 d537cf6c pbrook
    qemu_irq *qi;
61 d537cf6c pbrook
    int i;
62 d537cf6c pbrook
63 d537cf6c pbrook
    qi = qemu_allocate_irqs(cpu_mips_irq_request, env, 8);
64 d537cf6c pbrook
    for (i = 0; i < 8; i++) {
65 d537cf6c pbrook
        env->irq[i] = qi[i];
66 d537cf6c pbrook
    }
67 d537cf6c pbrook
}