From c19e386edba2534368d90d00a93bfbb0accd66b4 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 25 Oct 2019 14:09:03 +0300 Subject: [PATCH] Add test syscall: works --- usr/init.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/usr/init.c b/usr/init.c index 0114a2c..4e87127 100644 --- a/usr/init.c +++ b/usr/init.c @@ -1,8 +1,27 @@ #include +typedef uint64_t size_t; +typedef int64_t ssize_t; + +#define ASM_REGISTER(name) \ + register uint64_t name asm (#name) + +#define ASM_SYSCALL3(r0, r1, r2, r3) ({ \ + ASM_REGISTER(rax) = (uint64_t) (r0); \ + ASM_REGISTER(rdi) = (uint64_t) (r1); \ + ASM_REGISTER(rsi) = (uint64_t) (r2); \ + ASM_REGISTER(rdx) = (uint64_t) (r3); \ + asm volatile ("syscall":::"memory"); \ + rax; \ + }) + +ssize_t sys_write(int fd, const void *buf, size_t count) { + return (ssize_t) ASM_SYSCALL3(1, fd, buf, count); +} + void _start(void) { + sys_write(1, "Hello!\n", 7); + while (1) { - // XXX: I'm still allowed to do so (for testing, of course) - *((uint16_t *) 0xFFFFFF00000B8000) = 'A' | 0x900; } }