Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7a8f55f)
raw | patch | inline | side by side (parent: 7a8f55f)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Tue, 29 Jul 2014 16:29:36 +0000 (00:29 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Wed, 3 Nov 2021 02:45:41 +0000 (10:45 +0800) |
| .gitignore | patch | blob | history | |
| bin/shell.c | patch | blob | history | |
| include/stdio.h | patch | blob | history | |
| kernel/fork.c | patch | blob | history | |
| kernel/init.c | patch | blob | history | |
| kernel/innerint.c | patch | blob | history | |
| kernel/syscall.c | patch | blob | history | |
| mm/buddy.c | patch | blob | history | |
| mm/page.c | patch | blob | history |
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
bin/hello
bin/shell
a.*
+snapshot.txt
diff --git a/bin/shell.c b/bin/shell.c
--- a/bin/shell.c
+++ b/bin/shell.c
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
--- a/include/stdio.h
+++ b/include/stdio.h
*--------------------------------------------------------------------------
*/
-#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);
diff --git a/kernel/fork.c b/kernel/fork.c
--- a/kernel/fork.c
+++ b/kernel/fork.c
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
--- a/kernel/init.c
+++ b/kernel/init.c
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()
{
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
--- a/kernel/innerint.c
+++ b/kernel/innerint.c
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
--- a/kernel/syscall.c
+++ b/kernel/syscall.c
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
--- a/mm/buddy.c
+++ b/mm/buddy.c
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
--- a/mm/page.c
+++ b/mm/page.c
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;
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);
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 --;
#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
}