mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-04 02:23:10 +00:00
Cleaned and slightly refactored stdio.h and file I/O syscalls
This commit is contained in:
+32
-3
@@ -1,12 +1,14 @@
|
||||
#ifndef SYSCALLNUMS_H
|
||||
#define SYSCALLNUMS_H
|
||||
#ifndef SYSCALL_H
|
||||
#define SYSCALL_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define MAX_SYSCALLS 9
|
||||
|
||||
typedef enum {
|
||||
SYS_RESERVED,
|
||||
SYS_SLEEP,
|
||||
SYS_GETS,
|
||||
SYS_READ,
|
||||
SYS_WRITE,
|
||||
SYS_OPEN,
|
||||
SYS_CLOSE,
|
||||
@@ -25,4 +27,31 @@ typedef enum {
|
||||
O_BIN = 0x40, // Read bytes, not text
|
||||
} OFLAGS;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user