From 31ad08b7ae67bc9c0d87ecd227ceedc2da521c85 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 21 Feb 2011 08:36:06 +0100 Subject: [PATCH] Remap lapic and ioapic to the kernel space + some cosmetic changes --- arch/x86/kernel/apic.c | 18 ++++++++++++------ arch/x86/kernel/gdt.c | 1 + arch/x86/mm/page.c | 36 ++++++++++++------------------------ 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/arch/x86/kernel/apic.c b/arch/x86/kernel/apic.c index 5f0e208e..ab113c68 100644 --- a/arch/x86/kernel/apic.c +++ b/arch/x86/kernel/apic.c @@ -249,9 +249,12 @@ int apic_calibration(void) if (!has_apic()) return -ENXIO; - map_region(per_core(current_task), lapic, lapic, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE); + lapic = map_region(per_core(current_task), 0 /*lapic*/, lapic, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE); + if (BUILTIN_EXPECT(!lapic, 0)) + return -ENXIO; + if (ioapic) - map_region(per_core(current_task), (size_t)ioapic, (size_t)ioapic, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE); + ioapic = map_region(per_core(current_task), 0 /*(size_t)ioapic*/, (size_t)ioapic, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE); old = get_clock_tick(); @@ -288,10 +291,13 @@ int apic_calibration(void) if (!has_apic()) return -ENXIO; - map_region(per_core(current_task), lapic, lapic, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE); - if (ioapic) - map_region(per_core(current_task), (size_t)ioapic, (size_t)ioapic, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE); - + lapic = map_region(per_core(current_task), 0 /*lapic*/, lapic, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE); + if (BUILTIN_EXPECT(!lapic, 0)) + return -ENXIO; + + if (ioapic) + ioapic = map_region(per_core(current_task), 0 /*(size_t)ioapic*/, (size_t)ioapic, 1, MAP_KERNEL_SPACE|MAP_NO_CACHE); + lapic_write(APIC_DCR, 0xB); // set it to 1 clock increments lapic_write(APIC_LVT_T, 0x2007B); // connects the timer to 123 and enables it lapic_write(APIC_ICR, 0xFFFFFFFF); diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index 1763e822..f49430eb 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -23,6 +23,7 @@ #include #include #include +#include gdt_ptr_t gp; static tss_t task_state_segments[MAX_TASKS] __attribute__ ((aligned (4096))); diff --git a/arch/x86/mm/page.c b/arch/x86/mm/page.c index 84c5d88a..8371212a 100644 --- a/arch/x86/mm/page.c +++ b/arch/x86/mm/page.c @@ -84,7 +84,7 @@ int get_user_pgd(task_t* task) pgd = kmalloc(sizeof(page_dir_t)); if (!pgd) return -ENOMEM; - //memcpy(pgd, &boot_pgd, sizeof(page_dir_t)); + memset(pgd, 0, sizeof(page_dir_t)); // create a new "page table container" for the new task pgt = kmalloc(sizeof(page_table_t)); @@ -94,21 +94,12 @@ int get_user_pgd(task_t* task) } memset(pgt, 0, sizeof(page_table_t)); - for(i=0; i<1024 /*KERNEL_SPACE/(1024*4096)*/; i++) { + for(i=0; ientries[i] = boot_pgd.entries[i]; - if (pgd->entries[i]) { - kprintf("pgd->entries[%d] = %p\n", i, pgd->entries[i]); + if (pgd->entries[i]) pgt->entries[i] = pgt_container->entries[i]; - kprintf("pgt->entries[%d] = %p\n", i, pgt->entries[i]); - } } - //for(i=0/*1024-KERNEL_SPACE/(1024*4096)*/; i<1024; i++) { - // pgt->entries[i] = pgt_container->entries[i]; - // if (pgt->entries[i]) - // kprintf("pgt->entries[%d] = %p\n", i, pgt->entries[i]); - //} - // map page table container at the end of the kernel space viraddr = (KERNEL_SPACE - PAGE_SIZE) & 0xFFFFF000; index1 = viraddr >> 22; @@ -118,9 +109,6 @@ int get_user_pgd(task_t* task) pgd->entries[index1] = ((size_t) virt_to_phys(per_core(current_task), (size_t) pgt) & 0xFFFFF000)|KERN_TABLE; pgt->entries[index2] = ((size_t) virt_to_phys(per_core(current_task), (size_t) pgt) & 0xFFFFF000)|KERN_PAGE; - kprintf("AAA pgd->entries[%d] = %p\n", index1, pgd->entries[index1]); - kprintf("AAA pgt->entries[%d] = %p\n", index2, pgt->entries[index2]); - task->pgd = pgd; task->pgd_lock = &boot_pgd_lock; @@ -149,11 +137,11 @@ size_t virt_to_phys(task_t* task, size_t viraddr) if (!pgt || !(pgt->entries[index2])) goto out; - ret = pgt->entries[index2] & 0xFFFFF000; // determine page frame + ret = pgt->entries[index2] & 0xFFFFF000; // determine page frame ret = ret | (viraddr & 0xFFF); // add page offset out: //kprintf("vir %p to phy %p\n", viraddr, ret); - + return ret; } @@ -208,8 +196,8 @@ size_t map_region(task_t* task, size_t viraddr, size_t phyaddr, uint32_t npages, if (BUILTIN_EXPECT(!pgt_container, 0)) { spinlock_unlock(task->pgd_lock); - kputs("map_address: internal error\n"); - return 0; + kputs("map_address: internal error\n"); + return 0; } // map the new table into the address space of the kernel space @@ -255,7 +243,7 @@ size_t map_region(task_t* task, size_t viraddr, size_t phyaddr, uint32_t npages, size_t vm_alloc(task_t* task, uint32_t npages, uint32_t flags) { uint32_t index1, index2, j; - size_t viraddr, i; + size_t viraddr, i; size_t start, end; page_table_t* pgt; @@ -277,7 +265,7 @@ size_t vm_alloc(task_t* task, uint32_t npages, uint32_t flags) j = 0; do { index1 = i >> 22; - index2 = (i >> 12) & 0x3FF; + index2 = (i >> 12) & 0x3FF; pgt = (page_table_t*) ((KERNEL_SPACE - 1024*PAGE_SIZE + index1*PAGE_SIZE) & 0xFFFFF000); if (!pgt || !(pgt->entries[index2])) { @@ -309,7 +297,7 @@ int vm_free(task_t* task, size_t viraddr, uint32_t npages) for(i=0; i> 22; - index2 = (viraddr >> 12) & 0x3FF; + index2 = (viraddr >> 12) & 0x3FF; pgt = (page_table_t*) ((KERNEL_SPACE - 1024*PAGE_SIZE + index1*PAGE_SIZE) & 0xFFFFF000); if (!pgt) @@ -338,7 +326,7 @@ int print_paging_tree(size_t viraddr) if (pgd) { kprintf("0x%0x\n", pgd->entries[index1]); pgt = (page_table_t*) (pgd->entries[index1] & 0xFFFFF000); - } else + } else kputs("invalid page directory\n"); /* convert physical address to virtual */ @@ -380,7 +368,7 @@ int arch_paging_init(void) return -ENOMEM; } memset(pgt, 0, PAGE_SIZE); - + // map this table at the end of the kernel space viraddr = KERNEL_SPACE - PAGE_SIZE; index1 = viraddr >> 22;