int.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* int.c --- M32C interrupt handling.
  2. Copyright (C) 2005-2015 Free Software Foundation, Inc.
  3. Contributed by Red Hat, Inc.
  4. This file is part of the GNU simulators.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "int.h"
  16. #include "cpu.h"
  17. #include "mem.h"
  18. static void
  19. trigger_interrupt (int addr, int clear_u)
  20. {
  21. int s = get_reg (sp);
  22. int f = get_reg (flags);
  23. int p = get_reg (pc);
  24. if (clear_u)
  25. set_flags (FLAGBIT_U, 0);
  26. set_flags (FLAGBIT_I | FLAGBIT_D, 0);
  27. if (A16)
  28. {
  29. s -= 4;
  30. put_reg (sp, s);
  31. mem_put_hi (s, p);
  32. mem_put_qi (s + 2, f);
  33. mem_put_qi (s + 3, ((f >> 4) & 0x0f) | (p >> 16));
  34. }
  35. else
  36. {
  37. s -= 6;
  38. put_reg (sp, s);
  39. mem_put_si (s, p);
  40. mem_put_hi (s + 4, f);
  41. }
  42. put_reg (pc, mem_get_psi (addr));
  43. }
  44. void
  45. trigger_fixed_interrupt (int addr)
  46. {
  47. trigger_interrupt (addr, 1);
  48. }
  49. void
  50. trigger_based_interrupt (int vector)
  51. {
  52. int addr = get_reg (intb) + vector * 4;
  53. trigger_interrupt (addr, vector <= 31);
  54. }
  55. void
  56. trigger_peripheral_interrupt (int vector, int icaddr)
  57. {
  58. unsigned char old_ic = mem_get_qi (icaddr);
  59. int addr = get_reg (intb) + vector * 4;
  60. trigger_interrupt (addr, 1);
  61. put_reg (flags, (get_reg (flags) & 0x8fff) | ((old_ic & 7) << 12));
  62. mem_put_qi (icaddr, old_ic & ~ 0x08);
  63. }