From f4082b86b15989a1d43e62050c6ba9b363c91ece Mon Sep 17 00:00:00 2001 From: LoGin Date: Tue, 24 Oct 2023 16:40:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=B3=BB=E7=BB=9F=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E5=AF=84=E5=AD=98=E5=99=A8=E4=BC=A0=E5=8F=82?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=20(#409)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/Cargo.toml | 1 + kernel/src/arch/x86_64/syscall.rs | 10 +++---- user/apps/shell/cmd.c | 2 +- user/dadk/config/dragon_reach-0.1.0.dadk | 2 +- user/dadk/config/relibc-0.1.0.dadk | 2 +- user/libs/libc/src/dirent.c | 2 +- user/libs/libc/src/fcntl.c | 4 +-- user/libs/libc/src/printf.c | 2 +- user/libs/libc/src/signal.c | 4 +-- user/libs/libc/src/stdlib.c | 2 +- user/libs/libc/src/sys/stat.c | 2 +- user/libs/libc/src/sys/wait.c | 2 +- user/libs/libc/src/time.c | 8 ++--- user/libs/libc/src/unistd.c | 38 ++++++++++++------------ user/libs/libsystem/syscall.c | 20 ++++++------- user/libs/libsystem/syscall.h | 5 +--- 16 files changed, 50 insertions(+), 56 deletions(-) diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index d7e577b6..ab3ddf70 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -51,6 +51,7 @@ features = ["spin_no_std"] [profile.dev] # opt-level = 0 # Controls the --opt-level the compiler builds with debug = true # Controls whether the compiler passes `-g` + # The release profile, used for `cargo build --release` [profile.release] debug = false diff --git a/kernel/src/arch/x86_64/syscall.rs b/kernel/src/arch/x86_64/syscall.rs index a0c8ea09..54af8be8 100644 --- a/kernel/src/arch/x86_64/syscall.rs +++ b/kernel/src/arch/x86_64/syscall.rs @@ -27,14 +27,12 @@ macro_rules! syscall_return { pub extern "C" fn syscall_handler(frame: &mut TrapFrame) -> () { let syscall_num = frame.rax as usize; let args = [ + frame.rdi as usize, + frame.rsi as usize, + frame.rdx as usize, + frame.r10 as usize, frame.r8 as usize, frame.r9 as usize, - frame.r10 as usize, - frame.r11 as usize, - frame.r12 as usize, - frame.r13 as usize, - frame.r14 as usize, - frame.r15 as usize, ]; mfence(); diff --git a/user/apps/shell/cmd.c b/user/apps/shell/cmd.c index 8cf0fb5c..7f24da83 100644 --- a/user/apps/shell/cmd.c +++ b/user/apps/shell/cmd.c @@ -586,7 +586,7 @@ out:; */ int shell_cmd_reboot(int argc, char **argv) { - return syscall_invoke(SYS_REBOOT, 0, 0, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_REBOOT, 0, 0, 0, 0, 0, 0); } int shell_cmd_free(int argc, char **argv) diff --git a/user/dadk/config/dragon_reach-0.1.0.dadk b/user/dadk/config/dragon_reach-0.1.0.dadk index b4ba1e92..a22412cd 100644 --- a/user/dadk/config/dragon_reach-0.1.0.dadk +++ b/user/dadk/config/dragon_reach-0.1.0.dadk @@ -6,7 +6,7 @@ "BuildFromSource": { "Git": { "url" : "https://git.mirrors.dragonos.org/DragonOS-Community/DragonReach.git", - "revision": "4aac1004fa" + "revision": "a3341790a8" } } }, diff --git a/user/dadk/config/relibc-0.1.0.dadk b/user/dadk/config/relibc-0.1.0.dadk index 92a18d1d..491b701f 100644 --- a/user/dadk/config/relibc-0.1.0.dadk +++ b/user/dadk/config/relibc-0.1.0.dadk @@ -6,7 +6,7 @@ "BuildFromSource": { "Git": { "url": "https://git.mirrors.dragonos.org/DragonOS-Community/relibc.git", - "revision": "0a1b6ce239" + "revision": "ac1ea83106" } } }, diff --git a/user/libs/libc/src/dirent.c b/user/libs/libc/src/dirent.c index 38d28dd3..b56a0565 100644 --- a/user/libs/libc/src/dirent.c +++ b/user/libs/libc/src/dirent.c @@ -56,7 +56,7 @@ int closedir(struct DIR *dirp) int64_t getdents(int fd, struct dirent *dirent, long count) { - return syscall_invoke(SYS_GET_DENTS, fd, (uint64_t)dirent, count, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_GET_DENTS, fd, (uint64_t)dirent, count, 0, 0, 0); } /** * @brief 从目录中读取数据 diff --git a/user/libs/libc/src/fcntl.c b/user/libs/libc/src/fcntl.c index 024c2b30..4ac43132 100644 --- a/user/libs/libc/src/fcntl.c +++ b/user/libs/libc/src/fcntl.c @@ -11,7 +11,7 @@ */ int open(const char *path, int options, ...) { - return syscall_invoke(SYS_OPEN, (uint64_t)path, options, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_OPEN, (uint64_t)path, options, 0, 0, 0, 0); } /** @@ -24,5 +24,5 @@ int open(const char *path, int options, ...) */ int ioctl(int fd, int cmd, uint64_t data, ...) { - return syscall_invoke(SYS_IOCTL, fd, cmd, data, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_IOCTL, fd, cmd, data, 0, 0, 0); } \ No newline at end of file diff --git a/user/libs/libc/src/printf.c b/user/libs/libc/src/printf.c index d5f51812..1e813bde 100644 --- a/user/libs/libc/src/printf.c +++ b/user/libs/libc/src/printf.c @@ -35,7 +35,7 @@ static int skip_and_atoi(const char **s) */ int64_t put_string(char *str, uint64_t front_color, uint64_t bg_color) { - return syscall_invoke(SYS_PUT_STRING, (uint64_t)str, front_color, bg_color, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_PUT_STRING, (uint64_t)str, front_color, bg_color, 0, 0, 0); } int printf(const char *fmt, ...) diff --git a/user/libs/libc/src/signal.c b/user/libs/libc/src/signal.c index b87f51d0..1b6d7bf2 100644 --- a/user/libs/libc/src/signal.c +++ b/user/libs/libc/src/signal.c @@ -40,7 +40,7 @@ int signal(int signum, __sighandler_t handler) */ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { - return syscall_invoke(SYS_SIGACTION, (uint64_t)signum, (uint64_t)act, (uint64_t)oldact, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_SIGACTION, (uint64_t)signum, (uint64_t)act, (uint64_t)oldact, 0, 0, 0); } /** @@ -63,5 +63,5 @@ int raise(int sig) */ int kill(pid_t pid, int sig) { - syscall_invoke(SYS_KILL, pid, sig, 0, 0, 0, 0, 0, 0); + syscall_invoke(SYS_KILL, pid, sig, 0, 0, 0, 0); } \ No newline at end of file diff --git a/user/libs/libc/src/stdlib.c b/user/libs/libc/src/stdlib.c index b916f3c3..acd3caf3 100644 --- a/user/libs/libc/src/stdlib.c +++ b/user/libs/libc/src/stdlib.c @@ -57,7 +57,7 @@ int atoi(const char *str) void exit(int status) { _fini(); - syscall_invoke(SYS_EXIT, status, 0, 0, 0, 0, 0, 0, 0); + syscall_invoke(SYS_EXIT, status, 0, 0, 0, 0, 0); } /** diff --git a/user/libs/libc/src/sys/stat.c b/user/libs/libc/src/sys/stat.c index ff112679..f804acde 100644 --- a/user/libs/libc/src/sys/stat.c +++ b/user/libs/libc/src/sys/stat.c @@ -8,7 +8,7 @@ int mkdir(const char *path, mode_t mode) { - return syscall_invoke(SYS_MKDIR, (uint64_t)path, (uint64_t)mode, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_MKDIR, (uint64_t)path, (uint64_t)mode, 0, 0, 0, 0); } /** diff --git a/user/libs/libc/src/sys/wait.c b/user/libs/libc/src/sys/wait.c index edb78ceb..47df1bd2 100644 --- a/user/libs/libc/src/sys/wait.c +++ b/user/libs/libc/src/sys/wait.c @@ -22,5 +22,5 @@ pid_t wait(int *stat_loc) */ pid_t waitpid(pid_t pid, int *stat_loc, int options) { - return (pid_t)syscall_invoke(SYS_WAIT4, (uint64_t)pid, (uint64_t)stat_loc, options, 0, 0, 0, 0, 0); + return (pid_t)syscall_invoke(SYS_WAIT4, (uint64_t)pid, (uint64_t)stat_loc, options, 0, 0, 0); } \ No newline at end of file diff --git a/user/libs/libc/src/time.c b/user/libs/libc/src/time.c index fbde9d9c..5fe3d79c 100644 --- a/user/libs/libc/src/time.c +++ b/user/libs/libc/src/time.c @@ -12,7 +12,7 @@ */ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { - return syscall_invoke(SYS_NANOSLEEP, (uint64_t)rqtp, (uint64_t)rmtp, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_NANOSLEEP, (uint64_t)rqtp, (uint64_t)rmtp, 0, 0, 0, 0); } /** @@ -33,10 +33,10 @@ int usleep(useconds_t usec) /** * @brief 获取系统当前cpu时间 - * - * @return clock_t + * + * @return clock_t */ clock_t clock() { - return (clock_t)syscall_invoke(SYS_CLOCK, 0,0,0,0,0,0,0,0); + return (clock_t)syscall_invoke(SYS_CLOCK, 0, 0, 0, 0, 0, 0); } \ No newline at end of file diff --git a/user/libs/libc/src/unistd.c b/user/libs/libc/src/unistd.c index 6a99fa37..a8304a89 100644 --- a/user/libs/libc/src/unistd.c +++ b/user/libs/libc/src/unistd.c @@ -14,7 +14,7 @@ */ int close(int fd) { - return syscall_invoke(SYS_CLOSE, fd, 0, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_CLOSE, fd, 0, 0, 0, 0, 0); } /** @@ -27,7 +27,7 @@ int close(int fd) */ ssize_t read(int fd, void *buf, size_t count) { - return (ssize_t)syscall_invoke(SYS_READ, fd, (uint64_t)buf, count, 0, 0, 0, 0, 0); + return (ssize_t)syscall_invoke(SYS_READ, fd, (uint64_t)buf, count, 0, 0, 0); } /** @@ -40,7 +40,7 @@ ssize_t read(int fd, void *buf, size_t count) */ ssize_t write(int fd, void const *buf, size_t count) { - return (ssize_t)syscall_invoke(SYS_WRITE, fd, (uint64_t)buf, count, 0, 0, 0, 0, 0); + return (ssize_t)syscall_invoke(SYS_WRITE, fd, (uint64_t)buf, count, 0, 0, 0); } /** @@ -53,7 +53,7 @@ ssize_t write(int fd, void const *buf, size_t count) */ off_t lseek(int fd, off_t offset, int whence) { - return (off_t)syscall_invoke(SYS_LSEEK, fd, offset, whence, 0, 0, 0, 0, 0); + return (off_t)syscall_invoke(SYS_LSEEK, fd, offset, whence, 0, 0, 0); } /** @@ -63,7 +63,7 @@ off_t lseek(int fd, off_t offset, int whence) */ pid_t fork(void) { - return (pid_t)syscall_invoke(SYS_FORK, 0, 0, 0, 0, 0, 0, 0, 0); + return (pid_t)syscall_invoke(SYS_FORK, 0, 0, 0, 0, 0, 0); } /** * @brief 调用匿名管道 @@ -72,7 +72,7 @@ pid_t fork(void) */ int pipe(int fd[2]) { - return (int)syscall_invoke(SYS_PIPE, fd, 0, 0, 0, 0, 0, 0, 0); + return (int)syscall_invoke(SYS_PIPE, fd, 0, 0, 0, 0, 0); } /** * @brief 调用带参数的匿名管道 @@ -81,7 +81,7 @@ int pipe(int fd[2]) */ int pipe2(int fd[2], int flags) { - return (int)syscall_invoke(SYS_PIPE, fd, flags, 0, 0, 0, 0, 0, 0); + return (int)syscall_invoke(SYS_PIPE, fd, flags, 0, 0, 0, 0); } /** * @brief fork当前进程,但是与父进程共享VM、flags、fd @@ -90,7 +90,7 @@ int pipe2(int fd[2], int flags) */ pid_t vfork(void) { - return (pid_t)syscall_invoke(SYS_VFORK, 0, 0, 0, 0, 0, 0, 0, 0); + return (pid_t)syscall_invoke(SYS_VFORK, 0, 0, 0, 0, 0, 0); } /** @@ -104,7 +104,7 @@ pid_t vfork(void) */ uint64_t brk(uint64_t end_brk) { - uint64_t x = (uint64_t)syscall_invoke(SYS_BRK, (uint64_t)end_brk, 0, 0, 0, 0, 0, 0, 0); + uint64_t x = (uint64_t)syscall_invoke(SYS_BRK, (uint64_t)end_brk, 0, 0, 0, 0, 0); if (x < end_brk) { errno = -ENOMEM; @@ -121,7 +121,7 @@ uint64_t brk(uint64_t end_brk) */ void *sbrk(int64_t increment) { - void *retval = (void *)syscall_invoke(SYS_SBRK, (uint64_t)increment, 0, 0, 0, 0, 0, 0, 0); + void *retval = (void *)syscall_invoke(SYS_SBRK, (uint64_t)increment, 0, 0, 0, 0, 0); if (retval == (void *)-ENOMEM) return (void *)(-1); else @@ -146,7 +146,7 @@ int64_t chdir(char *dest_path) } else { - return syscall_invoke(SYS_CHDIR, (uint64_t)dest_path, 0, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_CHDIR, (uint64_t)dest_path, 0, 0, 0, 0, 0); } } @@ -165,7 +165,7 @@ int execv(const char *path, char *const argv[]) return -1; } - int retval = syscall_invoke(SYS_EXECVE, (uint64_t)path, (uint64_t)argv, 0, 0, 0, 0, 0, 0); + int retval = syscall_invoke(SYS_EXECVE, (uint64_t)path, (uint64_t)argv, 0, 0, 0, 0); if (retval != 0) return -1; else @@ -180,7 +180,7 @@ int execv(const char *path, char *const argv[]) */ int rmdir(const char *path) { - return syscall_invoke(SYS_UNLINK_AT, 0, (uint64_t)path, AT_REMOVEDIR, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_UNLINK_AT, 0, (uint64_t)path, AT_REMOVEDIR, 0, 0, 0); } /** @@ -191,7 +191,7 @@ int rmdir(const char *path) */ int rm(const char *path) { - return syscall_invoke(SYS_UNLINK_AT, 0, (uint64_t)path, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_UNLINK_AT, 0, (uint64_t)path, 0, 0, 0, 0); } /** @@ -224,20 +224,20 @@ void swab(void *restrict src, void *restrict dest, ssize_t nbytes) */ pid_t getpid(void) { - return syscall_invoke(SYS_GETPID, 0, 0, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_GETPID, 0, 0, 0, 0, 0, 0); } int dup(int fd) { - return syscall_invoke(SYS_DUP, fd, 0, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_DUP, fd, 0, 0, 0, 0, 0); } int dup2(int ofd, int nfd) { - return syscall_invoke(SYS_DUP2, ofd, nfd, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_DUP2, ofd, nfd, 0, 0, 0, 0); } -char *getcwd(char* buf, size_t size) +char *getcwd(char *buf, size_t size) { - return syscall_invoke(SYS_GETCWD, buf, size, 0, 0, 0, 0, 0, 0); + return syscall_invoke(SYS_GETCWD, buf, size, 0, 0, 0, 0); } \ No newline at end of file diff --git a/user/libs/libsystem/syscall.c b/user/libs/libsystem/syscall.c index f215b8ec..19b8eeca 100644 --- a/user/libs/libsystem/syscall.c +++ b/user/libs/libsystem/syscall.c @@ -1,23 +1,21 @@ #include "syscall.h" #include #include -long syscall_invoke(uint64_t syscall_id, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7) +long syscall_invoke(uint64_t syscall_id, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) { uint64_t __err_code; __asm__ __volatile__( - "movq %2, %%r8 \n\t" - "movq %3, %%r9 \n\t" - "movq %4, %%r10 \n\t" - "movq %5, %%r11 \n\t" - "movq %6, %%r12 \n\t" - "movq %7, %%r13 \n\t" - "movq %8, %%r14 \n\t" - "movq %9, %%r15 \n\t" + "movq %2, %%rdi \n\t" + "movq %3, %%rsi \n\t" + "movq %4, %%rdx \n\t" + "movq %5, %%r10 \n\t" + "movq %6, %%r8 \n\t" + "movq %7, %%r9 \n\t" "int $0x80 \n\t" "movq %%rax, %0 \n\t" :"=a"(__err_code) - : "a"(syscall_id), "m"(arg0), "m"(arg1), "m"(arg2), "m"(arg3), "m"(arg4), "m"(arg5), "m"(arg6), "m"(arg7) - : "memory", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "rcx", "rdx"); + : "a"(syscall_id), "m"(arg0), "m"(arg1), "m"(arg2), "m"(arg3), "m"(arg4), "m"(arg5) + : "memory", "r8", "r9", "r10", "r11", "rcx", "rdx", "rdi", "rsi"); // printf("errcode = %#018lx\n", __err_code); errno = __err_code; diff --git a/user/libs/libsystem/syscall.h b/user/libs/libsystem/syscall.h index 15dadee3..99401256 100644 --- a/user/libs/libsystem/syscall.h +++ b/user/libs/libsystem/syscall.h @@ -63,9 +63,6 @@ * @param arg3 * @param arg4 * @param arg5 - * @param arg6 - * @param arg7 * @return long */ -long syscall_invoke(uint64_t syscall_id, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, - uint64_t arg5, uint64_t arg6, uint64_t arg7); \ No newline at end of file +long syscall_invoke(uint64_t syscall_id, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5); \ No newline at end of file