blob: 41f51d324577541b8fa53b0b61ebd0dea4cf47c6 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include <init/types.h>
#include <shared/syscalls.h>
#include <stdint.h>
#define argify(str) str, sizeof(str) - 1
#define log(str) _syscall_write(tty_fd, argify(str))
__attribute__((section("text")))
int tty_fd;
void misc_tests(void);
void fs_test(void);
// takes a cstring and copies it right before a page boundary
const char *multipageify(const char *str);
#define mount(fd, path) _syscall_mount(fd, path, sizeof(path)-1)
int main(void) {
tty_fd = _syscall_open("/tty", sizeof("/tty") - 1);
if (tty_fd < 0)
_syscall_exit(argify("couldn't open tty"));
log(" opened /tty ");
misc_tests();
fs_test();
_syscall_exit(argify("my job here is done."));
}
void fs_test(void) {
handle_t front, back, file;
front = _syscall_fs_create((void*)&back); // TODO change user_ptr to void*
_syscall_mount(front, argify("/mnt"));
file = _syscall_open(argify("/mnt/test"));
}
void misc_tests(void) {
int res;
res = _syscall_open(argify("/tty/nonexistant"));
if (res >= 0) log("test failed ");
res = _syscall_open(argify("/ttynonexistant"));
if (res >= 0) log("test failed ");
log("the \"tests\" went ok");
}
// 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;
}
|