]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Stack trace better if I take my stack trace better pill.
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Wed, 12 Nov 2008 00:36:28 +0000 (19:36 -0500)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Wed, 12 Nov 2008 00:36:28 +0000 (19:36 -0500)
aseg-paging/pagingstub.c
include/minilib.h
include/paging.h
lib/minilib.c
net/http/fs.c
net/http/fsdata.c

index 161dc1f52661c023cbd721a79f81af2ff23886f9..7d430b92c5e200d1efb2d61d3f3b9510833972fb 100644 (file)
@@ -40,6 +40,8 @@ static unsigned long *pd;
 
 extern int _bss, _bssend, _end;
 
+static unsigned long curmapped = 0xFFFFFFFF;
+
 unsigned long v2p(void *virt)
 {
        unsigned long _virt = (unsigned long)virt;
@@ -51,6 +53,11 @@ unsigned long v2p(void *virt)
                return _virt;
        if (_virt >= 0x200000 && _virt < 0x300000)
                return _virt - 0x200000 + /* XXX */ 0x1FF82000;
+       if (_virt >= 0x1F0000 && _virt < 0x1F2000)
+               return _virt - 0x1F0000 + 0x1FF80000;
+       if ((_virt & ~0xFFF) == 0x4000)
+               return _virt - 0x4000 + curmapped;
+       
        outputf("WARNING: v2p(%08x)", _virt);
        return 0xFFFFFFFF;
 }
@@ -62,14 +69,21 @@ void *p2v(unsigned long phys)
        
        if (phys >= 0xA0000 && phys < 0xC0000)
                return (void*)phys;
-       if (phys >= 0x1FF80000 && phys < 0x20000000)
+       if (phys >= 0x1FF82000 && phys < 0x20000000)
                return (void*)(phys - 0x1FF82000 + 0x200000);
-       outputf("WARNING: p2v(%08x)", phys);
-       return (void *)0xFFFFFFFF;
+       if (phys >= 0x1FF80000 && phys < 0x1FF82000)
+               return (void*)(phys - 0x1FF80000 + 0x1F0000);
+               
+       if ((phys & ~0xFFF) != curmapped)       /* If it's not mapped, map it in. */
+       {
+               curmapped = phys & ~0xFFF;
+               addmap(0x4000, curmapped);
+               asm volatile("invlpg 0x4000");
+       }
+       return (void*)(0x4000 + (phys & 0xFFF));
 }
 
-
-inline int pt_addmap(unsigned long *pd, unsigned long vaddr, unsigned long paddr)
+int addmap(unsigned long vaddr, unsigned long paddr)
 {
        unsigned long pde = ((unsigned long *)p2v((unsigned long)pd))[PDE_FOR(vaddr)];
        unsigned long *pt;
@@ -83,13 +97,28 @@ inline int pt_addmap(unsigned long *pd, unsigned long vaddr, unsigned long paddr
        return 0;
 }
 
-static void * pt_setup(int tseg_start, int tseg_size) {
+void *demap(unsigned long client_pd, unsigned long vaddr)
+{
+       unsigned long pde = ((unsigned long *)p2v(client_pd))[PDE_FOR(vaddr)];
+       unsigned long pte;
+       
+       if (!(pde & PTE_PRESENT))
+               return (void*)0x0;
+       pte = ((unsigned long *)p2v(ADDR_12_MASK(pde)))[PTE_FOR(vaddr)];
+       if (!(pte & PTE_PRESENT))
+               return (void*)0x0;
+       return p2v((pte & ~0xFFF) + (vaddr & 0xFFF));
+}
+
+static void pt_setup(int tseg_start, int tseg_size) {
        int i;
 
        /* 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);
+       
+       pd = pagedirectory;
 
        /* Clear out the page directory except for one entry pointing to the
         * page table, and clear the page table entirely. */
@@ -102,18 +131,20 @@ static void * pt_setup(int tseg_start, int tseg_size) {
 
        /* Map 0x0A0000:0x0BFFFF to itself. */
        for (i = 0; i < 32; i++)
-               pt_addmap(pagedirectory, 0xA0000 + i * 0x1000, 0xA0000 + i * 0x1000);
+               addmap(0xA0000 + i * 0x1000, 0xA0000 + i * 0x1000);
 
-       /* Map 0x200000:0x300000 to TSEG */
+       /* Map 0x200000:0x300000 to TSEG data */
        for (i = 0; i < 256; i++)
-               pt_addmap(pagedirectory, 0x200000 + i * 0x1000, tseg_start + 0x2000 + i * 0x1000);
+               addmap(0x200000 + i * 0x1000, tseg_start + (i + 2) * 0x1000);
 
        /* Map 0x300000:0x400000 to 0x200000, so we can copy our code out of
         * RAM the first time around */
        for (i = 0; i < 256; i++)
-               pt_addmap(pagedirectory, 0x300000 + i * 0x1000, 0x200000 + i * 0x1000);
+               addmap(0x300000 + i * 0x1000, 0x200000 + i * 0x1000);
 
-       return pagedirectory;
+       /* Map 0x1F0000:0x1F2000 to TSEG paging info */
+       for (i = 0; i < 2; i++)
+               addmap(0x1F0000 + i * 0x1000, tseg_start + i * 0x1000);
 }
 
 void c_entry(void)
@@ -122,7 +153,7 @@ void c_entry(void)
 
        outb(0x80, 0x01);       
        if (!initialized)
-               pd = pt_setup(0x1FF80000, 0x80000);
+               pt_setup(0x1FF80000, 0x80000);
        outb(0x80, 0x02);
                
        /* Enable paging. */
index 7d66efb3b39e5171d3f6108057582f8fc25e0bef..d743d5ba28bac90abd3a239d0e6e9d9c3fe6cbf1 100644 (file)
@@ -10,6 +10,7 @@ extern int memcmp(const char *a2, const char *a1, int bytes);
 extern int strcmp(const char *a2, const char *a1);
 extern int strncmp(const char *a2, const char *a1, int n);
 extern int strlen(const char *c);
+extern void strcat(char *dest, char *src);
 extern void strcpy(char *a2, const char *a1);
 extern void puts(const char *c);
 extern void tohex(char *s, unsigned long l);
index fb74a0dd6b2e6ca354eaa55fac1718a6cf4f8271..90c44e95513ebdf37f35b5ec0b8a3d852510d36b 100644 (file)
@@ -3,5 +3,7 @@
 
 extern unsigned long v2p(void *virt);
 extern void *p2v(unsigned long phys);
+extern int addmap(unsigned long vaddr, unsigned long paddr);
+extern void *demap(unsigned long _pd, unsigned long vaddr);
 
 #endif
index e90f7aff62a89ce9295ad8f9fe4a322aa766b458..664a0b42a7abe24229793a7490fd5b5cc934a923 100644 (file)
@@ -75,6 +75,15 @@ void strcpy(char *a2, const char *a1)
        } while (*(a1++));
 }
 
+void strcat(char *dest, char *src)
+{
+       while (*dest)
+               dest++;
+       while (*src)
+               *(dest++) = *(src++);
+       *(dest++) = *(src++);
+}
+
 void puts(const char *c)
 {
        putbytes(c, strlen(c));
index 54c5bd95fbdb4104b6b5d11e917f4fc11b42c368..cb7a2263c7bf5980fd3b7db059fa3ed67922ef1b 100644 (file)
@@ -34,6 +34,9 @@
 #include "fsdata.h"
 #include "fsdata.c"
 #include <io.h>
+#include <minilib.h>
+#include <paging.h>
+#include <output.h>
 
 /*-----------------------------------------------------------------------------------*/
 
@@ -67,6 +70,50 @@ void handle_regs(struct fs_file *file)
   file->len = strlen(buf)-1;
 }
 
+void handle_backtrace(struct fs_file *file)
+{
+  static unsigned char buf[2048];
+  static unsigned char buf2[64];
+  int i = 10;
+  unsigned long *pebp, *peip;
+  unsigned long ebp;
+  unsigned long cr3;
+  
+  strcpy(buf, "<html><head><title>Backtrace</title></head><body><tt><pre>");
+  ebp = *(unsigned long *)0xAFFE4;
+  cr3 = *(unsigned long *)0xAFFF8;
+  
+  sprintf(buf2, "0x%08x, from\n", *(unsigned long*)0xAFFF0);
+  strcat(buf, buf2);
+  
+  /* I never thought I'd do this again. */
+  while ((peip = demap(cr3, ebp+4)) != 0x0 && i--)
+  {
+    sprintf(buf2, "0x%08x, from\n", *peip);
+    strcat(buf, buf2);
+    pebp = demap(cr3, ebp);
+    if (!pebp)
+    {
+      strcat(buf, "&lt;unreadable %ebp&gt;\n");
+      break;
+    }
+    if (ebp >= *pebp && *pebp)
+    {
+      strcat(buf, "&lt;recursive %ebp&gt;\n");
+      break;
+    }
+    ebp = *pebp;
+  }
+  if (i == -1)
+    strcat(buf, "...\n");
+  else
+    strcat(buf, "&lt;root&gt;");
+  strcat(buf, "</pre></tt></body></html>");
+  
+  file->data = buf;
+  file->len = strlen(buf)-1;
+}
+
 void handle_reboot(struct fs_file *file)
 {
   outb(0xCF9, 0x4);
@@ -87,6 +134,11 @@ fs_open(const char *name, struct fs_file *file)
     handle_regs(file);
     return 1;
   }
+  if (!strcmp(name, "/backtrace.html"))
+  {
+    handle_backtrace(file);
+    return 1;
+  }
   if (!strcmp(name, "/reboot"))
   {
     handle_reboot(file);
index 57180f3c79614cfec652a50148b805f5c79dfc9d..70337a8c354590218c5ff25f30a476df70ee3e68 100644 (file)
@@ -5,8 +5,11 @@ 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></iframe><form action=reboot type=post><input type=submit value=\"Reboot!\"></form></body>"
-  "</html>";
+  "<body><h1>NetWatch</h1>"
+  "<iframe src=\"registers.html\" height=100 width=600></iframe><br>"
+  "<iframe src=\"backtrace.html\" height=250 width=150></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)}};
 const struct fsdata_file file_index_html[] = {{file_404_html, "/index.html", data_index_html, sizeof(data_index_html)}};
This page took 0.030128 seconds and 4 git commands to generate.