]> Zhao Yanbai Git Server - kernel.git/commitdiff
修复在ret_from_fork_krnl中没有正确恢复eflags寄存器的问题
authoracevest <zhaoyanbai@126.com>
Wed, 3 Nov 2021 01:27:01 +0000 (09:27 +0800)
committeracevest <zhaoyanbai@126.com>
Wed, 3 Nov 2021 02:45:48 +0000 (10:45 +0800)
include/task.h
kernel/fork.c
kernel/init.c
kernel/syscall.S

index be0b525b55a89a77ad50660c199c2c93fba9f9af..ad950a94a10e582f53d6811fdef7faffe346e217 100644 (file)
@@ -29,6 +29,7 @@ enum {
     TASK_UNUSED,
     TASK_RUNNING,
     TASK_WAIT,
+    TASK_INITING,
     TASK_EXITING,
     TASK_END,
 };
index 77b80132019959934138bcc858d62fee3669a304..094cb9f2b7e1156e45e4bead5106e92c9cd12564 100644 (file)
@@ -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;
index 41cff0afb438ea47324be29efd21b37d7622d511..fe21e2487a00a739e750efaaf53fab817c9fefe8 100644 (file)
@@ -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 *)&regs, 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(&regs, FORK_KRNL);
 
     printk("kernel task pid is %d\n", pid);
-
-    enable_irq();
 }
 
 void root_task_entry() {
index 072f9a3ff698071f7d1117435c68edc045825c48..21f8b43f6c757bce2909347eab0f76a41b99d1ab 100644 (file)
@@ -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