From: AceVest Date: Mon, 28 Jul 2014 15:24:39 +0000 (+0800) Subject: fix bug in put_paging X-Git-Tag: 0.3.0~9 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=d13b9f44b65b7d48091f2abcfa1eaafc126632c8;p=kernel.git fix bug in put_paging --- diff --git a/bin/shell.c b/bin/shell.c index 3640d9e..9631d97 100644 --- a/bin/shell.c +++ b/bin/shell.c @@ -42,7 +42,7 @@ int main() sysdebug(0x0A0B0C0D); } } - + if(pid > 0) { printf("prarent child pid %u\n", pid); diff --git a/include/page.h b/include/page.h index 8624991..96cdec5 100644 --- a/include/page.h +++ b/include/page.h @@ -98,9 +98,11 @@ typedef struct page } page_t; void *page2va(page_t *page); -page_t *va2page(unsigned long addr); +page_t *_va2page(unsigned long addr); +page_t *_pa2page(unsigned long addr); -#define pa2page(addr) va2page((unsigned long)pa2va(PAGE_ALIGN(addr))) +#define va2page(addr) _va2page(PAGE_ALIGN(addr)) +#define pa2page(addr) _pa2page(PAGE_ALIGN(addr)) static inline page_t *get_head_page(page_t *page) { return page->head_page; } diff --git a/kernel/exec.c b/kernel/exec.c index 04e84de..d76a35b 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -37,7 +37,9 @@ void put_paging(unsigned long vaddr, unsigned long paddr, unsigned long flags) if(page_table == 0) { - page_table = (pte_t *) va2pa(alloc_one_page(0)); + page_table = (pte_t *) alloc_one_page(0); + memset(page_table, 0, PAGE_SIZE); + page_table = (pte_t *) va2pa(page_table); assert(page_table != 0); } @@ -110,8 +112,10 @@ int sysc_exec(const char *path, char *const argv[]) load_cr3(current); + disable_irq(); pt_regs_t *regs = ((pt_regs_t *)(TASK_SIZE+(unsigned long)current)) - 1; +#if 0 memset((void*)regs, 0, sizeof(pt_regs_t)); regs->ss = SELECTOR_USER_DS; regs->ds = SELECTOR_USER_DS; @@ -121,6 +125,7 @@ int sysc_exec(const char *path, char *const argv[]) regs->esp = (KRNLADDR-4*sizeof(unsigned long)); regs->eflags= 0x200; regs->cs = SELECTOR_USER_CS; +#endif regs->eip = (unsigned long)ehdr->e_entry; regs->edx = regs->eip; regs->ecx = (0xC0000000 - 16); diff --git a/kernel/init.c b/kernel/init.c index d84bd19..391e592 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -61,8 +61,6 @@ void kernel_task(void *entry) void root_task_entry() { - kernel_task(init_task_entry); - kernel_task(init_task_entry); kernel_task(init_task_entry); kernel_task(user_task_entry); diff --git a/kernel/innerint.c b/kernel/innerint.c index 77feb17..7e064e8 100644 --- a/kernel/innerint.c +++ b/kernel/innerint.c @@ -104,7 +104,7 @@ US RW P - Description asm("movl %%cr2,%%eax":"=a"(addr)); - printk("do page fault errcode %x addr %08x [%08x]\n", errcode, addr, current); + //printk("do page fault errcode %x addr %08x [%08x]\n", errcode, addr, current); //assert(errcode != 2 && errcode != 6); diff --git a/mm/buddy.c b/mm/buddy.c index 596666f..cf4abe6 100644 --- a/mm/buddy.c +++ b/mm/buddy.c @@ -27,15 +27,27 @@ int buddy_is_free(page_t *page, unsigned int order) return 0; } -page_t *va2page(unsigned long addr) +page_t *_va2page(unsigned long addr) { page_t *page = buddy_system.page_map + va2pfn(addr); assert(page >= buddy_system.page_map); - assert(page < buddy_system.page_map_end); + //assert(page < buddy_system.page_map_end); + if(page >= buddy_system.page_map_end) + { + printk("buddy_system.page_map %08x buddy_system.page_map_end %08x\n", buddy_system.page_map, buddy_system.page_map_end); + printk("error %s page %08x addr %08x\n", __func__, page, addr); + panic("error"); + } return page; } +page_t *_pa2page(unsigned long paddr) +{ + unsigned long vaddr = (unsigned long) pa2va(paddr); + printk("%s paddr %08x vaddr %08x\n", __func__, paddr, vaddr); + return va2page(vaddr); +} void *page2va(page_t *page) { @@ -90,7 +102,7 @@ found: p->order = order; } - page->count = 1; + page->count = 0; return page; }