refactor: decouple i386 specific instruction invocation
[lunaix-os.git] / lunaix-os / kernel / process / sched.c
index 1587848a8034fc440b15319bab15324fbc8be00e..2fa5ca686bd85d17a8d9f7bec584d59f98cb2212 100644 (file)
@@ -1,5 +1,5 @@
 #include <arch/abi.h>
-#include <arch/x86/interrupts.h>
+#include <arch/i386/interrupts.h>
 
 #include <hal/apic.h>
 #include <hal/cpu.h>
@@ -60,29 +60,13 @@ sched_init_dummy()
     extern void my_dummy();
     static char dummy_stack[DUMMY_STACK_SIZE] __attribute__((aligned(16)));
 
-    struct exec_param* execp =
-      (void*)dummy_stack + DUMMY_STACK_SIZE - sizeof(struct exec_param);
+    ptr_t stktop = (ptr_t)dummy_stack + DUMMY_STACK_SIZE;
 
-    isr_param* isrp = (void*)execp - sizeof(isr_param);
-
-    *execp = (struct exec_param){
-        .cs = KCODE_SEG,
-        .eflags = cpu_reflags() | 0x0200,
-        .eip = (ptr_t)my_dummy,
-        .ss = KDATA_SEG,
-    };
-
-    *isrp = (isr_param){ .registers = { .ds = KDATA_SEG,
-                                        .es = KDATA_SEG,
-                                        .fs = KDATA_SEG,
-                                        .gs = KDATA_SEG },
-                         .execp = execp };
-
-    // memset to 0
     dummy_proc = (struct proc_info){};
-    dummy_proc.intr_ctx = isrp;
 
-    dummy_proc.page_table = cpu_rcr3();
+    proc_init_transfer(&dummy_proc, stktop, (ptr_t)my_dummy, TRANSFER_IE);
+
+    dummy_proc.page_table = cpu_ldvmspace();
     dummy_proc.state = PS_READY;
     dummy_proc.parent = &dummy_proc;
     dummy_proc.pid = KERNEL_PID;
@@ -142,7 +126,7 @@ check_sleepers()
     time_t now = clock_systime();
     llist_for_each(pos, n, &leader->sleep.sleepers, sleep.sleepers)
     {
-        if (PROC_TERMINATED(pos->state)) {
+        if (proc_terminated(pos)) {
             goto del;
         }
 
@@ -209,7 +193,7 @@ void
 sched_yieldk()
 {
     cpu_enable_interrupt();
-    cpu_int(LUNAIX_SCHED);
+    cpu_trap_sched();
 }
 
 __DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
@@ -343,8 +327,6 @@ alloc_process()
     proc->created = clock_systime();
     proc->pgid = proc->pid;
     proc->fdtable = vzalloc(sizeof(struct v_fdtable));
-    proc->fxstate =
-      vzalloc_dma(512); // FXSAVE需要十六位对齐地址,使用DMA块(128位对齐)
 
     llist_init_head(&proc->mm.regions);
     llist_init_head(&proc->tasks);
@@ -415,7 +397,6 @@ destroy_process(pid_t pid)
     }
 
     vfree(proc->fdtable);
-    vfree_dma(proc->fxstate);
 
     vmm_mount_pd(VMS_MOUNT_1, proc->page_table);
 
@@ -466,5 +447,5 @@ orphaned_proc(pid_t pid)
 
     // 如果其父进程的状态是terminated 或 destroy中的一种
     // 或者其父进程是在该进程之后创建的,那么该进程为孤儿进程
-    return PROC_TERMINATED(parent->state) || parent->created > proc->created;
+    return proc_terminated(parent) || parent->created > proc->created;
 }
\ No newline at end of file