]> Zhao Yanbai Git Server - kernel.git/commitdiff
printf use stack buffer
authorAceVest <zhaoyanbai@126.com>
Tue, 29 Jul 2014 16:29:36 +0000 (00:29 +0800)
committerAceVest <zhaoyanbai@126.com>
Tue, 29 Jul 2014 16:29:36 +0000 (00:29 +0800)
.gitignore
bin/shell.c
include/stdio.h
kernel/fork.c
kernel/init.c
kernel/innerint.c
kernel/syscall.c
mm/buddy.c
mm/page.c

index bd1f8f418134dc15225e447c4e2d25720a5c6e3c..67abe4365d00d85739d700176892d8a78d5ac8a5 100644 (file)
@@ -27,3 +27,4 @@
 bin/hello
 bin/shell
 a.*
+snapshot.txt
index b3e57248319d0c5917e6b0d7a42f88d762cdfa51..746ff2b123bf26ff9b57d4abc8c12a7214ef8e75 100644 (file)
@@ -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;
 }
index 5f803c6c0d57c73aa293753507f37300e6c09f7c..ac830585291537f555bd1093f4d03d6fbcc1a62b 100644 (file)
  *--------------------------------------------------------------------------
  */
 
-#ifndef    _STDIO_H
+#ifndef _STDIO_H
 #define _STDIO_H
 #include <string.h>
 #include <syscall.h>
 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);
 
index a6d2eb5064ac8d8f92d64a38c4b819ff5fba5763..57d67bc8cd37aafe545bf73925c13216a3df3b3a 100644 (file)
@@ -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;
 }
index 391e59256c5b14e76c244ec5a973c296b800daac..6ac3a7e90406b3f7d3a9dbae6ae7f8cb5499a8e1 100644 (file)
@@ -56,6 +56,7 @@ void kernel_task(void *entry)
     regs.edx = (unsigned long) entry;
     int pid = do_fork(&regs, 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);
     }
index 7e064e8d885a0db9b7260852f0a8537a3f52b1d6..77feb174b8b437145d8b350a601941da7db5f5f9 100644 (file)
@@ -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);
 
index c60d5acc0275a6391e8fd578e02fa61eb89a63ad..a9327200dc19ea61f48c54b059678c1634b6c033 100644 (file)
@@ -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()
index cf4abe6b844ec3eea513a0e54063e34116228b9b..0b8e767ce063c13f1ca17ee5a3ac53b5c54a8234 100644 (file)
@@ -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);
 }
 
index 22ecae8d529d4606c0d117af95e8a095681d4dfe..0f6f8770148c9cffec02fef0a4025be7e52ce5de 100644 (file)
--- 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
 }