mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
🆕 运行文件系统中的二进制程序
This commit is contained in:
8
user/libs/libsystem/Makefile
Normal file
8
user/libs/libsystem/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
all: libsystem
|
||||
# echo $(shell pwd)
|
||||
|
||||
|
||||
libsystem: syscall.o
|
||||
|
||||
syscall.o: syscall.c
|
||||
gcc $(CFLAGS) -c syscall.c -o syscall.o
|
20
user/libs/libsystem/syscall.c
Normal file
20
user/libs/libsystem/syscall.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include "syscall.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 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"
|
||||
"int $0x80 \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");
|
||||
return err_code;
|
||||
}
|
30
user/libs/libsystem/syscall.h
Normal file
30
user/libs/libsystem/syscall.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// 系统调用号
|
||||
#define SYS_NOT_EXISTS 0
|
||||
#define SYS_PUT_STRING 1
|
||||
#define SYS_OPEN 2
|
||||
#define SYS_CLOSE 3
|
||||
#define SYS_READ 4
|
||||
#define SYS_WRITE 5
|
||||
#define SYS_LSEEK 6
|
||||
#define SYS_FORK 7
|
||||
#define SYS_VFORK 8
|
||||
|
||||
/**
|
||||
* @brief 用户态系统调用函数
|
||||
*
|
||||
* @param syscall_id
|
||||
* @param arg0
|
||||
* @param arg1
|
||||
* @param arg2
|
||||
* @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);
|
Reference in New Issue
Block a user