]> Joshua Wise's Git repositories - netwatch.git/blob - aseg-paging/main.c
Enable DHCP.
[netwatch.git] / aseg-paging / main.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 "../aseg/packet.h"
10 #include "../aseg/keyboard.h"
11
12 unsigned int lastctr = 0;
13 extern unsigned int counter;
14
15 static int curdev = 0;
16
17 static void cause_kbd_irq()
18 {
19         outl(0x844, 0x0);
20         outl(0x848, 0x0);
21         while (inb(0x64) & 0x1)
22                 inb(0x60);
23         outb(0x60, 0xee);       /* Cause an IRQ. */
24         while (inb(0x60) != 0xEE)
25                 ;
26 }
27
28 void pci_dump() {
29         unsigned long cts;
30                 
31         cts = inl(0x84C);
32         
33         outl(0x840, 0x0);
34         outl(0x848, 0x0);
35         switch(cts&0xF0000)
36         {
37         case 0x20000:
38         {
39                 unsigned char b;
40                 
41                 switch (cts & 0xFFFF)
42                 {
43                 case 0x64:
44                         /* Read the real hardware and mask in our OBF if need be. */
45                         b = inb(0x64);
46                         if (kbd_has_injected_scancode())
47                         {
48                                 dologf("OS wants to know; we have data");
49                                 lastctr = counter;
50                                 b |= 0x01;
51                                 b &= ~0x20;     /* no mouse for you! */
52                                 curdev = 0;
53                         } else 
54                                 curdev = (b & 0x20) ? 1 : 0;
55                         *(unsigned char*)0xAFFD0 /* EAX */ = b;
56                         break;
57                 case 0x60:
58                         if (kbd_has_injected_scancode())
59                         {
60                                 b = kbd_get_injected_scancode();
61                                 lastctr = counter;
62                                 while (inb(0x64) & 0x1)
63                                         inb(0x60);
64                         } else
65                                 b = inb(0x60);
66                         if ((curdev == 0) && (b == 0x01)) {     /* Escape */
67                                 outb(0xCF9, 0x4);       /* Reboot */
68                                 return;
69                         }
70                         
71                         /* If there is more nus to come, generate another IRQ. */
72                         if (kbd_has_injected_scancode())
73                                 cause_kbd_irq();
74                         
75                         *(unsigned char*)0xAFFD0 /* EAX */ = b;
76                         break;
77                 }
78
79                 *(unsigned char*)0xAFFD0 /* EAX */ = b;
80                 break;
81         }
82         case 0x30000:
83         {
84                 unsigned char b;
85                 
86                 b = *(unsigned char*)0xAFFD0 /* EAX */;
87                 dologf("WRITE: %08x (%02x)", cts, b);
88                 outb(cts & 0xFFFF, b);
89                 break;
90         }
91         default:
92                 dolog("Unhandled PCI cycle");
93         }
94         
95         outl(0x840, 0x0);
96         outl(0x844, 0x1000);
97         outl(0x848, 0x1000);
98 }
99
100 void timer_handler(smi_event_t ev)
101 {
102         static unsigned int ticks = 0;
103         
104         smi_disable_event(SMI_EVENT_FAST_TIMER);
105         smi_enable_event(SMI_EVENT_FAST_TIMER);
106         
107         if (kbd_has_injected_scancode() && (counter > (lastctr + 2)))
108         {
109                 smi_disable_event(SMI_EVENT_DEVTRAP_KBC);
110                 dolog("Kicking timer");
111                 cause_kbd_irq();
112                 smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
113         }
114         
115         outb(0x80, (ticks++) & 0xFF);
116         
117         outlog();
118 }
119
120 void kbc_handler(smi_event_t ev)
121 {
122         pci_dump();
123 }
124
125 void gbl_rls_handler(smi_event_t ev)
126 {
127         unsigned long ecx;
128         
129         ecx = *(unsigned long*)0xAFFD4;
130
131         packet_t * packet = check_packet(ecx);
132         if (!packet)
133         {
134                 dologf("WARN: bad packet at %08x", ecx);
135                 return;
136         }
137
138         dologf("Got packet: type %08x", packet->type);
139
140         if (packet->type == 42) {
141                 dump_log((char *)packet->data);
142                 *(unsigned long*)0xAFFD4 = 42;
143         } else if (packet->type == 0xAA) {
144                 kbd_inject_key('A');
145         } else {
146                 *(unsigned long*)0xAFFD4 = 0x2BADD00D;
147         }
148 }
This page took 0.035773 seconds and 4 git commands to generate.