2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
5 * PURPOSE: 32-bit Interrupt Handlers
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
10 /* INCLUDES *******************************************************************/
19 /* PRIVATE VARIABLES **********************************************************/
22 * This is the list of registered 32-bit Interrupt handlers.
24 EMULATOR_INT32_PROC Int32Proc
[EMULATOR_MAX_INT32_NUM
] = { NULL
};
27 #define BOP_CONTROL 0xFF // Control BOP Handler
28 #define BOP_CONTROL_DEFFUNC 0x00 // Default Control BOP Function
30 /* 32-bit Interrupt dispatcher function code for the Control BOP Handler */
31 #define BOP_CONTROL_INT32 0xFF
33 /* PUBLIC FUNCTIONS ***********************************************************/
35 VOID WINAPI
Int32Dispatch(LPWORD Stack
)
37 /* Get the interrupt number */
38 BYTE IntNum
= LOBYTE(Stack
[STACK_INT_NUM
]);
40 /* Call the 32-bit Interrupt handler */
41 if (Int32Proc
[IntNum
] != NULL
)
42 Int32Proc
[IntNum
](Stack
);
44 DPRINT("Unhandled 32-bit interrupt: 0x%02X, AX = 0x%04X\n", IntNum
, getAX());
47 VOID WINAPI
ControlBop(LPWORD Stack
)
49 /* Get the Function Number and skip it */
50 BYTE FuncNum
= *(PBYTE
)SEG_OFF_TO_PTR(getCS(), getIP());
53 if (FuncNum
== BOP_CONTROL_INT32
)
56 DPRINT("Unassigned Control BOP Function: 0x%02X\n", FuncNum
);
59 VOID
InitializeInt32(WORD BiosSegment
)
61 LPDWORD IntVecTable
= (LPDWORD
)BaseAddress
;
62 LPBYTE BiosCode
= (LPBYTE
)SEG_OFF_TO_PTR(BiosSegment
, 0);
64 WORD BopSeqOffset
, Offset
= 0;
66 /* Generate ISR stubs and fill the IVT */
67 for (i
= 0x00; i
<= 0xFF; i
++)
69 Offset
= INT_HANDLER_OFFSET
+ (i
<< 4);
70 IntVecTable
[i
] = MAKELONG(Offset
, BiosSegment
);
72 BiosCode
[Offset
++] = 0xFA; // cli
74 BiosCode
[Offset
++] = 0x6A; // push i
75 BiosCode
[Offset
++] = (UCHAR
)i
;
77 BiosCode
[Offset
++] = 0x6A; // push 0
78 BiosCode
[Offset
++] = 0x00;
80 BopSeqOffset
= COMMON_STUB_OFFSET
- (Offset
+ 3);
82 BiosCode
[Offset
++] = 0xE9; // jmp near BOP_SEQ
83 BiosCode
[Offset
++] = LOBYTE(BopSeqOffset
);
84 BiosCode
[Offset
++] = HIBYTE(BopSeqOffset
);
87 /* Write the common stub code */
88 Offset
= COMMON_STUB_OFFSET
;
91 BiosCode
[Offset
++] = 0xF8; // clc
93 BiosCode
[Offset
++] = LOBYTE(EMULATOR_BOP
); // BOP sequence
94 BiosCode
[Offset
++] = HIBYTE(EMULATOR_BOP
);
95 BiosCode
[Offset
++] = BOP_CONTROL
; // Control BOP
96 BiosCode
[Offset
++] = BOP_CONTROL_INT32
; // 32-bit Interrupt dispatcher
98 BiosCode
[Offset
++] = 0x73; // jnc EXIT (offset +4)
99 BiosCode
[Offset
++] = 0x04;
101 BiosCode
[Offset
++] = 0xFB; // sti
103 // HACK: The following instruction should be HLT!
104 BiosCode
[Offset
++] = 0x90; // nop
106 BiosCode
[Offset
++] = 0xEB; // jmp BOP_SEQ (offset -11)
107 BiosCode
[Offset
++] = 0xF5;
110 BiosCode
[Offset
++] = 0x83; // add sp, 4
111 BiosCode
[Offset
++] = 0xC4;
112 BiosCode
[Offset
++] = 0x04;
114 BiosCode
[Offset
++] = 0xCF; // iret
116 /* Register the Control BOP */
117 RegisterBop(BOP_CONTROL
, ControlBop
);
120 VOID
RegisterInt32(BYTE IntNumber
, EMULATOR_INT32_PROC IntHandler
)
122 Int32Proc
[IntNumber
] = IntHandler
;