#pragma once

#define SYS_READ   0
#define SYS_WRITE  1
#define SYS_OPEN   2
#define SYS_CLOSE  3
#define SYS_SCHED_YIELD    24

static inline long syscall(long num,
                            unsigned long a1,
                            unsigned long a2,
                            unsigned long a3,
                            unsigned long a4,
                            unsigned long a5,
                            unsigned long a6)
{
    long ret;
    asm volatile (
        "mov %4, %%r10\n"
        "mov %5, %%r8\n"
        "mov %6, %%r9\n"
        "syscall"
        : "=a"(ret)
        : "a"(num), "D"(a1), "S"(a2), "d"(a3),
          "r"(a4), "r"(a5), "r"(a6)
        : "r10", "r8", "r9", "rcx", "r11", "memory"
    );
    return ret;
}