[NTVDM]
[reactos.git] / reactos / subsystems / mvdm / ntvdm / bios / kbdbios.c
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: kbdbios.c
5 * PURPOSE: VDM Keyboard BIOS Support Library
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #define NDEBUG
12
13 #include "ntvdm.h"
14 #include "emulator.h"
15 #include "cpu/bop.h"
16 #include "int32.h"
17
18 #include "bios.h"
19 // #include "kbdbios.h"
20
21 /* DEFINES ********************************************************************/
22
23 /* BOP Identifiers */
24 #define BOP_KBD_IRQ 0x09
25 #define BOP_KBD_INT 0x16
26
27 /* PUBLIC FUNCTIONS ***********************************************************/
28
29 extern VOID WINAPI BiosKeyboardIrq(LPWORD Stack);
30 static VOID WINAPI KbdBiosIRQ(LPWORD Stack)
31 {
32 /*
33 * Set up a false stack to hardwire the BOP function (that can directly
34 * manipulate CPU registers) to the 32-bit interrupt function (which uses
35 * the stack to be able to modify the original CS:IP and FLAGS).
36 *
37 * See int32.h stack codes.
38 */
39 WORD EmuStack[4];
40 DWORD Flags = getEFLAGS();
41
42 DPRINT1("Calling BOP KbdBiosIRQ\n");
43
44 EmuStack[STACK_FLAGS] = LOWORD(Flags);
45 EmuStack[STACK_CS] = getCS();
46 EmuStack[STACK_IP] = getIP();
47 EmuStack[STACK_INT_NUM] = BOP_KBD_IRQ;
48
49 BiosKeyboardIrq(EmuStack);
50
51 setIP(EmuStack[STACK_IP]);
52 setCS(EmuStack[STACK_CS]);
53 setEFLAGS(MAKELONG(EmuStack[STACK_FLAGS], HIWORD(Flags)));
54 }
55
56 extern VOID WINAPI BiosKeyboardService(LPWORD Stack);
57 static VOID WINAPI KbdBiosINT(LPWORD Stack)
58 {
59 /*
60 * Set up a false stack to hardwire the BOP function (that can directly
61 * manipulate CPU registers) to the 32-bit interrupt function (which uses
62 * the stack to be able to modify the original CS:IP and FLAGS).
63 *
64 * See int32.h stack codes.
65 */
66 WORD EmuStack[4];
67 DWORD Flags = getEFLAGS();
68
69 DPRINT1("Calling BOP KbdBiosINT\n");
70
71 EmuStack[STACK_FLAGS] = LOWORD(Flags);
72 EmuStack[STACK_CS] = getCS();
73 EmuStack[STACK_IP] = getIP();
74 EmuStack[STACK_INT_NUM] = BOP_KBD_IRQ;
75
76 BiosKeyboardService(EmuStack);
77
78 setIP(EmuStack[STACK_IP]);
79 setCS(EmuStack[STACK_CS]);
80 setEFLAGS(MAKELONG(EmuStack[STACK_FLAGS], HIWORD(Flags)));
81 }
82
83 BOOLEAN KbdBiosInitialize(VOID)
84 {
85 /* Register the BIOS support BOPs */
86 RegisterBop(BOP_KBD_IRQ, KbdBiosIRQ); // BiosKeyboardIrq in kbdbios32.c
87 RegisterBop(BOP_KBD_INT, KbdBiosINT); // BiosKeyboardService in kbdbios32.c
88 return TRUE;
89 }
90
91 VOID KbdBiosCleanup(VOID)
92 {
93 /* Unregister the BIOS support BOPs */
94 RegisterBop(BOP_KBD_IRQ, NULL);
95 RegisterBop(BOP_KBD_INT, NULL);
96 }
97
98 /* EOF */