From: AceVest Date: Tue, 29 Jul 2014 16:29:36 +0000 (+0800) Subject: printf use stack buffer X-Git-Tag: 0.3.0~6 X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=f5f94d0ba17962c73f6abec2edc9c19ad3e2fc60;p=kernel.git printf use stack buffer --- diff --git a/.gitignore b/.gitignore index bd1f8f4..67abe43 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ bin/hello bin/shell a.* +snapshot.txt diff --git a/bin/shell.c b/bin/shell.c index b3e5724..746ff2b 100644 --- a/bin/shell.c +++ b/bin/shell.c @@ -19,56 +19,23 @@ int pause(unsigned long tick); int main() { int pid = fork(); + printf("pid %u\n", pid); if(pid > 0) { - int n = 10000000; - //while(n--); - printf("parent\n"); - while(1) - { - printf("parent\n"); + while(1) { + printf("parent. child pid %u\n", pid); systest(); - //sysdebug(0x77777777); sysdebug(0x44444444); } } else { - printf("child\n"); while(1) { - printf("child\n"); - systest(); - sysdebug(0xAABBCCDD); - sysdebug(0x0A0B0C0D); - } - } - - if(pid > 0) - { - printf("prarent child pid %u\n", pid); - wait(pid); - printf(">prarent child pid %u\n", pid); - while(1) - { - systest(); - sysdebug(0x112233); - } - } - else if(pid == 0) - { - printf("child\n"); - //execv("/bin/hello", 0); - printf(">child\n"); - while(1) - { + printf("child\n"); systest(); sysdebug(0xAABBCCDD); } } - else - { - - } return 0; } diff --git a/include/stdio.h b/include/stdio.h index 5f803c6..ac83058 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -14,14 +14,14 @@ *-------------------------------------------------------------------------- */ -#ifndef _STDIO_H +#ifndef _STDIO_H #define _STDIO_H #include #include extern int write(int fd, const char *buf, unsigned long size); -char ptfbuf[1024]; static inline int printf(const char *fmt, ...) { + char ptfbuf[512]; char *args = (char*)(((char*)&fmt)+4); vsprintf(ptfbuf, fmt, args); diff --git a/kernel/fork.c b/kernel/fork.c index a6d2eb5..57d67bc 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -120,11 +120,14 @@ int do_fork(pt_regs_t *regs, unsigned long flags) INIT_LIST_HEAD(&tsk->list); + disable_irq(); + unsigned long iflags; irq_save(iflags); list_add(&tsk->list, &root_task.list); irq_restore(iflags); printk("%s:%d\n", __func__, __LINE__); + return (int)tsk->pid; } diff --git a/kernel/init.c b/kernel/init.c index 391e592..6ac3a7e 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -56,6 +56,7 @@ void kernel_task(void *entry) regs.edx = (unsigned long) entry; int pid = do_fork(®s, FORK_KRNL); printk("kernel task pid is %d\n", pid); + enable_irq(); } void root_task_entry() @@ -70,7 +71,7 @@ void root_task_entry() { sysc_test(); //printl(MPL_ROOT, "root:0 [%08x] weight %d cnt %d", current, root_task.weight, cnt++); - asm("sti;hlt;"); + //asm("sti;hlt;"); //sysc_test(); //syscall0(SYSC_TEST); } diff --git a/kernel/innerint.c b/kernel/innerint.c index 7e064e8..77feb17 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/kernel/syscall.c b/kernel/syscall.c index c60d5ac..a932720 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -54,16 +54,15 @@ int sysc_test() current->cnt++; printl(MPL_TEST, "sysc_test cnt %u current %08x cnt %u", cnt++, current, current->cnt); + + return 0; } int sysc_debug(unsigned int v) { static unsigned int cnt=0; -#if 1 - printl(MPL_DEBUG, "task debug syscall %u", cnt++); -#else printl(MPL_DEBUG, "task debug syscall %u value %08x", cnt++, v); -#endif + return 0; } void init_sysc_handler_table() diff --git a/mm/buddy.c b/mm/buddy.c index cf4abe6..0b8e767 100644 --- a/mm/buddy.c +++ b/mm/buddy.c @@ -45,7 +45,7 @@ page_t *_va2page(unsigned long addr) page_t *_pa2page(unsigned long paddr) { unsigned long vaddr = (unsigned long) pa2va(paddr); - printk("%s paddr %08x vaddr %08x\n", __func__, paddr, vaddr); + //printk("%s paddr %08x vaddr %08x\n", __func__, paddr, vaddr); return va2page(vaddr); } diff --git a/mm/page.c b/mm/page.c index 22ecae8..0f6f877 100644 --- a/mm/page.c +++ b/mm/page.c @@ -19,8 +19,7 @@ void do_no_page(void *addr) { - printk("%s addr %08x\n", __func__, (unsigned long)addr); -#if 1 + //printk("%s addr %08x current %08x", __func__, (unsigned long)addr, current); pde_t *page_dir = (pde_t *)current->cr3; pte_t *page_tbl = 0; @@ -44,46 +43,17 @@ void do_no_page(void *addr) page_tbl[npte] = va2pa(page) | PAGE_P | PAGE_WR | PAGE_US; load_cr3(current); - -#else - pde_t *pde = (pde_t *)current->cr3; - pte_t *pte; - unsigned long page = alloc_one_page(0); - page = va2pa(page); - if(page == 0) - panic("failed alloc page"); - - int npde = get_npd(addr); - int npte = get_npt(addr); - - if(PAGE_ALIGN(pde[npde]) == 0) - { - pte = (pte_t*) alloc_one_page(0); - memset((void*)pte, 0, PAGE_SIZE); - if(pte == NULL) - panic("failed alloc pte"); - - pte[npte] = (pte_t) page | PAGE_P | PAGE_WR | PAGE_US; - pde[npde] = va2pa(pte) | PAGE_P | PAGE_WR | PAGE_US; - } - else - { - pte = (pte_t*)(PAGE_ALIGN(pde[npde])); - pte = pa2va(pte); - pte[npte] = (u32) page | PAGE_P | PAGE_WR | PAGE_US; - } -#endif } void do_wp_page(void *addr) { - printk("%s addr %08x\n", __func__, (unsigned long)addr); + //printk("%s addr %08x current %08x\n", __func__, (unsigned long)addr, current); if((unsigned long) addr >= PAGE_OFFSET) { panic("%s invalid addr", __func__); } -#if 1 + int npde = get_npd(addr); int npte = get_npt(addr); @@ -96,7 +66,7 @@ void do_wp_page(void *addr) unsigned long wp_pa_addr = PAGE_ALIGN(page_tbl[npte]); page_t *page = pa2page(wp_pa_addr); - + //printk("page count %u\n", page->count); if(page->count > 0) { page->count --; @@ -118,55 +88,4 @@ void do_wp_page(void *addr) #endif load_cr3(current); - -#else - //printk("%s addr %08x\n", __func__, (unsigned long)addr); - int npde = get_npd(addr); - int npte = get_npt(addr); - - unsigned long *pd = (u32 *)(current->cr3); - unsigned long *pt = NULL; - - pt = pa2va(PAGE_ALIGN(pd[npde])); - assert(va2pa(pt) != 0); - - unsigned long src, dst; - - src = pt[npte]; - - page_t *page = pa2page(src); - - if(page->count > 0) - { - unsigned long flags = PAGE_FLAGS(src); - - page->count--; - - src = (unsigned long) pa2va(PAGE_ALIGN(src)); - - dst = alloc_one_page(0); - - if(0 == dst) - panic("out of memory"); - - dst = va2pa(dst); - - pt[npte] = dst | flags; - pt[npte] |= PAGE_WR; - pd[npde] |= PAGE_WR; - - dst = (unsigned long)pa2va(PAGE_ALIGN(dst)); - - memcpy((void *)dst, (void *)src, PAGE_SIZE); - } - else - { - pd[npde] |= PAGE_WR; - pt[npte] |= PAGE_WR; - //pd[npde] |= PAGE_US; - //pt[npte] |= PAGE_US; - } - - load_cr3(current); -#endif }