feature. See also
. The project being documented here (as the example) is the Zig library itself.
sparc64.clone
pub fn clone() callconv(.naked) u64
File
Code
pub fn clone() callconv(.naked) u64 {
// 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, -192, %%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, -192, %%sp
\\ flushw
\\ 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, -16, %%i1
\\ sub %%i1, 192 + 2047, %%o1
\\
\\ mov %%i4, %%o2
\\ mov %%i5, %%o3
\\ ldx [%%fp + 176 + 2047], %%o4
\\ t 0x6d
\\ bcs,pn %%xcc, 1f
\\ nop
\\ # The child pid is returned in o0 while o1 tells if this
\\ # process is the child (=1) or the parent (=0).
\\ brnz %%o1, 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 0x6d
);
}