]> Joshua Wise's Git repositories - netwatch.git/blob - aseg/counter.c
split vga and logging code out into vga-overlay.[ch]
[netwatch.git] / aseg / counter.c
1 #include <io.h>
2 #include <smram.h>
3 #include <video_defines.h>
4 #include <minilib.h>
5
6 char thestr[512];
7
8 #include "vga-overlay.h"
9
10 unsigned int counter = 0;
11 unsigned long pcisave;
12 unsigned char vgasave;
13
14 void pci_dump() {
15         char s[40];
16         unsigned long cts;
17         static int curdev = 0;  /* 0 if kbd, 1 if mouse */
18                 
19         cts = inl(0x84C);
20         
21         outl(0x848, 0x0);
22         
23         switch(cts&0xF0000)
24         {
25         case 0x20000:
26         {
27                 unsigned char b;
28                 strcpy(s, "READxxxxxxxxxxxxxxxx");
29                 tohex(s+4, cts);
30                 b = inb(cts & 0xFFFF);
31                 tohex(s+12, b);
32                 if ((cts & 0xFFFF) == 0x64)
33                         curdev = (b & 0x20) ? 1 : 0;
34                 if ((curdev == 0) && ((cts & 0xFFFF) == 0x60) && (b == 0x01))
35                         outb(0xCF9, 0x4);
36                 dolog(s);
37                 *(unsigned char*)0xAFFD0 /* EAX */ = b;
38                 break;
39         }
40         case 0x30000:
41         {
42                 unsigned char b;
43                 
44                 strcpy(s, "WRITxxxxxxxxxxxxxxxx");
45                 b = *(unsigned char*)0xAFFD0 /* EAX */;
46                 tohex(s+4, cts);
47                 tohex(s+12, b);
48                 dolog(s);
49                 outb(cts & 0xFFFF, b);
50                 break;
51         }
52         default:
53                 dolog("Unhandled PCI cycle");
54         }
55 }
56
57 void __start (void)
58 {
59         static int first = 1;
60         
61         pcisave = inl(0xCF8);
62         vgasave = inb(0x3D4);
63         
64         if (first)
65         {
66                 first = 0;
67                 dolog("NetWatch running...");
68         }
69
70         counter++;
71         outb(0x80, (counter & 0xFF));
72         
73         strcpy(thestr, "15-412! xxxxxxxx xxxxxxxx");
74         tohex(thestr + 8, inl(0x0834));
75         tohex(thestr + 17, counter);
76         strblit(thestr, 0, 0);
77         
78         if (inl(0x834) & 0x20)
79                 dolog("Warning: unhandled APM access");
80         if (inl(0x834) & 0x1000)
81         {
82                 if (inl(0x844) & 0x1000)        /* devact_sts */
83                 {
84                         pci_dump();
85                         outl(0x848, 0x1000);
86                         outl(0x844, 0x1000);
87                 }
88         }
89         if (inl(0x834) & 0x4000)
90                 dolog("Long periodic timer");
91         if (inl(0x840) & 0x1000)
92         {
93                 dolog("Caught device monitor trap");
94                 pci_dump();
95                 outl(0x840, 0x1100);
96                 outl(0x840, 0x0100);
97         }
98         if (inl(0x834) & ~(0x4160))
99         {
100                 char s[40];
101                 strcpy(s, "Unknown: xxxxxxxx");
102                 tohex(s + 9, inl(0x834) & ~(0x140));
103                 dolog(s);
104         }
105
106
107         outlog();
108         
109         outl(0xCF8, pcisave);
110         outb(0x3D4, vgasave);
111         
112         outl(0x848, 0x1000);
113         outl(0x834, /*0x40*/0xFFFF);    // ack the periodic IRQ
114         outb(0x830, (inb(0x830) | 0x2) & ~0x40);
115         outb(0x830, inb(0x830) | 0x40);
116         
117 }
118
This page took 0.030227 seconds and 4 git commands to generate.