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