]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Hit paging to clean it up a bit. Add a reboot button.
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Tue, 11 Nov 2008 22:38:22 +0000 (17:38 -0500)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Tue, 11 Nov 2008 22:38:22 +0000 (17:38 -0500)
aseg-paging/Makefile
aseg-paging/pagingstub.c
aseg-paging/traps.c
aseg-paging/vm_flags.h
include/paging.h
lib/paging.c [deleted file]
net/3c90x.c
net/http/fs.c
net/http/fsdata.c

index 2a509359ec65a059ee6ba84370915d5ddd272d50..9117d9dfc737dea5db4fa70a2e47cc3adc549b02 100644 (file)
@@ -48,7 +48,6 @@ OBJS =        ../ich2/smi.o \
        ../lib/sprintf.o \
        ../lib/console.o \
        ../lib/serial.o \
-       ../lib/paging.o \
        ../aseg/keyboard.o \
        ../aseg/packet.o \
        $(LWIP_OBJS) \
index 0115713bf93d29e4e990243aade030bb27a22a36..161dc1f52661c023cbd721a79f81af2ff23886f9 100644 (file)
@@ -5,6 +5,7 @@
 #include <smi.h>
 #include <pci-bother.h>
 #include <serial.h>
+#include <output.h>
 #include "traps.h"
 #include "../net/net.h"
 #include "vga-overlay.h"
 extern void smi_init();
 #include "vm_flags.h"
 
+extern void smi_entry();
 void set_cr0(unsigned int);
 void ps_switch_stack (void (*call)(), int stack);
 
-extern int entry_initialized;
-extern int _bss, _bssend, _end;
-void smi_entry();
 #define get_cr0() \
     ({ \
         register unsigned int _temp__; \
@@ -35,107 +34,135 @@ void smi_entry();
 
 #define MAP_FLAGS      (PTE_PRESENT | PTE_READ_WRITE)
 
-void * pt_setup(int smbase, int tseg_start, int tseg_size) {
+static int initialized = 0;
+static int paging_enb = 0;
+static unsigned long *pd;
+
+extern int _bss, _bssend, _end;
+
+unsigned long v2p(void *virt)
+{
+       unsigned long _virt = (unsigned long)virt;
+       
+       if (!paging_enb)
+               return _virt;
+       
+       if (_virt >= 0xA0000 && _virt < 0xC0000)
+               return _virt;
+       if (_virt >= 0x200000 && _virt < 0x300000)
+               return _virt - 0x200000 + /* XXX */ 0x1FF82000;
+       outputf("WARNING: v2p(%08x)", _virt);
+       return 0xFFFFFFFF;
+}
+
+void *p2v(unsigned long phys)
+{
+       if (!paging_enb)
+               return (void*)phys;
+       
+       if (phys >= 0xA0000 && phys < 0xC0000)
+               return (void*)phys;
+       if (phys >= 0x1FF80000 && phys < 0x20000000)
+               return (void*)(phys - 0x1FF82000 + 0x200000);
+       outputf("WARNING: p2v(%08x)", phys);
+       return (void *)0xFFFFFFFF;
+}
+
+
+inline int pt_addmap(unsigned long *pd, unsigned long vaddr, unsigned long paddr)
+{
+       unsigned long pde = ((unsigned long *)p2v((unsigned long)pd))[PDE_FOR(vaddr)];
+       unsigned long *pt;
+       
+       if (!(pde & PTE_PRESENT))
+               return -1;
+       
+       pt = (unsigned long *)p2v(ADDR_12_MASK(pde));
+       pt[PTE_FOR(vaddr)] = paddr | PTE_PRESENT | PTE_READ_WRITE;
+       
+       return 0;
+}
+
+static void * pt_setup(int tseg_start, int tseg_size) {
        int i;
-       outb(0x80, 0x51);
 
-       /* The page directory and page table live at SMBASE and SMBASE + 0x1000,
-        * respectively; clear them. */
-       int * pagedirectory = (int *) tseg_start;
-       int * pagetable = (int *) (tseg_start + 0x1000);
+       /* The page directory and page table live at TSEG and TSEG + 0x1000,
+        * respectively. */
+       unsigned long *pagedirectory = (unsigned long *) tseg_start;
+       unsigned long *pagetable = (unsigned long *) (tseg_start + 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] = (tseg_start + 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. */
 
-       for (i = 0; i < 32; i++) { 
-               pagetable[0xA0 + i] = (0xA0000 + i * 0x1000) | MAP_FLAGS;
-       }
+       /* Map 0x0A0000:0x0BFFFF to itself. */
+       for (i = 0; i < 32; i++)
+               pt_addmap(pagedirectory, 0xA0000 + i * 0x1000, 0xA0000 + i * 0x1000);
 
-       /* Map 0x200000 to TSEG */
-       for (i = 0; i < 128; i++) {
-               pagetable[0x200 + i] = (tseg_start + 0x2000 + i * 0x1000) | MAP_FLAGS;
-       }
+       /* Map 0x200000:0x300000 to TSEG */
+       for (i = 0; i < 256; i++)
+               pt_addmap(pagedirectory, 0x200000 + i * 0x1000, tseg_start + 0x2000 + i * 0x1000);
 
-       /* Map 0x300000 -> 0x200000, so we can copy our code out of
+       /* Map 0x300000:0x400000 to 0x200000, so we can copy our code out of
         * RAM the first time around */
-       for (i = 0; i < 256; i++) {
-               pagetable[0x300 + i] = (0x200000 + i * 0x1000) | MAP_FLAGS;
-       }
+       for (i = 0; i < 256; i++)
+               pt_addmap(pagedirectory, 0x300000 + i * 0x1000, 0x200000 + i * 0x1000);
 
-       outb(0x80, 0x57);
        return pagedirectory;
 }
 
 void c_entry(void)
 {
-       unsigned char *bp;
+       paging_enb = 0;
 
-       outb(0x80, 0x41);
-       if (!entry_initialized)
-               pt_setup(0xA0000, 0x1FF80000, 0x80000);
+       outb(0x80, 0x01);       
+       if (!initialized)
+               pd = pt_setup(0x1FF80000, 0x80000);
+       outb(0x80, 0x02);
                
        /* Enable paging. */
-       outb(0x80, 0x42);
-       set_cr3(0x1FF80000);
+       set_cr3((unsigned long)pd);
        set_cr0(get_cr0() | CR0_PG);
-       
-       outb(0x80, 0x43);
+       outb(0x80, 0x03);
+       paging_enb = 1;
 
-       if (!entry_initialized) {
+       /* If this is the first goround, copy in data. */
+       if (!initialized)
+       {
+               unsigned char *p;
+               
+               outb(0x80, 0x04);
+               for (p = (void *)0x200000; (void *)p < (void *)&_bss; p++)
+                       *p = *(p + 0x100000);
+               for (p = (void *)&_bss; (void *)p < (void *)&_bssend; p++)
+                       *p = 0;
+               outb(0x80, 0x05);
                
-               /* If needed, copy in data. */
-               for (bp = (void *)0x200000; (void *)bp < (void *)&_bss; bp++)
-                       *bp = *(bp + 0x100000);
-               for (bp = (void *)&_bss; (void *)bp < (void *)&_bssend; bp++)
-                       *bp = 0;
+               /* Only now is it safe to call other functions. */
                serial_init();
-               dolog("Paging enabled.");
+               dolog("Evacuation to TSEG complete.");
        }
+       
+       outb(0x80, 0x06);
 
        traps_install();
+       
+       outb(0x80, 0x07);
 
-       if (!entry_initialized) {
-               smi_init();
+       if (!initialized)
+       {
+               smi_init();     /* Run the firstrun. */
+               outb(0x80, 0x08);
                
-               entry_initialized = 1;
+               initialized = 1;
        }
-
-       outb(0x80, 0x44);
+       
+       outb(0x80, 0x09);
        ps_switch_stack(smi_entry, 0x270000);
        outb(0x80, 0xFA);
 }
index 8184bdb74dcfd39520c825dcb950508a88139cbf..f41068fd0604f7cc060ca971ec69cc2e8ca75586 100644 (file)
@@ -92,7 +92,7 @@ void traps_install(void) {
 
         struct pseudo_descriptor pdesc;
        pdesc.limit = sizeof(idt) - 1;
-       pdesc.linear_base = memory_v2p(&idt);
+       pdesc.linear_base = v2p(&idt);
 
        WRAPPER_INSTALL(idt, TRAP, fault_divide, T_DIVIDE_ERROR);
        WRAPPER_INSTALL(idt, TRAP, fault_gp, T_GENERAL_PROTECTION);
index d89c9a89879717366dfb079ff447cf05b9606329..f003516cf267acb6bd85b118edf8f54aa411142a 100644 (file)
@@ -8,6 +8,13 @@
 #ifndef _VM_FLAGS_H
 #define _VM_FLAGS_H
 
+#define PTE_FOR(x)      (((unsigned int)(x) >> 12) & 0x3FF)
+#define PDE_FOR(x)      ((unsigned int)(x) >> 22)
+#define ADDR_12_MASK(x)        ((unsigned int)(x) & ~((1 << 12) - 1))
+#define ADDR_22_MASK(x)        ((unsigned int)(x) & ~((1 << 22) - 1))
+#define LOWER_12(x)    ((unsigned int)(x) & ((1 << 12) - 1))
+#define LOWER_22(x)    ((unsigned int)(x) & ((1 << 22) - 1))
+
 #define PDE_4M_ADDR_SHIFT       22
 #define PTE_4K_ADDR_SHIFT       12
 #define PDE_TABLE_ADDR_SHIFT    12
index 69c12eb95395e80c4d571b417b27c9467eef5120..fb74a0dd6b2e6ca354eaa55fac1718a6cf4f8271 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __PAGING_H
 #define __PAGING_H
 
-extern unsigned long memory_v2p(void *virt);
-extern void *memory_p2v(unsigned long phys);
+extern unsigned long v2p(void *virt);
+extern void *p2v(unsigned long phys);
 
 #endif
diff --git a/lib/paging.c b/lib/paging.c
deleted file mode 100644 (file)
index fc54983..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <minilib.h>
-#include <output.h>
-
-unsigned long memory_v2p(void *virt)
-{
-       unsigned long _virt = (unsigned long)virt;
-       
-       if (_virt >= 0xA0000 && _virt < 0xC0000)
-               return _virt;
-       if (_virt >= 0x200000 && _virt < 0x300000)
-               return _virt - 0x200000 + /* XXX */ 0x1FF82000;
-       outputf("WARNING: v2p(%08x)", _virt);
-       return 0xFFFFFFFF;
-}
-
-void *memory_p2v(unsigned long phys)
-{
-       if (phys >= 0xA0000 && phys < 0xC0000)
-               return (void*)phys;
-       if (phys >= 0x1FF80000 && phys < 0x20000000)
-               return (void*)(phys - 0x1FF82000 + 0x200000);
-       outputf("WARNING: p2v(%08x)", phys);
-       return (void *)0xFFFFFFFF;
-}
index a9d15df28700c84f25942c1a403ea44492812fe4..40edafecd7653c2d39073f1fc9638cde5bbb6d5b 100644 (file)
@@ -489,11 +489,11 @@ a3c90x_transmit(unsigned int size, const char *pkt)
                INF_3C90X.TransmitDPD.DnNextPtr = 0;
                /** set notification for transmission completion (bit 15) **/
                INF_3C90X.TransmitDPD.FrameStartHeader = (size) | 0x8000;
-               INF_3C90X.TransmitDPD.DataAddr = memory_v2p((void*)pkt);
+               INF_3C90X.TransmitDPD.DataAddr = v2p((void*)pkt);
                INF_3C90X.TransmitDPD.DataLength = size + (1<<31);
 
                /** Send the packet **/
-               outl(INF_3C90X.IOAddr + regDnListPtr_l, memory_v2p(&(INF_3C90X.TransmitDPD)));
+               outl(INF_3C90X.IOAddr + regDnListPtr_l, v2p(&(INF_3C90X.TransmitDPD)));
                _issue_command(INF_3C90X.IOAddr, cmdStallCtl, 3 /* Unstall download */);
                
                oneshot_start_ms(100);
@@ -578,11 +578,11 @@ a3c90x_poll(struct nic *nic, int retrieve)
     /** Build the up-load descriptor **/
     INF_3C90X.ReceiveUPD.UpNextPtr = 0;
     INF_3C90X.ReceiveUPD.UpPktStatus = 0;
-    INF_3C90X.ReceiveUPD.DataAddr = memory_v2p(nic->packet);
+    INF_3C90X.ReceiveUPD.DataAddr = v2p(nic->packet);
     INF_3C90X.ReceiveUPD.DataLength = 1536 + (1<<31);
 
     /** Submit the upload descriptor to the NIC **/
-    _outl(memory_v2p(&(INF_3C90X.ReceiveUPD)),
+    _outl(v2p(&(INF_3C90X.ReceiveUPD)),
          INF_3C90X.IOAddr + regUpListPtr_l);
 
     /** Wait for upload completion (upComplete(15) or upError (14)) **/
index 9e6358d627632bbef54410f5047402402164764a..54c5bd95fbdb4104b6b5d11e917f4fc11b42c368 100644 (file)
 #include "fs.h"
 #include "fsdata.h"
 #include "fsdata.c"
+#include <io.h>
 
 /*-----------------------------------------------------------------------------------*/
 
-void fill_regs(struct fs_file *file)
+void handle_regs(struct fs_file *file)
 {
   static unsigned char buf[2048];
   
@@ -63,7 +64,14 @@ void fill_regs(struct fs_file *file)
     
   
   file->data = buf;
-  file->len = strlen(buf);
+  file->len = strlen(buf)-1;
+}
+
+void handle_reboot(struct fs_file *file)
+{
+  outb(0xCF9, 0x4);
+  file->data = "So long!";
+  file->len = 8;
 }
 
 
@@ -76,7 +84,12 @@ fs_open(const char *name, struct fs_file *file)
   /* /registers.html is CGI */
   if (!strcmp(name, "/registers.html"))
   {
-    fill_regs(file);
+    handle_regs(file);
+    return 1;
+  }
+  if (!strcmp(name, "/reboot"))
+  {
+    handle_reboot(file);
     return 1;
   }
 
@@ -85,7 +98,7 @@ fs_open(const char *name, struct fs_file *file)
       f = f->next) {
     if (!strcmp(name, (const char*)f->name)) {
       file->data = f->data;
-      file->len = f->len;
+      file->len = f->len-1;
       return 1;
     }
   }
index 7e700232df9feefd68158a4941bcf31d294e1864..57180f3c79614cfec652a50148b805f5c79dfc9d 100644 (file)
@@ -5,7 +5,7 @@ static const unsigned char data_404_html[] =
 
 static const unsigned char data_index_html[] =
   "<html><head><title>NetWatch</title></head>"
-  "<body><h1>NetWatch</h1><iframe src=\"registers.html\" height=100 width=600 /></body>"
+  "<body><h1>NetWatch</h1><iframe src=\"registers.html\" height=100 width=600></iframe><form action=reboot type=post><input type=submit value=\"Reboot!\"></form></body>"
   "</html>";
 
 const struct fsdata_file file_404_html[] = {{NULL, "/404.html", data_404_html, sizeof(data_404_html)}};
This page took 0.040928 seconds and 4 git commands to generate.