Selaa lähdekoodia

fix(syscall): tell compiler it affects eax and edx

greatbridf 2 vuotta sitten
vanhempi
commit
f10031fe36
3 muutettua tiedostoa jossa 24 lisäystä ja 15 poistoa
  1. 14 2
      include/kernel/syscall.hpp
  2. 1 4
      src/kernel/process.cpp
  3. 9 9
      user-space-program/basic-lib.h

+ 14 - 2
include/kernel/syscall.hpp

@@ -1,11 +1,23 @@
 #pragma once
 
-#include <types/types.h>
 #include <kernel/interrupt.h>
+#include <types/types.h>
 
 // return value is stored in %eax and %edx
 typedef void (*syscall_handler)(interrupt_stack* data);
 
-#define syscall(eax) asm volatile("movl %0, %%eax\n\tint $0x80"::"r"(eax):"eax","edx")
+inline uint32_t syscall(uint32_t num, uint32_t arg1 = 0, uint32_t arg2 = 0)
+{
+    asm volatile(
+        "movl %1, %%edi\n"
+        "movl %2, %%esi\n"
+        "movl %3, %%eax\n"
+        "int $0x80\n"
+        "movl %%eax, %0"
+        : "=g"(num)
+        : "g"(arg1), "g"(arg2), "g"(num)
+        : "eax", "edx", "edi", "esi");
+    return num;
+}
 
 void init_syscall(void);

+ 1 - 4
src/kernel/process.cpp

@@ -170,10 +170,7 @@ void kernel_threadd_main(void)
             spin_unlock(&kthreadd_lock);
 
             // syscall_fork
-            asm volatile("movl $0x00, %%eax\nint $0x80\nmovl %%eax, %0"
-                         : "=a"(return_value)
-                         :
-                         :);
+            return_value = syscall(0x00);
 
             if (return_value != 0) {
                 // child

+ 9 - 9
user-space-program/basic-lib.h

@@ -4,14 +4,14 @@ typedef __UINT8_TYPE__ uint8_t;
 
 static inline uint32_t syscall(uint32_t num, uint32_t arg1, uint32_t arg2)
 {
-    asm ("movl %3, %%eax\n\
-          movl %1, %%edi\n\
-          movl %2, %%esi\n\
-          int $0x80\n\
-          movl %%eax, %0"
-         :"=r"(num)
-         :"0"(arg1), "r"(arg2), "r"(num)
-         :"eax", "edi", "esi"
-         );
+    asm volatile(
+        "movl %1, %%edi\n"
+        "movl %2, %%esi\n"
+        "movl %3, %%eax\n"
+        "int $0x80\n"
+        "movl %%eax, %0"
+        : "=g"(num)
+        : "g"(arg1), "g"(arg2), "g"(num)
+        : "eax", "edx", "edi", "esi");
     return num;
 }