From: acevest Date: Wed, 3 Nov 2021 01:27:01 +0000 (+0800) Subject: 修复在ret_from_fork_krnl中没有正确恢复eflags寄存器的问题 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/named.html?a=commitdiff_plain;h=591833af7b1eafd846119601d2ff5944b61899b8;p=kernel.git 修复在ret_from_fork_krnl中没有正确恢复eflags寄存器的问题 --- diff --git a/include/task.h b/include/task.h index be0b525..ad950a9 100644 --- a/include/task.h +++ b/include/task.h @@ -29,6 +29,7 @@ enum { TASK_UNUSED, TASK_RUNNING, TASK_WAIT, + TASK_INITING, TASK_EXITING, TASK_END, }; diff --git a/kernel/fork.c b/kernel/fork.c index 77b8013..094cb9f 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -90,13 +90,11 @@ int do_fork(pt_regs_t *regs, unsigned long flags) { pt_regs_t *child_regs = ((pt_regs_t *)(TASK_SIZE + (unsigned long)tsk)) - 1; - printk("child regs: %x %x %d\n", child_regs, regs, sizeof(regs)); - //*child_regs = *regs; + printk("child regs: %x %x\n", child_regs, regs); memcpy(child_regs, regs, sizeof(*regs)); - asm("xchg %bx, %bx"); child_regs->eax = 0; - //child_regs->eflags |= 0x200; // enable IF + child_regs->eflags |= 0x200; // enable IF tsk->esp0 = TASK_SIZE + (unsigned long)tsk; tsk->esp = (unsigned long)child_regs; @@ -108,18 +106,18 @@ int do_fork(pt_regs_t *regs, unsigned long flags) { printk("tsk %08x child_regs esp %08x esp0 %08x\n", tsk, tsk->esp, tsk->esp0); - tsk->state = TASK_RUNNING; + tsk->state = TASK_INITING; tsk->weight = TASK_INIT_WEIGHT; INIT_LIST_HEAD(&tsk->list); - disable_irq(); - unsigned long iflags; irq_save(iflags); list_add(&tsk->list, &all_tasks); irq_restore(iflags); + tsk->state = TASK_RUNNING; + printk("%s:%d\n", __func__, __LINE__); return (int)tsk->pid; diff --git a/kernel/init.c b/kernel/init.c index 41cff0a..fe21e24 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -49,12 +49,12 @@ void init_task_entry() { extern void ret_from_fork_krnl(); void kernel_task(char *name, void *entry) { pt_regs_t regs; - + memset((void *)®s, 0, sizeof(regs)); - + // 内核任务入口 regs.edx = (unsigned long)entry; - + // 创建内核任务的时候就直接指定其在fork后走的路径 // 就不用走sysexit那个路径了 regs.eip = (unsigned long)ret_from_fork_krnl; @@ -62,13 +62,10 @@ void kernel_task(char *name, void *entry) { regs.ds = SELECTOR_KRNL_DS; regs.es = SELECTOR_KRNL_DS; regs.ss = SELECTOR_KRNL_DS; - regs.eflags = (1 << 9); // enable IF int pid = do_fork(®s, FORK_KRNL); printk("kernel task pid is %d\n", pid); - - enable_irq(); } void root_task_entry() { diff --git a/kernel/syscall.S b/kernel/syscall.S index 072f9a3..21f8b43 100644 --- a/kernel/syscall.S +++ b/kernel/syscall.S @@ -87,7 +87,9 @@ ret_from_fork_user: // 内核线程fork出路 ret_from_fork_krnl: RESTORE_REGS - addl $24, %esp + addl $12, %esp + popfl + addl $8, %esp call *%edx # 还没有实现do_exit