ReactOS 0.4.15-dev-7958-gcd0bb1a
pic.c File Reference
#include "ntvdm.h"
#include <debug.h>
#include "emulator.h"
#include "pic.h"
#include "io.h"
Include dependency graph for pic.c:

Go to the source code of this file.

Classes

struct  _PIC
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _PIC PIC
 
typedef struct _PICPPIC
 

Functions

static BYTE WINAPI PicReadCommand (USHORT Port)
 
static VOID WINAPI PicWriteCommand (USHORT Port, BYTE Data)
 
static BYTE WINAPI PicReadData (USHORT Port)
 
static VOID WINAPI PicWriteData (USHORT Port, BYTE Data)
 
VOID PicInterruptRequest (BYTE Number)
 
BYTE PicGetInterrupt (VOID)
 
VOID PicInitialize (VOID)
 
VOID WINAPI call_ica_hw_interrupt (INT ms, BYTE line, INT count)
 
WORD WINAPI VDDReserveIrqLine (IN HANDLE hVdd, IN WORD IrqLine)
 
BOOL WINAPI VDDReleaseIrqLine (IN HANDLE hVdd, IN WORD IrqLine)
 

Variables

static PIC MasterPic
 
static PIC SlavePic
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file pic.c.

Typedef Documentation

◆ PIC

typedef struct _PIC PIC

◆ PPIC

typedef struct _PIC * PPIC

Function Documentation

◆ call_ica_hw_interrupt()

VOID WINAPI call_ica_hw_interrupt ( INT  ms,
BYTE  line,
INT  count 
)

Definition at line 308 of file pic.c.

311{
312 BYTE InterruptNumber = line;
313
314 /* Check for PIC validity */
315 if (ms != ICA_MASTER && ms != ICA_SLAVE) return;
316
317 /*
318 * Adjust the interrupt request number according to the parameters,
319 * by adding an offset == 8 to the interrupt number.
320 *
321 * Indeed VDDs calling this function usually subtracts 8 so that they give:
322 *
323 * ms | line | corresponding interrupt number
324 * ------------+--------+--------------------------------
325 * ICA_MASTER | 0 -- 7 | 0 -- 7
326 * ICA_SLAVE | 0 -- 7 | 8 -- 15
327 *
328 * and PicInterruptRequest subtracts again 8 to the interrupt number
329 * if it is greater or equal than 8 (so that it determines which PIC
330 * to use via the interrupt number).
331 */
332 if (ms == ICA_SLAVE) InterruptNumber += 8;
333
334 /* Send the specified number of interrupt requests */
335 while (count-- > 0)
336 {
337 PicInterruptRequest(InterruptNumber);
338 /*
339 * FIXME: We should now restart 16-bit emulation and wait for its termination:
340 *
341 * "When the VDD calls VDDSimulateInterrupt, the address pointed to by
342 * the interrupt vector starts running in 16-bit mode. For an asynchronous
343 * interrupt, the VDD should create another thread and call VDDSimulateInterrupt
344 * from that thread."
345 */
346 }
347}
GLuint GLuint GLsizei count
Definition: gl.h:1545
Definition: parser.c:49
VOID PicInterruptRequest(BYTE Number)
Definition: pic.c:192
#define ICA_MASTER
Definition: vddsvc.h:32
#define ICA_SLAVE
Definition: vddsvc.h:33
unsigned char BYTE
Definition: xxhash.c:193

◆ PicGetInterrupt()

BYTE PicGetInterrupt ( VOID  )

Definition at line 244 of file pic.c.

245{
246 UINT i;
247
248 /* Search the master PIC interrupts by priority */
249 for (i = 0; i < 8; i++)
250 {
251 if (MasterPic.IntRequestRegister & (1 << i))
252 {
253 /* Clear the IRR flag */
254 MasterPic.IntRequestRegister &= ~(1 << i);
255
256 /* Set the ISR flag, unless AEOI is enabled */
258
259 /* Return the interrupt number */
260 return MasterPic.IntOffset + i;
261 }
262 }
263
264 /* Search the slave PIC interrupts by priority */
265 for (i = 0; i < 8; i++)
266 {
267 if (SlavePic.IntRequestRegister & (1 << i))
268 {
269 /* Clear the IRR flag */
270 SlavePic.IntRequestRegister &= ~(1 << i);
271
272 if ((i == 1) && SlavePic.CascadeRegisterSet)
273 {
274 /* This interrupt is routed to the master PIC */
276 }
277 else
278 {
279 /* Set the ISR flag, unless AEOI is enabled */
281
282 /* Return the interrupt number */
283 return SlavePic.IntOffset + i;
284 }
285 }
286 }
287
288 /* Spurious interrupt */
289 if (MasterPic.InServiceRegister & (1 << 2))
290 return SlavePic.IntOffset + 7;
291 else
292 return MasterPic.IntOffset + 7;
293}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
BYTE CascadeRegister
Definition: pic.c:32
BOOLEAN CascadeRegisterSet
Definition: pic.c:33
BYTE IntOffset
Definition: pic.c:30
BYTE IntRequestRegister
Definition: pic.c:28
BOOLEAN AutoEoi
Definition: pic.c:34
BYTE InServiceRegister
Definition: pic.c:29
static PIC MasterPic
Definition: pic.c:39
static PIC SlavePic
Definition: pic.c:39

Referenced by EmulatorIntAcknowledge().

◆ PicInitialize()

VOID PicInitialize ( VOID  )

Definition at line 295 of file pic.c.

296{
297 /* Register the I/O Ports */
302}
static BYTE WINAPI PicReadCommand(USHORT Port)
Definition: pic.c:43
static BYTE WINAPI PicReadData(USHORT Port)
Definition: pic.c:120
static VOID WINAPI PicWriteCommand(USHORT Port, BYTE Data)
Definition: pic.c:66
static VOID WINAPI PicWriteData(USHORT Port, BYTE Data)
Definition: pic.c:129
#define PIC_SLAVE_DATA
Definition: pic.h:18
#define PIC_MASTER_CMD
Definition: pic.h:15
#define PIC_SLAVE_CMD
Definition: pic.h:17
#define PIC_MASTER_DATA
Definition: pic.h:16
VOID RegisterIoPort(USHORT Port, EMULATOR_INB_PROC InHandler, EMULATOR_OUTB_PROC OutHandler)
Definition: io.c:320

Referenced by EmulatorInitialize().

◆ PicInterruptRequest()

VOID PicInterruptRequest ( BYTE  Number)

Definition at line 192 of file pic.c.

193{
194 BYTE i;
195
196 if (/* Number >= 0 && */ Number < 8)
197 {
198 /* Check if any of the higher-priority interrupts are busy */
199 for (i = 0; i <= Number; i++)
200 {
201 if (MasterPic.InServiceRegister & (1 << Number)) return;
202 }
203
204 /* Check if the interrupt is masked */
205 if (MasterPic.MaskRegister & (1 << Number)) return;
206
207 /* Set the appropriate bit in the IRR and interrupt the CPU */
210 }
211 else if (Number >= 8 && Number < 16)
212 {
213 Number -= 8;
214
215 /*
216 * The slave PIC is connected to IRQ 2, always! If the master PIC
217 * was misconfigured, don't do anything.
218 */
219 if (!(MasterPic.CascadeRegister & (1 << 2))
221 {
222 return;
223 }
224
225 /* Check if any of the higher-priority interrupts are busy */
226 if (MasterPic.InServiceRegister != 0) return;
227 for (i = 0; i <= Number; i++)
228 {
229 if (SlavePic.InServiceRegister & (1 << Number)) return;
230 }
231
232 /* Check if the interrupt is masked */
233 if (SlavePic.MaskRegister & (1 << Number)) return;
234
235 /* Set the IRQ 2 bit in the master ISR */
237
238 /* Set the appropriate bit in the IRR and interrupt the CPU */
241 }
242}
VOID EmulatorInterruptSignal(VOID)
Definition: emulator.c:120
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
BYTE MaskRegister
Definition: pic.c:27

Referenced by call_ica_hw_interrupt(), EmulatorFpu(), GeneratePS2Irq(), PitChan0Out(), RtcPeriodicTick(), and RtcTimeUpdate().

◆ PicReadCommand()

static BYTE WINAPI PicReadCommand ( USHORT  Port)
static

Definition at line 43 of file pic.c.

44{
45 PPIC Pic;
46
47 /* Which PIC are we accessing? */
48 if (Port == PIC_MASTER_CMD)
49 Pic = &MasterPic;
50 else // if (Port == PIC_SLAVE_CMD)
51 Pic = &SlavePic;
52
53 if (Pic->ReadIsr)
54 {
55 /* Read the in-service register */
56 Pic->ReadIsr = FALSE;
57 return Pic->InServiceRegister;
58 }
59 else
60 {
61 /* Read the interrupt request register */
62 return Pic->IntRequestRegister;
63 }
64}
#define FALSE
Definition: types.h:117
CPPORT Port[4]
Definition: headless.c:35
Definition: pic.c:25
BOOLEAN ReadIsr
Definition: pic.c:36

Referenced by PicInitialize().

◆ PicReadData()

static BYTE WINAPI PicReadData ( USHORT  Port)
static

Definition at line 120 of file pic.c.

121{
122 /* Read the mask register */
123 if (Port == PIC_MASTER_DATA)
124 return MasterPic.MaskRegister;
125 else // if (Port == PIC_SLAVE_DATA)
126 return SlavePic.MaskRegister;
127}

Referenced by PicInitialize().

◆ PicWriteCommand()

static VOID WINAPI PicWriteCommand ( USHORT  Port,
BYTE  Data 
)
static

Definition at line 66 of file pic.c.

67{
68 PPIC Pic;
69
70 /* Which PIC are we accessing? */
71 if (Port == PIC_MASTER_CMD)
72 Pic = &MasterPic;
73 else // if (Port == PIC_SLAVE_CMD)
74 Pic = &SlavePic;
75
76 if (Data & PIC_ICW1)
77 {
78 /* Start initialization */
79 Pic->Initialization = TRUE;
80 Pic->IntOffset = 0xFF;
82 Pic->ConfigRegister = Data;
83 return;
84 }
85
86 if (Data & PIC_OCW3)
87 {
88 /* This is an OCR3 */
90 {
91 /* Return the ISR on next read from command port */
92 Pic->ReadIsr = TRUE;
93 }
94
95 return;
96 }
97
98 /* This is an OCW2 */
99 if (Data & PIC_OCW2_EOI)
100 {
101 if (Data & PIC_OCW2_SL)
102 {
103 /* If the SL bit is set, clear a specific IRQ */
104 Pic->InServiceRegister &= ~(1 << (Data & PIC_OCW2_NUM_MASK));
105 }
106 else
107 {
108 /* Otherwise, clear all of them */
109 Pic->InServiceRegister = 0;
110 }
111
113 {
114 /* Signal the next IRQ */
116 }
117 }
118}
#define TRUE
Definition: types.h:120
BOOLEAN Initialization
Definition: pic.c:26
BYTE ConfigRegister
Definition: pic.c:31
#define PIC_OCW2_NUM_MASK
Definition: pic.h:26
#define PIC_OCW2_SL
Definition: pic.h:28
#define PIC_OCW2_EOI
Definition: pic.h:27
#define PIC_OCW3_READ_ISR
Definition: pic.h:31
#define PIC_OCW3
Definition: pic.h:30
#define PIC_ICW1
Definition: pic.h:20

Referenced by PicInitialize().

◆ PicWriteData()

static VOID WINAPI PicWriteData ( USHORT  Port,
BYTE  Data 
)
static

Definition at line 129 of file pic.c.

130{
131 PPIC Pic;
132
133 /* Which PIC are we accessing? */
134 if (Port == PIC_MASTER_DATA)
135 Pic = &MasterPic;
136 else // if (Port == PIC_SLAVE_DATA)
137 Pic = &SlavePic;
138
139 /* Is the PIC ready? */
140 if (!Pic->Initialization)
141 {
142 /* Yes, this is an OCW1 */
143 Pic->MaskRegister = Data;
144 return;
145 }
146
147 /* Has the interrupt offset been set? */
148 if (Pic->IntOffset == 0xFF)
149 {
150 /* This is an ICW2, set the offset (last three bits always zero) */
151 Pic->IntOffset = Data & 0xF8;
152
153 /* Check if we are in single mode and don't need an ICW4 */
155 && !(Pic->ConfigRegister & PIC_ICW1_ICW4))
156 {
157 /* Yes, done initializing */
158 Pic->Initialization = FALSE;
159 }
160 return;
161 }
162
163 /* Check if we are in cascade mode and the cascade register was not set */
165 {
166 /* This is an ICW3 */
167 Pic->CascadeRegister = Data;
169
170 /* Check if we need an ICW4 */
171 if (!(Pic->ConfigRegister & PIC_ICW1_ICW4))
172 {
173 /* No, done initializing */
174 Pic->Initialization = FALSE;
175 }
176 return;
177 }
178
179 /* This must be an ICW4, we will ignore the 8086 bit (assume always set) */
180 if (Data & PIC_ICW4_AEOI)
181 {
182 /* Use automatic end-of-interrupt */
183 Pic->AutoEoi = TRUE;
184 }
185
186 /* Done initializing */
187 Pic->Initialization = FALSE;
188}
#define PIC_ICW1_SINGLE
Definition: pic.h:22
#define PIC_ICW1_ICW4
Definition: pic.h:21
#define PIC_ICW4_AEOI
Definition: pic.h:24

Referenced by PicInitialize().

◆ VDDReleaseIrqLine()

BOOL WINAPI VDDReleaseIrqLine ( IN HANDLE  hVdd,
IN WORD  IrqLine 
)

Definition at line 361 of file pic.c.

363{
366 return FALSE;
367}
#define UNIMPLEMENTED
Definition: debug.h:115
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752

◆ VDDReserveIrqLine()

WORD WINAPI VDDReserveIrqLine ( IN HANDLE  hVdd,
IN WORD  IrqLine 
)

Definition at line 351 of file pic.c.

353{
356 return 0xFFFF;
357}

Variable Documentation

◆ MasterPic

PIC MasterPic
static

◆ SlavePic

PIC SlavePic
static