| ... | ... | @@ -491,6 +491,71 @@ fn clone() callconv(.Naked) void { |
| 491 | 491 | \\ syscall |
| 492 | 492 | ); |
| 493 | 493 | }, |
| 494 | .powerpc => { |
| 495 | // __clone(func, stack, flags, arg, ptid, tls, ctid) |
| 496 | // 3, 4, 5, 6, 7, 8, 9 |
| 497 | |
| 498 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) |
| 499 | // 0 3, 4, 5, 6, 7 |
| 500 | asm volatile ( |
| 501 | \\# store non-volatile regs r30, r31 on stack in order to put our |
| 502 | \\# start func and its arg there |
| 503 | \\stwu 30, -16(1) |
| 504 | \\stw 31, 4(1) |
| 505 | \\ |
| 506 | \\# save r3 (func) into r30, and r6(arg) into r31 |
| 507 | \\mr 30, 3 |
| 508 | \\mr 31, 6 |
| 509 | \\ |
| 510 | \\# create initial stack frame for new thread |
| 511 | \\clrrwi 4, 4, 4 |
| 512 | \\li 0, 0 |
| 513 | \\stwu 0, -16(4) |
| 514 | \\ |
| 515 | \\#move c into first arg |
| 516 | \\mr 3, 5 |
| 517 | \\#mr 4, 4 |
| 518 | \\mr 5, 7 |
| 519 | \\mr 6, 8 |
| 520 | \\mr 7, 9 |
| 521 | \\ |
| 522 | \\# move syscall number into r0 |
| 523 | \\li 0, 120 |
| 524 | \\ |
| 525 | \\sc |
| 526 | \\ |
| 527 | \\# check for syscall error |
| 528 | \\bns+ 1f # jump to label 1 if no summary overflow. |
| 529 | \\#else |
| 530 | \\neg 3, 3 #negate the result (errno) |
| 531 | \\1: |
| 532 | \\# compare sc result with 0 |
| 533 | \\cmpwi cr7, 3, 0 |
| 534 | \\ |
| 535 | \\# if not 0, jump to end |
| 536 | \\bne cr7, 2f |
| 537 | \\ |
| 538 | \\#else: we're the child |
| 539 | \\#call funcptr: move arg (d) into r3 |
| 540 | \\mr 3, 31 |
| 541 | \\#move r30 (funcptr) into CTR reg |
| 542 | \\mtctr 30 |
| 543 | \\# call CTR reg |
| 544 | \\bctrl |
| 545 | \\# mov SYS_exit into r0 (the exit param is already in r3) |
| 546 | \\li 0, 1 |
| 547 | \\sc |
| 548 | \\ |
| 549 | \\2: |
| 550 | \\ |
| 551 | \\# restore stack |
| 552 | \\lwz 30, 0(1) |
| 553 | \\lwz 31, 4(1) |
| 554 | \\addi 1, 1, 16 |
| 555 | \\ |
| 556 | \\blr |
| 557 | ); |
| 558 | }, |
| 494 | 559 | .powerpc64, .powerpc64le => { |
| 495 | 560 | // __clone(func, stack, flags, arg, ptid, tls, ctid) |
| 496 | 561 | // 3, 4, 5, 6, 7, 8, 9 |