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