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

xtensa.clone
pub fn clone() callconv(.naked) u32

File

lib/std/os/linux/xtensa.zig:112

Code

pub fn clone() callconv(.naked) u32 {
    // __clone(func, stack, flags, arg, ptid, tls, ctid)
    //         a2,   a3,    a4,    a5,  a6,   a7,  +16
    //
    // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
    //         a2         a6,    a3,    a4,   a5,  a8
    if (builtin.abi != .call0) asm volatile (
        \\ entry sp, 16
    );
    asm volatile (
        \\ movi a8, -16
        \\ and a3, a3, a8
        \\
        \\ mov a9, a2
        \\ mov a10, a5
        \\
        \\ mov a5, a7
        \\ mov a8, a6
        \\ mov a6, a4
        \\ mov a4, a8
    );
    if (builtin.abi == .call0) asm volatile (
        \\ l32i a8, sp, 0
    ) else asm volatile (
        \\ l32i a8, sp, 16
    );
    asm volatile (
        \\ movi a2, 116 // SYS_clone
        \\ syscall
    );
    if (builtin.abi == .call0) asm volatile (
        \\ beqz a2, 1f
        \\ // parent
        \\ ret
        \\
        \\ // child
        \\1:
        \\ movi a15, 0
        \\ movi a0, 0
        \\
        \\ mov a2, a10
        \\ callx0 a9
    ) else asm volatile (
        \\ beqz a2, 1f
        \\ // parent
        \\ retw
        \\
        \\ // child
        \\1:
        \\ movi a7, 0
        \\ movi a0, 0
        \\
        \\ mov a6, a10
        \\ callx4 a9
    );
    asm volatile (
        \\ movi a2, 118 // SYS_exit
        \\ syscall
    );
}