3 #include <video_defines.h>
6 #include <pci-bother.h>
9 #include "../net/net.h"
10 #include "vga-overlay.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;
20 static int adding_locks_from_time_to_time = 0;
22 static int _inject_ready()
24 return _ibf_ready && !_waiting_for_data && !adding_locks_from_time_to_time;
29 if (kbd_has_injected_scancode() && _inject_ready())
31 smi_disable_event(SMI_EVENT_DEVTRAP_KBC);
33 while (inb(0x64) & 0x02) /* Busy? */
35 outb(0x64, 0xD2); /* "Inject, please!" */
36 while (inb(0x64) & 0x02) /* Busy? */
38 outb(0x60, kbd_get_injected_scancode()); /* data */
39 while ((inb(0x64) & 0x02) && i--) /* wait for completion */
42 adding_locks_from_time_to_time++;
43 smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
44 } else if (kbd_has_injected_scancode())
45 outputf("Would like to inject, but %d %d", _ibf_ready, _waiting_for_data);
64 /* Read the real hardware and mask in our OBF if need be. */
67 curdev = (b & 0x20 /* KBD_STAT_MOUSE_OBF */) ? 1 : 0;
69 if ((curdev == 0) && kbd_has_injected_scancode())
72 _ibf_ready = (b & 0x2 /* IBF */) ? 0 : 1;
76 if ((curdev == 0) && kbd_has_injected_scancode() && !adding_locks_from_time_to_time)
77 b = kbd_get_injected_scancode();
80 if (adding_locks_from_time_to_time)
81 adding_locks_from_time_to_time--;
82 if ((curdev == 0) && (b == 0x01)) { /* Escape */
83 outb(0xCF9, 0x4); /* Reboot */
89 b = inb(cts & 0xFFFF);
92 dologf("READ : %08x (%02x)", cts, b);
93 *(unsigned char*)0xAFFD0 /* EAX */ = b;
100 b = *(unsigned char*)0xAFFD0 /* EAX */;
101 dologf("WRITE: %08x (%02x)", cts, b);
102 if ((cts & 0xFFFF) == 0x64)
105 case 0x60 /*KBD_CCMD_WRITE_MODE*/:
106 case 0xD2 /*KBD_CCMD_WRITE_OBUF*/:
107 case 0xD3 /*KBD_CCMD_WRITE_AUX_OBUF*/:
108 case 0xD4 /*KBD_CCMD_WRITE_MOUSE*/:
109 case 0xD1 /*KBD_CCMD_WRITE_OUTPORT*/:
110 _waiting_for_data = 1; /* These all should not be interrupted. */
112 else if ((cts & 0xFFFF) == 0x60)
113 _waiting_for_data = 0;
114 outb(cts & 0xFFFF, b);
118 dolog("Unhandled PCI cycle");
126 void timer_handler(smi_event_t ev)
128 static unsigned int ticks = 0;
130 smi_disable_event(SMI_EVENT_FAST_TIMER);
131 smi_enable_event(SMI_EVENT_FAST_TIMER);
135 outb(0x80, (ticks++) & 0xFF);
137 if (!fb || fb->curmode.text)
141 void kbc_handler(smi_event_t ev)
146 void gbl_rls_handler(smi_event_t ev)
150 ecx = *(unsigned long*)0xAFFD4;
152 packet_t * packet = check_packet(ecx);
155 dologf("WARN: bad packet at %08x", ecx);
159 outputf("Got packet: type %08x", packet->type);
161 if (packet->type == 42) {
162 dump_log((char *)packet->data);
163 *(unsigned long*)0xAFFD4 = 42;
164 } else if (packet->type == 0xAA) {
165 kbd_inject_keysym('A', 1);
166 kbd_inject_keysym('A', 0);
168 *(unsigned long*)0xAFFD4 = 0x2BADD00D;