Browse Source

change: use linux x86_64 syscall no.

greatbridf 2 years ago
parent
commit
ea0c108eea

+ 17 - 17
gblibc/private-include/syscall.h

@@ -3,23 +3,23 @@
 
 #include <stdint.h>
 
-#define SYS_fork (0x00)
-#define SYS_write (0x01)
-#define SYS_sleep (0x02)
-#define SYS_chdir (0x03)
-#define SYS_exec (0x04)
-#define SYS_exit (0x05)
-#define SYS_wait (0x06)
-#define SYS_read (0x07)
-#define SYS_getdents (0x08)
-#define SYS_open (0x09)
-#define SYS_getcwd (0x0a)
-#define SYS_setsid (0x0b)
-#define SYS_getsid (0x0c)
-#define SYS_close (0x0d)
-#define SYS_dup (0x0e)
-#define SYS_dup2 (0x0f)
-#define SYS_pipe (0x10)
+#define SYS_read (0)
+#define SYS_write (1)
+#define SYS_open (2)
+#define SYS_close (3)
+#define SYS_pipe (22)
+#define SYS_dup (32)
+#define SYS_dup2 (33)
+#define SYS_sleep (35)
+#define SYS_fork (57)
+#define SYS_execve (59)
+#define SYS_exit (60)
+#define SYS_wait (61)
+#define SYS_getdents (78)
+#define SYS_getcwd (79)
+#define SYS_chdir (80)
+#define SYS_setsid (112)
+#define SYS_getsid (124)
 
 #ifdef __cplusplus
 extern "C" {

+ 1 - 1
gblibc/src/crt0.s

@@ -23,5 +23,5 @@ _start:
     call main
 
     movl %eax, %edi  # code
-    movl $0x05, %eax # SYS_exit
+    movl $60, %eax # SYS_exit
     int $0x80        # syscall

+ 1 - 1
gblibc/src/unistd.c

@@ -45,7 +45,7 @@ pid_t fork(void)
 
 int execve(const char* pathname, char* const argv[], char* const envp[])
 {
-    return syscall3(SYS_exec, (uint32_t)pathname, (uint32_t)argv, (uint32_t)envp);
+    return syscall3(SYS_execve, (uint32_t)pathname, (uint32_t)argv, (uint32_t)envp);
 }
 
 unsigned int sleep(unsigned int seconds)

+ 20 - 18
src/kernel/syscall.cpp

@@ -17,7 +17,7 @@
 #include <types/elf.hpp>
 #include <types/status.h>
 
-#define SYSCALL_HANDLERS_SIZE (32)
+#define SYSCALL_HANDLERS_SIZE (128)
 syscall_handler syscall_handlers[SYSCALL_HANDLERS_SIZE];
 
 extern "C" void _syscall_stub_fork_return(void);
@@ -155,7 +155,7 @@ int _syscall_chdir(interrupt_stack* data)
 // @param exec: the path of program to execute
 // @param argv: arguments end with nullptr
 // @param envp: environment variables end with nullptr
-int _syscall_exec(interrupt_stack* data)
+int _syscall_execve(interrupt_stack* data)
 {
     const char* exec = reinterpret_cast<const char*>(data->s_regs.edi);
     char* const* argv = reinterpret_cast<char* const*>(data->s_regs.esi);
@@ -360,21 +360,23 @@ extern "C" void syscall_entry(interrupt_stack* data)
 SECTION(".text.kinit")
 void init_syscall(void)
 {
-    syscall_handlers[0] = _syscall_fork;
+    memset(syscall_handlers, 0x00, sizeof(syscall_handlers));
+
+    syscall_handlers[0] = _syscall_read;
     syscall_handlers[1] = _syscall_write;
-    syscall_handlers[2] = _syscall_sleep;
-    syscall_handlers[3] = _syscall_chdir;
-    syscall_handlers[4] = _syscall_exec;
-    syscall_handlers[5] = _syscall_exit;
-    syscall_handlers[6] = _syscall_wait;
-    syscall_handlers[7] = _syscall_read;
-    syscall_handlers[8] = _syscall_getdents;
-    syscall_handlers[9] = _syscall_open;
-    syscall_handlers[10] = _syscall_getcwd;
-    syscall_handlers[11] = _syscall_setsid;
-    syscall_handlers[12] = _syscall_getsid;
-    syscall_handlers[13] = _syscall_close;
-    syscall_handlers[14] = _syscall_dup;
-    syscall_handlers[15] = _syscall_dup2;
-    syscall_handlers[16] = _syscall_pipe;
+    syscall_handlers[2] = _syscall_open;
+    syscall_handlers[3] = _syscall_close;
+    syscall_handlers[22] = _syscall_pipe;
+    syscall_handlers[32] = _syscall_dup;
+    syscall_handlers[33] = _syscall_dup2;
+    syscall_handlers[35] = _syscall_sleep;
+    syscall_handlers[57] = _syscall_fork;
+    syscall_handlers[59] = _syscall_execve;
+    syscall_handlers[60] = _syscall_exit;
+    syscall_handlers[61] = _syscall_wait;
+    syscall_handlers[78] = _syscall_getdents;
+    syscall_handlers[79] = _syscall_getcwd;
+    syscall_handlers[80] = _syscall_chdir;
+    syscall_handlers[112] = _syscall_setsid;
+    syscall_handlers[124] = _syscall_getsid;
 }

+ 1 - 1
user-space-program/hello-world.s

@@ -7,7 +7,7 @@ main:
 	movl $0xcbcbcbcb, %eax
 	movl $0xacacacac, %edx
 
-	movl $0x01, %eax
+	movl $1, %eax
 	movl $1, %edi
 	movl $_str, %esi
 	movl $_str_size, %ecx

+ 2 - 2
user-space-program/interrupt-test.s

@@ -5,11 +5,11 @@
 .globl main
 main:
 # fork 1 -> 2
-	xorl %eax, %eax
+	movl $57, %eax
 	int $0x80
 	movl %eax, %esi
 # fork 2 -> 4
-	xorl %eax, %eax
+	movl $57, %eax
 	int $0x80
 	movl %eax, %ecx
 # write