Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

clone

alpha.clone
pub fn clone() callconv(.naked) u64

File

lib/std/os/linux/alpha.zig:288

Code

pub fn clone() callconv(.naked) u64 {
    // __clone(func, stack, flags, arg, ptid, tls, ctid)
    //         a0,   a1,    a2,    a3,  a4,   a5,  +0
    //
    // syscall(SYS_clone, flags, stack, ptid, ctid, tls)
    //         v0         a0,    a1,    a2,   a3,   a4
    asm volatile (
    // a0 = $16, a1 = $17, a2 = $18, a3 = $19,
    // a4 = $20, a5 = $21, sp = $30, v0 = $0
        \\ # Save function pointer and argument pointer on new thread stack
        \\ ldi $1, -8
        \\ and $17, $17, $1
        \\ lda $17, -16($17)
        \\ stq $16, 0($17)
        \\ stq $19, 8($17)
        \\
        \\ # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,ctid,tls)
        \\ mov $18, $16
        \\ mov $20, $18
        \\ ldq $19, 0($30)
        \\ mov $21, $20
        \\
        \\ # Actual syscall
        \\ ldi $0, 312 # SYS_clone
        \\ callsys
        \\ beq $19, 1f
        \\ negq $0, $0
        \\ ret
        \\1:
        \\ beq $0, 2f
        \\ ret
        \\2:
    );
    if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
    // ra = $26
        \\ .cfi_undefined $26
    );
    asm volatile (
    // v0 = $0, t9 = $23, a0 = $16, ra = $26, sp = $30, fp = $15
        \\ mov 0, $15
        \\
        \\ ldq $23, 0($30)
        \\ ldq $16, 8($30)
        \\ lda $30, 16($30)
        \\ jsr $26, ($23)
        \\
        \\ mov $0, $16
        \\ ldi $0, 1 # SYS_EXIT
        \\ callsys
    );
}