aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/include/syscall.h17
-rw-r--r--src/lib/libkogata/syscall.c43
2 files changed, 59 insertions, 1 deletions
diff --git a/src/lib/include/syscall.h b/src/lib/include/syscall.h
index e0f08eb..3d9fcd5 100644
--- a/src/lib/include/syscall.h
+++ b/src/lib/include/syscall.h
@@ -10,14 +10,31 @@
#include <fs.h>
#include <debug.h>
+typedef int fd_t;
+
void dbg_print(const char* str);
void yield();
void exit(int code);
bool mmap(void* addr, size_t size, int mode);
+bool mmap_file(fd_t file, size_t offset, void* addr, size_t size, int mode);
bool mchmap(void* addr, int mode);
bool munmap(void* addr);
+bool create(const char* name, int type);
+bool delete(const char* name);
+bool move(const char* oldname, const char* newname);
+bool stat(const char* name, stat_t *s);
+int ioctl(const char* filename, int command, void* data);
+
+fd_t open(const char* name, int mode);
+void close(fd_t file);
+size_t read(fd_t file, size_t offset, size_t len, char *buf);
+size_t write(fd_t file, size_t offset, size_t len, const char* buf);
+bool readdir(fd_t file, dirent_t *d);
+bool stat_open(fd_t file, stat_t *s);
+int get_mode(fd_t file);
+
// more todo
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libkogata/syscall.c b/src/lib/libkogata/syscall.c
index 8d24628..008a2a9 100644
--- a/src/lib/libkogata/syscall.c
+++ b/src/lib/libkogata/syscall.c
@@ -4,7 +4,7 @@
#include <string.h>
#include <printf.h>
-static uint32_t call(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t ss, uint32_t dd) {
+static inline uint32_t call(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t ss, uint32_t dd) {
uint32_t ret;
asm volatile("int $0x40"
:"=a"(ret)
@@ -38,6 +38,9 @@ void exit(int code) {
bool mmap(void* addr, size_t size, int mode) {
return call(SC_MMAP, (uint32_t)addr, size, mode, 0, 0);
}
+bool mmap_file(fd_t file, size_t offset, void* addr, size_t size, int mode) {
+ return call(SC_MMAP_FILE, file, offset, (uint32_t)addr, size, mode);
+}
bool mchmap(void* addr, int mode) {
return call(SC_MCHMAP, (uint32_t)addr, mode, 0, 0, 0);
}
@@ -45,4 +48,42 @@ bool munmap(void* addr) {
return call(SC_MUNMAP, (uint32_t)addr, 0, 0, 0, 0);
}
+bool create(const char* name, int type) {
+ return call(SC_CREATE, (uint32_t)name, strlen(name), type, 0, 0);
+}
+bool delete(const char* name) {
+ return call(SC_CREATE, (uint32_t)name, strlen(name), 0, 0, 0);
+}
+bool move(const char* oldname, const char* newname) {
+ return call(SC_MOVE, (uint32_t)oldname, strlen(oldname), (uint32_t)newname, strlen(newname), 0);
+}
+bool stat(const char* name, stat_t *s) {
+ return call(SC_STAT, (uint32_t)name, strlen(name), (uint32_t)s, 0, 0);
+}
+int ioctl(const char* filename, int command, void* data) {
+ return call(SC_IOCTL, (uint32_t)filename, strlen(filename), command, (uint32_t)data, 0);
+}
+
+fd_t open(const char* name, int mode) {
+ return call(SC_OPEN, (uint32_t)name, strlen(name), mode, 0, 0);
+}
+void close(fd_t file) {
+ call(SC_CLOSE, file, 0, 0, 0, 0);
+}
+size_t read(fd_t file, size_t offset, size_t len, char *buf) {
+ return call(SC_READ, file, offset, len, (uint32_t)buf, 0);
+}
+size_t write(fd_t file, size_t offset, size_t len, const char* buf) {
+ return call(SC_WRITE, file, offset, len, (uint32_t)buf, 0);
+}
+bool readdir(fd_t file, dirent_t *d) {
+ return call(SC_READDIR, file, (uint32_t)d, 0, 0, 0);
+}
+bool stat_open(fd_t file, stat_t *s) {
+ return call(SC_STAT_OPEN, file, (uint32_t)s, 0, 0, 0);
+}
+int get_mode(fd_t file) {
+ return call(SC_GET_MODE, file, 0, 0, 0, 0);
+}
+
/* vim: set ts=4 sw=4 tw=0 noet :*/