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

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

File

lib/std/os/linux/or1k.zig:119

Code

pub fn clone() callconv(.naked) u32 {
    // __clone(func, stack, flags, arg, ptid, tls, ctid)
    //         r3,   r4,    r5,    r6,  r7,   r8,  +0
    //
    // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
    //         r11        r3,    r4,    r5,   r6,  r7
    asm volatile (
        \\ # Save function pointer and argument pointer on new thread stack
        \\ l.andi r4, r4, -4
        \\ l.addi r4, r4, -8
        \\ l.sw 0(r4), r3
        \\ l.sw 4(r4), r6
        \\
        \\ # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
        \\ l.ori r11, r0, 220 # SYS_clone
        \\ l.ori r3, r5, 0
        \\ l.ori r5, r7, 0
        \\ l.ori r6, r8, 0
        \\ l.lwz r7, 0(r1)
        \\ l.sys 1
        \\ l.sfeqi r11, 0
        \\ l.bf 1f
        \\ l.jr r9
        \\1:
    );
    if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
        \\ .cfi_undefined r9
    );
    asm volatile (
        \\ l.ori r2, r0, 0
        \\ l.ori r9, r0, 0
        \\
        \\ l.lwz r11, 0(r1)
        \\ l.lwz r3, 4(r1)
        \\ l.jalr r11
        \\
        \\ l.ori r3, r11, 0
        \\ l.ori r11, r0, 93 # SYS_exit
        \\ l.sys 1
    );
}