First run at an E1000 driver, with various LWIP fixes.
[akaros.git] / kern / arch / i686 / pmap.c
index c221f3a..cd46434 100644 (file)
@@ -9,7 +9,7 @@
 #include <arch/mmu.h>
 #include <arch/apic.h>
 
-#include <ros/error.h>
+#include <error.h>
 #include <sys/queue.h>
 
 #include <atomic.h>
@@ -55,7 +55,7 @@ segdesc_t gdt[] =
        // 0x28 - tss, initialized in idt_init()
        [GD_TSS >> 3] = SEG_NULL,
 
-       // 0x30 - LDT, set per-process in proc_startcore()
+       // 0x30 - LDT, set per-process
        [GD_LDT >> 3] = SEG_NULL
 };
 
@@ -203,6 +203,7 @@ void setup_default_mtrrs(barrier_t* smp_barrier)
        // flush tlb
        tlb_flush_global();
        // disable MTRRs, and sets default type to WB (06)
+#ifdef __CONFIG_NOMTRRS__ 
        write_msr(IA32_MTRR_DEF_TYPE, 0x00000006);
 
        // Now we can actually safely adjust the MTRRs
@@ -228,6 +229,7 @@ void setup_default_mtrrs(barrier_t* smp_barrier)
 
        // keeps default type to WB (06), turns MTRRs on, and turns off fixed ranges
        write_msr(IA32_MTRR_DEF_TYPE, 0x00000806);
+#endif 
        // reflush caches and TLB
        cache_flush();
        tlb_flush_global();
@@ -364,6 +366,12 @@ vm_init(void)
        boot_map_segment(pgdir, (uintptr_t)LAPIC_BASE, PGSIZE, LAPIC_BASE,
                         PTE_PCD | PTE_PWT | PTE_W | PTE_G);
 
+#ifdef __CONFIG_E1000_MMIO_HACK__
+       // MMIO HACK
+       boot_map_segment(pgdir, (uintptr_t)LAPIC_BASE + PGSIZE, 0x20000, 
+                        E1000_MMIO_ADDR, PTE_PCD | PTE_PWT | PTE_W | PTE_G);
+#endif
+
        // Check that the initial page directory has been set up correctly.
        check_boot_pgdir(pse);
 
@@ -632,6 +640,23 @@ int get_va_perms(pde_t *pgdir, const void *SNT va)
 
 void *get_free_va_range(pde_t *pgdir, uintptr_t addr, size_t len)
 {
+       addr = ROUNDUP(MAX(addr,BRK_END),PGSIZE);
+       len = ROUNDUP(len,PGSIZE);
+
+       for(char* a = (char*)addr; a < (char*)USTACKBOT; a += PGSIZE)
+       {
+               for(char* b = a; b < a+len; b += PGSIZE)
+               {
+                       pte_t* pte = pgdir_walk(pgdir,b,0);
+                       if(pte && !PAGE_UNMAPPED(*pte))
+                       {
+                               a = b;
+                               break;
+                       }
+                       if(b+PGSIZE == a+len)
+                               return a;
+               }
+       }
        return NULL;
 }