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"
12 #include "../aseg/keyboard.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;
37 /* Read the real hardware and mask in our OBF if need be. */
40 curdev = (b & 0x20 /* KBD_STAT_MOUSE_OBF */) ? 1 : 0;
41 _ibf_ready = (b & 0x2 /* IBF */) ? 0 : 1;
46 if ((curdev == 0) && (b == 0x01)) { /* Escape */
47 outb(0xCF9, 0x4); /* Reboot */
53 *(unsigned char*)0xAFFD0 /* EAX */ = b;
60 b = *(unsigned char*)0xAFFD0 /* EAX */;
61 dologf("WRITE: %08x (%02x)", cts, b);
62 if ((cts & 0xFFFF) == 0x64)
65 case 0x60 /*KBD_CCMD_WRITE_MODE*/:
66 case 0xD2 /*KBD_CCMD_WRITE_OBUF*/:
67 case 0xD3 /*KBD_CCMD_WRITE_AUX_OBUF*/:
68 case 0xD4 /*KBD_CCMD_WRITE_MOUSE*/:
69 case 0xD1 /*KBD_CCMD_WRITE_OUTPORT*/:
70 _waiting_for_data = 1; /* These all should not be interrupted. */
72 else if ((cts & 0xFFFF) == 0x60)
73 _waiting_for_data = 0;
74 outb(cts & 0xFFFF, b);
78 dolog("Unhandled PCI cycle");
86 static int _inject_ready()
88 return _ibf_ready && !_waiting_for_data;
91 void timer_handler(smi_event_t ev)
93 static unsigned int ticks = 0;
95 smi_disable_event(SMI_EVENT_FAST_TIMER);
96 smi_enable_event(SMI_EVENT_FAST_TIMER);
98 if (kbd_has_injected_scancode() && _inject_ready())
100 smi_disable_event(SMI_EVENT_DEVTRAP_KBC);
101 outputf("Injecting key");
102 /* Actually do the inject. */
103 outb(0x64, 0xD2); /* "Inject, please!" */
104 while (inb(0x64) & 0x02) /* Busy? */
106 outb(0x60, kbd_get_injected_scancode()); /* data */
107 while (inb(0x64) & 0x02) /* wait for completion */
109 smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
112 outb(0x80, (ticks++) & 0xFF);
114 if (!fb || fb->curmode.text)
118 void kbc_handler(smi_event_t ev)
123 void gbl_rls_handler(smi_event_t ev)
127 ecx = *(unsigned long*)0xAFFD4;
129 packet_t * packet = check_packet(ecx);
132 dologf("WARN: bad packet at %08x", ecx);
136 outputf("Got packet: type %08x", packet->type);
138 if (packet->type == 42) {
139 dump_log((char *)packet->data);
140 *(unsigned long*)0xAFFD4 = 42;
141 } else if (packet->type == 0xAA) {
144 *(unsigned long*)0xAFFD4 = 0x2BADD00D;