diff --git a/init/init.c b/init/init.c index fe8a2ca..7cc42fa 100644 --- a/init/init.c +++ b/init/init.c @@ -1,9 +1,18 @@ #include #include +#include int main(int argc, char **argv) { (void) argc; (void) argv; + printf("Hello, world!\n"); + printf("Some numbers:%d\n", 12345); + printf("And hex:%#x\n", 0xabcdef); + printf("And a string:%s\n", "Hello!"); + + printf("Arguments passed to init:\n"); + for(int i=0; i < argc; i++) + printf("%d: %s\n", i, argv[i]); for(;;); return 0; } diff --git a/kernel/include/debug.h b/kernel/include/debug.h index 6a61f52..c7721a1 100644 --- a/kernel/include/debug.h +++ b/kernel/include/debug.h @@ -2,11 +2,14 @@ #include #include #include +#include #ifndef NDEBUG #define debug(...) ({spin_lock(&debug_lock);debug_printf(__VA_ARGS__);spin_unlock(&debug_lock);}) + #define debugn(str, n) ({spin_lock(&debug_lock);debug_putsn((str), (n)); spin_unlock(&debug_lock);}) #else #define debug(...) ((void)0) + #define debugn(...) ((void)0) #endif #define debug_info(...) do{debug("[INFO] ");debug(__VA_ARGS__);}while(0) #define debug_ok(...) do{debug("[OK] ");debug(__VA_ARGS__);}while(0) diff --git a/kernel/include/syscall.h b/kernel/include/syscall.h index 2d7f49b..87dca0f 100644 --- a/kernel/include/syscall.h +++ b/kernel/include/syscall.h @@ -39,3 +39,5 @@ typedef long (*syscall_handler_t)(long num, long, long, long, long, long, long); #define SYSCALL_INIT(...) _SYSCALL_INIT(_SYSCALL_INIT,__VA_ARGS__) #define SYSCALL_REGISTER(name, num) syscall_handlers[num] = syscall_##name + +SYSCALL_DECL(write); diff --git a/kernel/syscall/sys_fs.c b/kernel/syscall/sys_fs.c new file mode 100644 index 0000000..00288b8 --- /dev/null +++ b/kernel/syscall/sys_fs.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include +#include + +SYSCALL_DEF(write) +{ + SYSCALL_INIT(int, fd, void *, buffer, size_t, nbyte); + + + if(fd == 1) + { + debugn(buffer, nbyte); + return nbyte; + } + + return 0; +} diff --git a/kernel/syscall/syscall.c b/kernel/syscall/syscall.c index 89fbdc5..40ea3f4 100644 --- a/kernel/syscall/syscall.c +++ b/kernel/syscall/syscall.c @@ -5,6 +5,7 @@ #include #include #include "../../libc/syscall_num.h" +#include extern void syscall_entry(); @@ -34,6 +35,7 @@ registers_t *syscall_handler(registers_t *r) } debug_error("Unknown syscall, No:%d\n", r->rax); + debug("syscall_%d(%x, %x, %x, %x, %x, %x)\n", r->rax, r->rdi, r->rsi, r->rdx, r->r10, r->r8, r->r9); for(;;); } @@ -54,6 +56,7 @@ void syscall_init() memset(syscall_handlers, 0, 1024*sizeof(syscall_handler_t)); SYSCALL_REGISTER(debug, SYS_DEBUG); + SYSCALL_REGISTER(write, SYS_WRITE); } } diff --git a/libc/file_io.c b/libc/file_io.c new file mode 100644 index 0000000..138598c --- /dev/null +++ b/libc/file_io.c @@ -0,0 +1,38 @@ +#include "syscalls.h" +#include +#include +#include +#include + +SYSCALL_DEF(ioctl) +{ + SYSCALL_INIT(int, fd, unsigned long, request); + + if(fd == 1 && request == TIOCGWINSZ) + { + return 0; + } + kernel_debug("==> IOCTL - unsupported request:%lx\n", request); + return -1; +} + +SYSCALL_DEF(writev) +{ + SYSCALL_INIT(int, fd, const struct iovec *, iov, int, iovcnt); + + size_t len = 0; + + for(int i=0; i < iovcnt; i++) + { + len += write(fd, iov[i].iov_base, iov[i].iov_len); + } + + return (long)len; +} + +SYSCALL_DEF(write) +{ + SYSCALL_INIT(int, fd, void *, buffer, size_t, nbyte); + + return kernel_syscall(SYS_WRITE, fd, buffer, nbyte); +} diff --git a/libc/syscall_num.h b/libc/syscall_num.h index 62fbd1d..5b473fc 100644 --- a/libc/syscall_num.h +++ b/libc/syscall_num.h @@ -1,3 +1,4 @@ #pragma once +#define SYS_WRITE 0x001 #define SYS_DEBUG 0x3FF