SYSCALLS(2)

NAME
    syscalls - overview of MontaukOS system calls

DESCRIPTION
    MontaukOS provides 46 system calls (numbers 0-45) for userspace
    programs. Syscalls use the x86-64 SYSCALL instruction with the
    following register convention:
        RAX Syscall number (in) / return value (out)
        RDI Argument 1
        RSI Argument 2
        RDX Argument 3
        R10 Argument 4
        R8 Argument 5
        R9 Argument 6
    Include <montauk/syscall.h> for typed wrappers in the montauk::
    namespace.

PROCESS MANAGEMENT
SYS_EXIT (0)
    Terminate the calling process.
        void montauk::exit(int code = 0); SYS_YIELD (1)
    Yield the remainder of the time slice.
        void montauk::yield(); SYS_SLEEP_MS (2)
    Sleep for at least the given number of milliseconds.
        void montauk::sleep_ms(uint64_t ms); SYS_GETPID (3)
    Return the PID of the calling process.
        int montauk::getpid(); SYS_SPAWN (20)
    Spawn a new process from an ELF binary on the VFS.
        int montauk::spawn(const char* path, const char* args = nullptr); SYS_WAITPID (23)
    Block until the given process has exited.
        void montauk::waitpid(int pid);

CONSOLE I/O
SYS_PRINT (4)
    Write a null-terminated string to the terminal.
        void montauk::print(const char* text); SYS_PUTCHAR (5)
    Write a single character to the terminal.
        void montauk::putchar(char c);

FILE I/O
SYS_OPEN (6)
    Open a file. Returns a handle or negative on error.
        int montauk::open(const char* path); SYS_READ (7)
    Read bytes from a file at a given offset.
        int montauk::read(int h, uint8_t* buf, uint64_t off, uint64_t sz); SYS_GETSIZE (8)
    Get the size of an open file in bytes.
        uint64_t montauk::getsize(int handle); SYS_CLOSE (9)
    Close a file handle.
        void montauk::close(int handle); SYS_READDIR (10)
    List directory entries (max 64 per call).
        int montauk::readdir(const char* path, const char** names, int max);

MEMORY
SYS_ALLOC (11)
    Map zeroed pages into the process address space.
        void* montauk::alloc(uint64_t size); SYS_FREE (12)
    Reserved (currently a no-op).
        void montauk::free(void* ptr);

TIMEKEEPING
SYS_GETTICKS (13)
    Get APIC timer ticks since boot.
        uint64_t montauk::get_ticks(); SYS_GETMILLISECONDS (14)
    Get milliseconds elapsed since boot.
        uint64_t montauk::get_milliseconds(); SYS_GETTIME (28)
    Get the current wall-clock date and time (UTC).
    Fills a Montauk::DateTime struct with Year, Month, Day,
    Hour, Minute, and Second fields.
        void montauk::gettime(Montauk::DateTime* out);

SYSTEM
SYS_GETINFO (15)
    Get OS name, version, and configuration.
        void montauk::get_info(Montauk::SysInfo* info);

KEYBOARD
SYS_ISKEYAVAILABLE (16)
    Check if a key event is pending (non-blocking).
        bool montauk::is_key_available(); SYS_GETKEY (17)
    Get the next key event (press or release).
        void montauk::getkey(Montauk::KeyEvent* out); SYS_GETCHAR (18)
    Block until a printable character is typed.
        char montauk::getchar();

NETWORKING
SYS_PING (19)
    Send an ICMP echo request and wait for reply.
        int32_t montauk::ping(uint32_t ip, uint32_t timeoutMs); SYS_GETNETCFG (37)
    Get the current network configuration (IP, mask, gateway, MAC,
    DNS server).
        void montauk::get_netcfg(Montauk::NetCfg* out); SYS_SETNETCFG (38)
    Set the network configuration (IP, mask, gateway, DNS server).
        int montauk::set_netcfg(const Montauk::NetCfg* cfg); SYS_NETSTATUS (125)
    Get adapter status including driver name, link state, polling mode,
    and RX/TX packet counters.
        int montauk::net_status(Montauk::NetStatus* out); SYS_RESOLVE (44)
    Resolve a hostname to an IPv4 address via DNS. Sends a UDP
    query to the configured DNS server and waits up to 5 seconds
    for a reply. Returns the IP in network byte order, or 0 on
    failure. IP address strings (e.g. "10.0.0.1") are detected
    and returned directly without a DNS query.
        uint32_t montauk::resolve(const char* hostname);

SOCKETS
SYS_SOCKET (29)
    Create a socket. type=SOCK_TCP (1) or SOCK_UDP (2).
    Returns fd or -1.
        int montauk::socket(int type); SYS_CONNECT (30)
    Connect a TCP socket to a remote host.
        int montauk::connect(int fd, uint32_t ip, uint16_t port); SYS_BIND (31)
    Bind a socket to a local port for listening.
        int montauk::bind(int fd, uint16_t port); SYS_LISTEN (32)
    Start listening for incoming TCP connections.
        int montauk::listen(int fd); SYS_ACCEPT (33)
    Accept an incoming connection on a listening socket.
    Returns a new socket fd for the client connection.
        int montauk::accept(int fd); SYS_SEND (34)
    Send data on a connected socket. Returns bytes sent.
        int montauk::send(int fd, const void* data, uint32_t len); SYS_RECV (35)
    Receive data from a connected socket. Returns bytes
    received, 0 if no data available, or -1 on close/error.
        int montauk::recv(int fd, void* buf, uint32_t maxLen); SYS_CLOSESOCK (36)
    Close a socket and release its resources.
        int montauk::closesocket(int fd); SYS_SENDTO (39)
    Send a UDP datagram to a specific destination.
        int montauk::sendto(int fd, const void* data, uint32_t len,
                        uint32_t destIp, uint16_t destPort); SYS_RECVFROM (40)
    Receive a UDP datagram. Returns the source address.
        int montauk::recvfrom(int fd, void* buf, uint32_t maxLen,
                        uint32_t* srcIp, uint16_t* srcPort);

FILE WRITE
SYS_FWRITE (41)
    Write bytes to a file at a given offset.
        int montauk::fwrite(int handle, const uint8_t* buf,
                        uint64_t offset, uint64_t size); SYS_FCREATE (42)
    Create a new file on the ramdisk. Returns a handle or negative
    on error.
        int montauk::fcreate(const char* path);

FRAMEBUFFER
SYS_FBINFO (21)
    Get framebuffer dimensions and format.
        void montauk::fb_info(Montauk::FbInfo* info); SYS_FBMAP (22)
    Map the framebuffer into process memory at 0x50000000.
        void* montauk::fb_map();

TERMINAL
SYS_TERMSIZE (24)
    Get terminal dimensions (columns and rows).
        void montauk::termsize(int* cols, int* rows); SYS_TERMSCALE (43)
    Get or set the terminal font scale factor. When scale_x is 0,
    returns the current scale as (scale_y << 32 | scale_x). When
    scale_x is non-zero, sets the font scale and returns the new
    terminal dimensions as (rows << 32 | cols).
        void montauk::termscale(int scale_x, int scale_y);
        void montauk::get_termscale(int* scale_x, int* scale_y);

ARGUMENTS
SYS_GETARGS (25)
    Get the argument string passed to this process at spawn time.
        int montauk::getargs(char* buf, uint64_t maxLen);

RANDOM
SYS_GETRANDOM (45)
    Fill a buffer with random bytes using RDTSC-seeded entropy.
    Returns the number of bytes written.
        int64_t montauk::getrandom(void* buf, uint32_t len);

POWER MANAGEMENT
SYS_RESET (26)
    Reboot the system.
        [[noreturn]] void montauk::reset(); SYS_SHUTDOWN (27)
    Shut down the system (currently unimplemented).
        [[noreturn]] void montauk::shutdown();

SEE ALSO
    spawn(2), file(2), framebuffer(2), malloc(3)