interrupts.h revision 1.1 1 1.1 christos /* interrupts.h -- 68HC11 Interrupts Emulation
2 1.1 christos Copyright 1999, 2000, 2001, 2002, 2007, 2008, 2009, 2010, 2011
3 1.1 christos Free Software Foundation, Inc.
4 1.1 christos Written by Stephane Carrez (stcarrez (at) worldnet.fr)
5 1.1 christos
6 1.1 christos This file is part of GDB, GAS, and the GNU binutils.
7 1.1 christos
8 1.1 christos This program is free software; you can redistribute it and/or modify
9 1.1 christos it under the terms of the GNU General Public License as published by
10 1.1 christos the Free Software Foundation; either version 3 of the License, or
11 1.1 christos (at your option) any later version.
12 1.1 christos
13 1.1 christos This program is distributed in the hope that it will be useful,
14 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 1.1 christos GNU General Public License for more details.
17 1.1 christos
18 1.1 christos You should have received a copy of the GNU General Public License
19 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 1.1 christos
21 1.1 christos #ifndef _M6811_SIM_INTERRUPTS_H
22 1.1 christos #define _M6811_SIM_INTERRUPTS_H
23 1.1 christos
24 1.1 christos /* Definition of 68HC11 interrupts. These enum are used as an index
25 1.1 christos in the interrupt table. */
26 1.1 christos enum M6811_INT
27 1.1 christos {
28 1.1 christos M6811_INT_RESERVED1 = 0,
29 1.1 christos M6811_INT_RESERVED2,
30 1.1 christos M6811_INT_RESERVED3,
31 1.1 christos M6811_INT_RESERVED4,
32 1.1 christos M6811_INT_RESERVED5,
33 1.1 christos M6811_INT_RESERVED6,
34 1.1 christos M6811_INT_RESERVED7,
35 1.1 christos M6811_INT_RESERVED8,
36 1.1 christos
37 1.1 christos M6811_INT_RESERVED9,
38 1.1 christos M6811_INT_RESERVED10,
39 1.1 christos M6811_INT_RESERVED11,
40 1.1 christos
41 1.1 christos M6811_INT_SCI,
42 1.1 christos M6811_INT_SPI,
43 1.1 christos M6811_INT_AINPUT,
44 1.1 christos M6811_INT_AOVERFLOW,
45 1.1 christos M6811_INT_TCTN,
46 1.1 christos
47 1.1 christos M6811_INT_OUTCMP5,
48 1.1 christos M6811_INT_OUTCMP4,
49 1.1 christos M6811_INT_OUTCMP3,
50 1.1 christos M6811_INT_OUTCMP2,
51 1.1 christos M6811_INT_OUTCMP1,
52 1.1 christos
53 1.1 christos M6811_INT_INCMP3,
54 1.1 christos M6811_INT_INCMP2,
55 1.1 christos M6811_INT_INCMP1,
56 1.1 christos
57 1.1 christos M6811_INT_RT,
58 1.1 christos M6811_INT_IRQ,
59 1.1 christos M6811_INT_XIRQ,
60 1.1 christos M6811_INT_SWI,
61 1.1 christos M6811_INT_ILLEGAL,
62 1.1 christos
63 1.1 christos M6811_INT_COPRESET,
64 1.1 christos M6811_INT_COPFAIL,
65 1.1 christos
66 1.1 christos M6811_INT_RESET,
67 1.1 christos M6811_INT_NUMBER
68 1.1 christos };
69 1.1 christos
70 1.1 christos
71 1.1 christos /* Structure to describe how to recognize an interrupt in the
72 1.1 christos 68hc11 IO regs. */
73 1.1 christos struct interrupt_def
74 1.1 christos {
75 1.1 christos enum M6811_INT int_number;
76 1.1 christos unsigned char int_paddr;
77 1.1 christos unsigned char int_mask;
78 1.1 christos unsigned char enable_paddr;
79 1.1 christos unsigned char enabled_mask;
80 1.1 christos };
81 1.1 christos
82 1.1 christos #define MAX_INT_HISTORY 64
83 1.1 christos
84 1.1 christos /* Structure used to keep track of interrupt history.
85 1.1 christos This is used to understand in which order interrupts were
86 1.1 christos raised and when. */
87 1.1 christos struct interrupt_history
88 1.1 christos {
89 1.1 christos enum M6811_INT type;
90 1.1 christos
91 1.1 christos /* CPU cycle when interrupt handler is called. */
92 1.1 christos signed64 taken_cycle;
93 1.1 christos
94 1.1 christos /* CPU cycle when the interrupt is first raised by the device. */
95 1.1 christos signed64 raised_cycle;
96 1.1 christos };
97 1.1 christos
98 1.1 christos #define SIM_STOP_WHEN_RAISED 1
99 1.1 christos #define SIM_STOP_WHEN_TAKEN 2
100 1.1 christos
101 1.1 christos /* Information and control of pending interrupts. */
102 1.1 christos struct interrupt
103 1.1 christos {
104 1.1 christos /* CPU cycle when the interrupt is raised by the device. */
105 1.1 christos signed64 cpu_cycle;
106 1.1 christos
107 1.1 christos /* Number of times the interrupt was raised. */
108 1.1 christos unsigned long raised_count;
109 1.1 christos
110 1.1 christos /* Controls whether we must stop the simulator. */
111 1.1 christos int stop_mode;
112 1.1 christos };
113 1.1 christos
114 1.1 christos
115 1.1 christos /* Management of 68HC11 interrupts:
116 1.1 christos - We use a table of 'interrupt_def' to describe the interrupts that must be
117 1.1 christos raised depending on IO register flags (enable and present flags).
118 1.1 christos - We keep a mask of pending interrupts. This mask is refreshed by
119 1.1 christos calling 'interrupts_update_pending'. It must be refreshed each time
120 1.1 christos an IO register is changed.
121 1.1 christos - 'interrupts_process' must be called after each insn. It has two purposes:
122 1.1 christos first it maintains a min/max count of CPU cycles between which interrupts
123 1.1 christos are masked; second it checks for pending interrupts and raise one if
124 1.1 christos interrupts are enabled. */
125 1.1 christos struct interrupts {
126 1.1 christos struct _sim_cpu *cpu;
127 1.1 christos
128 1.1 christos /* Mask of current pending interrupts. */
129 1.1 christos unsigned long pending_mask;
130 1.1 christos
131 1.1 christos /* Address of vector table. This is set depending on the
132 1.1 christos 68hc11 init mode. */
133 1.1 christos uint16 vectors_addr;
134 1.1 christos
135 1.1 christos /* Priority order of interrupts. This is controlled by setting the HPRIO
136 1.1 christos IO register. */
137 1.1 christos enum M6811_INT interrupt_order[M6811_INT_NUMBER];
138 1.1 christos struct interrupt interrupts[M6811_INT_NUMBER];
139 1.1 christos
140 1.1 christos /* Simulator statistics to report useful debug information to users. */
141 1.1 christos
142 1.1 christos /* - Max/Min number of CPU cycles executed with interrupts masked. */
143 1.1 christos signed64 start_mask_cycle;
144 1.1 christos signed64 min_mask_cycles;
145 1.1 christos signed64 max_mask_cycles;
146 1.1 christos signed64 last_mask_cycles;
147 1.1 christos
148 1.1 christos /* - Same for XIRQ. */
149 1.1 christos signed64 xirq_start_mask_cycle;
150 1.1 christos signed64 xirq_min_mask_cycles;
151 1.1 christos signed64 xirq_max_mask_cycles;
152 1.1 christos signed64 xirq_last_mask_cycles;
153 1.1 christos
154 1.1 christos /* - Total number of interrupts raised. */
155 1.1 christos unsigned long nb_interrupts_raised;
156 1.1 christos
157 1.1 christos /* Interrupt history to help understand which interrupts
158 1.1 christos were raised recently and in which order. */
159 1.1 christos int history_index;
160 1.1 christos struct interrupt_history interrupts_history[MAX_INT_HISTORY];
161 1.1 christos };
162 1.1 christos
163 1.1 christos extern void interrupts_initialize (SIM_DESC sd, struct _sim_cpu* cpu);
164 1.1 christos extern void interrupts_reset (struct interrupts* interrupts);
165 1.1 christos extern void interrupts_update_pending (struct interrupts* interrupts);
166 1.1 christos extern int interrupts_get_current (struct interrupts* interrupts);
167 1.1 christos extern int interrupts_process (struct interrupts* interrupts);
168 1.1 christos extern void interrupts_raise (struct interrupts* interrupts,
169 1.1 christos enum M6811_INT number);
170 1.1 christos
171 1.1 christos extern void interrupts_info (SIM_DESC sd,
172 1.1 christos struct interrupts* interrupts);
173 1.1 christos
174 1.1 christos #endif
175