]> Joshua Wise's Git repositories - netwatch.git/blob - aseg/counter.c
Have a slightly nicer takeover scheme.
[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         static int takeover = 0;
20                 
21         cts = inl(0x84C);
22         
23         outl(0x848, 0x0);
24         outl(0x840, 0x0);
25         switch(cts&0xF0000)
26         {
27         case 0x20000:
28         {
29                 unsigned char b;
30                 
31                 switch (cts & 0xFFFF)
32                 {
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                         {
49                                 b = kbd_get_injected_scancode();
50                                 takeover = 0;
51                         } else
52                                 b = inb(0x60);
53                         if ((curdev == 0) && (b == 0x01)) {     /* Escape */
54                                 outb(0xCF9, 0x4);       /* Reboot */
55                                 return;
56                         }
57                         *(unsigned char*)0xAFFD0 /* EAX */ = b;
58                         break;
59                 }
60
61                 *(unsigned char*)0xAFFD0 /* EAX */ = b;
62                 break;
63         }
64         case 0x30000:
65         {
66                 unsigned char b;
67                 
68                 b = *(unsigned char*)0xAFFD0 /* EAX */;
69                 dologf("WRITE: %08x (%02x)", cts, b);
70                 outb(cts & 0xFFFF, b);
71                 break;
72         }
73         default:
74                 dolog("Unhandled PCI cycle");
75         }
76         
77         outl(0x848, 0x1000);
78         outl(0x840, 0x0100);
79 }
80
81 void 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
93 void kbc_handler(smi_event_t ev)
94 {
95         pci_dump();
96 }
97
98 void gbl_rls_handler(smi_event_t ev)
99 {
100         unsigned long ecx;
101         
102         ecx = *(unsigned long*)0xAFFD4;
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
113         if (packet->type == 42) {
114                 dump_log((char *)packet->data);
115                 *(unsigned long*)0xAFFD4 = 42;
116         } else if (packet->type == 0xAA) {
117                 kbd_inject_key('A');
118         } else {
119                 *(unsigned long*)0xAFFD4 = 0x2BADD00D;
120         }
121 }
122
123 void smi_entry(void)
124 {
125         char statstr[512];
126         
127         pcisave = inl(0xCF8);
128         vgasave = inb(0x3D4);
129         pci_unbother_all();
130         
131         counter++;
132         sprintf(statstr, "15-412! %08x %08x", smi_status(), counter);
133         strblit(statstr, 0, 0);
134         
135         eth_poll();
136         
137         if (inl(0x840) & 0x1000)
138         {
139                 pci_dump();
140                 outl(0x840, 0x1100);
141                 outl(0x840, 0x0100);
142         }
143
144         smi_poll();
145         
146         pci_bother_all();
147         outl(0xCF8, pcisave);
148         outb(0x3D4, vgasave);
149 }
150
This page took 0.030258 seconds and 4 git commands to generate.