~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to hw/nios2/cpu_pic.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Altera Nios2 CPU PIC
 
3
 *
 
4
 * Copyright (c) 2016 Marek Vasut <marek.vasut@gmail.com>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, see
 
18
 * <http://www.gnu.org/licenses/lgpl-2.1.html>
 
19
 */
 
20
 
 
21
#include "qemu/osdep.h"
 
22
#include "qapi/error.h"
 
23
#include "qemu-common.h"
 
24
#include "cpu.h"
 
25
 
 
26
#include "qemu/config-file.h"
 
27
 
 
28
#include "boot.h"
 
29
 
 
30
static void nios2_pic_cpu_handler(void *opaque, int irq, int level)
 
31
{
 
32
    Nios2CPU *cpu = opaque;
 
33
    CPUNios2State *env = &cpu->env;
 
34
    CPUState *cs = CPU(cpu);
 
35
    int type = irq ? CPU_INTERRUPT_NMI : CPU_INTERRUPT_HARD;
 
36
 
 
37
    if (type == CPU_INTERRUPT_HARD) {
 
38
        env->irq_pending = level;
 
39
 
 
40
        if (level && (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
 
41
            env->irq_pending = 0;
 
42
            cpu_interrupt(cs, type);
 
43
        } else if (!level) {
 
44
            env->irq_pending = 0;
 
45
            cpu_reset_interrupt(cs, type);
 
46
        }
 
47
    } else {
 
48
        if (level) {
 
49
            cpu_interrupt(cs, type);
 
50
        } else {
 
51
            cpu_reset_interrupt(cs, type);
 
52
        }
 
53
    }
 
54
}
 
55
 
 
56
void nios2_check_interrupts(CPUNios2State *env)
 
57
{
 
58
    Nios2CPU *cpu = nios2_env_get_cpu(env);
 
59
    CPUState *cs = CPU(cpu);
 
60
 
 
61
    if (env->irq_pending) {
 
62
        env->irq_pending = 0;
 
63
        cpu_interrupt(cs, CPU_INTERRUPT_HARD);
 
64
    }
 
65
}
 
66
 
 
67
qemu_irq *nios2_cpu_pic_init(Nios2CPU *cpu)
 
68
{
 
69
    return qemu_allocate_irqs(nios2_pic_cpu_handler, cpu, 2);
 
70
}