qemu/hw/nios2/cpu_pic.c
<<
>>
Prefs
   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 "cpu.h"
  23
  24#include "qemu/config-file.h"
  25
  26#include "boot.h"
  27
  28static void nios2_pic_cpu_handler(void *opaque, int irq, int level)
  29{
  30    Nios2CPU *cpu = opaque;
  31    CPUNios2State *env = &cpu->env;
  32    CPUState *cs = CPU(cpu);
  33    int type = irq ? CPU_INTERRUPT_NMI : CPU_INTERRUPT_HARD;
  34
  35    if (type == CPU_INTERRUPT_HARD) {
  36        env->irq_pending = level;
  37
  38        if (level && (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
  39            env->irq_pending = 0;
  40            cpu_interrupt(cs, type);
  41        } else if (!level) {
  42            env->irq_pending = 0;
  43            cpu_reset_interrupt(cs, type);
  44        }
  45    } else {
  46        if (level) {
  47            cpu_interrupt(cs, type);
  48        } else {
  49            cpu_reset_interrupt(cs, type);
  50        }
  51    }
  52}
  53
  54void nios2_check_interrupts(CPUNios2State *env)
  55{
  56    if (env->irq_pending) {
  57        env->irq_pending = 0;
  58        cpu_interrupt(env_cpu(env), CPU_INTERRUPT_HARD);
  59    }
  60}
  61
  62qemu_irq *nios2_cpu_pic_init(Nios2CPU *cpu)
  63{
  64    return qemu_allocate_irqs(nios2_pic_cpu_handler, cpu, 2);
  65}
  66