From 591833af7b1eafd846119601d2ff5944b61899b8 Mon Sep 17 00:00:00 2001 From: acevest Date: Wed, 3 Nov 2021 09:27:01 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8ret=5Ffrom=5Ffork=5Fk?= =?utf8?q?rnl=E4=B8=AD=E6=B2=A1=E6=9C=89=E6=AD=A3=E7=A1=AE=E6=81=A2?= =?utf8?q?=E5=A4=8Deflags=E5=AF=84=E5=AD=98=E5=99=A8=E7=9A=84=E9=97=AE?= =?utf8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/task.h | 1 + kernel/fork.c | 12 +++++------- kernel/init.c | 9 +++------ kernel/syscall.S | 4 +++- 4 files changed, 12 insertions(+), 14 deletions(-) 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 -- 2.44.0