interrupt.c 2.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * OpenRISC interrupt.
 *
 * Copyright (c) 2011-2012 Jia Liu <proljc@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

20
#include "qemu/osdep.h"
21
#include "cpu.h"
22
#include "exec/exec-all.h"
23
#include "qemu-common.h"
24
#include "exec/gdbstub.h"
25
#include "qemu/host-utils.h"
26 27 28 29
#ifndef CONFIG_USER_ONLY
#include "hw/loader.h"
#endif

30
void openrisc_cpu_do_interrupt(CPUState *cs)
31
{
32
#ifndef CONFIG_USER_ONLY
33 34
    OpenRISCCPU *cpu = OPENRISC_CPU(cs);
    CPUOpenRISCState *env = &cpu->env;
35 36 37

    env->epcr = env->pc;
    if (env->flags & D_FLAG) {
38 39
        env->flags &= ~D_FLAG;
        env->sr |= SR_DSX;
40 41
        env->epcr -= 4;
    }
42
    if (cs->exception_index == EXCP_SYSCALL) {
43
        env->epcr += 4;
44 45 46 47
    }

    /* For machine-state changed between user-mode and supervisor mode,
       we need flush TLB when we enter&exit EXCP.  */
48
    tlb_flush(cs, 1);
49 50 51 52 53 54 55 56 57 58

    env->esr = env->sr;
    env->sr &= ~SR_DME;
    env->sr &= ~SR_IME;
    env->sr |= SR_SM;
    env->sr &= ~SR_IEE;
    env->sr &= ~SR_TEE;
    env->tlb->cpu_openrisc_map_address_data = &cpu_openrisc_get_phys_nommu;
    env->tlb->cpu_openrisc_map_address_code = &cpu_openrisc_get_phys_nommu;

59 60
    if (cs->exception_index > 0 && cs->exception_index < EXCP_NR) {
        env->pc = (cs->exception_index << 8);
61
    } else {
62
        cpu_abort(cs, "Unhandled exception 0x%x\n", cs->exception_index);
63 64 65
    }
#endif

66
    cs->exception_index = -1;
67
}
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

bool openrisc_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
{
    OpenRISCCPU *cpu = OPENRISC_CPU(cs);
    CPUOpenRISCState *env = &cpu->env;
    int idx = -1;

    if ((interrupt_request & CPU_INTERRUPT_HARD) && (env->sr & SR_IEE)) {
        idx = EXCP_INT;
    }
    if ((interrupt_request & CPU_INTERRUPT_TIMER) && (env->sr & SR_TEE)) {
        idx = EXCP_TICK;
    }
    if (idx >= 0) {
        cs->exception_index = idx;
        openrisc_cpu_do_interrupt(cs);
        return true;
    }
    return false;
}