Updated syscall.h

This commit is contained in:
2024-10-25 15:36:35 +02:00
parent bd7e00e7e8
commit 1efc7b7e7e
3 changed files with 32 additions and 42 deletions
+26 -5
View File
@@ -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
-32
View File
@@ -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);
}
+6 -5
View File
@@ -36,7 +36,8 @@ Legend:
- [ ] complex.h (idk why we would need this)
- [x] ctype.h
- [x] errno.h
- [ ] float.h
- [x] fcntl.h
- [x] float.h
- [x] limits.h
- [x] math.h (maybe a separate libm?) TODO: add errno errors in there
- [x] setjmp.h (this plagues my mind)
@@ -45,11 +46,11 @@ Legend:
- [x] stdbool.h
- [x] stddef.h
- [x] stdint.h
- [ ] stdio.h
- [ ] stdlib.h
- [x] stdio.h
- [x] stdlib.h
- [x] string.h
- [x] syscall.h
- [ ] time.h
- [x] time.h
- [ ] unistd.h (do we do POSIX?)
- [ ] wchar.h (we would need text support for wide chars ig?)
- [ ] wctype.h (same as above)
@@ -67,7 +68,7 @@ Legend:
- [x] ports - handles IO ports (eg. serial console)
- [x] screen - everything that displays on the screen
- [x] sound - handles everything related to sound
- [ ] syscall - system calls
- [x] syscall - system calls
- [x] tty - handles terminal output
- [x] Multistage Bootloader