]> Joshua Wise's Git repositories - netwatch.git/blame - aseg/counter.c
more keys
[netwatch.git] / aseg / counter.c
CommitLineData
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
JP
12unsigned int counter = 0;
13unsigned long pcisave;
14unsigned char vgasave;
4bea7daf 15
98765740 16void pci_dump() {
98765740
JP
17 unsigned long cts;
18 static int curdev = 0; /* 0 if kbd, 1 if mouse */
c3c652f7 19 static int takeover = 0;
98765740
JP
20
21 cts = inl(0x84C);
22
23 outl(0x848, 0x0);
85bc8ca6 24 outl(0x840, 0x0);
98765740
JP
25 switch(cts&0xF0000)
26 {
27 case 0x20000:
28 {
29 unsigned char b;
c3c652f7
JW
30
31 switch (cts & 0xFFFF)
50d89a31 32 {
c3c652f7
JW
33 case 0x64:
34 /* Read the real hardware and mask in our OBF if need be. */
35 b = inb(0x64);
36 if (kbd_has_injected_scancode())
37 {
38 takeover = 1;
39 b |= 0x01;
40 b &= ~0x20; /* no mouse for you! */
41 curdev = 0;
42 } else
43 curdev = (b & 0x20) ? 1 : 0;
44 *(unsigned char*)0xAFFD0 /* EAX */ = b;
45 break;
46 case 0x60:
47 if (takeover)
48 {
50d89a31 49 b = kbd_get_injected_scancode();
c3c652f7
JW
50 takeover = 0;
51 } else
52 b = inb(0x60);
53 if ((curdev == 0) && (b == 0x01)) { /* Escape */
54 outb(0xCF9, 0x4); /* Reboot */
55 return;
50d89a31 56 }
c3c652f7
JW
57 *(unsigned char*)0xAFFD0 /* EAX */ = b;
58 break;
50d89a31
JP
59 }
60
98765740
JP
61 *(unsigned char*)0xAFFD0 /* EAX */ = b;
62 break;
63 }
64 case 0x30000:
65 {
66 unsigned char b;
67
98765740 68 b = *(unsigned char*)0xAFFD0 /* EAX */;
34205a17 69 dologf("WRITE: %08x (%02x)", cts, b);
98765740
JP
70 outb(cts & 0xFFFF, b);
71 break;
72 }
73 default:
74 dolog("Unhandled PCI cycle");
75 }
85bc8ca6
JW
76
77 outl(0x848, 0x1000);
78 outl(0x840, 0x0100);
98765740
JP
79}
80
07d1dd26
JW
81void timer_handler(smi_event_t ev)
82{
83 static unsigned int ticks = 0;
84
85 smi_disable_event(SMI_EVENT_FAST_TIMER);
86 smi_enable_event(SMI_EVENT_FAST_TIMER);
87
88 outb(0x80, (ticks++) & 0xFF);
89
90 outlog();
91}
92
8a677ebb
JW
93void kbc_handler(smi_event_t ev)
94{
95 pci_dump();
96}
97
73fb9b4c
JW
98void gbl_rls_handler(smi_event_t ev)
99{
100 unsigned long ecx;
101
7d252e04 102 ecx = *(unsigned long*)0xAFFD4;
0cd80c51
JP
103
104 packet_t * packet = check_packet(ecx);
105 if (!packet)
106 {
107 dologf("WARN: bad packet at %08x", ecx);
108 return;
109 }
110
111 dologf("Got packet: type %08x", packet->type);
112
d5cffad7
JP
113 if (packet->type == 42) {
114 dump_log((char *)packet->data);
115 *(unsigned long*)0xAFFD4 = 42;
50d89a31
JP
116 } else if (packet->type == 0xAA) {
117 kbd_inject_key('A');
d5cffad7
JP
118 } else {
119 *(unsigned long*)0xAFFD4 = 0x2BADD00D;
120 }
73fb9b4c
JW
121}
122
d71d9872 123void smi_entry(void)
015cd976 124{
34205a17
JW
125 char statstr[512];
126
035d7af7
JW
127 pcisave = inl(0xCF8);
128 vgasave = inb(0x3D4);
4d898e0b 129 pci_unbother_all();
31be35cd 130
4bea7daf 131 counter++;
34205a17
JW
132 sprintf(statstr, "15-412! %08x %08x", smi_status(), counter);
133 strblit(statstr, 0, 0);
035d7af7 134
3b3161a1 135 eth_poll();
e8351f1a 136
98765740
JP
137 if (inl(0x840) & 0x1000)
138 {
98765740
JP
139 pci_dump();
140 outl(0x840, 0x1100);
141 outl(0x840, 0x0100);
142 }
98765740 143
4fb81ad0 144 smi_poll();
035d7af7 145
4d898e0b 146 pci_bother_all();
035d7af7
JW
147 outl(0xCF8, pcisave);
148 outb(0x3D4, vgasave);
4bea7daf
JW
149}
150
This page took 0.042563 seconds and 4 git commands to generate.