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