summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/init/main.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/src/init/main.c b/src/init/main.c
index 07a5f8f..413cdad 100644
--- a/src/init/main.c
+++ b/src/init/main.c
@@ -2,44 +2,48 @@
#include <shared/syscalls.h>
#include <stdint.h>
-// takes a cstring and copies it right before a page boundary
-const char *multipageify(const char *str) {
- static char buf[0x2000] __attribute__((section("text")));
+#define argify(str) str, sizeof(str) - 1
+#define log(str) _syscall_fd_write(tty_fd, argify(str))
- char *out = (void*)((uintptr_t)buf & ~0xFFF) + 0xFFF;
- char *cur = out;
- do {
- *cur++ = *str;
- } while (*str++ != '\0');
- return out;
-}
+__attribute__((section("text")))
+int tty_fd;
+
+void misc_tests(void);
+// takes a cstring and copies it right before a page boundary
+const char *multipageify(const char *str);
#define mount(fd, path) _syscall_fd_mount(fd, path, sizeof(path)-1)
int main(void) {
- int fd;
+ // TODO don't dispatch /ttywhatever to the tty driver
- mount(0, "/some/where");
- mount(0, "/some");
+ tty_fd = _syscall_fs_open("/tty", sizeof("/tty") - 1);
+ if (tty_fd < 0)
+ _syscall_exit(argify("couldn't open tty"));
+ log(" opened /tty ");
- _syscall_fs_open( // should fail
- multipageify("/some/where/file"),
- sizeof("/some/where/file") - 1);
+ misc_tests();
- fd = _syscall_fs_open(
- multipageify("/tty"),
- sizeof("/tty") - 1);
- // TODO don't dispatch /ttywhatever to the tty driver
+ _syscall_exit(argify("my job here is done."));
+}
- if (fd < 0) {
- _syscall_exit("couldn't open tty",
- sizeof("couldn't open tty") - 1);
- }
+void misc_tests(void) {
+ int res;
+ res = _syscall_fs_open(argify("/tty/nonexistant"));
+ if (res >= 0) log("test failed ");
+ res = _syscall_fs_open(argify("/ttynonexistant"));
+ if (res >= 0) log("test failed ");
+ log("the \"tests\" went ok");
+}
- _syscall_fd_write(fd, "fd test ", 8);
- _syscall_fd_close(fd);
- _syscall_fd_write(fd, "fd test ", 8); // should fail
+// takes a cstring and copies it right before a page boundary
+const char *multipageify(const char *str) {
+ static char buf[0x2000] __attribute__((section("text")));
- _syscall_exit("bye from init! ",
- sizeof("bye from init! ") - 1);
+ char *out = (void*)((uintptr_t)buf & ~0xFFF) + 0xFFF;
+ char *cur = out;
+ do {
+ *cur++ = *str;
+ } while (*str++ != '\0');
+ return out;
}