Statistics
| Branch: | Revision:

root / target-openrisc / interrupt.c @ 14a10fc3

History | View | Annotate | Download (2.4 kB)

1 e67db06e Jia Liu
/*
2 e67db06e Jia Liu
 * OpenRISC interrupt.
3 e67db06e Jia Liu
 *
4 e67db06e Jia Liu
 * Copyright (c) 2011-2012 Jia Liu <proljc@gmail.com>
5 e67db06e Jia Liu
 *
6 e67db06e Jia Liu
 * This library is free software; you can redistribute it and/or
7 e67db06e Jia Liu
 * modify it under the terms of the GNU Lesser General Public
8 e67db06e Jia Liu
 * License as published by the Free Software Foundation; either
9 e67db06e Jia Liu
 * version 2 of the License, or (at your option) any later version.
10 e67db06e Jia Liu
 *
11 e67db06e Jia Liu
 * This library is distributed in the hope that it will be useful,
12 e67db06e Jia Liu
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 e67db06e Jia Liu
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 e67db06e Jia Liu
 * Lesser General Public License for more details.
15 e67db06e Jia Liu
 *
16 e67db06e Jia Liu
 * You should have received a copy of the GNU Lesser General Public
17 e67db06e Jia Liu
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 e67db06e Jia Liu
 */
19 e67db06e Jia Liu
20 e67db06e Jia Liu
#include "cpu.h"
21 e67db06e Jia Liu
#include "qemu-common.h"
22 022c62cb Paolo Bonzini
#include "exec/gdbstub.h"
23 1de7afc9 Paolo Bonzini
#include "qemu/host-utils.h"
24 e67db06e Jia Liu
#ifndef CONFIG_USER_ONLY
25 e67db06e Jia Liu
#include "hw/loader.h"
26 e67db06e Jia Liu
#endif
27 e67db06e Jia Liu
28 97a8ea5a Andreas Färber
void openrisc_cpu_do_interrupt(CPUState *cs)
29 e67db06e Jia Liu
{
30 97a8ea5a Andreas Färber
    OpenRISCCPU *cpu = OPENRISC_CPU(cs);
31 97a8ea5a Andreas Färber
    CPUOpenRISCState *env = &cpu->env;
32 b6a71ef7 Jia Liu
#ifndef CONFIG_USER_ONLY
33 b6a71ef7 Jia Liu
    if (env->flags & D_FLAG) { /* Delay Slot insn */
34 b6a71ef7 Jia Liu
        env->flags &= ~D_FLAG;
35 b6a71ef7 Jia Liu
        env->sr |= SR_DSX;
36 b6a71ef7 Jia Liu
        if (env->exception_index == EXCP_TICK    ||
37 b6a71ef7 Jia Liu
            env->exception_index == EXCP_INT     ||
38 b6a71ef7 Jia Liu
            env->exception_index == EXCP_SYSCALL ||
39 b6a71ef7 Jia Liu
            env->exception_index == EXCP_FPE) {
40 b6a71ef7 Jia Liu
            env->epcr = env->jmp_pc;
41 b6a71ef7 Jia Liu
        } else {
42 b6a71ef7 Jia Liu
            env->epcr = env->pc - 4;
43 b6a71ef7 Jia Liu
        }
44 b6a71ef7 Jia Liu
    } else {
45 b6a71ef7 Jia Liu
        if (env->exception_index == EXCP_TICK    ||
46 b6a71ef7 Jia Liu
            env->exception_index == EXCP_INT     ||
47 b6a71ef7 Jia Liu
            env->exception_index == EXCP_SYSCALL ||
48 b6a71ef7 Jia Liu
            env->exception_index == EXCP_FPE) {
49 b6a71ef7 Jia Liu
            env->epcr = env->npc;
50 b6a71ef7 Jia Liu
        } else {
51 b6a71ef7 Jia Liu
            env->epcr = env->pc;
52 b6a71ef7 Jia Liu
        }
53 b6a71ef7 Jia Liu
    }
54 b6a71ef7 Jia Liu
55 b6a71ef7 Jia Liu
    /* For machine-state changed between user-mode and supervisor mode,
56 b6a71ef7 Jia Liu
       we need flush TLB when we enter&exit EXCP.  */
57 b6a71ef7 Jia Liu
    tlb_flush(env, 1);
58 b6a71ef7 Jia Liu
59 b6a71ef7 Jia Liu
    env->esr = env->sr;
60 b6a71ef7 Jia Liu
    env->sr &= ~SR_DME;
61 b6a71ef7 Jia Liu
    env->sr &= ~SR_IME;
62 b6a71ef7 Jia Liu
    env->sr |= SR_SM;
63 b6a71ef7 Jia Liu
    env->sr &= ~SR_IEE;
64 b6a71ef7 Jia Liu
    env->sr &= ~SR_TEE;
65 b6a71ef7 Jia Liu
    env->tlb->cpu_openrisc_map_address_data = &cpu_openrisc_get_phys_nommu;
66 b6a71ef7 Jia Liu
    env->tlb->cpu_openrisc_map_address_code = &cpu_openrisc_get_phys_nommu;
67 b6a71ef7 Jia Liu
68 b6a71ef7 Jia Liu
    if (env->exception_index > 0 && env->exception_index < EXCP_NR) {
69 b6a71ef7 Jia Liu
        env->pc = (env->exception_index << 8);
70 b6a71ef7 Jia Liu
    } else {
71 b6a71ef7 Jia Liu
        cpu_abort(env, "Unhandled exception 0x%x\n", env->exception_index);
72 b6a71ef7 Jia Liu
    }
73 b6a71ef7 Jia Liu
#endif
74 b6a71ef7 Jia Liu
75 b6a71ef7 Jia Liu
    env->exception_index = -1;
76 e67db06e Jia Liu
}