feature. See also
. The project being documented here (as the example) is the Zig library itself.
powerpc.clone
pub fn clone() callconv(.naked) u32
File
Code
pub fn clone() callconv(.naked) u32 {
// 3, 4, 5, 6, 7, 8, 9
//
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// 0 3, 4, 5, 6, 7
asm volatile (
\\ # store non-volatile regs r29, r30 on stack in order to put our
\\ # start func and its arg there
\\ stwu 29, -16(1)
\\ stw 30, 4(1)
\\
\\ # save r3 (func) into r29, and r6(arg) into r30
\\ mr 29, 3
\\ mr 30, 6
\\
\\ # create initial stack frame for new thread
\\ clrrwi 4, 4, 4
\\ li 0, 0
\\ stwu 0, -16(4)
\\
\\ #move c into first arg
\\ mr 3, 5
\\ #mr 4, 4
\\ mr 5, 7
\\ mr 6, 8
\\ mr 7, 9
\\
\\ # move syscall number into r0
\\ li 0, 120 # SYS_clone
\\
\\ sc
\\
\\ # check for syscall error
\\ bns+ 1f # jump to label 1 if no summary overflow.
\\ #else
\\ neg 3, 3 #negate the result (errno)
\\ 1:
\\ # compare sc result with 0
\\ cmpwi cr7, 3, 0
\\
\\ # if not 0, restore stack and return
\\ beq cr7, 2f
\\ lwz 29, 0(1)
\\ lwz 30, 4(1)
\\ addi 1, 1, 16
\\ blr
\\
\\ #else: we're the child
\\ 2:
);
if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
\\ .cfi_undefined lr
);
asm volatile (
\\ li 31, 0
\\ mtlr 0
\\
\\ #call funcptr: move arg (d) into r3
\\ mr 3, 30
\\ #move r29 (funcptr) into CTR reg
\\ mtctr 29
\\ # call CTR reg
\\ bctrl
\\ # mov SYS_exit into r0 (the exit param is already in r3)
\\ li 0, 1
\\ sc
);
}