]> Joshua Wise's Git repositories - netwatch.git/commitdiff
some more haxing
authorJacob Potter <jdpotter@andrew.cmu.edu>
Sun, 9 Nov 2008 23:22:41 +0000 (18:22 -0500)
committerJacob Potter <jdpotter@andrew.cmu.edu>
Sun, 9 Nov 2008 23:22:41 +0000 (18:22 -0500)
aseg-paging/Makefile
aseg-paging/aseg.lds
aseg-paging/firstrun.c
aseg-paging/main.c [new file with mode: 0644]
aseg-paging/pagetable.c [deleted file]
aseg-paging/pagetable.h [deleted file]
aseg-paging/pagingstub.c
aseg-paging/smi.c

index a3a52f8a1c65cd1823f09ab576d0c862b2807fb1..58d2652eabb0609311f3c3b411940dc63fd80408 100644 (file)
@@ -6,7 +6,54 @@ CFLAGS=-I../include -I../include/raw \
 
 STUBOBJS=entry.o pagingstub-asm.o pagingstub.o
 
-OBJS=smi.o ../ich2/smi.o ../ich2/smram-ich2.o vga-overlay.o ../pci/pci-raw.o ../lib/minilib.o ../lib/doprnt.o ../lib/sprintf.o ../lib/console.o ../lib/serial.o
+LWIP_OBJS = \
+       ../lwip/src/core/dhcp.o \
+       ../lwip/src/core/dns.o \
+       ../lwip/src/core/init.o \
+       ../lwip/src/core/ipv4/autoip.o \
+       ../lwip/src/core/ipv4/icmp.o \
+       ../lwip/src/core/ipv4/igmp.o \
+       ../lwip/src/core/ipv4/inet.o \
+       ../lwip/src/core/ipv4/inet_chksum.o \
+       ../lwip/src/core/ipv4/ip.o \
+       ../lwip/src/core/ipv4/ip_addr.o \
+       ../lwip/src/core/ipv4/ip_frag.o \
+       ../lwip/src/core/mem.o \
+       ../lwip/src/core/memp.o \
+       ../lwip/src/core/netif.o \
+       ../lwip/src/core/pbuf.o \
+       ../lwip/src/core/raw.o \
+       ../lwip/src/core/stats.o \
+       ../lwip/src/core/sys.o \
+       ../lwip/src/core/tcp.o \
+       ../lwip/src/core/tcp_in.o \
+       ../lwip/src/core/tcp_out.o \
+       ../lwip/src/core/udp.o \
+       ../lwip/src/netif/etharp.o \
+       ../lwip/src/netif/ethernetif.o
+
+
+OBJS = ../ich2/smi.o \
+       ../ich2/smram-ich2.o \
+       ../ich2/ich2-timer.o \
+       ../pci/pci.o \
+       ../pci/pci-raw.o \
+       ../pci/pci-bother.o \
+       ../net/net.o \
+       ../net/3c90x.o \
+       ../lib/minilib.o \
+       ../lib/doprnt.o \
+       ../lib/sprintf.o \
+       ../lib/console.o \
+       ../lib/serial.o \
+       ../aseg/keyboard.o \
+       ../aseg/packet.o \
+       $(LWIP_OBJS) \
+       smi.o \
+       vga-overlay.o \
+       main.o \
+       firstrun.o
+
 
 all: aseg.elf
 
index 760fe92175c252059aa107f1fc07a6fd572a59e7..7c70a08b64b7606344894ad288e8721e7b9b0988 100644 (file)
@@ -39,7 +39,7 @@ SECTIONS
        .info : {
                _start = .;
                LONG(0x5754454E);
-               LONG(__firstrun_start);
+               LONG(__firstrun_stub);
        }
 
 }
index 97e86920215f8d661a9a9feb711a13c5554cef6a..ca611fa006e5f2a7e820b639711b6e91ebd82d41 100644 (file)
@@ -13,20 +13,12 @@ extern void timer_handler(smi_event_t ev);
 extern void kbc_handler(smi_event_t ev);
 extern void gbl_rls_handler(smi_event_t ev);
 
-void __firstrun_start() {
-       unsigned char *bp;
+void smi_init() {
        smram_state_t smram;
        
        smram = smram_save_state();
        smram_tseg_set_state(SMRAM_TSEG_OPEN);
-       serial_init();
-/*     
-       for (bp = (void *)&_bss; (void *)bp < (void *)&_bssend; bp++)
-               *bp = 0;
-       
-       vga_flush_imm(0);
-*/
-       
+
        outputf("NetWatch running");
 
        /* Try really hard to shut up USB_LEGKEY. */
@@ -37,19 +29,18 @@ void __firstrun_start() {
 
        /* Turn on the SMIs we want */
        smi_disable();
-       /*
        
        eth_init();
-       
+
        smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler);
        smi_enable_event(SMI_EVENT_FAST_TIMER);
-       
+
        smi_register_handler(SMI_EVENT_DEVTRAP_KBC, kbc_handler);
        smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
        
        smi_register_handler(SMI_EVENT_GBL_RLS, gbl_rls_handler);
        smi_enable_event(SMI_EVENT_GBL_RLS);
-*/
+
        smi_enable();
        
        vga_flush_imm(1);
diff --git a/aseg-paging/main.c b/aseg-paging/main.c
new file mode 100644 (file)
index 0000000..7b5c093
--- /dev/null
@@ -0,0 +1,148 @@
+#include <io.h>
+#include <smram.h>
+#include <video_defines.h>
+#include <minilib.h>
+#include <smi.h>
+#include <pci-bother.h>
+#include "../net/net.h"
+#include "vga-overlay.h"
+#include "../aseg/packet.h"
+#include "../aseg/keyboard.h"
+
+unsigned int lastctr = 0;
+extern unsigned int counter;
+
+static int curdev = 0;
+
+static void cause_kbd_irq()
+{
+       outl(0x844, 0x0);
+       outl(0x848, 0x0);
+       while (inb(0x64) & 0x1)
+               inb(0x60);
+       outb(0x60, 0xee);       /* Cause an IRQ. */
+       while (inb(0x60) != 0xEE)
+               ;
+}
+
+void pci_dump() {
+       unsigned long cts;
+               
+       cts = inl(0x84C);
+       
+       outl(0x840, 0x0);
+       outl(0x848, 0x0);
+       switch(cts&0xF0000)
+       {
+       case 0x20000:
+       {
+               unsigned char b;
+               
+               switch (cts & 0xFFFF)
+               {
+               case 0x64:
+                       /* Read the real hardware and mask in our OBF if need be. */
+                       b = inb(0x64);
+                       if (kbd_has_injected_scancode())
+                       {
+                               dologf("OS wants to know; we have data");
+                               lastctr = counter;
+                               b |= 0x01;
+                               b &= ~0x20;     /* no mouse for you! */
+                               curdev = 0;
+                       } else 
+                               curdev = (b & 0x20) ? 1 : 0;
+                       *(unsigned char*)0xAFFD0 /* EAX */ = b;
+                       break;
+               case 0x60:
+                       if (kbd_has_injected_scancode())
+                       {
+                               b = kbd_get_injected_scancode();
+                               lastctr = counter;
+                               while (inb(0x64) & 0x1)
+                                       inb(0x60);
+                       } else
+                               b = inb(0x60);
+                       if ((curdev == 0) && (b == 0x01)) {     /* Escape */
+                               outb(0xCF9, 0x4);       /* Reboot */
+                               return;
+                       }
+                       
+                       /* If there is more nus to come, generate another IRQ. */
+                       if (kbd_has_injected_scancode())
+                               cause_kbd_irq();
+                       
+                       *(unsigned char*)0xAFFD0 /* EAX */ = b;
+                       break;
+               }
+
+               *(unsigned char*)0xAFFD0 /* EAX */ = b;
+               break;
+       }
+       case 0x30000:
+       {
+               unsigned char b;
+               
+               b = *(unsigned char*)0xAFFD0 /* EAX */;
+               dologf("WRITE: %08x (%02x)", cts, b);
+               outb(cts & 0xFFFF, b);
+               break;
+       }
+       default:
+               dolog("Unhandled PCI cycle");
+       }
+       
+       outl(0x840, 0x0);
+       outl(0x844, 0x1000);
+       outl(0x848, 0x1000);
+}
+
+void timer_handler(smi_event_t ev)
+{
+       static unsigned int ticks = 0;
+       
+       smi_disable_event(SMI_EVENT_FAST_TIMER);
+       smi_enable_event(SMI_EVENT_FAST_TIMER);
+       
+       if (kbd_has_injected_scancode() && (counter > (lastctr + 2)))
+       {
+               smi_disable_event(SMI_EVENT_DEVTRAP_KBC);
+               dolog("Kicking timer");
+               cause_kbd_irq();
+               smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
+       }
+       
+       outb(0x80, (ticks++) & 0xFF);
+       
+       outlog();
+}
+
+void kbc_handler(smi_event_t ev)
+{
+       pci_dump();
+}
+
+void gbl_rls_handler(smi_event_t ev)
+{
+       unsigned long ecx;
+       
+       ecx = *(unsigned long*)0xAFFD4;
+
+       packet_t * packet = check_packet(ecx);
+       if (!packet)
+       {
+               dologf("WARN: bad packet at %08x", ecx);
+               return;
+       }
+
+       dologf("Got packet: type %08x", packet->type);
+
+       if (packet->type == 42) {
+               dump_log((char *)packet->data);
+               *(unsigned long*)0xAFFD4 = 42;
+       } else if (packet->type == 0xAA) {
+               kbd_inject_key('A');
+       } else {
+               *(unsigned long*)0xAFFD4 = 0x2BADD00D;
+       }
+}
diff --git a/aseg-paging/pagetable.c b/aseg-paging/pagetable.c
deleted file mode 100644 (file)
index 83a1e54..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "vm_flags.h"
-#include <io.h>
-
-#define MAP_FLAGS      (PTE_PRESENT | PTE_READ_WRITE)
-
-void * pt_setup(int smbase) {
-       int i;
-       outb(0x80, 0x51);
-
-       /* The page directory and page table live at SMBASE and SMBASE + 0x1000,
-        * respectively; clear them. */
-       int * pagedirectory = (int *) smbase;
-       int * pagetable = (int *) (smbase + 0x1000);
-
-       /* Clear out the page directory except for one entry pointing to the
-        * page table, and clear the page table entirely. */
-       outb(0x80, 0x52);
-       pagedirectory[0] = (smbase + 0x1000) | PTE_PRESENT | PTE_READ_WRITE;
-       outb(0x80, 0x53);
-       for (i = 1; i < 1024; i++)
-       {
-               pagedirectory[i] = 0;
-       }
-
-       outb(0x80, 0x54);
-       for (i = 0; i < 1024; i++)
-       {
-               pagetable[i] = 0;
-       }
-       outb(0x80, 0x55);
-
-       /* The page at 0x10000 - 0x10FFF points to the SMI entry point,
-        * SMBASE + 0x8000. */
-       pagetable[16] = (0x8000 + smbase) | MAP_FLAGS;
-
-       /* 0x11000 to 0x1EFFF map to the rest of ASEG up to SMBASE + 0xF000;
-        * the page containing the saved state is not mappped to our code
-        * region.  */
-
-       for (i = 0; i < 8; i++)
-       {
-               pagetable[17 + i] = (i * 0x1000 + smbase) | MAP_FLAGS;
-       }
-
-       for (i = 0; i < 6; i++)
-       {
-               pagetable[25 + i] = (smbase + 0x9000 + i * 0x1000) | MAP_FLAGS;
-       }
-
-       outb(0x80, 0x56);
-       /* Map 0xA8000 to itself. */
-       pagetable[0xA8] = 0xA8000 | MAP_FLAGS;
-       pagetable[0xA9] = 0xA9000 | MAP_FLAGS;
-
-       /* No TSEG yet. */
-
-       outb(0x80, 0x57);
-       return pagedirectory;
-}
diff --git a/aseg-paging/pagetable.h b/aseg-paging/pagetable.h
deleted file mode 100644 (file)
index e69de29..0000000
index 0a79385a31c0cdeaf1377752bae8b170956f441d..d839966749dbb8dd919f897df80dcda5ac129471 100644 (file)
@@ -8,8 +8,8 @@
 #include "../net/net.h"
 #include "vga-overlay.h"
 
+extern void smi_init();
 #include "vm_flags.h"
-#include "pagetable.h"
 
 void set_cr0(unsigned int);
 void ps_switch_stack (void (*call)(), int stack);
@@ -115,7 +115,6 @@ void c_entry(void)
        
        outb(0x80, 0x43);
        if (!entry_initialized) {
-               extern void __firstrun_start();
                
                /* If needed, copy in data. */
                for (bp = (void *)0x200000; (void *)bp < (void *)&_bss; bp++)
@@ -124,7 +123,7 @@ void c_entry(void)
                        *bp = 0;
                serial_init();
                dolog("Paging enabled.");
-               __firstrun_start();     /* Now initialize BSS, etc. */
+               smi_init();
                
                entry_initialized = 1;
        }
index 9bc124eba642396ba246ec8c3dcd063917e9cce1..eada78df797f1e81514c0977649bf13c5bfc5e25 100644 (file)
@@ -8,31 +8,10 @@
 #include "../net/net.h"
 #include "vga-overlay.h"
 
-#include "pagetable.h"
-
 unsigned int counter = 0;
-unsigned int lastctr = 0;
 unsigned long pcisave = 0;
 unsigned char vgasave = 0;
 
-void set_cr0(unsigned int);
-
-#define get_cr0() \
-    ({ \
-        register unsigned int _temp__; \
-        asm volatile("mov %%cr0, %0" : "=r" (_temp__)); \
-        _temp__; \
-    })
-
-
-#define set_cr3(value) \
-    { \
-        register unsigned int _temp__ = (value); \
-        asm volatile("mov %0, %%cr3" : : "r" (_temp__)); \
-     }
-#define        CR0_PG  0x80000000
-
-
 void smi_entry(void)
 {
        char statstr[512];
@@ -45,13 +24,14 @@ void smi_entry(void)
  */
        counter++;
        outb(0x80, 0x2B);
-       sprintf(statstr, "15-412! %08x %08x", smi_status(), counter);
+       sprintf(statstr, "NetWatch! %08x %08x", smi_status(), counter);
        outb(0x80, 0x3B);
        strblit(statstr, 0, 0);
        outb(0x80, 0x4B);
        
        serial_init();
-       dolog("wee!");
+/*     dolog("wee!");
+ */
        
        /*
        eth_poll();
@@ -75,30 +55,29 @@ void smi_entry(void)
        outb(0x3D4, vgasave);
 }
 
-void timer_handler(smi_event_t ev)
-{
-        static unsigned int ticks = 0;
-
-        smi_disable_event(SMI_EVENT_FAST_TIMER);
-        smi_enable_event(SMI_EVENT_FAST_TIMER);
-
-        outb(0x80, (ticks++) & 0xFF);
+extern void timer_handler(smi_event_t ev);
+extern void kbc_handler(smi_event_t ev);
+extern void gbl_rls_handler(smi_event_t ev);
 
-        outlog();
-}
+void __firstrun_stub() {
 
+        /* Try really hard to shut up USB_LEGKEY. */
+        pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0));
+        pci_write16(0, 31, 2, 0xC0, 0);
+        pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0));
+        pci_write16(0, 31, 4, 0xC0, 0);
 
-void __firstrun_start() {
-       smram_state_t smram;
-       
-       smram = smram_save_state();
-       smram_tseg_set_state(SMRAM_TSEG_OPEN);
-       smi_disable();
-       outb(0x80, 0x41);
+        /* Turn on the SMIs we want */
+        smi_disable();
 
         smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler);
         smi_enable_event(SMI_EVENT_FAST_TIMER);
 
+        smi_register_handler(SMI_EVENT_DEVTRAP_KBC, kbc_handler);
+        smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
+
+        smi_register_handler(SMI_EVENT_GBL_RLS, gbl_rls_handler);
+        smi_enable_event(SMI_EVENT_GBL_RLS);
+
         smi_enable();
 }
-
This page took 0.039443 seconds and 4 git commands to generate.