2
0

cpu_pic.c 1.8 KB

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