feature. See also
. The project being documented here (as the example) is the Zig library itself.
mips.clone
pub fn clone() callconv(.naked) u32
File
Code
pub fn clone() callconv(.naked) u32 {
// a0, a1, a2, a3, +0, +4, +8
//
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// v0 a0, a1, a2, a3, +0
asm volatile (
\\ # Save function pointer and argument pointer on new thread stack
\\ and $a1, $a1, -8
\\ subu $a1, $a1, 16
\\ sw $a0, 0($a1)
\\ sw $a3, 4($a1)
\\
\\ # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
\\ move $a0, $a2
\\ lw $a2, 16($sp)
\\ lw $a3, 20($sp)
\\ lw $t1, 24($sp)
\\ subu $sp, $sp, 16
\\ sw $t1, 16($sp)
\\ li $v0, 4120 # SYS_clone
\\ syscall
\\ beq $a3, $zero, 1f
\\ blez $v0, 2f
\\ subu $v0, $zero, $v0
\\ b 2f
\\1:
\\ beq $v0, $zero, 3f
\\2:
\\ addu $sp, $sp, 16
\\ jr $ra
\\3:
);
if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
\\ .cfi_undefined $ra
);
asm volatile (
\\ move $fp, $zero
\\ move $ra, $zero
\\
\\ lw $t9, 0($sp)
\\ lw $a0, 4($sp)
\\ jalr $t9
\\
\\ move $a0, $v0
\\ li $v0, 4001 # SYS_exit
\\ syscall
);
}