]>
Commit | Line | Data |
---|---|---|
035d7af7 | 1 | #include <io.h> |
36ce375d JP |
2 | #include <smram.h> |
3 | #include <video_defines.h> | |
4 | #include <minilib.h> | |
d71d9872 | 5 | #include <smi.h> |
4d898e0b | 6 | #include <pci-bother.h> |
3e6d6106 | 7 | #include "../net/net.h" |
91a6abf7 | 8 | #include "vga-overlay.h" |
0cd80c51 | 9 | #include "packet.h" |
50d89a31 | 10 | #include "keyboard.h" |
36ce375d | 11 | |
91a6abf7 | 12 | unsigned int counter = 0; |
d9de6545 | 13 | unsigned int lastctr = 0; |
91a6abf7 JP |
14 | unsigned long pcisave; |
15 | unsigned char vgasave; | |
d9de6545 JW |
16 | static int curdev = 0; /* 0 if kbd, 1 if mouse */ |
17 | ||
18 | static void cause_kbd_irq() | |
19 | { | |
20 | outl(0x844, 0x0); | |
21 | outl(0x848, 0x0); | |
22 | while (inb(0x64) & 0x1) | |
23 | inb(0x60); | |
24 | outb(0x60, 0xee); /* Cause an IRQ. */ | |
d3411e0d | 25 | while (inb(0x60) != 0xEE) |
d9de6545 | 26 | ; |
d9de6545 | 27 | } |
4bea7daf | 28 | |
98765740 | 29 | void pci_dump() { |
98765740 | 30 | unsigned long cts; |
98765740 JP |
31 | |
32 | cts = inl(0x84C); | |
33 | ||
85bc8ca6 | 34 | outl(0x840, 0x0); |
d9de6545 | 35 | outl(0x848, 0x0); |
98765740 JP |
36 | switch(cts&0xF0000) |
37 | { | |
38 | case 0x20000: | |
39 | { | |
40 | unsigned char b; | |
c3c652f7 JW |
41 | |
42 | switch (cts & 0xFFFF) | |
50d89a31 | 43 | { |
c3c652f7 JW |
44 | case 0x64: |
45 | /* Read the real hardware and mask in our OBF if need be. */ | |
46 | b = inb(0x64); | |
47 | if (kbd_has_injected_scancode()) | |
48 | { | |
d9de6545 JW |
49 | dologf("OS wants to know; we have data"); |
50 | lastctr = counter; | |
c3c652f7 JW |
51 | b |= 0x01; |
52 | b &= ~0x20; /* no mouse for you! */ | |
53 | curdev = 0; | |
54 | } else | |
55 | curdev = (b & 0x20) ? 1 : 0; | |
56 | *(unsigned char*)0xAFFD0 /* EAX */ = b; | |
57 | break; | |
58 | case 0x60: | |
d9de6545 | 59 | if (kbd_has_injected_scancode()) |
c3c652f7 | 60 | { |
50d89a31 | 61 | b = kbd_get_injected_scancode(); |
d9de6545 | 62 | lastctr = counter; |
d3411e0d JW |
63 | while (inb(0x64) & 0x1) |
64 | inb(0x60); | |
c3c652f7 JW |
65 | } else |
66 | b = inb(0x60); | |
67 | if ((curdev == 0) && (b == 0x01)) { /* Escape */ | |
68 | outb(0xCF9, 0x4); /* Reboot */ | |
69 | return; | |
50d89a31 | 70 | } |
d9de6545 JW |
71 | |
72 | /* If there is more nus to come, generate another IRQ. */ | |
73 | if (kbd_has_injected_scancode()) | |
74 | cause_kbd_irq(); | |
75 | ||
c3c652f7 JW |
76 | *(unsigned char*)0xAFFD0 /* EAX */ = b; |
77 | break; | |
50d89a31 JP |
78 | } |
79 | ||
98765740 JP |
80 | *(unsigned char*)0xAFFD0 /* EAX */ = b; |
81 | break; | |
82 | } | |
83 | case 0x30000: | |
84 | { | |
85 | unsigned char b; | |
86 | ||
98765740 | 87 | b = *(unsigned char*)0xAFFD0 /* EAX */; |
34205a17 | 88 | dologf("WRITE: %08x (%02x)", cts, b); |
98765740 JP |
89 | outb(cts & 0xFFFF, b); |
90 | break; | |
91 | } | |
92 | default: | |
93 | dolog("Unhandled PCI cycle"); | |
94 | } | |
85bc8ca6 | 95 | |
d9de6545 | 96 | outl(0x844, 0x1000); |
85bc8ca6 | 97 | outl(0x848, 0x1000); |
98765740 JP |
98 | } |
99 | ||
07d1dd26 JW |
100 | void timer_handler(smi_event_t ev) |
101 | { | |
102 | static unsigned int ticks = 0; | |
103 | ||
104 | smi_disable_event(SMI_EVENT_FAST_TIMER); | |
105 | smi_enable_event(SMI_EVENT_FAST_TIMER); | |
106 | ||
d9de6545 JW |
107 | if (kbd_has_injected_scancode() && (counter > (lastctr + 2))) |
108 | { | |
109 | smi_disable_event(SMI_EVENT_DEVTRAP_KBC); | |
110 | dolog("Kicking timer"); | |
111 | cause_kbd_irq(); | |
112 | smi_enable_event(SMI_EVENT_DEVTRAP_KBC); | |
113 | } | |
114 | ||
07d1dd26 JW |
115 | outb(0x80, (ticks++) & 0xFF); |
116 | ||
117 | outlog(); | |
118 | } | |
119 | ||
8a677ebb JW |
120 | void kbc_handler(smi_event_t ev) |
121 | { | |
122 | pci_dump(); | |
123 | } | |
124 | ||
73fb9b4c JW |
125 | void gbl_rls_handler(smi_event_t ev) |
126 | { | |
127 | unsigned long ecx; | |
128 | ||
7d252e04 | 129 | ecx = *(unsigned long*)0xAFFD4; |
0cd80c51 JP |
130 | |
131 | packet_t * packet = check_packet(ecx); | |
132 | if (!packet) | |
133 | { | |
134 | dologf("WARN: bad packet at %08x", ecx); | |
135 | return; | |
136 | } | |
137 | ||
138 | dologf("Got packet: type %08x", packet->type); | |
139 | ||
d5cffad7 JP |
140 | if (packet->type == 42) { |
141 | dump_log((char *)packet->data); | |
142 | *(unsigned long*)0xAFFD4 = 42; | |
50d89a31 JP |
143 | } else if (packet->type == 0xAA) { |
144 | kbd_inject_key('A'); | |
d5cffad7 JP |
145 | } else { |
146 | *(unsigned long*)0xAFFD4 = 0x2BADD00D; | |
147 | } | |
73fb9b4c JW |
148 | } |
149 | ||
d71d9872 | 150 | void smi_entry(void) |
015cd976 | 151 | { |
34205a17 JW |
152 | char statstr[512]; |
153 | ||
035d7af7 JW |
154 | pcisave = inl(0xCF8); |
155 | vgasave = inb(0x3D4); | |
4d898e0b | 156 | pci_unbother_all(); |
31be35cd | 157 | |
4bea7daf | 158 | counter++; |
34205a17 JW |
159 | sprintf(statstr, "15-412! %08x %08x", smi_status(), counter); |
160 | strblit(statstr, 0, 0); | |
035d7af7 | 161 | |
3b3161a1 | 162 | eth_poll(); |
e8351f1a | 163 | |
98765740 JP |
164 | if (inl(0x840) & 0x1000) |
165 | { | |
98765740 JP |
166 | pci_dump(); |
167 | outl(0x840, 0x1100); | |
168 | outl(0x840, 0x0100); | |
169 | } | |
98765740 | 170 | |
4fb81ad0 | 171 | smi_poll(); |
035d7af7 | 172 | |
4d898e0b | 173 | pci_bother_all(); |
035d7af7 JW |
174 | outl(0xCF8, pcisave); |
175 | outb(0x3D4, vgasave); | |
4bea7daf JW |
176 | } |
177 |