summaryrefslogtreecommitdiff
path: root/src/init/main.c
blob: d24dda04e45ddc36f04a50f99b60b146a2e4fc85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <shared/magic.h>
#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")));

	char *out = (void*)((uintptr_t)buf & ~0xFFF) + 0xFFF;
	char *cur = out;
	do {
		*cur++ = *str;
	} while (*str++ != '\0');
	return out;
}

#define mount(path) _syscall_mount(path, sizeof(path)-1, 0)

int main(void) {
	mount("/");
	mount("/some/where");
	mount("/some");

	_syscall_fs_open(
			multipageify("/some/where/file"),
			      sizeof("/some/where/file") - 1);

	_syscall_fd_write(FD_STDOUT, "fd test ", 8);
	_syscall_fd_close(FD_STDOUT);
	_syscall_fd_write(FD_STDOUT, "fd test ", 8); // should fail

	_syscall_exit("bye from init! ",
	       sizeof("bye from init! ") - 1);
}