From: acevest Date: Mon, 15 Nov 2021 01:25:10 +0000 (+0800) Subject: kernel_task不把名字传递给内核函数入口,直接在do_fork里赋值 X-Git-Url: http://zhaoyanbai.com/repos/%24relpath%24doxygen.css?a=commitdiff_plain;h=48bc88cf10e9284e45c418e3fbb68ba0753e99ad;p=kernel.git kernel_task不把名字传递给内核函数入口,直接在do_fork里赋值 --- diff --git a/kernel/fork.c b/kernel/fork.c index ea2848c..6291501 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -85,16 +85,17 @@ int do_fork(pt_regs_t *regs, unsigned long flags) { printk("child regs: %x %x\n", child_regs, regs); memcpy(child_regs, regs, sizeof(*regs)); - child_regs->eax = 0; - child_regs->eflags |= 0x200; // enable IF - tsk->esp0 = TASK_SIZE + (unsigned long)tsk; tsk->esp = (unsigned long)child_regs; tsk->eip = (unsigned long)ret_from_fork_user; if (flags & FORK_KRNL) { + strcpy(tsk->name, (char *)(child_regs->eax)); tsk->eip = (unsigned long)ret_from_fork_krnl; } + child_regs->eax = 0; + child_regs->eflags |= 0x200; // enable IF + printk("tsk %08x child_regs esp %08x esp0 %08x\n", tsk, tsk->esp, tsk->esp0); tsk->state = TASK_INITING; diff --git a/kernel/init.c b/kernel/init.c index 4d0707c..3abeb06 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -58,9 +58,7 @@ void __ring3text__ __attribute__((__aligned__(PAGE_SIZE))) ring3_entry() { } } -void user_task_entry(char *name) { - strcpy(current->name, name); - +void user_task_entry() { current->priority = 90; unsigned long ring3_text_page = va2pa(ring3_entry); @@ -93,12 +91,10 @@ void user_task_entry(char *name) { asm volatile("sysexit;" ::"d"(0x08000000), "c"(0x30000000 + PAGE_SIZE - 100)); } -void init_task_entry(char *name) { +void init_task_entry() { int cnt = 0; pid_t id = sysc_getpid(); - strcpy(current->name, name); - // 赋予不同的优先级 current->priority = id * 30; @@ -119,6 +115,12 @@ void init_task_entry(char *name) { } } +void disk_task_entry() { + while (1) { + schedule(); + } +} + void kernel_task(char *name, void *entry) { pt_regs_t regs; @@ -127,6 +129,8 @@ void kernel_task(char *name, void *entry) { // 内核任务入口 regs.edx = (unsigned long)entry; + regs.eax = (u32)name; + // 创建内核任务的时候就直接指定其在fork后走的路径 // 就不用走sysexit那个路径了 extern void ret_from_fork_krnl(); @@ -138,8 +142,6 @@ void kernel_task(char *name, void *entry) { regs.fs = SELECTOR_KRNL_DS; regs.gs = SELECTOR_KRNL_DS; - regs.ebx = (unsigned long)name; // 用ebx传递参数 - int pid = do_fork(®s, FORK_KRNL); printk("kernel[%s] task pid is %d\n", name, pid); @@ -161,18 +163,10 @@ void root_task_entry() { setup_under_irq(); kernel_task("init", init_task_entry); - kernel_task("test", init_task_entry); + kernel_task("disk", disk_task_entry); kernel_task("user", user_task_entry); - int cnt = 0; - while (1) { - // sysc_test(); - // printl(MPL_TASK_0, "root:0 [%08x] weight %d cnt %d", current, root_task.weight, cnt++); - // printk("root:0 [%08x] weight %d cnt %d", current, current->weight, cnt++); asm("hlt;"); - // asm("nop;nop;nop;"); - // sysc_test(); - // syscall0(SYSC_TEST); } } diff --git a/kernel/sched.c b/kernel/sched.c index f3ce8e3..fd5a8c7 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -49,7 +49,7 @@ LIST_HEAD(all_tasks); LIST_HEAD(delay_tasks); -void init_root_tsk() { +void init_root_task() { int i; root_task.preempt_cnt = 0; @@ -83,7 +83,7 @@ void setup_tasks() { INIT_LIST_HEAD(&all_tasks); INIT_LIST_HEAD(&delay_tasks); - init_root_tsk(); + init_root_task(); task_union_cache = kmem_cache_create("task_union", sizeof(task_union), PAGE_SIZE); if (0 == task_union_cache) { @@ -144,7 +144,9 @@ static const char *task_state(unsigned int state) { " ERROR", "RUNNING", " WAIT", "INITING", "EXITING", }; - if (state >= TASK_END) state = TASK_UNUSED; + if (state >= TASK_END) { + state = TASK_UNUSED; + } return s[state]; } diff --git a/kernel/syscall.S b/kernel/syscall.S index 76b3ad1..f813627 100644 --- a/kernel/syscall.S +++ b/kernel/syscall.S @@ -90,8 +90,6 @@ ret_from_fork_krnl: popfl addl $8, %esp - # 用ebx传递参数 - pushl %ebx call *%edx addl $4, %esp