]> Joshua Wise's Git repositories - netwatch.git/blame - aseg/counter.c
Reboot the machine when you hit escape. Wait, what?
[netwatch.git] / aseg / counter.c
CommitLineData
035d7af7
JW
1#include <io.h>
2
31be35cd 3unsigned int counter = 0;
035d7af7
JW
4unsigned long pcisave;
5unsigned char vgasave;
6unsigned char thestr[512];
31be35cd 7unsigned char logents[4][41] = {0};
035d7af7
JW
8
9unsigned char vgaread(unsigned char idx)
10{
11 outb(0x3D4, idx);
12 inb(0x3D5);
13}
14
31be35cd 15void strblit(char *src, int r, int c)
035d7af7 16{
31be35cd
JW
17 char *destp = (char*)(0xB8000UL | (((unsigned int)vgaread(0xC)) << 9) | (((unsigned int)vgaread(0xD)) << 1)) + r*80*2 + c*2;
18 unsigned char smramc;
19
20 smramc = pci_read8(0, 0, 0, 0x70);
21 pci_write8(0, 0, 0, 0x70, (smramc & 0xF3) | 0x08);
035d7af7
JW
22 while (*src)
23 {
24 *(destp++) = *(src++);
25 *(destp++) = 0x1F;
26 }
31be35cd
JW
27 pci_write8(0, 0, 0, 0x70, smramc);
28}
29
30void outlog()
31{
32 int y, x;
33 unsigned char smramc;
34 unsigned char *basep = (char*)(0xB8000UL | (((unsigned int)vgaread(0xC)) << 9) | (((unsigned int)vgaread(0xD)) << 1));
35
36 smramc = pci_read8(0, 0, 0, 0x70);
37 pci_write8(0, 0, 0, 0x70, (smramc & 0xF3) | 0x08);
38 for (y = 0; y < 4; y++)
39 for (x = 40; x < 80; x++)
40 {
41 basep[y*80*2+x*2] = ' ';
42 basep[y*80*2+x*2+1] = 0x1F;
43 }
44 pci_write8(0, 0, 0, 0x70, smramc);
45
46 for (y = 0; y < 4; y++)
47 strblit(logents[y], y, 40);
48
49}
50
51void dolog(char *s)
52{
53 memmove(logents[0], logents[1], sizeof(logents[0])*3);
54 strcpy(logents[3], s);
035d7af7 55}
4bea7daf 56
015cd976
JW
57void __start (void)
58{
035d7af7 59 unsigned char smramc;
31be35cd 60 static int first = 1;
035d7af7
JW
61
62 pcisave = inl(0xCF8);
63 vgasave = inb(0x3D4);
31be35cd
JW
64
65 if (first)
66 {
67 first = 0;
68 dolog("NetWatch running...");
69 }
035d7af7 70
4bea7daf 71 counter++;
31be35cd 72 outb(0x80, (counter & 0xFF));
035d7af7 73
31be35cd
JW
74 strcpy(thestr, "15-412! xxxxxxxx xxxxxxxx");
75 tohex(thestr + 8, inl(0x0834));
76 tohex(thestr + 17, counter);
77 strblit(thestr, 0, 0);
035d7af7 78
31be35cd
JW
79 if (inl(0x834) & 0x20)
80 dolog("Warning: unhandled APM access");
4122ee13
JW
81 if (inl(0x834) & 0x1000)
82 {
83 if (inl(0x844) & 0x1000) /* devact_sts */
84 {
85 unsigned char s[40];
86 unsigned long cts;
87 static int curdev = 0; /* 0 if kbd, 1 if mouse */
88
89 cts = inl(0x84C);
90
91 outl(0x848, 0x0);
92
93 switch(cts&0xF0000)
94 {
95 case 0x20000:
96 {
97 unsigned char b;
98 strcpy(s, "READxxxxxxxxxxxxxxxx");
99 tohex(s+4, cts);
100 b = inb(cts & 0xFFFF);
101 tohex(s+12, b);
102 if ((cts & 0xFFFF) == 0x64)
103 curdev = (b & 0x20) ? 1 : 0;
104 if ((curdev == 0) && ((cts & 0xFFFF) == 0x60) && (b == 0x01))
105 outb(0xCF9, 0x4);
106 dolog(s);
107 *(unsigned char*)0xAFFD0 /* EAX */ = b;
108 break;
109 }
110 case 0x30000:
111 {
112 unsigned char b;
113
114 strcpy(s, "WRITxxxxxxxxxxxxxxxx");
115 b = *(unsigned char*)0xAFFD0 /* EAX */;
116 tohex(s+4, cts);
117 tohex(s+12, b);
118 dolog(s);
119 outb(cts & 0xFFFF, b);
120 break;
121 }
122 default:
123 dolog("Unhandled PCI cycle");
124 }
125 outl(0x848, 0x1000);
126 outl(0x844, 0x1000);
127 }
128 }
31be35cd
JW
129 if (inl(0x834) & 0x4000)
130 dolog("Long periodic timer");
131 if (inl(0x834) & ~(0x4160))
132 {
133 unsigned char s[40];
134 strcpy(s, "Unknown: xxxxxxxx");
135 tohex(s + 9, inl(0x834) & ~(0x140));
136 dolog(s);
137 }
138
139 outlog();
035d7af7
JW
140
141 outl(0xCF8, pcisave);
142 outb(0x3D4, vgasave);
a46bffee 143
4122ee13 144 outl(0x848, 0x1000);
31be35cd 145 outl(0x834, /*0x40*/0xFFFF); // ack the periodic IRQ
a46bffee
JW
146 outb(0x830, (inb(0x830) | 0x2) & ~0x40);
147 outb(0x830, inb(0x830) | 0x40);
148
4bea7daf
JW
149}
150
This page took 0.03662 seconds and 4 git commands to generate.