1// Copyright 2023 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.4//5// System calls and other sys.stuff for ppc64, OpenBSD6// System calls are implemented in libc/libpthread, this file7// contains trampolines that convert from Go to C calling convention.8// Some direct system call implementations currently remain.9//1011#include "go_asm.h"12#include "go_tls.h"13#include "textflag.h"1415#define CLOCK_REALTIME $016#define CLOCK_MONOTONIC $31718// mstart_stub is the first function executed on a new thread started by pthread_create.19// It just does some low-level setup and then calls mstart.20// Note: called with the C calling convention.21TEXT runtime·mstart_stub(SB),NOSPLIT,$3222 // R3 points to the m.23 // We are already on m's g0 stack.2425 // Go relies on R0 being $0.26 XOR R0, R02728 // TODO(jsing): Save callee-save registers (R14-R31, F14-F31, V20-V31).2930 MOVD m_g0(R3), g31 BL runtime·save_g(SB)3233 BL runtime·mstart(SB)3435 // TODO(jsing): Restore callee-save registers (R14-R31, F14-F31, V20-V31).3637 // Go is all done with this OS thread.38 // Tell pthread everything is ok (we never join with this thread, so39 // the value here doesn't really matter).40 MOVD $0, R34142 RET4344TEXT runtime·sigfwd(SB),NOSPLIT,$0-3245 MOVW sig+8(FP), R346 MOVD info+16(FP), R447 MOVD ctx+24(FP), R548 MOVD fn+0(FP), R1249 MOVD R12, CTR50 CALL (CTR) // Alignment for ELF ABI?51 RET5253TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$1654 // Go relies on R0 being $0 and we may have been executing non-Go code.55 XOR R0, R05657 // TODO(jsing): Save callee-save registers (R2, R14-R31, F14-F31).58 // in the case of signal forwarding.59 // Please refer to https://golang.org/issue/31827 .6061 // If called from an external code context, g will not be set.62 BL runtime·load_g(SB)6364 BL runtime·sigtrampgo<ABIInternal>(SB)6566 // TODO(jsing): Restore callee-save registers.6768 RET6970// These trampolines help convert from Go calling convention to C calling convention.71// They should be called with asmcgocall.72// A pointer to the arguments is passed in R3.73// A single int32 result is returned in R3.74// (For more results, make an args/results structure.)75TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$3276 MOVD 0(R3), R3 // arg 1 - attr77 CALL libc_pthread_attr_init(SB)78 RET7980TEXT runtime·pthread_attr_destroy_trampoline(SB),NOSPLIT,$3281 MOVD 0(R3), R3 // arg 1 - attr82 CALL libc_pthread_attr_destroy(SB)83 RET8485TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$3286 MOVD 8(R3), R4 // arg 2 - size87 MOVD 0(R3), R3 // arg 1 - attr88 CALL libc_pthread_attr_getstacksize(SB)89 RET9091TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$3292 MOVD 8(R3), R4 // arg 2 - state93 MOVD 0(R3), R3 // arg 1 - attr94 CALL libc_pthread_attr_setdetachstate(SB)95 RET9697TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$3298 MOVD 0(R3), R4 // arg 2 - attr99 MOVD 8(R3), R5 // arg 3 - start100 MOVD 16(R3), R6 // arg 4 - arg101102 MOVD R1, R15103 SUB $64, R1104 RLDCR $0, R1, $~15, R1105 MOVD R1, R3 // arg 1 - &threadid (discard)106 CALL libc_pthread_create(SB)107 MOVD R15, R1108109 RET110111TEXT runtime·thrkill_trampoline(SB),NOSPLIT,$32112 MOVD 8(R3), R4 // arg 2 - signal (int64)113 MOVD $0, R5 // arg 3 - tcb114 MOVW 0(R3), R3 // arg 1 - tid115 CALL libc_thrkill(SB)116 RET117118TEXT runtime·thrsleep_trampoline(SB),NOSPLIT,$32119 MOVW 8(R3), R4 // arg 2 - clock_id120 MOVD 16(R3), R5 // arg 3 - abstime121 MOVD 24(R3), R6 // arg 4 - lock122 MOVD 32(R3), R7 // arg 5 - abort123 MOVD 0(R3), R3 // arg 1 - id124 CALL libc_thrsleep(SB)125 RET126127TEXT runtime·thrwakeup_trampoline(SB),NOSPLIT,$32128 MOVW 8(R3), R4 // arg 2 - count129 MOVD 0(R3), R3 // arg 1 - id130 CALL libc_thrwakeup(SB)131 RET132133TEXT runtime·exit_trampoline(SB),NOSPLIT,$32134 MOVW 0(R3), R3 // arg 1 - status135 CALL libc_exit(SB)136 MOVD $0, R3 // crash on failure137 MOVD R3, (R3)138 RET139140TEXT runtime·getthrid_trampoline(SB),NOSPLIT,$32141 MOVD R3, R14 // pointer to args142 CALL libc_getthrid(SB)143 MOVW R3, 0(R14) // return value144 RET145146TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$32147 MOVD R3, R14 // pointer to args148 CALL libc_getpid(SB) // arg 1 - pid149 MOVW 0(R14), R4 // arg 2 - signal150 CALL libc_kill(SB)151 RET152153TEXT runtime·sched_yield_trampoline(SB),NOSPLIT,$32154 CALL libc_sched_yield(SB)155 RET156157TEXT runtime·mmap_trampoline(SB),NOSPLIT,$32158 MOVD R3, R14 // pointer to args159 MOVD 0(R14), R3 // arg 1 - addr160 MOVD 8(R14), R4 // arg 2 - len161 MOVW 16(R14), R5 // arg 3 - prot162 MOVW 20(R14), R6 // arg 4 - flags163 MOVW 24(R14), R7 // arg 5 - fid164 MOVW 28(R14), R8 // arg 6 - offset165 CALL libc_mmap(SB)166 MOVD $0, R4167 CMP R3, $-1168 BNE noerr169 CALL libc_errno(SB)170 MOVW (R3), R4 // errno171 MOVD $0, R3172noerr:173 MOVD R3, 32(R14)174 MOVD R4, 40(R14)175 RET176177TEXT runtime·munmap_trampoline(SB),NOSPLIT,$32178 MOVD 8(R3), R4 // arg 2 - len179 MOVD 0(R3), R3 // arg 1 - addr180 CALL libc_munmap(SB)181 CMP R3, $-1182 BNE 3(PC)183 MOVD $0, R3 // crash on failure184 MOVD R3, (R3)185 RET186187TEXT runtime·madvise_trampoline(SB),NOSPLIT,$32188 MOVD 8(R3), R4 // arg 2 - len189 MOVW 16(R3), R5 // arg 3 - advice190 MOVD 0(R3), R3 // arg 1 - addr191 CALL libc_madvise(SB)192 // ignore failure - maybe pages are locked193 RET194195TEXT runtime·open_trampoline(SB),NOSPLIT,$32196 MOVW 8(R3), R4 // arg 2 - flags197 MOVW 12(R3), R5 // arg 3 - mode198 MOVD 0(R3), R3 // arg 1 - path199 MOVD $0, R6 // varargs200 CALL libc_open(SB)201 RET202203TEXT runtime·close_trampoline(SB),NOSPLIT,$32204 MOVW 0(R3), R3 // arg 1 - fd205 CALL libc_close(SB)206 RET207208TEXT runtime·read_trampoline(SB),NOSPLIT,$32209 MOVD 8(R3), R4 // arg 2 - buf210 MOVW 16(R3), R5 // arg 3 - count211 MOVW 0(R3), R3 // arg 1 - fd (int32)212 CALL libc_read(SB)213 CMP R3, $-1214 BNE noerr215 CALL libc_errno(SB)216 MOVW (R3), R3 // errno217 NEG R3, R3 // caller expects negative errno value218noerr:219 RET220221TEXT runtime·write_trampoline(SB),NOSPLIT,$32222 MOVD 8(R3), R4 // arg 2 - buf223 MOVW 16(R3), R5 // arg 3 - count224 MOVD 0(R3), R3 // arg 1 - fd (uintptr)225 CALL libc_write(SB)226 CMP R3, $-1227 BNE noerr228 CALL libc_errno(SB)229 MOVW (R3), R3 // errno230 NEG R3, R3 // caller expects negative errno value231noerr:232 RET233234TEXT runtime·pipe2_trampoline(SB),NOSPLIT,$32235 MOVW 8(R3), R4 // arg 2 - flags236 MOVD 0(R3), R3 // arg 1 - filedes237 CALL libc_pipe2(SB)238 CMP R3, $-1239 BNE noerr240 CALL libc_errno(SB)241 MOVW (R3), R3 // errno242 NEG R3, R3 // caller expects negative errno value243noerr:244 RET245246TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$32247 MOVD 8(R3), R4 // arg 2 - new248 MOVD 16(R3), R5 // arg 3 - old249 MOVW 0(R3), R3 // arg 1 - which250 CALL libc_setitimer(SB)251 RET252253TEXT runtime·usleep_trampoline(SB),NOSPLIT,$32254 MOVW 0(R3), R3 // arg 1 - usec255 CALL libc_usleep(SB)256 RET257258TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$32259 MOVW 8(R3), R4 // arg 2 - miblen260 MOVD 16(R3), R5 // arg 3 - out261 MOVD 24(R3), R6 // arg 4 - size262 MOVD 32(R3), R7 // arg 5 - dst263 MOVD 40(R3), R8 // arg 6 - ndst264 MOVD 0(R3), R3 // arg 1 - mib265 CALL libc_sysctl(SB)266 RET267268TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$32269 CALL libc_kqueue(SB)270 RET271272TEXT runtime·kevent_trampoline(SB),NOSPLIT,$32273 MOVD 8(R3), R4 // arg 2 - keventt274 MOVW 16(R3), R5 // arg 3 - nch275 MOVD 24(R3), R6 // arg 4 - ev276 MOVW 32(R3), R7 // arg 5 - nev277 MOVD 40(R3), R8 // arg 6 - ts278 MOVW 0(R3), R3 // arg 1 - kq279 CALL libc_kevent(SB)280 CMP R3, $-1281 BNE noerr282 CALL libc_errno(SB)283 MOVW (R3), R3 // errno284 NEG R3, R3 // caller expects negative errno value285noerr:286 RET287288TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$32289 MOVD 8(R3), R4 // arg 2 - tp290 MOVW 0(R3), R3 // arg 1 - clock_id291 CALL libc_clock_gettime(SB)292 CMP R3, $-1293 BNE noerr294 CALL libc_errno(SB)295 MOVW (R3), R3 // errno296 NEG R3, R3 // caller expects negative errno value297noerr:298 RET299300TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$32301 MOVD R3, R14 // pointer to args302 MOVW 0(R14), R3 // arg 1 - fd303 MOVW 4(R14), R4 // arg 2 - cmd304 MOVW 8(R14), R5 // arg 3 - arg305 MOVD $0, R6 // vararg306 CALL libc_fcntl(SB)307 MOVD $0, R4308 CMP R3, $-1309 BNE noerr310 CALL libc_errno(SB)311 MOVW (R3), R4 // errno312 MOVW $-1, R3313noerr:314 MOVW R3, 12(R14)315 MOVW R4, 16(R14)316 RET317318TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$32319 MOVD 8(R3), R4 // arg 2 - new320 MOVD 16(R3), R5 // arg 3 - old321 MOVW 0(R3), R3 // arg 1 - sig322 CALL libc_sigaction(SB)323 CMP R3, $-1324 BNE 3(PC)325 MOVD $0, R3 // crash on syscall failure326 MOVD R3, (R3)327 RET328329TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$32330 MOVD 8(R3), R4 // arg 2 - new331 MOVD 16(R3), R5 // arg 3 - old332 MOVW 0(R3), R3 // arg 1 - how333 CALL libc_pthread_sigmask(SB)334 CMP R3, $-1335 BNE 3(PC)336 MOVD $0, R3 // crash on syscall failure337 MOVD R3, (R3)338 RET339340TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$32341 MOVD 8(R3), R4 // arg 2 - old342 MOVD 0(R3), R3 // arg 1 - new343 CALL libc_sigaltstack(SB)344 CMP R3, $-1345 BNE 3(PC)346 MOVD $0, R3 // crash on syscall failure347 MOVD R3, (R3)348 RET349350TEXT runtime·issetugid_trampoline(SB),NOSPLIT,$32351 MOVD R3, R14 // pointer to args352 CALL libc_getthrid(SB)353 MOVW R3, 0(R14) // return value354 RET355356// syscall calls a function in libc on behalf of the syscall package.357// syscall takes a pointer to a struct like:358// struct {359// fn uintptr360// a1 uintptr361// a2 uintptr362// a3 uintptr363// r1 uintptr364// r2 uintptr365// err uintptr366// }367// syscall must be called on the g0 stack with the368// C calling convention (use libcCall).369//370// syscall expects a 32-bit result and tests for 32-bit -1371// to decide there was an error.372TEXT runtime·syscall(SB),NOSPLIT,$32373 MOVD R3, R14 // pointer to args374375 MOVD (0*8)(R14), R12 // fn376 MOVD (1*8)(R14), R3 // a1377 MOVD (2*8)(R14), R4 // a2378 MOVD (3*8)(R14), R5 // a3379 MOVD $0, R6 // vararg380381 MOVD R12, CTR382 CALL (CTR)383384 MOVD R3, (4*8)(R14) // r1385 MOVD R4, (5*8)(R14) // r2386387 // Standard libc functions return -1 on error388 // and set errno.389 CMPW R3, $-1390 BNE ok391392 // Get error code from libc.393 CALL libc_errno(SB)394 MOVW (R3), R3395 MOVD R3, (6*8)(R14) // err396397ok:398 RET399400// syscallX calls a function in libc on behalf of the syscall package.401// syscallX takes a pointer to a struct like:402// struct {403// fn uintptr404// a1 uintptr405// a2 uintptr406// a3 uintptr407// r1 uintptr408// r2 uintptr409// err uintptr410// }411// syscallX must be called on the g0 stack with the412// C calling convention (use libcCall).413//414// syscallX is like syscall but expects a 64-bit result415// and tests for 64-bit -1 to decide there was an error.416TEXT runtime·syscallX(SB),NOSPLIT,$32417 MOVD R3, R14 // pointer to args418419 MOVD (0*8)(R14), R12 // fn420 MOVD (1*8)(R14), R3 // a1421 MOVD (2*8)(R14), R4 // a2422 MOVD (3*8)(R14), R5 // a3423 MOVD $0, R6 // vararg424425 MOVD R12, CTR426 CALL (CTR)427428 MOVD R3, (4*8)(R14) // r1429 MOVD R4, (5*8)(R14) // r2430431 // Standard libc functions return -1 on error432 // and set errno.433 CMP R3, $-1434 BNE ok435436 // Get error code from libc.437 CALL libc_errno(SB)438 MOVW (R3), R3439 MOVD R3, (6*8)(R14) // err440441ok:442 RET443444// syscall6 calls a function in libc on behalf of the syscall package.445// syscall6 takes a pointer to a struct like:446// struct {447// fn uintptr448// a1 uintptr449// a2 uintptr450// a3 uintptr451// a4 uintptr452// a5 uintptr453// a6 uintptr454// r1 uintptr455// r2 uintptr456// err uintptr457// }458// syscall6 must be called on the g0 stack with the459// C calling convention (use libcCall).460//461// syscall6 expects a 32-bit result and tests for 32-bit -1462// to decide there was an error.463TEXT runtime·syscall6(SB),NOSPLIT,$32464 MOVD R3, R14 // pointer to args465466 MOVD (0*8)(R14), R12 // fn467 MOVD (1*8)(R14), R3 // a1468 MOVD (2*8)(R14), R4 // a2469 MOVD (3*8)(R14), R5 // a3470 MOVD (4*8)(R14), R6 // a4471 MOVD (5*8)(R14), R7 // a5472 MOVD (6*8)(R14), R8 // a6473 MOVD $0, R9 // vararg474475 MOVD R12, CTR476 CALL (CTR)477478 MOVD R3, (7*8)(R14) // r1479 MOVD R4, (8*8)(R14) // r2480481 // Standard libc functions return -1 on error482 // and set errno.483 CMPW R3, $-1484 BNE ok485486 // Get error code from libc.487 CALL libc_errno(SB)488 MOVW (R3), R3489 MOVD R3, (9*8)(R14) // err490491ok:492 RET493494// syscall6X calls a function in libc on behalf of the syscall package.495// syscall6X takes a pointer to a struct like:496// struct {497// fn uintptr498// a1 uintptr499// a2 uintptr500// a3 uintptr501// a4 uintptr502// a5 uintptr503// a6 uintptr504// r1 uintptr505// r2 uintptr506// err uintptr507// }508// syscall6X must be called on the g0 stack with the509// C calling convention (use libcCall).510//511// syscall6X is like syscall6 but expects a 64-bit result512// and tests for 64-bit -1 to decide there was an error.513TEXT runtime·syscall6X(SB),NOSPLIT,$32514 MOVD R3, R14 // pointer to args515516 MOVD (0*8)(R14), R12 // fn517 MOVD (1*8)(R14), R3 // a1518 MOVD (2*8)(R14), R4 // a2519 MOVD (3*8)(R14), R5 // a3520 MOVD (4*8)(R14), R6 // a4521 MOVD (5*8)(R14), R7 // a5522 MOVD (6*8)(R14), R8 // a6523 MOVD $0, R9 // vararg524525 MOVD R12, CTR526 CALL (CTR)527528 MOVD R3, (7*8)(R14) // r1529 MOVD R4, (8*8)(R14) // r2530531 // Standard libc functions return -1 on error532 // and set errno.533 CMP R3, $-1534 BNE ok535536 // Get error code from libc.537 CALL libc_errno(SB)538 MOVW (R3), R3539 MOVD R3, (9*8)(R14) // err540541ok:542 RET543544// syscall10 calls a function in libc on behalf of the syscall package.545// syscall10 takes a pointer to a struct like:546// struct {547// fn uintptr548// a1 uintptr549// a2 uintptr550// a3 uintptr551// a4 uintptr552// a5 uintptr553// a6 uintptr554// a7 uintptr555// a8 uintptr556// a9 uintptr557// a10 uintptr558// r1 uintptr559// r2 uintptr560// err uintptr561// }562// syscall10 must be called on the g0 stack with the563// C calling convention (use libcCall). Note that this is564// really syscall8 as a maximum of eight parameters can be565// passed via registers (and current usage does not exceed566// this).567TEXT runtime·syscall10(SB),NOSPLIT,$32568 MOVD R3, R14 // pointer to args569570 MOVD (0*8)(R14), R12 // fn571 MOVD (1*8)(R14), R3 // a1572 MOVD (2*8)(R14), R4 // a2573 MOVD (3*8)(R14), R5 // a3574 MOVD (4*8)(R14), R6 // a4575 MOVD (5*8)(R14), R7 // a5576 MOVD (6*8)(R14), R8 // a6577 MOVD (7*8)(R14), R9 // a7578 MOVD (8*8)(R14), R10 // a8579580 MOVD R12, CTR581 CALL (CTR)582583 MOVD R3, (11*8)(R14) // r1584 MOVD R4, (12*8)(R14) // r2585586 // Standard libc functions return -1 on error587 // and set errno.588 CMPW R3, $-1589 BNE ok590591 // Get error code from libc.592 CALL libc_errno(SB)593 MOVW (R3), R3594 MOVD R3, (13*8)(R14) // err595596ok:597 RET598599// syscall10X calls a function in libc on behalf of the syscall package.600// syscall10X takes a pointer to a struct like:601// struct {602// fn uintptr603// a1 uintptr604// a2 uintptr605// a3 uintptr606// a4 uintptr607// a5 uintptr608// a6 uintptr609// a7 uintptr610// a8 uintptr611// a9 uintptr612// a10 uintptr613// r1 uintptr614// r2 uintptr615// err uintptr616// }617// syscall10X must be called on the g0 stack with the618// C calling convention (use libcCall). Note that this is619// really syscall8X as a maximum of eight parameters can be620// passed via registers (and current usage does not exceed621// this).622//623// syscall10X is like syscall10 but expects a 64-bit result624// and tests for 64-bit -1 to decide there was an error.625TEXT runtime·syscall10X(SB),NOSPLIT,$32626 MOVD R3, R14 // pointer to args627628 MOVD (0*8)(R14), R12 // fn629 MOVD (1*8)(R14), R3 // a1630 MOVD (2*8)(R14), R4 // a2631 MOVD (3*8)(R14), R5 // a3632 MOVD (4*8)(R14), R6 // a4633 MOVD (5*8)(R14), R7 // a5634 MOVD (6*8)(R14), R8 // a6635 MOVD (7*8)(R14), R9 // a7636 MOVD (8*8)(R14), R10 // a8637638 MOVD R12, CTR639 CALL (CTR)640641 MOVD R3, (11*8)(R14) // r1642 MOVD R4, (12*8)(R14) // r2643644 // Standard libc functions return -1 on error645 // and set errno.646 CMP R3, $-1647 BNE ok648649 // Get error code from libc.650 CALL libc_errno(SB)651 MOVW (R3), R3652 MOVD R3, (13*8)(R14) // err653654ok:655 RET
Findings
✓ No findings reported for this file.