mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 02:46:47 +00:00
更改系统调用的寄存器传参顺序 (#409)
This commit is contained in:
parent
40314b30ab
commit
f4082b86b1
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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)
|
||||
|
@ -6,7 +6,7 @@
|
||||
"BuildFromSource": {
|
||||
"Git": {
|
||||
"url" : "https://git.mirrors.dragonos.org/DragonOS-Community/DragonReach.git",
|
||||
"revision": "4aac1004fa"
|
||||
"revision": "a3341790a8"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -6,7 +6,7 @@
|
||||
"BuildFromSource": {
|
||||
"Git": {
|
||||
"url": "https://git.mirrors.dragonos.org/DragonOS-Community/relibc.git",
|
||||
"revision": "0a1b6ce239"
|
||||
"revision": "ac1ea83106"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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 从目录中读取数据
|
||||
|
@ -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);
|
||||
}
|
@ -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, ...)
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,23 +1,21 @@
|
||||
#include "syscall.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
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;
|
||||
|
||||
|
@ -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);
|
||||
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);
|
Loading…
x
Reference in New Issue
Block a user