3 #include <video_defines.h>
6 #include <pci-bother.h>
9 #include "../net/net.h"
10 #include "vga-overlay.h"
11 #include "../aseg/packet.h"
14 unsigned int lastctr = 0;
15 extern unsigned int counter;
17 static int _ibf_ready = 0;
18 static int _waiting_for_data = 0;
19 static int curdev = 0;
21 static int _inject_ready()
23 return _ibf_ready && !_waiting_for_data;
28 if (kbd_has_injected_scancode() && _inject_ready())
30 smi_disable_event(SMI_EVENT_DEVTRAP_KBC);
32 while (inb(0x64) & 0x02) /* Busy? */
34 outb(0x64, 0xD2); /* "Inject, please!" */
35 while (inb(0x64) & 0x02) /* Busy? */
37 outb(0x60, kbd_get_injected_scancode()); /* data */
38 while ((inb(0x64) & 0x02) && i--) /* wait for completion */
40 smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
41 } else if (kbd_has_injected_scancode())
42 outputf("Would like to inject, but %d %d", _ibf_ready, _waiting_for_data);
61 /* Read the real hardware and mask in our OBF if need be. */
64 curdev = (b & 0x20 /* KBD_STAT_MOUSE_OBF */) ? 1 : 0;
66 if ((curdev == 0) && kbd_has_injected_scancode())
69 _ibf_ready = (b & 0x2 /* IBF */) ? 0 : 1;
73 if ((curdev == 0) && kbd_has_injected_scancode())
74 b = kbd_get_injected_scancode();
77 if ((curdev == 0) && (b == 0x01)) { /* Escape */
78 outb(0xCF9, 0x4); /* Reboot */
84 dologf("READ : %08x (%02x)", cts, b);
85 *(unsigned char*)0xAFFD0 /* EAX */ = b;
92 b = *(unsigned char*)0xAFFD0 /* EAX */;
93 dologf("WRITE: %08x (%02x)", cts, b);
94 if ((cts & 0xFFFF) == 0x64)
97 case 0x60 /*KBD_CCMD_WRITE_MODE*/:
98 case 0xD2 /*KBD_CCMD_WRITE_OBUF*/:
99 case 0xD3 /*KBD_CCMD_WRITE_AUX_OBUF*/:
100 case 0xD4 /*KBD_CCMD_WRITE_MOUSE*/:
101 case 0xD1 /*KBD_CCMD_WRITE_OUTPORT*/:
102 _waiting_for_data = 1; /* These all should not be interrupted. */
104 else if ((cts & 0xFFFF) == 0x60)
105 _waiting_for_data = 0;
106 outb(cts & 0xFFFF, b);
110 dolog("Unhandled PCI cycle");
118 void timer_handler(smi_event_t ev)
120 static unsigned int ticks = 0;
122 smi_disable_event(SMI_EVENT_FAST_TIMER);
123 smi_enable_event(SMI_EVENT_FAST_TIMER);
127 outb(0x80, (ticks++) & 0xFF);
129 if (!fb || fb->curmode.text)
133 void kbc_handler(smi_event_t ev)
138 void gbl_rls_handler(smi_event_t ev)
142 ecx = *(unsigned long*)0xAFFD4;
144 packet_t * packet = check_packet(ecx);
147 dologf("WARN: bad packet at %08x", ecx);
151 outputf("Got packet: type %08x", packet->type);
153 if (packet->type == 42) {
154 dump_log((char *)packet->data);
155 *(unsigned long*)0xAFFD4 = 42;
156 } else if (packet->type == 0xAA) {
157 kbd_inject_keysym('A', 1);
158 kbd_inject_keysym('A', 0);
160 *(unsigned long*)0xAFFD4 = 0x2BADD00D;