]> Joshua Wise's Git repositories - netwatch.git/blame - aseg-paging/main.c
Add a first cut at text.
[netwatch.git] / aseg-paging / main.c
CommitLineData
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
14unsigned int lastctr = 0;
15extern unsigned int counter;
16
5d467741
JW
17static int _ibf_ready = 0;
18static int _waiting_for_data = 0;
722e5aea 19static int curdev = 0;
ba90bd5c 20static int adding_locks_from_time_to_time = 0;
722e5aea 21
692f070e
JW
22static int _inject_ready()
23{
59ceede5 24 return _ibf_ready && !_waiting_for_data && !adding_locks_from_time_to_time;
692f070e
JW
25}
26
27void _try_inject()
28{
29 if (kbd_has_injected_scancode() && _inject_ready())
30 {
31 smi_disable_event(SMI_EVENT_DEVTRAP_KBC);
32 int i = 1000;
33 while (inb(0x64) & 0x02) /* Busy? */
34 ;
35 outb(0x64, 0xD2); /* "Inject, please!" */
36 while (inb(0x64) & 0x02) /* Busy? */
37 ;
38 outb(0x60, kbd_get_injected_scancode()); /* data */
39 while ((inb(0x64) & 0x02) && i--) /* wait for completion */
40 ;
633292e9 41 outl(0x844, 0x1000);
ba90bd5c 42 adding_locks_from_time_to_time++;
692f070e
JW
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);
46}
47
722e5aea
JP
48void pci_dump() {
49 unsigned long cts;
50
51 cts = inl(0x84C);
52
53 outl(0x840, 0x0);
54 outl(0x848, 0x0);
55 switch(cts&0xF0000)
56 {
57 case 0x20000:
58 {
59 unsigned char b;
60
61 switch (cts & 0xFFFF)
62 {
63 case 0x64:
64 /* Read the real hardware and mask in our OBF if need be. */
65 b = inb(0x64);
5d467741
JW
66
67 curdev = (b & 0x20 /* KBD_STAT_MOUSE_OBF */) ? 1 : 0;
692f070e
JW
68
69 if ((curdev == 0) && kbd_has_injected_scancode())
70 b |= 0x1;
71
5d467741
JW
72 _ibf_ready = (b & 0x2 /* IBF */) ? 0 : 1;
73
722e5aea
JP
74 break;
75 case 0x60:
ba90bd5c 76 if ((curdev == 0) && kbd_has_injected_scancode() && !adding_locks_from_time_to_time)
692f070e
JW
77 b = kbd_get_injected_scancode();
78 else
79 b = inb(0x60);
ba90bd5c
JW
80 if (adding_locks_from_time_to_time)
81 adding_locks_from_time_to_time--;
722e5aea
JP
82 if ((curdev == 0) && (b == 0x01)) { /* Escape */
83 outb(0xCF9, 0x4); /* Reboot */
84 return;
85 }
722e5aea
JP
86 break;
87 }
692f070e
JW
88
89 dologf("READ : %08x (%02x)", cts, b);
722e5aea
JP
90 *(unsigned char*)0xAFFD0 /* EAX */ = b;
91 break;
92 }
93 case 0x30000:
94 {
95 unsigned char b;
96
97 b = *(unsigned char*)0xAFFD0 /* EAX */;
98 dologf("WRITE: %08x (%02x)", cts, b);
5d467741
JW
99 if ((cts & 0xFFFF) == 0x64)
100 switch(b)
101 {
102 case 0x60 /*KBD_CCMD_WRITE_MODE*/:
103 case 0xD2 /*KBD_CCMD_WRITE_OBUF*/:
104 case 0xD3 /*KBD_CCMD_WRITE_AUX_OBUF*/:
105 case 0xD4 /*KBD_CCMD_WRITE_MOUSE*/:
106 case 0xD1 /*KBD_CCMD_WRITE_OUTPORT*/:
107 _waiting_for_data = 1; /* These all should not be interrupted. */
108 }
109 else if ((cts & 0xFFFF) == 0x60)
110 _waiting_for_data = 0;
722e5aea
JP
111 outb(cts & 0xFFFF, b);
112 break;
113 }
114 default:
115 dolog("Unhandled PCI cycle");
116 }
117
118 outl(0x840, 0x0);
119 outl(0x844, 0x1000);
120 outl(0x848, 0x1000);
121}
122
123void timer_handler(smi_event_t ev)
124{
125 static unsigned int ticks = 0;
126
127 smi_disable_event(SMI_EVENT_FAST_TIMER);
128 smi_enable_event(SMI_EVENT_FAST_TIMER);
129
692f070e 130 _try_inject();
722e5aea
JP
131
132 outb(0x80, (ticks++) & 0xFF);
133
5cb80fe1
JW
134 if (!fb || fb->curmode.text)
135 outlog();
722e5aea
JP
136}
137
138void kbc_handler(smi_event_t ev)
139{
140 pci_dump();
141}
142
143void gbl_rls_handler(smi_event_t ev)
144{
145 unsigned long ecx;
146
147 ecx = *(unsigned long*)0xAFFD4;
148
149 packet_t * packet = check_packet(ecx);
150 if (!packet)
151 {
152 dologf("WARN: bad packet at %08x", ecx);
153 return;
154 }
155
5d467741 156 outputf("Got packet: type %08x", packet->type);
722e5aea
JP
157
158 if (packet->type == 42) {
159 dump_log((char *)packet->data);
160 *(unsigned long*)0xAFFD4 = 42;
161 } else if (packet->type == 0xAA) {
91cc1340
JP
162 kbd_inject_keysym('A', 1);
163 kbd_inject_keysym('A', 0);
722e5aea
JP
164 } else {
165 *(unsigned long*)0xAFFD4 = 0x2BADD00D;
166 }
167}
This page took 0.042509 seconds and 4 git commands to generate.