Эх сурвалжийг харах

fix(scheduler): push pseudo ret.addr. of go_kernel

greatbridf 2 жил өмнө
parent
commit
07d5acdffa

+ 0 - 55
src/asm/interrupt.s

@@ -251,58 +251,3 @@ asm_ctx_switch:
 
 _ctx_switch_return:
     ret
-
-# param:
-# #1: uint32_t esp
-# #2: void (*k_init)()
-.globl go_kernel
-.type  go_kernel @function
-go_kernel:
-    movl 4(%esp), %eax
-    movl 8(%esp), %ecx
-    movl %eax, %esp
-    pushl %ecx
-
-    movw $0x10, %ax
-    movw %ax, %ss
-    movw %ax, %ds
-    movw %ax, %es
-    movw %ax, %fs
-    movw %ax, %gs
-
-    xorl %eax, %eax
-    xorl %ebx, %ebx
-    xorl %ecx, %ecx
-    xorl %edx, %edx
-    xorl %esi, %esi
-    xorl %edi, %edi
-    xorl %ebp, %ebp
-
-# eflags: IN
-    pushl $0x200
-    popfl
-
-    ret
-
-# parameters
-# #1: eip
-# #2: esp
-.globl go_user
-.type  go_user @function
-go_user:
-    movw $0x23, %ax
-    movw %ax, %ds
-    movw %ax, %es
-    movw %ax, %fs
-    movw %ax, %gs
-
-    movl 4(%esp), %eax
-    movl 8(%esp), %ecx
-
-    pushl $0x23
-    pushl %ecx
-    pushl $0x200
-    pushl $0x1b
-    pushl %eax
-
-    iret

+ 50 - 5
src/kernel/process.cpp

@@ -132,9 +132,6 @@ inline void NORETURN _noreturn_crash(void)
         assert(false);
 }
 
-extern "C" void NORETURN go_kernel(uint32_t* kstack, void (*k_main)(void));
-extern "C" void NORETURN go_user(void* eip, uint32_t* esp);
-
 void kernel_threadd_main(void)
 {
     tty_print(console, "kernel thread daemon started\n");
@@ -200,7 +197,27 @@ void NORETURN _kernel_init(void)
 
     is_scheduler_ready = true;
 
-    go_user(d.eip, d.sp);
+    asm volatile (
+        "movw $0x23, %%ax\n"
+        "movw %%ax, %%ds\n"
+        "movw %%ax, %%es\n"
+        "movw %%ax, %%fs\n"
+        "movw %%ax, %%gs\n"
+
+        "pushl $0x23\n"
+        "pushl %0\n"
+        "pushl $0x200\n"
+        "pushl $0x1b\n"
+        "pushl %1\n"
+
+        "iret\n"
+        :
+        : "c"(d.sp), "d"(d.eip)
+        : "eax", "memory"
+    );
+
+    for (;;)
+        assert(false);
 }
 
 void k_new_thread(void (*func)(void*), void* data)
@@ -232,7 +249,35 @@ void NORETURN init_scheduler()
 
     asm_switch_pd(current_process->mms.m_pd);
 
-    go_kernel(current_thread->esp, _kernel_init);
+    asm volatile(
+        "movl %0, %%esp\n"
+        "pushl %=f\n"
+        "pushl %1\n"
+
+        "movw $0x10, %%ax\n"
+        "movw %%ax, %%ss\n"
+        "movw %%ax, %%ds\n"
+        "movw %%ax, %%es\n"
+        "movw %%ax, %%fs\n"
+        "movw %%ax, %%gs\n"
+
+        "xorl %%ebp, %%ebp\n"
+        "xorl %%edx, %%edx\n"
+
+        "pushl $0x200\n"
+        "popfl\n"
+
+        "ret\n"
+
+        "%=:\n"
+        "ud2"
+        :
+        : "a"(current_thread->esp), "c"(_kernel_init)
+        : "memory"
+    );
+
+    for (;;)
+        assert(false);
 }
 
 pid_t add_to_process_list(process&& proc)