forked from PoliEcho-holding-org/kern
Updated syscall.h
This commit is contained in:
+26
-5
@@ -17,12 +17,33 @@ typedef enum {
|
|||||||
SYS_SLEEP,
|
SYS_SLEEP,
|
||||||
} SYSCALL_NUMBERS;
|
} 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 */
|
/* Syscall wrappers */
|
||||||
int read(int fd, void* ptr, size_t count);
|
inline int _exit(int status) { return syscall(SYS_EXIT, status, 0, 0, 0, 0); }
|
||||||
int write(int fd, const void* ptr, size_t count);
|
inline int read(int fd, void* ptr, size_t count) { return syscall(SYS_READ, fd, (int)ptr, (int)count, 0, 0); }
|
||||||
int open(const char* path, int oflag);
|
inline int write(int fd, const void* ptr, size_t count) { return syscall(SYS_WRITE, fd, (int)ptr, (int)count, 0, 0); }
|
||||||
int close(int fd);
|
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
|
#endif
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
#include <syscall.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#define MAX_SYSCALLS 9
|
|
||||||
|
|
||||||
int syscall(int nr, int arg0, int arg1, int arg2) {
|
|
||||||
int ret = 0;
|
|
||||||
__asm__ volatile ("int $0x80" : "=a"(ret) : "a"(nr), "b"(arg0), "c"(arg1), "d"(arg2));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Syscall wrappers */
|
|
||||||
int read(int fd, void* ptr, size_t count) {
|
|
||||||
// Returns: int fd
|
|
||||||
return syscall(SYS_READ, fd, (int)ptr, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
int write(int fd, const void* ptr, size_t count) {
|
|
||||||
// Returns: int count
|
|
||||||
return syscall(SYS_WRITE, fd, (int)ptr, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
int open(const char* path, int oflag) {
|
|
||||||
// Returns: int fd
|
|
||||||
return syscall(SYS_OPEN, (int)path, oflag, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int close(int fd) {
|
|
||||||
// Returns: int status
|
|
||||||
return syscall(SYS_CLOSE, fd, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -36,7 +36,8 @@ Legend:
|
|||||||
- [ ] complex.h (idk why we would need this)
|
- [ ] complex.h (idk why we would need this)
|
||||||
- [x] ctype.h
|
- [x] ctype.h
|
||||||
- [x] errno.h
|
- [x] errno.h
|
||||||
- [ ] float.h
|
- [x] fcntl.h
|
||||||
|
- [x] float.h
|
||||||
- [x] limits.h
|
- [x] limits.h
|
||||||
- [x] math.h (maybe a separate libm?) TODO: add errno errors in there
|
- [x] math.h (maybe a separate libm?) TODO: add errno errors in there
|
||||||
- [x] setjmp.h (this plagues my mind)
|
- [x] setjmp.h (this plagues my mind)
|
||||||
@@ -45,11 +46,11 @@ Legend:
|
|||||||
- [x] stdbool.h
|
- [x] stdbool.h
|
||||||
- [x] stddef.h
|
- [x] stddef.h
|
||||||
- [x] stdint.h
|
- [x] stdint.h
|
||||||
- [ ] stdio.h
|
- [x] stdio.h
|
||||||
- [ ] stdlib.h
|
- [x] stdlib.h
|
||||||
- [x] string.h
|
- [x] string.h
|
||||||
- [x] syscall.h
|
- [x] syscall.h
|
||||||
- [ ] time.h
|
- [x] time.h
|
||||||
- [ ] unistd.h (do we do POSIX?)
|
- [ ] unistd.h (do we do POSIX?)
|
||||||
- [ ] wchar.h (we would need text support for wide chars ig?)
|
- [ ] wchar.h (we would need text support for wide chars ig?)
|
||||||
- [ ] wctype.h (same as above)
|
- [ ] wctype.h (same as above)
|
||||||
@@ -67,7 +68,7 @@ Legend:
|
|||||||
- [x] ports - handles IO ports (eg. serial console)
|
- [x] ports - handles IO ports (eg. serial console)
|
||||||
- [x] screen - everything that displays on the screen
|
- [x] screen - everything that displays on the screen
|
||||||
- [x] sound - handles everything related to sound
|
- [x] sound - handles everything related to sound
|
||||||
- [ ] syscall - system calls
|
- [x] syscall - system calls
|
||||||
- [x] tty - handles terminal output
|
- [x] tty - handles terminal output
|
||||||
|
|
||||||
- [x] Multistage Bootloader
|
- [x] Multistage Bootloader
|
||||||
|
|||||||
Reference in New Issue
Block a user