]> Joshua Wise's Git repositories - netwatch.git/blob - aseg/counter.c
73003da26c6890024b2e32d28266a194d51ec693
[netwatch.git] / aseg / counter.c
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>
7 #include "../net/net.h"
8 #include "vga-overlay.h"
9 #include "packet.h"
10 #include "keyboard.h"
11
12 unsigned int counter = 0;
13 unsigned long pcisave;
14 unsigned char vgasave;
15
16 void pci_dump() {
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);
23         outl(0x840, 0x0);
24         switch(cts&0xF0000)
25         {
26         case 0x20000:
27         {
28                 unsigned char b;
29                 b = inb(cts & 0xFFFF);
30                 //dologf("READ: %08x (%02x)", cts, b);
31                 if ((cts & 0xFFFF) == 0x64)
32                         curdev = (b & 0x20) ? 1 : 0;
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
48                 *(unsigned char*)0xAFFD0 /* EAX */ = b;
49                 break;
50         }
51         case 0x30000:
52         {
53                 unsigned char b;
54                 
55                 b = *(unsigned char*)0xAFFD0 /* EAX */;
56                 dologf("WRITE: %08x (%02x)", cts, b);
57                 outb(cts & 0xFFFF, b);
58                 break;
59         }
60         default:
61                 dolog("Unhandled PCI cycle");
62         }
63         
64         outl(0x848, 0x1000);
65         outl(0x840, 0x0100);
66 }
67
68 void 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
80 void kbc_handler(smi_event_t ev)
81 {
82         pci_dump();
83 }
84
85 void gbl_rls_handler(smi_event_t ev)
86 {
87         unsigned long ecx;
88         
89         ecx = *(unsigned long*)0xAFFD4;
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
100         if (packet->type == 42) {
101                 dump_log((char *)packet->data);
102                 *(unsigned long*)0xAFFD4 = 42;
103         } else if (packet->type == 0xAA) {
104                 kbd_inject_key('A');
105         } else {
106                 *(unsigned long*)0xAFFD4 = 0x2BADD00D;
107         }
108 }
109
110 void smi_entry(void)
111 {
112         char statstr[512];
113         
114         pcisave = inl(0xCF8);
115         vgasave = inb(0x3D4);
116         pci_unbother_all();
117         
118         counter++;
119         sprintf(statstr, "15-412! %08x %08x", smi_status(), counter);
120         strblit(statstr, 0, 0);
121         
122         eth_poll();
123         
124         if (inl(0x840) & 0x1000)
125         {
126                 pci_dump();
127                 outl(0x840, 0x1100);
128                 outl(0x840, 0x0100);
129         }
130
131         smi_poll();
132         
133         pci_bother_all();
134         outl(0xCF8, pcisave);
135         outb(0x3D4, vgasave);
136 }
137
This page took 0.027352 seconds and 2 git commands to generate.