]>
Commit | Line | Data |
---|---|---|
035d7af7 | 1 | #include <io.h> |
36ce375d JP |
2 | #include <smram.h> |
3 | #include <video_defines.h> | |
4 | #include <minilib.h> | |
035d7af7 | 5 | |
31be35cd | 6 | unsigned int counter = 0; |
035d7af7 JW |
7 | unsigned long pcisave; |
8 | unsigned char vgasave; | |
36ce375d JP |
9 | char thestr[512]; |
10 | char logents[4][41] = {{0}}; | |
035d7af7 | 11 | |
36ce375d JP |
12 | #define VRAM_BASE 0xA0000UL |
13 | #define TEXT_CONSOLE_OFFSET 0x18000UL | |
14 | ||
15 | #define TEXT_CONSOLE_BASE (VRAM_BASE + TEXT_CONSOLE_OFFSET) | |
16 | ||
17 | #define COLOR 0x1F | |
18 | ||
19 | unsigned char vga_read(unsigned char idx) | |
20 | { | |
21 | outb(CRTC_IDX_REG, idx); | |
22 | return inb(CRTC_DATA_REG); | |
23 | } | |
24 | ||
25 | char * vga_base() | |
035d7af7 | 26 | { |
36ce375d JP |
27 | return (char *) ( |
28 | TEXT_CONSOLE_BASE | |
29 | | (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 9) | |
30 | | (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 1) | |
31 | ); | |
035d7af7 JW |
32 | } |
33 | ||
36ce375d | 34 | void strblit(char *src, int row, int col) |
035d7af7 | 35 | { |
36ce375d JP |
36 | char *destp = vga_base() + row * 80 * 2 + col * 2; |
37 | smram_state_t old_state = smram_save_state(); | |
38 | ||
39 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
31be35cd | 40 | |
035d7af7 JW |
41 | while (*src) |
42 | { | |
43 | *(destp++) = *(src++); | |
36ce375d | 44 | *(destp++) = COLOR; |
035d7af7 | 45 | } |
36ce375d JP |
46 | |
47 | smram_restore_state(old_state); | |
31be35cd JW |
48 | } |
49 | ||
50 | void outlog() | |
51 | { | |
52 | int y, x; | |
36ce375d JP |
53 | char *basep = vga_base(); |
54 | ||
55 | smram_state_t old_state = smram_save_state(); | |
56 | ||
57 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
58 | ||
31be35cd JW |
59 | for (y = 0; y < 4; y++) |
60 | for (x = 40; x < 80; x++) | |
61 | { | |
62 | basep[y*80*2+x*2] = ' '; | |
63 | basep[y*80*2+x*2+1] = 0x1F; | |
64 | } | |
36ce375d JP |
65 | |
66 | smram_restore_state(old_state); | |
67 | ||
31be35cd JW |
68 | for (y = 0; y < 4; y++) |
69 | strblit(logents[y], y, 40); | |
31be35cd JW |
70 | } |
71 | ||
72 | void dolog(char *s) | |
73 | { | |
74 | memmove(logents[0], logents[1], sizeof(logents[0])*3); | |
75 | strcpy(logents[3], s); | |
035d7af7 | 76 | } |
4bea7daf | 77 | |
98765740 | 78 | void pci_dump() { |
36ce375d | 79 | char s[40]; |
98765740 JP |
80 | unsigned long cts; |
81 | static int curdev = 0; /* 0 if kbd, 1 if mouse */ | |
82 | ||
83 | cts = inl(0x84C); | |
84 | ||
85 | outl(0x848, 0x0); | |
85bc8ca6 | 86 | outl(0x840, 0x0); |
98765740 JP |
87 | switch(cts&0xF0000) |
88 | { | |
89 | case 0x20000: | |
90 | { | |
91 | unsigned char b; | |
92 | strcpy(s, "READxxxxxxxxxxxxxxxx"); | |
93 | tohex(s+4, cts); | |
94 | b = inb(cts & 0xFFFF); | |
95 | tohex(s+12, b); | |
96 | if ((cts & 0xFFFF) == 0x64) | |
97 | curdev = (b & 0x20) ? 1 : 0; | |
98 | if ((curdev == 0) && ((cts & 0xFFFF) == 0x60) && (b == 0x01)) | |
99 | outb(0xCF9, 0x4); | |
100 | dolog(s); | |
101 | *(unsigned char*)0xAFFD0 /* EAX */ = b; | |
102 | break; | |
103 | } | |
104 | case 0x30000: | |
105 | { | |
106 | unsigned char b; | |
107 | ||
108 | strcpy(s, "WRITxxxxxxxxxxxxxxxx"); | |
109 | b = *(unsigned char*)0xAFFD0 /* EAX */; | |
110 | tohex(s+4, cts); | |
111 | tohex(s+12, b); | |
112 | dolog(s); | |
113 | outb(cts & 0xFFFF, b); | |
114 | break; | |
115 | } | |
116 | default: | |
117 | dolog("Unhandled PCI cycle"); | |
118 | } | |
85bc8ca6 JW |
119 | |
120 | outl(0x848, 0x1000); | |
121 | outl(0x840, 0x0100); | |
98765740 JP |
122 | } |
123 | ||
015cd976 JW |
124 | void __start (void) |
125 | { | |
31be35cd | 126 | static int first = 1; |
035d7af7 JW |
127 | |
128 | pcisave = inl(0xCF8); | |
129 | vgasave = inb(0x3D4); | |
31be35cd JW |
130 | |
131 | if (first) | |
132 | { | |
133 | first = 0; | |
134 | dolog("NetWatch running..."); | |
135 | } | |
035d7af7 | 136 | |
4bea7daf | 137 | counter++; |
31be35cd | 138 | outb(0x80, (counter & 0xFF)); |
035d7af7 | 139 | |
31be35cd JW |
140 | strcpy(thestr, "15-412! xxxxxxxx xxxxxxxx"); |
141 | tohex(thestr + 8, inl(0x0834)); | |
142 | tohex(thestr + 17, counter); | |
143 | strblit(thestr, 0, 0); | |
035d7af7 | 144 | |
31be35cd JW |
145 | if (inl(0x834) & 0x20) |
146 | dolog("Warning: unhandled APM access"); | |
4122ee13 JW |
147 | if (inl(0x834) & 0x1000) |
148 | { | |
149 | if (inl(0x844) & 0x1000) /* devact_sts */ | |
150 | { | |
98765740 | 151 | pci_dump(); |
85bc8ca6 | 152 | outl(0x844, 0x1000); /* ack it */ |
4122ee13 JW |
153 | } |
154 | } | |
31be35cd JW |
155 | if (inl(0x834) & 0x4000) |
156 | dolog("Long periodic timer"); | |
98765740 JP |
157 | if (inl(0x840) & 0x1000) |
158 | { | |
98765740 JP |
159 | pci_dump(); |
160 | outl(0x840, 0x1100); | |
161 | outl(0x840, 0x0100); | |
162 | } | |
31be35cd JW |
163 | if (inl(0x834) & ~(0x4160)) |
164 | { | |
36ce375d | 165 | char s[40]; |
31be35cd JW |
166 | strcpy(s, "Unknown: xxxxxxxx"); |
167 | tohex(s + 9, inl(0x834) & ~(0x140)); | |
168 | dolog(s); | |
169 | } | |
98765740 JP |
170 | |
171 | ||
31be35cd | 172 | outlog(); |
035d7af7 JW |
173 | |
174 | outl(0xCF8, pcisave); | |
175 | outb(0x3D4, vgasave); | |
a46bffee | 176 | |
4122ee13 | 177 | outl(0x848, 0x1000); |
31be35cd | 178 | outl(0x834, /*0x40*/0xFFFF); // ack the periodic IRQ |
a46bffee JW |
179 | outb(0x830, (inb(0x830) | 0x2) & ~0x40); |
180 | outb(0x830, inb(0x830) | 0x40); | |
181 | ||
4bea7daf JW |
182 | } |
183 |