// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: MIT

#![allow(dead_code, unused_variables)]

// The system call API for x86_64.

use crate::syscall::*;

#[inline(always)]
pub fn caller_syscall_0(call: u64) -> u64 {
    let returncode: u64;
    unsafe {
        core::arch::asm!(
            "syscall",
            inlateout("rax") call => returncode,
            out("rcx") _,
            out("r11") _,
            options(nostack, preserves_flags)
        );
    }
    returncode
}
#[inline(always)]
pub fn caller_syscall_1(call: u64, one: u64) -> u64 {
    let returncode: u64;
    unsafe {
        core::arch::asm!(
            "syscall",
            inlateout("rax") call => returncode,
            in("rdi") one,
            out("rcx") _,
            out("r11") _,
            options(nostack, preserves_flags)
        );
    }
    returncode
}
#[inline(always)]
pub fn caller_syscall_2(call: u64, one: u64, two: u64) -> u64 {
    let returncode: u64;
    unsafe {
        core::arch::asm!(
            "syscall",
            inlateout("rax") call => returncode,
            in("rdi") one,
            in("rsi") two,
            out("rcx") _,
            out("r11") _,
            options(nostack, preserves_flags)
        );
    }
    returncode
}
#[inline(always)]
pub fn caller_syscall_3(call: u64, one: u64, two: u64, three: u64) -> u64 {
    let returncode: u64;
    unsafe {
        core::arch::asm!(
            "syscall",
            inlateout("rax") call => returncode,
            in("rdi") one,
            in("rsi") two,
            in("rdx") three,
            out("rcx") _,
            out("r11") _,
            options(nostack, preserves_flags)
        );
    }
    returncode
}
#[inline(always)]
pub fn caller_syscall_4(call: u64, one: u64, two: u64, three: u64, four: u64) -> u64 {
    let returncode: u64;
    unsafe {
        core::arch::asm!(
            "syscall",
            inlateout("rax") call => returncode,
            in("rdi") one,
            in("rsi") two,
            in("rdx") three,
            in("r10") four,
            out("rcx") _,
            out("r11") _,
            options(nostack, preserves_flags)
        );
    }
    returncode
}
#[inline(always)]
pub fn caller_syscall_5(call: u64, one: u64, two: u64, three: u64, four: u64, five: u64) -> u64 {
    let returncode: u64;
    unsafe {
        core::arch::asm!(
            "syscall",
            inlateout("rax") call => returncode,
            in("rdi") one,
            in("rsi") two,
            in("rdx") three,
            in("r10") four,
            in("r8") five,
            out("rcx") _,
            out("r11") _,
            options(nostack, preserves_flags)
        );
    }
    returncode
}
#[inline(always)]
pub fn caller_syscall_6(
    call: u64,
    one: u64,
    two: u64,
    three: u64,
    four: u64,
    five: u64,
    six: u64,
) -> u64 {
    let returncode: u64;
    unsafe {
        core::arch::asm!(
            "syscall",
            inlateout("rax") call => returncode,
            in("rdi") one,
            in("rsi") two,
            in("rdx") three,
            in("r10") four,
            in("r8") five,
            in("r9") six,
            out("rcx") _,
            out("r11") _,
            options(nostack, preserves_flags)
        );
    }
    returncode
}
