]>
Commit | Line | Data |
---|---|---|
722e5aea JP |
1 | #include <io.h> |
2 | #include <smram.h> | |
3 | #include <video_defines.h> | |
4 | #include <minilib.h> | |
5 | #include <smi.h> | |
6 | #include <pci-bother.h> | |
5cb80fe1 | 7 | #include <fb.h> |
5d467741 | 8 | #include <output.h> |
722e5aea JP |
9 | #include "../net/net.h" |
10 | #include "vga-overlay.h" | |
11 | #include "../aseg/packet.h" | |
91cc1340 | 12 | #include "keyboard.h" |
722e5aea JP |
13 | |
14 | unsigned int lastctr = 0; | |
15 | extern unsigned int counter; | |
16 | ||
5d467741 JW |
17 | static int _ibf_ready = 0; |
18 | static int _waiting_for_data = 0; | |
722e5aea JP |
19 | static int curdev = 0; |
20 | ||
722e5aea JP |
21 | void pci_dump() { |
22 | unsigned long cts; | |
23 | ||
24 | cts = inl(0x84C); | |
25 | ||
26 | outl(0x840, 0x0); | |
27 | outl(0x848, 0x0); | |
28 | switch(cts&0xF0000) | |
29 | { | |
30 | case 0x20000: | |
31 | { | |
32 | unsigned char b; | |
33 | ||
34 | switch (cts & 0xFFFF) | |
35 | { | |
36 | case 0x64: | |
37 | /* Read the real hardware and mask in our OBF if need be. */ | |
38 | b = inb(0x64); | |
5d467741 JW |
39 | |
40 | curdev = (b & 0x20 /* KBD_STAT_MOUSE_OBF */) ? 1 : 0; | |
41 | _ibf_ready = (b & 0x2 /* IBF */) ? 0 : 1; | |
42 | ||
722e5aea JP |
43 | break; |
44 | case 0x60: | |
5d467741 | 45 | b = inb(0x60); |
722e5aea JP |
46 | if ((curdev == 0) && (b == 0x01)) { /* Escape */ |
47 | outb(0xCF9, 0x4); /* Reboot */ | |
48 | return; | |
49 | } | |
722e5aea JP |
50 | break; |
51 | } | |
52 | ||
53 | *(unsigned char*)0xAFFD0 /* EAX */ = b; | |
54 | break; | |
55 | } | |
56 | case 0x30000: | |
57 | { | |
58 | unsigned char b; | |
59 | ||
60 | b = *(unsigned char*)0xAFFD0 /* EAX */; | |
61 | dologf("WRITE: %08x (%02x)", cts, b); | |
5d467741 JW |
62 | if ((cts & 0xFFFF) == 0x64) |
63 | switch(b) | |
64 | { | |
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. */ | |
71 | } | |
72 | else if ((cts & 0xFFFF) == 0x60) | |
73 | _waiting_for_data = 0; | |
722e5aea JP |
74 | outb(cts & 0xFFFF, b); |
75 | break; | |
76 | } | |
77 | default: | |
78 | dolog("Unhandled PCI cycle"); | |
79 | } | |
80 | ||
81 | outl(0x840, 0x0); | |
82 | outl(0x844, 0x1000); | |
83 | outl(0x848, 0x1000); | |
84 | } | |
85 | ||
5d467741 JW |
86 | static int _inject_ready() |
87 | { | |
88 | return _ibf_ready && !_waiting_for_data; | |
89 | } | |
90 | ||
722e5aea JP |
91 | void timer_handler(smi_event_t ev) |
92 | { | |
93 | static unsigned int ticks = 0; | |
94 | ||
95 | smi_disable_event(SMI_EVENT_FAST_TIMER); | |
96 | smi_enable_event(SMI_EVENT_FAST_TIMER); | |
97 | ||
5d467741 | 98 | if (kbd_has_injected_scancode() && _inject_ready()) |
722e5aea JP |
99 | { |
100 | smi_disable_event(SMI_EVENT_DEVTRAP_KBC); | |
5d467741 JW |
101 | outputf("Injecting key"); |
102 | /* Actually do the inject. */ | |
103 | outb(0x64, 0xD2); /* "Inject, please!" */ | |
104 | while (inb(0x64) & 0x02) /* Busy? */ | |
105 | ; | |
106 | outb(0x60, kbd_get_injected_scancode()); /* data */ | |
107 | while (inb(0x64) & 0x02) /* wait for completion */ | |
108 | ; | |
722e5aea JP |
109 | smi_enable_event(SMI_EVENT_DEVTRAP_KBC); |
110 | } | |
111 | ||
112 | outb(0x80, (ticks++) & 0xFF); | |
113 | ||
5cb80fe1 JW |
114 | if (!fb || fb->curmode.text) |
115 | outlog(); | |
722e5aea JP |
116 | } |
117 | ||
118 | void kbc_handler(smi_event_t ev) | |
119 | { | |
120 | pci_dump(); | |
121 | } | |
122 | ||
123 | void gbl_rls_handler(smi_event_t ev) | |
124 | { | |
125 | unsigned long ecx; | |
126 | ||
127 | ecx = *(unsigned long*)0xAFFD4; | |
128 | ||
129 | packet_t * packet = check_packet(ecx); | |
130 | if (!packet) | |
131 | { | |
132 | dologf("WARN: bad packet at %08x", ecx); | |
133 | return; | |
134 | } | |
135 | ||
5d467741 | 136 | outputf("Got packet: type %08x", packet->type); |
722e5aea JP |
137 | |
138 | if (packet->type == 42) { | |
139 | dump_log((char *)packet->data); | |
140 | *(unsigned long*)0xAFFD4 = 42; | |
141 | } else if (packet->type == 0xAA) { | |
91cc1340 JP |
142 | kbd_inject_keysym('A', 1); |
143 | kbd_inject_keysym('A', 0); | |
722e5aea JP |
144 | } else { |
145 | *(unsigned long*)0xAFFD4 = 0x2BADD00D; | |
146 | } | |
147 | } |