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