authorgravatar for shawn@anastas.ioShawn Anastasio <shawn@anastas.io> 2020-06-03 20:55:33-05:00
committergravatar for shawn@anastas.ioShawn Anastasio <shawn@anastas.io> 2020-07-01 16:11:26-05:00
log15371775d18e6425d1528643cedb70d6f0b7e6ea
tree69372981878db32b90427fa04c089c97f6135023
parentec0d775524e0b8b8f0bc41baa3e6d4e11c50557d

Implement clone() for powerpc64{,le}

Implementation borrowed from musl, as most (all?) of the other ones seem to be.

1 files changed, 55 insertions(+), 0 deletions(-)

lib/std/special/c.zig+55
......@@ -389,6 +389,61 @@ fn clone() callconv(.Naked) void {
389389 \\ syscall
390390 );
391391 },
392
393 .powerpc64, .powerpc64le => {
394 asm volatile (
395 \\ # store non-volatile regs r30, r31 on stack in order to put our
396 \\ # start func and its arg there
397 \\ stwu 30, -16(1)
398 \\ stw 31, 4(1)
399 \\ # save r3 (func) into r30, and r6(arg) into r31
400 \\ mr 30, 3
401 \\ mr 31, 6
402 \\ # create initial stack frame for new thread
403 \\ clrrwi 4, 4, 4
404 \\ li 0, 0
405 \\ stwu 0, -16(4)
406 \\ #move c into first arg
407 \\ mr 3, 5
408 \\ mr 5, 7
409 \\ mr 6, 8
410 \\ mr 7, 9
411 \\ # move syscall number into r0
412 \\ li 0, 120
413 \\ sc
414
415 \\ # check for syscall error
416 \\ bns+ 1f # jump to label 1 if no summary overflow.
417 \\ #else
418 \\ neg 3, 3 #negate the result (errno)
419 \\1:
420 \\ # compare sc result with 0
421 \\ cmpwi cr7, 3, 0
422
423 \\ # if not 0, jump to end
424 \\ bne cr7, 2f
425
426 \\ #else: we're the child
427 \\ #call funcptr: move arg (d) into r3
428 \\ mr 3, 31
429 \\ #move r30 (funcptr) into CTR reg
430 \\ mtctr 30
431 \\ # call CTR reg
432 \\ bctrl
433 \\ # mov SYS_exit into r0 (the exit param is already in r3)
434 \\ li 0, 1
435 \\ sc
436
437 \\2:
438 \\ # restore stack
439 \\ lwz 30, 0(1)
440 \\ lwz 31, 4(1)
441 \\ addi 1, 1, 16
442
443 \\ blr
444 );
445 },
446
392447 else => @compileError("Implement clone() for this arch."),
393448 }
394449}