-
Notifications
You must be signed in to change notification settings - Fork 6
/
emu-int.c
195 lines (148 loc) · 3.23 KB
/
emu-int.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//------------------------------------------------------------------------------
// EMU86 - Generic interrupt
//------------------------------------------------------------------------------
#include "emu-mem-io.h"
#include "emu-proc.h"
#include "emu-serial.h"
#include "emu-int.h"
#include <stdlib.h>
#include <stdio.h>
//------------------------------------------------------------------------------
// Interrupt controller
//------------------------------------------------------------------------------
int _int_cpu = 0;
// Interrupt controller procedure
static void int_proc ()
{
int i = 0;
for (int line = 0; line < _int_line_max; line++)
{
// Ignore requested if already serviced
if (_int_req [line] && !_int_serv [line])
{
// At least one to signal
i = 1;
break;
}
}
_int_cpu = i;
}
// Set interrupt line
void int_line_set (int line, int stat)
{
if (stat)
{
// Ignore the signal if masked
if (!_int_mask [line]) _int_req [line] = 1;
}
else
{
// Cancel request in level mode
if (_int_mode [line] == INT_LEVEL) _int_req [line] = 0;
}
int_proc ();
}
// Interrupt acknowledge
// Provide vector to processor
// then set interrupt as serviced
int int_ack (byte_t * vect)
{
int err = 0;
while (1) {
// Get requested of top priority
int req = -1;
int prio_min = _int_prio_max;
for (int line = 0; line < _int_line_max; line++) {
int prio = _int_prio [line];
if (_int_req [line] && prio < prio_min) {
req = line;
prio_min = prio;
}
}
// TODO: manage spurious ACK
if (req < 0)
{
printf ("\nerror: spurious ACK\n");
err = -1;
break;
}
if (_int_mode [req] == INT_EDGE) _int_req [req] = 0;
*vect = _int_vect [req];
_int_serv [req] = 1;
int_proc ();
break;
}
return err;
}
// End of interrupt servicing (EOI)
// Explicit mode with specified INT line
void int_end_line (int line)
{
if (_int_serv [line] == 0)
{
printf ("\nwarning: spurious EOI: line=%i\n", line);
}
else
{
_int_serv [line] = 0;
int_proc ();
}
}
// End of interrupt servicing (EOI)
// Implicit mode based on priority
void int_end_prio ()
{
// Get serviced of top priority
int serv = -1;
int prio_min = _int_prio_max;
for (int line = 0; line < _int_line_max; line++) {
int prio = _int_prio [line];
if (_int_serv [line] && prio < prio_min) {
serv = line;
prio_min = prio;
}
}
if (serv < 0)
{
puts ("\nwarning: spurious implicit EOI");
}
else
{
_int_serv [serv] = 0;
int_proc ();
}
}
//------------------------------------------------------------------------------
// Dummy INT3 as we already run under emulator
byte_t _break_int_flag = 0;
int int_03h (void)
{
//puts ("warning: INT3");
_break_int_flag = 1;
return 0;
}
//------------------------------------------------------------------------------
// Search for emulated interrupt handler
int int_hand (byte_t i)
{
int err;
int_num_hand_t * desc = _int_tab;
while (1)
{
byte_t num = desc->num;
int_hand_t hand = desc->hand;
if (!num || !hand)
{
err = 1; // no emulated handler
break;
}
if (num == i)
{
err = (*hand) ();
break;
}
desc++;
}
return err;
}
//------------------------------------------------------------------------------