Răsfoiți Sursa

Merge branch 'fix-release'

greatbridf 2 ani în urmă
părinte
comite
d5aa6193eb

+ 1 - 1
include/kernel/event/evtqueue.hpp

@@ -32,7 +32,7 @@ public:
     evtqueue(evtqueue&&);
 
     void push(evt&& event);
-    evt&& front();
+    evt front();
     const evt* peek(void) const;
 
     bool empty(void) const;

+ 2 - 1
include/types/assert.h

@@ -35,6 +35,7 @@ void _debugger_breakpoint(void);
 
 #else
 
-#define assert(_statement) ;
+#define assert(_statement) (void)(_statement)
+#define assert_likely(_statement) (void)(_statement)
 
 #endif

+ 2 - 2
include/types/lock.hpp

@@ -5,11 +5,11 @@
 inline void spin_lock(uint32_t volatile* lock_addr)
 {
     asm volatile(
-        "0:\n\t\
+        "%=:\n\t\
          movl $1, %%eax\n\t\
          xchgl %%eax, (%0)\n\t\
          test $0, %%eax\n\t\
-         jne 0\n\t\
+         jne %=b\n\t\
         "
         :
         : "r"(lock_addr)

+ 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

+ 2 - 2
src/kernel/event/event.cpp

@@ -59,7 +59,7 @@ void kernel::evtqueue::push(kernel::evt&& event)
     this->notify();
 }
 
-kernel::evt&& kernel::evtqueue::front()
+kernel::evt kernel::evtqueue::front()
 {
     assert(!this->empty());
     types::lock_guard lck(m_mtx);
@@ -67,7 +67,7 @@ kernel::evt&& kernel::evtqueue::front()
     auto iter = m_evts.begin();
     evt e = types::move(*iter);
     m_evts.erase(iter);
-    return types::move(e);
+    return e;
 }
 
 const kernel::evt* kernel::evtqueue::peek(void) const

+ 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)