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