feature. See also
. The project being documented here (as the example) is the Zig library itself.
m68k.clone
pub fn clone() callconv(.naked) u32
File
Code
pub fn clone() callconv(.naked) u32 {
// +4, +8, +12, +16, +20, +24, +28
//
// syscall(SYS_clone, flags, stack, ptid, ctid, tls)
// d0, d1, d2, d3, d4, d5
asm volatile (
\\ // Save callee-saved registers.
\\ movem.l %%d2-%%d5, -(%%sp) // sp -= 16
\\
\\ // Save func and arg.
\\ move.l 16+4(%%sp), %%a0
\\ move.l 16+16(%%sp), %%a1
\\
\\ // d0 = syscall(d0, d1, d2, d3, d4, d5)
\\ move.l #120, %%d0 // SYS_clone
\\ move.l 16+12(%%sp), %%d1
\\ move.l 16+8(%%sp), %%d2
\\ move.l 16+20(%%sp), %%d3
\\ move.l 16+28(%%sp), %%d4
\\ move.l 16+24(%%sp), %%d5
\\ and.l #-4, %%d2 // Align the child stack pointer.
\\ trap #0
\\
\\ // Are we in the parent or child?
\\ tst.l %%d0
\\ beq 1f
\\ // Parent:
\\
\\ // Restore callee-saved registers and return.
\\ movem.l (%%sp)+, %%d2-%%d5 // sp += 16
\\ rts
\\
\\ // Child:
\\1:
);
if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
\\ .cfi_undefined %%pc
);
asm volatile (
\\ suba.l %%fp, %%fp
\\
\\ // d0 = func(a1)
\\ move.l %%a1, -(%%sp)
\\ jsr (%%a0)
\\
\\ // syscall(d0, d1)
\\ move.l %%d0, %%d1
\\ move.l #1, %%d0 // SYS_exit
\\ trap #0
);
}