feature. See also
. The project being documented here (as the example) is the Zig library itself.
sparc.clone
pub fn clone() callconv(.naked) u32
File
Code
pub fn clone() callconv(.naked) u32 {
// i0, i1, i2, i3, i4, i5, sp
//
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// g1 o0, o1, o2, o3, o4
asm volatile (
\\ save %%sp, -96, %%sp
\\
\\ // clone() on SPARC can fail with EFAULT if %%sp points to uncommitted memory, so flush
\\ // all register windows up to this point to ensure that the kernel has enough committed
\\ // memory for its stack frame.
\\ save %%sp, -96, %%sp
\\ t 0x3
\\ restore
\\
\\ # Save the func pointer and the arg pointer
\\ mov %%i0, %%g2
\\ mov %%i3, %%g3
\\
\\ # Shuffle the arguments
\\ mov 217, %%g1 // SYS_clone
\\ mov %%i2, %%o0
\\
\\ # Align, and add some extra space for the initial frame
\\ and %%i1, -8, %%i1
\\ sub %%i1, 96 + 2047, %%o1
\\
\\ mov %%i4, %%o2
\\ mov %%i5, %%o3
\\ ld [%%fp + 92 + 2047], %%o4
\\ t 0x10
\\ bcs 1f
\\ nop
\\ # The child pid is returned in o0 while o1 tells if this
\\ # process is the child (=1) or the parent (=0).
\\ tst %%o1
\\ bne 2f
\\ nop
\\
\\ # Parent process, return the child pid
\\ mov %%o0, %%i0
\\ ret
\\ restore
\\
\\1:
\\ # The syscall failed
\\ sub %%g0, %%o0, %%i0
\\ ret
\\ restore
\\
\\2:
\\ # Child process
);
if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
\\ .cfi_undefined %%i7
);
asm volatile (
\\ mov %%g0, %%fp
\\ mov %%g0, %%i7
\\
\\ # call func(arg)
\\ call %%g2
\\ mov %%g3, %%o0
\\ # Exit
\\ mov 1, %%g1 // SYS_exit
\\ t 0x10
);
}