1// Copyright 2018 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.45//6// System calls and other sys.stuff for ppc64, Aix7//89#include "go_asm.h"10#include "go_tls.h"11#include "textflag.h"12#include "asm_ppc64x.h"1314// This function calls a C function with the function descriptor in R1215TEXT callCfunction<>(SB), NOSPLIT|NOFRAME,$016 MOVD 0(R12), R1217 MOVD R2, 40(R1)18 MOVD 0(R12), R019 MOVD 8(R12), R220 MOVD R0, CTR21 BR (CTR)222324// asmsyscall6 calls a library function with a function descriptor25// stored in libcall_fn and store the results in libcall structure26// Up to 6 arguments can be passed to this C function27// Called by runtime.asmcgocall28// It reserves a stack of 288 bytes for the C function. It must29// follow AIX convention, thus the first local variable must30// be stored at the offset 112, after the linker area (48 bytes)31// and the argument area (64).32// The AIX convention is described here:33// https://www.ibm.com/docs/en/aix/7.2?topic=overview-runtime-process-stack34// NOT USING GO CALLING CONVENTION35// runtime.asmsyscall6 is a function descriptor to the real asmsyscall6.36DATA runtime·asmsyscall6+0(SB)/8, $asmsyscall6<>(SB)37DATA runtime·asmsyscall6+8(SB)/8, $TOC(SB)38DATA runtime·asmsyscall6+16(SB)/8, $039GLOBL runtime·asmsyscall6(SB), NOPTR, $244041TEXT asmsyscall6<>(SB),NOSPLIT,$25642 // Save libcall for later43 MOVD R3, 112(R1)44 MOVD libcall_fn(R3), R1245 MOVD libcall_args(R3), R946 MOVD 0(R9), R347 MOVD 8(R9), R448 MOVD 16(R9), R549 MOVD 24(R9), R650 MOVD 32(R9), R751 MOVD 40(R9), R852 BL callCfunction<>(SB)5354 // Restore R0 and TOC55 XOR R0, R056 MOVD 40(R1), R25758 // Store result in libcall59 MOVD 112(R1), R560 MOVD R3, (libcall_r1)(R5)61 MOVD $-1, R662 CMP R6, R363 BNE skiperrno6465 // Save errno in libcall66 BL runtime·load_g(SB)67 MOVD g_m(g), R468 MOVD (m_mOS + mOS_perrno)(R4), R969 MOVW 0(R9), R970 MOVD R9, (libcall_err)(R5)71 RET72skiperrno:73 // Reset errno if no error has been returned74 MOVD R0, (libcall_err)(R5)75 RET767778TEXT runtime·sigfwd(SB),NOSPLIT,$0-3279 MOVW sig+8(FP), R380 MOVD info+16(FP), R481 MOVD ctx+24(FP), R582 MOVD fn+0(FP), R1283 // fn is a function descriptor84 // R2 must be saved on restore85 MOVD 0(R12), R086 MOVD R2, 40(R1)87 MOVD 8(R12), R288 MOVD R0, CTR89 BL (CTR)90 MOVD 40(R1), R291 BL runtime·reginit(SB)92 RET939495// runtime.sigtramp is a function descriptor to the real sigtramp.96DATA runtime·sigtramp+0(SB)/8, $sigtramp<>(SB)97DATA runtime·sigtramp+8(SB)/8, $TOC(SB)98DATA runtime·sigtramp+16(SB)/8, $099GLOBL runtime·sigtramp(SB), NOPTR, $24100101// This function must not have any frame as we want to control how102// every registers are used.103// TODO(aix): Implement SetCgoTraceback handler.104TEXT sigtramp<>(SB),NOSPLIT|NOFRAME|TOPFRAME,$0105 MOVD LR, R0106 MOVD R0, 16(R1)107 // initialize essential registers (just in case)108 BL runtime·reginit(SB)109110 // Note that we are executing on altsigstack here, so we have111 // more stack available than NOSPLIT would have us believe.112 // To defeat the linker, we make our own stack frame with113 // more space.114 SUB $144+FIXED_FRAME, R1115116 // Save registers117 MOVD R31, 56(R1)118 MOVD g, 64(R1)119 MOVD R29, 72(R1)120 MOVD R14, 80(R1)121 MOVD R15, 88(R1)122123 BL runtime·load_g(SB)124125 CMP $0, g126 BEQ sigtramp // g == nil127 MOVD g_m(g), R6128 CMP $0, R6129 BEQ sigtramp // g.m == nil130131 // Save m->libcall. We need to do this because we132 // might get interrupted by a signal in runtime·asmcgocall.133 MOVD (m_mOS+mOS_libcall+libcall_fn)(R6), R7134 MOVD R7, 96(R1)135 MOVD (m_mOS+mOS_libcall+libcall_args)(R6), R7136 MOVD R7, 104(R1)137 MOVD (m_mOS+mOS_libcall+libcall_n)(R6), R7138 MOVD R7, 112(R1)139 MOVD (m_mOS+mOS_libcall+libcall_r1)(R6), R7140 MOVD R7, 120(R1)141 MOVD (m_mOS+mOS_libcall+libcall_r2)(R6), R7142 MOVD R7, 128(R1)143144 // save errno, it might be EINTR; stuff we do here might reset it.145 MOVD (m_mOS+mOS_perrno)(R6), R8146 MOVD 0(R8), R8147 MOVD R8, 136(R1)148149sigtramp:150 MOVW R3, FIXED_FRAME+0(R1)151 MOVD R4, FIXED_FRAME+8(R1)152 MOVD R5, FIXED_FRAME+16(R1)153 MOVD $runtime·sigtrampgo(SB), R12154 MOVD R12, CTR155 BL (CTR)156157 CMP $0, g158 BEQ exit // g == nil159 MOVD g_m(g), R6160 CMP $0, R6161 BEQ exit // g.m == nil162163 // restore libcall164 MOVD 96(R1), R7165 MOVD R7, (m_mOS+mOS_libcall+libcall_fn)(R6)166 MOVD 104(R1), R7167 MOVD R7, (m_mOS+mOS_libcall+libcall_args)(R6)168 MOVD 112(R1), R7169 MOVD R7, (m_mOS+mOS_libcall+libcall_n)(R6)170 MOVD 120(R1), R7171 MOVD R7, (m_mOS+mOS_libcall+libcall_r1)(R6)172 MOVD 128(R1), R7173 MOVD R7, (m_mOS+mOS_libcall+libcall_r2)(R6)174175 // restore errno176 MOVD (m_mOS+mOS_perrno)(R6), R7177 MOVD 136(R1), R8178 MOVD R8, 0(R7)179180exit:181 // restore registers182 MOVD 56(R1),R31183 MOVD 64(R1),g184 MOVD 72(R1),R29185 MOVD 80(R1), R14186 MOVD 88(R1), R15187188 // Don't use RET because we need to restore R31 !189 ADD $144+FIXED_FRAME, R1190 MOVD 16(R1), R0191 MOVD R0, LR192 BR (LR)193194// runtime.tstart is a function descriptor to the real tstart.195DATA runtime·tstart+0(SB)/8, $tstart<>(SB)196DATA runtime·tstart+8(SB)/8, $TOC(SB)197DATA runtime·tstart+16(SB)/8, $0198GLOBL runtime·tstart(SB), NOPTR, $24199200// runtime.rt0LibGoDesc is a function descriptor to rt0_lib_go,201// used by libInit to create a new thread on AIX where202// pthread_create expects a function descriptor, not a raw203// code address.204DATA runtime·rt0LibGoDesc+0(SB)/8, $runtime·rt0_lib_go(SB)205DATA runtime·rt0LibGoDesc+8(SB)/8, $TOC(SB)206DATA runtime·rt0LibGoDesc+16(SB)/8, $0207GLOBL runtime·rt0LibGoDesc(SB), NOPTR, $24208209TEXT tstart<>(SB),NOSPLIT,$0210 XOR R0, R0 // reset R0211212 // set g213 MOVD m_g0(R3), g214 BL runtime·save_g(SB)215 MOVD R3, g_m(g)216217 // Layout new m scheduler stack on os stack.218 MOVD R1, R3219 MOVD R3, (g_stack+stack_hi)(g)220 SUB $(const_threadStackSize), R3 // stack size221 MOVD R3, (g_stack+stack_lo)(g)222 ADD $const_stackGuard, R3223 MOVD R3, g_stackguard0(g)224 MOVD R3, g_stackguard1(g)225226 BL runtime·mstart(SB)227228 MOVD R0, R3229 RET230231232#define CSYSCALL() \233 MOVD 0(R12), R12 \234 MOVD R2, 40(R1) \235 MOVD 0(R12), R0 \236 MOVD 8(R12), R2 \237 MOVD R0, CTR \238 BL (CTR) \239 MOVD 40(R1), R2 \240 BL runtime·reginit(SB)241242243// Runs on OS stack, called from runtime·osyield.244TEXT runtime·osyield1(SB),NOSPLIT,$0245 MOVD $libc_sched_yield(SB), R12246 CSYSCALL()247 RET248249250// Runs on OS stack, called from runtime·sigprocmask.251TEXT runtime·sigprocmask1(SB),NOSPLIT,$0-24252 MOVD how+0(FP), R3253 MOVD new+8(FP), R4254 MOVD old+16(FP), R5255 MOVD $libpthread_sigthreadmask(SB), R12256 CSYSCALL()257 RET258259// Runs on OS stack, called from runtime·usleep.260TEXT runtime·usleep1(SB),NOSPLIT,$0-4261 MOVW us+0(FP), R3262 MOVD $libc_usleep(SB), R12263 CSYSCALL()264 RET265266// Runs on OS stack, called from runtime·exit.267TEXT runtime·exit1(SB),NOSPLIT,$0-4268 MOVW code+0(FP), R3269 MOVD $libc_exit(SB), R12270 CSYSCALL()271 RET272273// Runs on OS stack, called from runtime·write1.274TEXT runtime·write2(SB),NOSPLIT,$0-28275 MOVD fd+0(FP), R3276 MOVD p+8(FP), R4277 MOVW n+16(FP), R5278 MOVD $libc_write(SB), R12279 CSYSCALL()280 MOVW R3, ret+24(FP)281 RET282283// Runs on OS stack, called from runtime·pthread_attr_init.284TEXT runtime·pthread_attr_init1(SB),NOSPLIT,$0-12285 MOVD attr+0(FP), R3286 MOVD $libpthread_attr_init(SB), R12287 CSYSCALL()288 MOVW R3, ret+8(FP)289 RET290291// Runs on OS stack, called from runtime·pthread_attr_setstacksize.292TEXT runtime·pthread_attr_setstacksize1(SB),NOSPLIT,$0-20293 MOVD attr+0(FP), R3294 MOVD size+8(FP), R4295 MOVD $libpthread_attr_setstacksize(SB), R12296 CSYSCALL()297 MOVW R3, ret+16(FP)298 RET299300// Runs on OS stack, called from runtime·pthread_setdetachstate.301TEXT runtime·pthread_attr_setdetachstate1(SB),NOSPLIT,$0-20302 MOVD attr+0(FP), R3303 MOVW state+8(FP), R4304 MOVD $libpthread_attr_setdetachstate(SB), R12305 CSYSCALL()306 MOVW R3, ret+16(FP)307 RET308309// Runs on OS stack, called from runtime·pthread_create.310TEXT runtime·pthread_create1(SB),NOSPLIT,$0-36311 MOVD tid+0(FP), R3312 MOVD attr+8(FP), R4313 MOVD fn+16(FP), R5314 MOVD arg+24(FP), R6315 MOVD $libpthread_create(SB), R12316 CSYSCALL()317 MOVW R3, ret+32(FP)318 RET319320// Runs on OS stack, called from runtime·sigaction.321TEXT runtime·sigaction1(SB),NOSPLIT,$0-24322 MOVD sig+0(FP), R3323 MOVD new+8(FP), R4324 MOVD old+16(FP), R5325 MOVD $libc_sigaction(SB), R12326 CSYSCALL()327 RET
Findings
✓ No findings reported for this file.