1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build ppc64 || ppc64le
11 #include "asm_ppc64x.h"
14 #define cgoCalleeStackSize 48
16 #define cgoCalleeStackSize 32
19 TEXT runtime·rt0_go(SB),NOSPLIT|TOPFRAME,$0
20 // R1 = stack; R3 = argc; R4 = argv; R13 = C TLS base pointer
22 // initialize essential registers
23 BL runtime·reginit(SB)
25 SUB $(FIXED_FRAME+16), R1
26 MOVD R2, 24(R1) // stash the TOC pointer away again now we've created a new frame
27 MOVW R3, FIXED_FRAME+0(R1) // argc
28 MOVD R4, FIXED_FRAME+8(R1) // argv
30 // create istack out of the given (operating system) stack.
31 // _cgo_init may update stackguard.
32 MOVD $runtime·g0(SB), g
36 MOVD R3, g_stackguard0(g)
37 MOVD R3, g_stackguard1(g)
38 MOVD R3, (g_stack+stack_lo)(g)
39 MOVD R1, (g_stack+stack_hi)(g)
41 // If there is a _cgo_init, call it using the gcc ABI.
42 MOVD _cgo_init(SB), R12
46 #ifdef GO_PPC64X_HAS_FUNCDESC
47 // Load the real entry address from the first slot of the function descriptor.
51 MOVD R12, CTR // r12 = "global function entry point"
52 MOVD R13, R5 // arg 2: TLS base pointer
53 MOVD $setg_gcc<>(SB), R4 // arg 1: setg
54 MOVD g, R3 // arg 0: G
55 // C functions expect 32 (48 for AIX) bytes of space on caller
56 // stack frame and a 16-byte aligned R1
57 MOVD R1, R14 // save current stack
58 SUB $cgoCalleeStackSize, R1 // reserve the callee area
59 RLDCR $0, R1, $~15, R1 // 16-byte align
60 BL (CTR) // may clobber R0, R3-R12
61 MOVD R14, R1 // restore stack
68 // update stackguard after _cgo_init
69 MOVD (g_stack+stack_lo)(g), R3
70 ADD $const__StackGuard, R3
71 MOVD R3, g_stackguard0(g)
72 MOVD R3, g_stackguard1(g)
74 // set the per-goroutine and per-mach "registers"
75 MOVD $runtime·m0(SB), R3
84 // args are already prepared
87 BL runtime·schedinit(SB)
89 // create a new goroutine to start program
90 MOVD $runtime·mainPC(SB), R3 // entry
96 BL runtime·newproc(SB)
97 ADD $(8+FIXED_FRAME), R1
100 BL runtime·mstart(SB)
105 DATA runtime·mainPC+0(SB)/8,$runtime·main<ABIInternal>(SB)
106 GLOBL runtime·mainPC(SB),RODATA,$8
108 TEXT runtime·breakpoint(SB),NOSPLIT|NOFRAME,$0-0
112 TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0
115 // Any changes must be reflected to runtime/cgo/gcc_aix_ppc64.S:.crosscall_ppc64
116 TEXT _cgo_reginit(SB),NOSPLIT|NOFRAME,$0-0
117 // crosscall_ppc64 and crosscall2 need to reginit, but can't
118 // get at the 'runtime.reginit' symbol.
119 BR runtime·reginit(SB)
121 TEXT runtime·reginit(SB),NOSPLIT|NOFRAME,$0-0
122 // set R0 to zero, it's expected by the toolchain
126 TEXT runtime·mstart(SB),NOSPLIT|TOPFRAME,$0
127 BL runtime·mstart0(SB)
135 // restore state from Gobuf; longjmp
136 TEXT runtime·gogo(SB), NOSPLIT|NOFRAME, $0-8
139 MOVD 0(R6), R4 // make sure g != nil
142 TEXT gogo<>(SB), NOSPLIT|NOFRAME, $0
144 BL runtime·save_g(SB)
146 MOVD gobuf_sp(R5), R1
147 MOVD gobuf_lr(R5), R31
149 MOVD 24(R1), R2 // restore R2
152 MOVD gobuf_ret(R5), R3
153 MOVD gobuf_ctxt(R5), R11
154 MOVD R0, gobuf_sp(R5)
155 MOVD R0, gobuf_ret(R5)
156 MOVD R0, gobuf_lr(R5)
157 MOVD R0, gobuf_ctxt(R5)
158 CMP R0, R0 // set condition codes for == test, needed by stack split
159 MOVD gobuf_pc(R5), R12
163 // void mcall(fn func(*g))
164 // Switch to m->g0's stack, call fn(g).
165 // Fn must never return. It should gogo(&g->sched)
166 // to keep running g.
167 TEXT runtime·mcall<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-8
168 // Save caller state in g->sched
169 // R11 should be safe across save_g??
171 MOVD R1, (g_sched+gobuf_sp)(g)
173 MOVD R31, (g_sched+gobuf_pc)(g)
174 MOVD R0, (g_sched+gobuf_lr)(g)
176 // Switch to m->g0 & its stack, call fn.
180 BL runtime·save_g(SB)
183 BR runtime·badmcall(SB)
184 MOVD 0(R11), R12 // code pointer
186 MOVD (g_sched+gobuf_sp)(g), R1 // sp = m->g0->sched.sp
187 // Don't need to do anything special for regabiargs here
188 // R3 is g; stack is set anyway
196 BR runtime·badmcall2(SB)
198 // systemstack_switch is a dummy routine that systemstack leaves at the bottom
199 // of the G stack. We need to distinguish the routine that
200 // lives at the bottom of the G stack from the one that lives
201 // at the top of the system stack because the one at the top of
202 // the system stack terminates the stack walk (see topofstack()).
203 TEXT runtime·systemstack_switch(SB), NOSPLIT, $0-0
204 // We have several undefs here so that 16 bytes past
205 // $runtime·systemstack_switch lies within them whether or not the
206 // instructions that derive r2 from r12 are there.
210 BL (LR) // make sure this function is not leaf
213 // func systemstack(fn func())
214 TEXT runtime·systemstack(SB), NOSPLIT, $0-8
215 MOVD fn+0(FP), R3 // R3 = fn
216 MOVD R3, R11 // context
217 MOVD g_m(g), R4 // R4 = m
219 MOVD m_gsignal(R4), R5 // R5 = gsignal
223 MOVD m_g0(R4), R5 // R5 = g0
231 // Bad: g is not gsignal, not g0, not curg. What is it?
232 // Hide call from linker nosplit analysis.
233 MOVD $runtime·badsystemstack(SB), R12
239 // save our state in g->sched. Pretend to
240 // be systemstack_switch if the G stack is scanned.
241 BL gosave_systemstack_switch<>(SB)
245 BL runtime·save_g(SB)
246 MOVD (g_sched+gobuf_sp)(g), R1
248 // call target function
249 MOVD 0(R11), R12 // code pointer
253 // restore TOC pointer. It seems unlikely that we will use systemstack
254 // to call a function defined in another module, but the results of
255 // doing so would be so confusing that it's worth doing this.
258 MOVD (g_sched+gobuf_sp)(g), R3
265 BL runtime·save_g(SB)
266 MOVD (g_sched+gobuf_sp)(g), R1
267 MOVD R0, (g_sched+gobuf_sp)(g)
271 // already on m stack, just call directly
272 // On other arches we do a tail call here, but it appears to be
273 // impossible to tail call a function pointer in shared mode on
274 // ppc64 because the caller is responsible for restoring the TOC.
275 MOVD 0(R11), R12 // code pointer
284 * support for morestack
287 // Called during function prolog when more stack is needed.
288 // Caller has already loaded:
289 // R3: framesize, R4: argsize, R5: LR
291 // The traceback routines see morestack on a g0 as being
292 // the top of a stack (for example, morestack calling newstack
293 // calling the scheduler calling newm calling gc), so we must
294 // record an argument size. For that purpose, it has no arguments.
295 TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
296 // Cannot grow scheduler stack (m->g0).
301 BL runtime·badmorestackg0(SB)
304 // Cannot grow signal stack (m->gsignal).
305 MOVD m_gsignal(R7), R8
308 BL runtime·badmorestackgsignal(SB)
312 // Set g->sched to context in f.
313 MOVD R1, (g_sched+gobuf_sp)(g)
315 MOVD R8, (g_sched+gobuf_pc)(g)
316 MOVD R5, (g_sched+gobuf_lr)(g)
317 MOVD R11, (g_sched+gobuf_ctxt)(g)
320 // Set m->morebuf to f's caller.
321 MOVD R5, (m_morebuf+gobuf_pc)(R7) // f's caller's PC
322 MOVD R1, (m_morebuf+gobuf_sp)(R7) // f's caller's SP
323 MOVD g, (m_morebuf+gobuf_g)(R7)
325 // Call newstack on m->g0's stack.
327 BL runtime·save_g(SB)
328 MOVD (g_sched+gobuf_sp)(g), R1
329 MOVDU R0, -(FIXED_FRAME+0)(R1) // create a call frame on g0
330 BL runtime·newstack(SB)
332 // Not reached, but make sure the return PC from the call to newstack
333 // is still in this function, and not the beginning of the next.
336 TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
337 // Force SPWRITE. This function doesn't actually write SP,
338 // but it is called with a special calling convention where
339 // the caller doesn't save LR on stack but passes it as a
340 // register (R5), and the unwinder currently doesn't understand.
341 // Make it SPWRITE to stop unwinding. (See issue 54332)
342 // Use OR R0, R1 instead of MOVD R1, R1 as the MOVD instruction
343 // has a special affect on Power8,9,10 by lowering the thread
344 // priority and causing a slowdown in execution time
348 BR runtime·morestack(SB)
350 // reflectcall: call a function with the given argument list
351 // func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs).
352 // we don't have variable-sized frames, so we use a small number
353 // of constant-sized-frame functions to encode a few bits of size in the pc.
354 // Caution: ugly multiline assembly macros in your future!
356 #define DISPATCH(NAME,MAXSIZE) \
357 MOVD $MAXSIZE, R31; \
360 MOVD $NAME(SB), R12; \
363 // Note: can't just "BR NAME(SB)" - bad inlining results.
365 TEXT ·reflectcall(SB), NOSPLIT|NOFRAME, $0-48
366 MOVWZ frameSize+32(FP), R3
367 DISPATCH(runtime·call16, 16)
368 DISPATCH(runtime·call32, 32)
369 DISPATCH(runtime·call64, 64)
370 DISPATCH(runtime·call128, 128)
371 DISPATCH(runtime·call256, 256)
372 DISPATCH(runtime·call512, 512)
373 DISPATCH(runtime·call1024, 1024)
374 DISPATCH(runtime·call2048, 2048)
375 DISPATCH(runtime·call4096, 4096)
376 DISPATCH(runtime·call8192, 8192)
377 DISPATCH(runtime·call16384, 16384)
378 DISPATCH(runtime·call32768, 32768)
379 DISPATCH(runtime·call65536, 65536)
380 DISPATCH(runtime·call131072, 131072)
381 DISPATCH(runtime·call262144, 262144)
382 DISPATCH(runtime·call524288, 524288)
383 DISPATCH(runtime·call1048576, 1048576)
384 DISPATCH(runtime·call2097152, 2097152)
385 DISPATCH(runtime·call4194304, 4194304)
386 DISPATCH(runtime·call8388608, 8388608)
387 DISPATCH(runtime·call16777216, 16777216)
388 DISPATCH(runtime·call33554432, 33554432)
389 DISPATCH(runtime·call67108864, 67108864)
390 DISPATCH(runtime·call134217728, 134217728)
391 DISPATCH(runtime·call268435456, 268435456)
392 DISPATCH(runtime·call536870912, 536870912)
393 DISPATCH(runtime·call1073741824, 1073741824)
394 MOVD $runtime·badreflectcall(SB), R12
398 #define CALLFN(NAME,MAXSIZE) \
399 TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \
401 /* copy arguments to stack */ \
402 MOVD stackArgs+16(FP), R3; \
403 MOVWZ stackArgsSize+24(FP), R4; \
407 /* copy 8 at a time if possible */ \
408 ADD $(FIXED_FRAME-8), R5; \
416 /* handle remaining bytes */ \
425 ADD $(FIXED_FRAME-1), R5; \
434 /* call function */ \
437 /* AIX won't trigger a SIGSEGV if R11 = nil */ \
438 /* So it manually triggers it */ \
443 MOVD regArgs+40(FP), R20; \
444 BL runtime·unspillArgs(SB); \
447 PCDATA $PCDATA_StackMapIndex, $0; \
452 /* copy return values back */ \
453 MOVD regArgs+40(FP), R20; \
454 BL runtime·spillArgs(SB); \
455 MOVD stackArgsType+0(FP), R7; \
456 MOVD stackArgs+16(FP), R3; \
457 MOVWZ stackArgsSize+24(FP), R4; \
458 MOVWZ stackRetOffset+28(FP), R6; \
459 ADD $FIXED_FRAME, R1, R5; \
466 // callRet copies return values back at the end of call*. This is a
467 // separate function so it can allocate stack space for the arguments
468 // to reflectcallmove. It does not follow the Go ABI; it expects its
469 // arguments in registers.
470 TEXT callRet<>(SB), NOSPLIT, $40-0
472 MOVD R7, FIXED_FRAME+0(R1)
473 MOVD R3, FIXED_FRAME+8(R1)
474 MOVD R5, FIXED_FRAME+16(R1)
475 MOVD R4, FIXED_FRAME+24(R1)
476 MOVD R20, FIXED_FRAME+32(R1)
477 BL runtime·reflectcallmove(SB)
483 CALLFN(·call128, 128)
484 CALLFN(·call256, 256)
485 CALLFN(·call512, 512)
486 CALLFN(·call1024, 1024)
487 CALLFN(·call2048, 2048)
488 CALLFN(·call4096, 4096)
489 CALLFN(·call8192, 8192)
490 CALLFN(·call16384, 16384)
491 CALLFN(·call32768, 32768)
492 CALLFN(·call65536, 65536)
493 CALLFN(·call131072, 131072)
494 CALLFN(·call262144, 262144)
495 CALLFN(·call524288, 524288)
496 CALLFN(·call1048576, 1048576)
497 CALLFN(·call2097152, 2097152)
498 CALLFN(·call4194304, 4194304)
499 CALLFN(·call8388608, 8388608)
500 CALLFN(·call16777216, 16777216)
501 CALLFN(·call33554432, 33554432)
502 CALLFN(·call67108864, 67108864)
503 CALLFN(·call134217728, 134217728)
504 CALLFN(·call268435456, 268435456)
505 CALLFN(·call536870912, 536870912)
506 CALLFN(·call1073741824, 1073741824)
508 TEXT runtime·procyield(SB),NOSPLIT|NOFRAME,$0-4
509 MOVW cycles+0(FP), R7
510 // POWER does not have a pause/yield instruction equivalent.
511 // Instead, we can lower the program priority by setting the
512 // Program Priority Register prior to the wait loop and set it
513 // back to default afterwards. On Linux, the default priority is
514 // medium-low. For details, see page 837 of the ISA 3.0.
515 OR R1, R1, R1 // Set PPR priority to low
520 OR R6, R6, R6 // Set PPR priority back to medium-low
523 // Save state of caller into g->sched,
524 // but using fake PC from systemstack_switch.
525 // Must only be called from functions with no locals ($0)
526 // or else unwinding from systemstack_switch is incorrect.
528 TEXT gosave_systemstack_switch<>(SB),NOSPLIT|NOFRAME,$0
529 MOVD $runtime·systemstack_switch(SB), R31
530 ADD $16, R31 // get past prologue (including r2-setting instructions when they're there)
531 MOVD R31, (g_sched+gobuf_pc)(g)
532 MOVD R1, (g_sched+gobuf_sp)(g)
533 MOVD R0, (g_sched+gobuf_lr)(g)
534 MOVD R0, (g_sched+gobuf_ret)(g)
535 // Assert ctxt is zero. See func save.
536 MOVD (g_sched+gobuf_ctxt)(g), R31
543 #define asmcgocallSaveOffset cgoCalleeStackSize + 8
545 #define asmcgocallSaveOffset cgoCalleeStackSize
548 // func asmcgocall(fn, arg unsafe.Pointer) int32
549 // Call fn(arg) on the scheduler stack,
550 // aligned appropriately for the gcc ABI.
551 // See cgocall.go for more details.
552 TEXT ·asmcgocall(SB),NOSPLIT,$0-20
556 MOVD R1, R7 // save original stack pointer
559 // Figure out if we need to switch to m->g0 stack.
560 // We get called to create new OS threads too, and those
561 // come in on the m->g0 stack already. Or we might already
562 // be on the m->gsignal stack.
564 MOVD m_gsignal(R8), R6
570 BL gosave_systemstack_switch<>(SB)
572 BL runtime·save_g(SB)
573 MOVD (g_sched+gobuf_sp)(g), R1
575 // Now on a scheduling stack (a pthread-created stack).
578 // Create a fake LR to improve backtrace.
579 MOVD $runtime·asmcgocall(SB), R6
581 // AIX also save one argument on the stack.
584 // Save room for two of our pointers, plus the callee
585 // save area that lives on the caller stack.
586 SUB $(asmcgocallSaveOffset+16), R1
587 RLDCR $0, R1, $~15, R1 // 16-byte alignment for gcc ABI
588 MOVD R5, (asmcgocallSaveOffset+8)(R1)// save old g on stack
589 MOVD (g_stack+stack_hi)(R5), R5
591 MOVD R5, asmcgocallSaveOffset(R1) // save depth in old g stack (can't just save SP, as stack might be copied during a callback)
593 MOVD R7, 0(R1) // Save frame pointer to allow manual backtrace with gdb
595 MOVD R0, 0(R1) // clear back chain pointer (TODO can we give it real back trace information?)
597 // This is a "global call", so put the global entry point in r12
600 #ifdef GO_PPC64X_HAS_FUNCDESC
601 // Load the real entry address from the first slot of the function descriptor.
606 MOVD R4, R3 // arg in r3
608 // C code can clobber R0, so set it back to 0. F27-F31 are
609 // callee save, so we don't need to recover those.
611 // Restore g, stack pointer, toc pointer.
612 // R3 is errno, so don't touch it
613 MOVD (asmcgocallSaveOffset+8)(R1), g
614 MOVD (g_stack+stack_hi)(g), R5
615 MOVD asmcgocallSaveOffset(R1), R6
621 BL runtime·save_g(SB)
626 // func cgocallback(fn, frame unsafe.Pointer, ctxt uintptr)
627 // See cgocall.go for more details.
628 TEXT ·cgocallback(SB),NOSPLIT,$24-24
631 // Skip cgocallbackg, just dropm when fn is nil, and frame is the saved g.
632 // It is used to dropm while thread is exiting.
636 // Restore the g from frame.
641 // Load m and g from thread-local storage.
642 MOVBZ runtime·iscgo(SB), R3
645 BL runtime·load_g(SB)
648 // If g is nil, Go did not create the current thread,
649 // or if this thread never called into Go on pthread platforms.
650 // Call needm to obtain one for temporary use.
651 // In this case, we're running on the thread stack, so there's
652 // lots of space, but the linker doesn't know. Hide the call from
653 // the linker analysis by using an indirect call.
658 MOVD R8, savedm-8(SP)
662 MOVD g, savedm-8(SP) // g is zero, so is m.
663 MOVD $runtime·needAndBindM(SB), R12
667 // Set m->sched.sp = SP, so that if a panic happens
668 // during the function we are about to execute, it will
669 // have a valid SP to run on the g0 stack.
670 // The next few lines (after the havem label)
671 // will save this SP onto the stack and then write
672 // the same SP back to m->sched.sp. That seems redundant,
673 // but if an unrecovered panic happens, unwindm will
674 // restore the g->sched.sp from the stack location
675 // and then systemstack will try to use it. If we don't set it here,
676 // that restored SP will be uninitialized (typically 0) and
677 // will not be usable.
680 MOVD R1, (g_sched+gobuf_sp)(R3)
683 // Now there's a valid m, and we're running on its m->g0.
684 // Save current m->g0->sched.sp on stack and then set it to SP.
685 // Save current sp in m->g0->sched.sp in preparation for
686 // switch back to m->curg stack.
687 // NOTE: unwindm knows that the saved g->sched.sp is at 8(R1) aka savedsp-16(SP).
689 MOVD (g_sched+gobuf_sp)(R3), R4
690 MOVD R4, savedsp-24(SP) // must match frame size
691 MOVD R1, (g_sched+gobuf_sp)(R3)
693 // Switch to m->curg stack and call runtime.cgocallbackg.
694 // Because we are taking over the execution of m->curg
695 // but *not* resuming what had been running, we need to
696 // save that information (m->curg->sched) so we can restore it.
697 // We can restore m->curg->sched.sp easily, because calling
698 // runtime.cgocallbackg leaves SP unchanged upon return.
699 // To save m->curg->sched.pc, we push it onto the curg stack and
700 // open a frame the same size as cgocallback's g0 frame.
701 // Once we switch to the curg stack, the pushed PC will appear
702 // to be the return PC of cgocallback, so that the traceback
703 // will seamlessly trace back into the earlier calls.
705 BL runtime·save_g(SB)
706 MOVD (g_sched+gobuf_sp)(g), R4 // prepare stack as R4
707 MOVD (g_sched+gobuf_pc)(g), R5
708 MOVD R5, -(24+FIXED_FRAME)(R4) // "saved LR"; must match frame size
709 // Gather our arguments into registers.
713 MOVD $-(24+FIXED_FRAME)(R4), R1 // switch stack; must match frame size
714 MOVD R5, FIXED_FRAME+0(R1)
715 MOVD R6, FIXED_FRAME+8(R1)
716 MOVD R7, FIXED_FRAME+16(R1)
718 MOVD $runtime·cgocallbackg(SB), R12
720 CALL (CTR) // indirect call to bypass nosplit check. We're on a different stack now.
722 // Restore g->sched (== m->curg->sched) from saved values.
724 MOVD R5, (g_sched+gobuf_pc)(g)
725 MOVD $(24+FIXED_FRAME)(R1), R4 // must match frame size
726 MOVD R4, (g_sched+gobuf_sp)(g)
728 // Switch back to m->g0's stack and restore m->g0->sched.sp.
729 // (Unlike m->curg, the g0 goroutine never uses sched.pc,
730 // so we do not have to restore it.)
733 BL runtime·save_g(SB)
734 MOVD (g_sched+gobuf_sp)(g), R1
735 MOVD savedsp-24(SP), R4 // must match frame size
736 MOVD R4, (g_sched+gobuf_sp)(g)
738 // If the m on entry was nil, we called needm above to borrow an m,
739 // 1. for the duration of the call on non-pthread platforms,
740 // 2. or the duration of the C thread alive on pthread platforms.
741 // If the m on entry wasn't nil,
742 // 1. the thread might be a Go thread,
743 // 2. or it's wasn't the first call from a C thread on pthread platforms,
744 // since the we skip dropm to resue the m in the first call.
745 MOVD savedm-8(SP), R6
749 // Skip dropm to reuse it in the next call, when a pthread key has been created.
750 MOVD _cgo_pthread_key_created(SB), R6
751 // It means cgo is disabled when _cgo_pthread_key_created is a nil pointer, need dropm.
759 MOVD $runtime·dropm(SB), R12
767 // void setg(G*); set g. for use by needm.
768 TEXT runtime·setg(SB), NOSPLIT, $0-8
770 // This only happens if iscgo, so jump straight to save_g
771 BL runtime·save_g(SB)
776 DATA setg_gcc<>+0(SB)/8, $_setg_gcc<>(SB)
777 DATA setg_gcc<>+8(SB)/8, $TOC(SB)
778 DATA setg_gcc<>+16(SB)/8, $0
779 GLOBL setg_gcc<>(SB), NOPTR, $24
781 TEXT setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
782 DWORD $_setg_gcc<>(SB)
788 // void setg_gcc(G*); set g in C TLS.
789 // Must obey the gcc calling convention.
790 #ifdef GOARCH_ppc64le
791 TEXT setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
793 TEXT _setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
795 // The standard prologue clobbers R31, which is callee-save in
796 // the C ABI, so we have to use $-8-0 and save LR ourselves.
798 // Also save g and R31, since they're callee-save in C ABI
803 BL runtime·save_g(SB)
810 TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
816 // int64 runtime·cputicks(void)
817 TEXT runtime·cputicks(SB),NOSPLIT,$0-8
822 // spillArgs stores return values from registers to a *internal/abi.RegArgs in R20.
823 TEXT runtime·spillArgs(SB),NOSPLIT,$0-0
850 // unspillArgs loads args into registers from a *internal/abi.RegArgs in R20.
851 TEXT runtime·unspillArgs(SB),NOSPLIT,$0-0
878 // AES hashing not implemented for ppc64
879 TEXT runtime·memhash<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-32
880 JMP runtime·memhashFallback<ABIInternal>(SB)
881 TEXT runtime·strhash<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
882 JMP runtime·strhashFallback<ABIInternal>(SB)
883 TEXT runtime·memhash32<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
884 JMP runtime·memhash32Fallback<ABIInternal>(SB)
885 TEXT runtime·memhash64<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
886 JMP runtime·memhash64Fallback<ABIInternal>(SB)
888 TEXT runtime·return0(SB), NOSPLIT, $0
892 // Called from cgo wrappers, this function returns g->m->curg.stack.hi.
893 // Must obey the gcc calling convention.
895 // On AIX, _cgo_topofstack is defined in runtime/cgo, because it must
896 // be a longcall in order to prevent trampolines from ld.
897 TEXT __cgo_topofstack(SB),NOSPLIT|NOFRAME,$0
899 TEXT _cgo_topofstack(SB),NOSPLIT|NOFRAME,$0
901 // g (R30) and R31 are callee-save in the C ABI, so save them
906 BL runtime·load_g(SB) // clobbers g (R30), R31
909 MOVD (g_stack+stack_hi)(R3), R3
916 // The top-most function running on a goroutine
917 // returns to goexit+PCQuantum.
919 // When dynamically linking Go, it can be returned to from a function
920 // implemented in a different module and so needs to reload the TOC pointer
921 // from the stack (although this function declares that it does not set up x-a
922 // frame, newproc1 does in fact allocate one for goexit and saves the TOC
923 // pointer in the correct place).
924 // goexit+_PCQuantum is halfway through the usual global entry point prologue
925 // that derives r2 from r12 which is a bit silly, but not harmful.
926 TEXT runtime·goexit(SB),NOSPLIT|NOFRAME|TOPFRAME,$0-0
928 BL runtime·goexit1(SB) // does not return
929 // traceback from goexit1 must hit code range of goexit
932 // prepGoExitFrame saves the current TOC pointer (i.e. the TOC pointer for the
933 // module containing runtime) to the frame that goexit will execute in when
934 // the goroutine exits. It's implemented in assembly mainly because that's the
935 // easiest way to get access to R2.
936 TEXT runtime·prepGoExitFrame(SB),NOSPLIT,$0-8
941 TEXT runtime·addmoduledata(SB),NOSPLIT|NOFRAME,$0-0
944 MOVD runtime·lastmoduledatap(SB), R4
945 MOVD R3, moduledata_next(R4)
946 MOVD R3, runtime·lastmoduledatap(SB)
951 TEXT ·checkASM(SB),NOSPLIT,$0-1
956 // gcWriteBarrier informs the GC about heap pointer writes.
958 // gcWriteBarrier does NOT follow the Go ABI. It accepts the
959 // number of bytes of buffer needed in R29, and returns a pointer
960 // to the buffer space in R29.
961 // It clobbers condition codes.
962 // It does not clobber R0 through R17 (except special registers),
963 // but may clobber any other register, *including* R31.
964 TEXT gcWriteBarrier<>(SB),NOSPLIT,$112
965 // The standard prologue clobbers R31.
966 // We use R18, R19, and R31 as scratch registers.
970 MOVD (p_wbBuf+wbBuf_next)(R18), R19
971 MOVD (p_wbBuf+wbBuf_end)(R18), R31
972 // Increment wbBuf.next position.
974 // Is the buffer full?
977 // Commit to the larger buffer.
978 MOVD R19, (p_wbBuf+wbBuf_next)(R18)
979 // Make return value (the original next position)
984 // Save registers R0 through R15 since these were not saved by the caller.
985 // We don't save all registers on ppc64 because it takes too much space.
986 MOVD R20, (FIXED_FRAME+0)(R1)
987 MOVD R21, (FIXED_FRAME+8)(R1)
988 // R0 is always 0, so no need to spill.
991 MOVD R3, (FIXED_FRAME+16)(R1)
992 MOVD R4, (FIXED_FRAME+24)(R1)
993 MOVD R5, (FIXED_FRAME+32)(R1)
994 MOVD R6, (FIXED_FRAME+40)(R1)
995 MOVD R7, (FIXED_FRAME+48)(R1)
996 MOVD R8, (FIXED_FRAME+56)(R1)
997 MOVD R9, (FIXED_FRAME+64)(R1)
998 MOVD R10, (FIXED_FRAME+72)(R1)
999 // R11, R12 may be clobbered by external-linker-inserted trampoline
1001 MOVD R14, (FIXED_FRAME+80)(R1)
1002 MOVD R15, (FIXED_FRAME+88)(R1)
1003 MOVD R16, (FIXED_FRAME+96)(R1)
1004 MOVD R17, (FIXED_FRAME+104)(R1)
1006 CALL runtime·wbBufFlush(SB)
1008 MOVD (FIXED_FRAME+0)(R1), R20
1009 MOVD (FIXED_FRAME+8)(R1), R21
1010 MOVD (FIXED_FRAME+16)(R1), R3
1011 MOVD (FIXED_FRAME+24)(R1), R4
1012 MOVD (FIXED_FRAME+32)(R1), R5
1013 MOVD (FIXED_FRAME+40)(R1), R6
1014 MOVD (FIXED_FRAME+48)(R1), R7
1015 MOVD (FIXED_FRAME+56)(R1), R8
1016 MOVD (FIXED_FRAME+64)(R1), R9
1017 MOVD (FIXED_FRAME+72)(R1), R10
1018 MOVD (FIXED_FRAME+80)(R1), R14
1019 MOVD (FIXED_FRAME+88)(R1), R15
1020 MOVD (FIXED_FRAME+96)(R1), R16
1021 MOVD (FIXED_FRAME+104)(R1), R17
1024 TEXT runtime·gcWriteBarrier1<ABIInternal>(SB),NOSPLIT,$0
1026 JMP gcWriteBarrier<>(SB)
1027 TEXT runtime·gcWriteBarrier2<ABIInternal>(SB),NOSPLIT,$0
1029 JMP gcWriteBarrier<>(SB)
1030 TEXT runtime·gcWriteBarrier3<ABIInternal>(SB),NOSPLIT,$0
1032 JMP gcWriteBarrier<>(SB)
1033 TEXT runtime·gcWriteBarrier4<ABIInternal>(SB),NOSPLIT,$0
1035 JMP gcWriteBarrier<>(SB)
1036 TEXT runtime·gcWriteBarrier5<ABIInternal>(SB),NOSPLIT,$0
1038 JMP gcWriteBarrier<>(SB)
1039 TEXT runtime·gcWriteBarrier6<ABIInternal>(SB),NOSPLIT,$0
1041 JMP gcWriteBarrier<>(SB)
1042 TEXT runtime·gcWriteBarrier7<ABIInternal>(SB),NOSPLIT,$0
1044 JMP gcWriteBarrier<>(SB)
1045 TEXT runtime·gcWriteBarrier8<ABIInternal>(SB),NOSPLIT,$0
1047 JMP gcWriteBarrier<>(SB)
1049 // Note: these functions use a special calling convention to save generated code space.
1050 // Arguments are passed in registers, but the space for those arguments are allocated
1051 // in the caller's stack frame. These stubs write the args into that stack space and
1052 // then tail call to the corresponding runtime handler.
1053 // The tail call makes these stubs disappear in backtraces.
1054 TEXT runtime·panicIndex<ABIInternal>(SB),NOSPLIT,$0-16
1055 JMP runtime·goPanicIndex<ABIInternal>(SB)
1056 TEXT runtime·panicIndexU<ABIInternal>(SB),NOSPLIT,$0-16
1057 JMP runtime·goPanicIndexU<ABIInternal>(SB)
1058 TEXT runtime·panicSliceAlen<ABIInternal>(SB),NOSPLIT,$0-16
1061 JMP runtime·goPanicSliceAlen<ABIInternal>(SB)
1062 TEXT runtime·panicSliceAlenU<ABIInternal>(SB),NOSPLIT,$0-16
1065 JMP runtime·goPanicSliceAlenU<ABIInternal>(SB)
1066 TEXT runtime·panicSliceAcap<ABIInternal>(SB),NOSPLIT,$0-16
1069 JMP runtime·goPanicSliceAcap<ABIInternal>(SB)
1070 TEXT runtime·panicSliceAcapU<ABIInternal>(SB),NOSPLIT,$0-16
1073 JMP runtime·goPanicSliceAcapU<ABIInternal>(SB)
1074 TEXT runtime·panicSliceB<ABIInternal>(SB),NOSPLIT,$0-16
1075 JMP runtime·goPanicSliceB<ABIInternal>(SB)
1076 TEXT runtime·panicSliceBU<ABIInternal>(SB),NOSPLIT,$0-16
1077 JMP runtime·goPanicSliceBU<ABIInternal>(SB)
1078 TEXT runtime·panicSlice3Alen<ABIInternal>(SB),NOSPLIT,$0-16
1081 JMP runtime·goPanicSlice3Alen<ABIInternal>(SB)
1082 TEXT runtime·panicSlice3AlenU<ABIInternal>(SB),NOSPLIT,$0-16
1085 JMP runtime·goPanicSlice3AlenU<ABIInternal>(SB)
1086 TEXT runtime·panicSlice3Acap<ABIInternal>(SB),NOSPLIT,$0-16
1089 JMP runtime·goPanicSlice3Acap<ABIInternal>(SB)
1090 TEXT runtime·panicSlice3AcapU<ABIInternal>(SB),NOSPLIT,$0-16
1093 JMP runtime·goPanicSlice3AcapU<ABIInternal>(SB)
1094 TEXT runtime·panicSlice3B<ABIInternal>(SB),NOSPLIT,$0-16
1097 JMP runtime·goPanicSlice3B<ABIInternal>(SB)
1098 TEXT runtime·panicSlice3BU<ABIInternal>(SB),NOSPLIT,$0-16
1101 JMP runtime·goPanicSlice3BU<ABIInternal>(SB)
1102 TEXT runtime·panicSlice3C<ABIInternal>(SB),NOSPLIT,$0-16
1103 JMP runtime·goPanicSlice3C<ABIInternal>(SB)
1104 TEXT runtime·panicSlice3CU<ABIInternal>(SB),NOSPLIT,$0-16
1105 JMP runtime·goPanicSlice3CU<ABIInternal>(SB)
1106 TEXT runtime·panicSliceConvert<ABIInternal>(SB),NOSPLIT,$0-16
1109 JMP runtime·goPanicSliceConvert<ABIInternal>(SB)
1111 // These functions are used when internal linking cgo with external
1112 // objects compiled with the -Os on gcc. They reduce prologue/epilogue
1113 // size by deferring preservation of callee-save registers to a shared
1114 // function. These are defined in PPC64 ELFv2 2.3.3 (but also present
1117 // These appear unused, but the linker will redirect calls to functions
1118 // like _savegpr0_14 or _restgpr1_14 to runtime.elf_savegpr0 or
1119 // runtime.elf_restgpr1 with an appropriate offset based on the number
1120 // register operations required when linking external objects which
1121 // make these calls. For GPR/FPR saves, the minimum register value is
1122 // 14, for VR it is 20.
1124 // These are only used when linking such cgo code internally. Note, R12
1125 // and R0 may be used in different ways than regular ELF compliant
1127 TEXT runtime·elf_savegpr0(SB),NOSPLIT|NOFRAME,$0
1128 // R0 holds the LR of the caller's caller, R1 holds save location
1149 TEXT runtime·elf_restgpr0(SB),NOSPLIT|NOFRAME,$0
1150 // R1 holds save location. This returns to the LR saved on stack (bypassing the caller)
1169 MOVD 16(R1), R0 // Load and return to saved LR
1172 TEXT runtime·elf_savegpr1(SB),NOSPLIT|NOFRAME,$0
1173 // R12 holds the save location
1193 TEXT runtime·elf_restgpr1(SB),NOSPLIT|NOFRAME,$0
1194 // R12 holds the save location
1214 TEXT runtime·elf_savefpr(SB),NOSPLIT|NOFRAME,$0
1215 // R0 holds the LR of the caller's caller, R1 holds save location
1236 TEXT runtime·elf_restfpr(SB),NOSPLIT|NOFRAME,$0
1237 // R1 holds save location. This returns to the LR saved on stack (bypassing the caller)
1256 MOVD 16(R1), R0 // Load and return to saved LR
1259 TEXT runtime·elf_savevr(SB),NOSPLIT|NOFRAME,$0
1260 // R0 holds the save location, R12 is clobbered
1286 TEXT runtime·elf_restvr(SB),NOSPLIT|NOFRAME,$0
1287 // R0 holds the save location, R12 is clobbered