mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Updated syscall.h
This commit is contained in:
+26
-5
@@ -17,12 +17,33 @@ typedef enum {
|
||||
SYS_SLEEP,
|
||||
} SYSCALL_NUMBERS;
|
||||
|
||||
int syscall(int nr, int arg0, int arg1, int arg2);
|
||||
inline int syscall(int nr, int a0, int a1, int a2, int a3, int a4) {
|
||||
int ret;
|
||||
__asm__ volatile (
|
||||
"movl %1, %%eax\n" // Syscall number
|
||||
"movl %2, %%ebx\n" // Arg 0
|
||||
"movl %3, %%ecx\n" // Arg 1
|
||||
"movl %4, %%edx\n" // Arg 2
|
||||
"movl %5, %%esi\n" // Arg 3
|
||||
"movl %6, %%edi\n" // Arg 4
|
||||
"int $0x80\n" // Trigger syscall
|
||||
"movl %%eax, %0" // Return
|
||||
: "=r"(ret) // Output
|
||||
: "r"(nr), "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(a4) // Input
|
||||
: "eax", "ebx", "ecx", "edx", "esi", "edi" // Clobbered regs
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Syscall wrappers */
|
||||
int read(int fd, void* ptr, size_t count);
|
||||
int write(int fd, const void* ptr, size_t count);
|
||||
int open(const char* path, int oflag);
|
||||
int close(int fd);
|
||||
inline int _exit(int status) { return syscall(SYS_EXIT, status, 0, 0, 0, 0); }
|
||||
inline int read(int fd, void* ptr, size_t count) { return syscall(SYS_READ, fd, (int)ptr, (int)count, 0, 0); }
|
||||
inline int write(int fd, const void* ptr, size_t count) { return syscall(SYS_WRITE, fd, (int)ptr, (int)count, 0, 0); }
|
||||
inline int open(const char* path, int oflag) { return syscall(SYS_OPEN, (int)path, oflag, 0, 0); }
|
||||
inline int close(int fd) { return syscall(SYS_CLOSE, fd, 0, 0, 0, 0); }
|
||||
inline int seek(int fd, size_t offset, int whence) { return syscall(SYS_SEEK, fd, offset, whence); }
|
||||
inline int _malloc(int size) { return syscall(SYS_MALLOC, size, 0, 0, 0, 0); }
|
||||
inline int _free(void* ptr) { return syscall(SYS_FREE, (int)ptr, 0, 0, 0, 0); }
|
||||
inline int _sleep(int t) { return syscall(SYS_SLEEP, t, 0, 0, 0, 0); }
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user