github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/runtime/sys_darwin_amd64.s (about) 1 // Copyright 2009 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. 4 5 // System calls and other sys.stuff for AMD64, Darwin 6 // System calls are implemented in libSystem, this file contains 7 // trampolines that convert from Go to C calling convention. 8 9 #include "go_asm.h" 10 #include "go_tls.h" 11 #include "textflag.h" 12 #include "cgo/abi_amd64.h" 13 14 #define CLOCK_REALTIME 0 15 16 // Exit the entire program (like C exit) 17 TEXT runtime·exit_trampoline(SB),NOSPLIT,$0 18 MOVL 0(DI), DI // arg 1 exit status 19 CALL libc_exit(SB) 20 MOVL $0xf1, 0xf1 // crash 21 RET 22 23 TEXT runtime·open_trampoline(SB),NOSPLIT,$0 24 MOVL 8(DI), SI // arg 2 flags 25 MOVL 12(DI), DX // arg 3 mode 26 MOVQ 0(DI), DI // arg 1 pathname 27 XORL AX, AX // vararg: say "no float args" 28 CALL libc_open(SB) 29 RET 30 31 TEXT runtime·close_trampoline(SB),NOSPLIT,$0 32 MOVL 0(DI), DI // arg 1 fd 33 CALL libc_close(SB) 34 RET 35 36 TEXT runtime·read_trampoline(SB),NOSPLIT,$0 37 MOVQ 8(DI), SI // arg 2 buf 38 MOVL 16(DI), DX // arg 3 count 39 MOVL 0(DI), DI // arg 1 fd 40 CALL libc_read(SB) 41 TESTL AX, AX 42 JGE noerr 43 CALL libc_error(SB) 44 MOVL (AX), AX 45 NEGL AX // caller expects negative errno value 46 noerr: 47 RET 48 49 TEXT runtime·write_trampoline(SB),NOSPLIT,$0 50 MOVQ 8(DI), SI // arg 2 buf 51 MOVL 16(DI), DX // arg 3 count 52 MOVQ 0(DI), DI // arg 1 fd 53 CALL libc_write(SB) 54 TESTL AX, AX 55 JGE noerr 56 CALL libc_error(SB) 57 MOVL (AX), AX 58 NEGL AX // caller expects negative errno value 59 noerr: 60 RET 61 62 TEXT runtime·pipe_trampoline(SB),NOSPLIT,$0 63 CALL libc_pipe(SB) // pointer already in DI 64 TESTL AX, AX 65 JEQ 3(PC) 66 CALL libc_error(SB) // return negative errno value 67 NEGL AX 68 RET 69 70 TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0 71 MOVQ 8(DI), SI // arg 2 new 72 MOVQ 16(DI), DX // arg 3 old 73 MOVL 0(DI), DI // arg 1 which 74 CALL libc_setitimer(SB) 75 RET 76 77 TEXT runtime·madvise_trampoline(SB), NOSPLIT, $0 78 MOVQ 8(DI), SI // arg 2 len 79 MOVL 16(DI), DX // arg 3 advice 80 MOVQ 0(DI), DI // arg 1 addr 81 CALL libc_madvise(SB) 82 // ignore failure - maybe pages are locked 83 RET 84 85 TEXT runtime·mlock_trampoline(SB), NOSPLIT, $0 86 UNDEF // unimplemented 87 88 GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size) 89 90 TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$0 91 MOVQ DI, BX 92 CALL libc_mach_absolute_time(SB) 93 MOVQ AX, 0(BX) 94 MOVL timebase<>+machTimebaseInfo_numer(SB), SI 95 MOVL timebase<>+machTimebaseInfo_denom(SB), DI // atomic read 96 TESTL DI, DI 97 JNE initialized 98 99 SUBQ $(machTimebaseInfo__size+15)/16*16, SP 100 MOVQ SP, DI 101 CALL libc_mach_timebase_info(SB) 102 MOVL machTimebaseInfo_numer(SP), SI 103 MOVL machTimebaseInfo_denom(SP), DI 104 ADDQ $(machTimebaseInfo__size+15)/16*16, SP 105 106 MOVL SI, timebase<>+machTimebaseInfo_numer(SB) 107 MOVL DI, AX 108 XCHGL AX, timebase<>+machTimebaseInfo_denom(SB) // atomic write 109 110 initialized: 111 MOVL SI, 8(BX) 112 MOVL DI, 12(BX) 113 RET 114 115 TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0 116 MOVQ DI, SI // arg 2 timespec 117 MOVL $CLOCK_REALTIME, DI // arg 1 clock_id 118 CALL libc_clock_gettime(SB) 119 RET 120 121 TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0 122 MOVQ 8(DI), SI // arg 2 new 123 MOVQ 16(DI), DX // arg 3 old 124 MOVL 0(DI), DI // arg 1 sig 125 CALL libc_sigaction(SB) 126 TESTL AX, AX 127 JEQ 2(PC) 128 MOVL $0xf1, 0xf1 // crash 129 RET 130 131 TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0 132 MOVQ 8(DI), SI // arg 2 new 133 MOVQ 16(DI), DX // arg 3 old 134 MOVL 0(DI), DI // arg 1 how 135 CALL libc_pthread_sigmask(SB) 136 TESTL AX, AX 137 JEQ 2(PC) 138 MOVL $0xf1, 0xf1 // crash 139 RET 140 141 TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0 142 MOVQ 8(DI), SI // arg 2 old 143 MOVQ 0(DI), DI // arg 1 new 144 CALL libc_sigaltstack(SB) 145 TESTQ AX, AX 146 JEQ 2(PC) 147 MOVL $0xf1, 0xf1 // crash 148 RET 149 150 TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$0 151 MOVL 0(DI), BX // signal 152 CALL libc_getpid(SB) 153 MOVL AX, DI // arg 1 pid 154 MOVL BX, SI // arg 2 signal 155 CALL libc_kill(SB) 156 RET 157 158 TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 159 MOVQ fn+0(FP), AX 160 MOVL sig+8(FP), DI 161 MOVQ info+16(FP), SI 162 MOVQ ctx+24(FP), DX 163 MOVQ SP, BX // callee-saved 164 ANDQ $~15, SP // alignment for x86_64 ABI 165 CALL AX 166 MOVQ BX, SP 167 RET 168 169 // This is the function registered during sigaction and is invoked when 170 // a signal is received. It just redirects to the Go function sigtrampgo. 171 // Called using C ABI. 172 TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0 173 // Transition from C ABI to Go ABI. 174 PUSH_REGS_HOST_TO_ABI0() 175 176 // Set up ABIInternal environment: g in R14, cleared X15. 177 get_tls(R12) 178 MOVQ g(R12), R14 179 PXOR X15, X15 180 181 // Reserve space for spill slots. 182 NOP SP // disable vet stack checking 183 ADJSP $24 184 185 // Call into the Go signal handler 186 MOVQ DI, AX // sig 187 MOVQ SI, BX // info 188 MOVQ DX, CX // ctx 189 CALL ·sigtrampgo<ABIInternal>(SB) 190 191 ADJSP $-24 192 193 POP_REGS_HOST_TO_ABI0() 194 RET 195 196 // Called using C ABI. 197 TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT|NOFRAME,$0 198 // Transition from C ABI to Go ABI. 199 PUSH_REGS_HOST_TO_ABI0() 200 201 // Call into the Go signal handler 202 NOP SP // disable vet stack checking 203 ADJSP $24 204 MOVL DI, 0(SP) // sig 205 MOVQ SI, 8(SP) // info 206 MOVQ DX, 16(SP) // ctx 207 CALL ·sigprofNonGo(SB) 208 ADJSP $-24 209 210 POP_REGS_HOST_TO_ABI0() 211 RET 212 213 // Used instead of sigtramp in programs that use cgo. 214 // Arguments from kernel are in DI, SI, DX. 215 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0 216 // If no traceback function, do usual sigtramp. 217 MOVQ runtime·cgoTraceback(SB), AX 218 TESTQ AX, AX 219 JZ sigtramp 220 221 // If no traceback support function, which means that 222 // runtime/cgo was not linked in, do usual sigtramp. 223 MOVQ _cgo_callers(SB), AX 224 TESTQ AX, AX 225 JZ sigtramp 226 227 // Figure out if we are currently in a cgo call. 228 // If not, just do usual sigtramp. 229 get_tls(CX) 230 MOVQ g(CX),AX 231 TESTQ AX, AX 232 JZ sigtrampnog // g == nil 233 MOVQ g_m(AX), AX 234 TESTQ AX, AX 235 JZ sigtramp // g.m == nil 236 MOVL m_ncgo(AX), CX 237 TESTL CX, CX 238 JZ sigtramp // g.m.ncgo == 0 239 MOVQ m_curg(AX), CX 240 TESTQ CX, CX 241 JZ sigtramp // g.m.curg == nil 242 MOVQ g_syscallsp(CX), CX 243 TESTQ CX, CX 244 JZ sigtramp // g.m.curg.syscallsp == 0 245 MOVQ m_cgoCallers(AX), R8 246 TESTQ R8, R8 247 JZ sigtramp // g.m.cgoCallers == nil 248 MOVL m_cgoCallersUse(AX), CX 249 TESTL CX, CX 250 JNZ sigtramp // g.m.cgoCallersUse != 0 251 252 // Jump to a function in runtime/cgo. 253 // That function, written in C, will call the user's traceback 254 // function with proper unwind info, and will then call back here. 255 // The first three arguments, and the fifth, are already in registers. 256 // Set the two remaining arguments now. 257 MOVQ runtime·cgoTraceback(SB), CX 258 MOVQ $runtime·sigtramp(SB), R9 259 MOVQ _cgo_callers(SB), AX 260 JMP AX 261 262 sigtramp: 263 JMP runtime·sigtramp(SB) 264 265 sigtrampnog: 266 // Signal arrived on a non-Go thread. If this is SIGPROF, get a 267 // stack trace. 268 CMPL DI, $27 // 27 == SIGPROF 269 JNZ sigtramp 270 271 // Lock sigprofCallersUse. 272 MOVL $0, AX 273 MOVL $1, CX 274 MOVQ $runtime·sigprofCallersUse(SB), R11 275 LOCK 276 CMPXCHGL CX, 0(R11) 277 JNZ sigtramp // Skip stack trace if already locked. 278 279 // Jump to the traceback function in runtime/cgo. 280 // It will call back to sigprofNonGo, via sigprofNonGoWrapper, to convert 281 // the arguments to the Go calling convention. 282 // First three arguments to traceback function are in registers already. 283 MOVQ runtime·cgoTraceback(SB), CX 284 MOVQ $runtime·sigprofCallers(SB), R8 285 MOVQ $runtime·sigprofNonGoWrapper<>(SB), R9 286 MOVQ _cgo_callers(SB), AX 287 JMP AX 288 289 TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0 290 MOVQ DI, BX 291 MOVQ 0(BX), DI // arg 1 addr 292 MOVQ 8(BX), SI // arg 2 len 293 MOVL 16(BX), DX // arg 3 prot 294 MOVL 20(BX), CX // arg 4 flags 295 MOVL 24(BX), R8 // arg 5 fid 296 MOVL 28(BX), R9 // arg 6 offset 297 CALL libc_mmap(SB) 298 XORL DX, DX 299 CMPQ AX, $-1 300 JNE ok 301 CALL libc_error(SB) 302 MOVLQSX (AX), DX // errno 303 XORL AX, AX 304 ok: 305 MOVQ AX, 32(BX) 306 MOVQ DX, 40(BX) 307 RET 308 309 TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0 310 MOVQ 8(DI), SI // arg 2 len 311 MOVQ 0(DI), DI // arg 1 addr 312 CALL libc_munmap(SB) 313 TESTQ AX, AX 314 JEQ 2(PC) 315 MOVL $0xf1, 0xf1 // crash 316 RET 317 318 TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0 319 MOVL 0(DI), DI // arg 1 usec 320 CALL libc_usleep(SB) 321 RET 322 323 TEXT runtime·settls(SB),NOSPLIT,$32 324 // Nothing to do on Darwin, pthread already set thread-local storage up. 325 RET 326 327 TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0 328 MOVL 8(DI), SI // arg 2 miblen 329 MOVQ 16(DI), DX // arg 3 oldp 330 MOVQ 24(DI), CX // arg 4 oldlenp 331 MOVQ 32(DI), R8 // arg 5 newp 332 MOVQ 40(DI), R9 // arg 6 newlen 333 MOVQ 0(DI), DI // arg 1 mib 334 CALL libc_sysctl(SB) 335 RET 336 337 TEXT runtime·sysctlbyname_trampoline(SB),NOSPLIT,$0 338 MOVQ 8(DI), SI // arg 2 oldp 339 MOVQ 16(DI), DX // arg 3 oldlenp 340 MOVQ 24(DI), CX // arg 4 newp 341 MOVQ 32(DI), R8 // arg 5 newlen 342 MOVQ 0(DI), DI // arg 1 name 343 CALL libc_sysctlbyname(SB) 344 RET 345 346 TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0 347 CALL libc_kqueue(SB) 348 RET 349 350 TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0 351 MOVQ 8(DI), SI // arg 2 keventt 352 MOVL 16(DI), DX // arg 3 nch 353 MOVQ 24(DI), CX // arg 4 ev 354 MOVL 32(DI), R8 // arg 5 nev 355 MOVQ 40(DI), R9 // arg 6 ts 356 MOVL 0(DI), DI // arg 1 kq 357 CALL libc_kevent(SB) 358 CMPL AX, $-1 359 JNE ok 360 CALL libc_error(SB) 361 MOVLQSX (AX), AX // errno 362 NEGQ AX // caller wants it as a negative error code 363 ok: 364 RET 365 366 TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0 367 MOVL 4(DI), SI // arg 2 cmd 368 MOVL 8(DI), DX // arg 3 arg 369 MOVL 0(DI), DI // arg 1 fd 370 XORL AX, AX // vararg: say "no float args" 371 CALL libc_fcntl(SB) 372 RET 373 374 // mstart_stub is the first function executed on a new thread started by pthread_create. 375 // It just does some low-level setup and then calls mstart. 376 // Note: called with the C calling convention. 377 TEXT runtime·mstart_stub(SB),NOSPLIT|NOFRAME,$0 378 // DI points to the m. 379 // We are already on m's g0 stack. 380 381 // Transition from C ABI to Go ABI. 382 PUSH_REGS_HOST_TO_ABI0() 383 384 MOVQ m_g0(DI), DX // g 385 386 // Initialize TLS entry. 387 // See cmd/link/internal/ld/sym.go:computeTLSOffset. 388 MOVQ DX, 0x30(GS) 389 390 CALL runtime·mstart(SB) 391 392 POP_REGS_HOST_TO_ABI0() 393 394 // Go is all done with this OS thread. 395 // Tell pthread everything is ok (we never join with this thread, so 396 // the value here doesn't really matter). 397 XORL AX, AX 398 RET 399 400 // These trampolines help convert from Go calling convention to C calling convention. 401 // They should be called with asmcgocall. 402 // A pointer to the arguments is passed in DI. 403 // A single int32 result is returned in AX. 404 // (For more results, make an args/results structure.) 405 TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0 406 MOVQ 0(DI), DI // arg 1 attr 407 CALL libc_pthread_attr_init(SB) 408 RET 409 410 TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0 411 MOVQ 8(DI), SI // arg 2 size 412 MOVQ 0(DI), DI // arg 1 attr 413 CALL libc_pthread_attr_getstacksize(SB) 414 RET 415 416 TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0 417 MOVQ 8(DI), SI // arg 2 state 418 MOVQ 0(DI), DI // arg 1 attr 419 CALL libc_pthread_attr_setdetachstate(SB) 420 RET 421 422 TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$16 423 MOVQ 0(DI), SI // arg 2 attr 424 MOVQ 8(DI), DX // arg 3 start 425 MOVQ 16(DI), CX // arg 4 arg 426 MOVQ SP, DI // arg 1 &threadid (which we throw away) 427 CALL libc_pthread_create(SB) 428 RET 429 430 TEXT runtime·raise_trampoline(SB),NOSPLIT,$0 431 MOVL 0(DI), DI // arg 1 signal 432 CALL libc_raise(SB) 433 RET 434 435 TEXT runtime·pthread_mutex_init_trampoline(SB),NOSPLIT,$0 436 MOVQ 8(DI), SI // arg 2 attr 437 MOVQ 0(DI), DI // arg 1 mutex 438 CALL libc_pthread_mutex_init(SB) 439 RET 440 441 TEXT runtime·pthread_mutex_lock_trampoline(SB),NOSPLIT,$0 442 MOVQ 0(DI), DI // arg 1 mutex 443 CALL libc_pthread_mutex_lock(SB) 444 RET 445 446 TEXT runtime·pthread_mutex_unlock_trampoline(SB),NOSPLIT,$0 447 MOVQ 0(DI), DI // arg 1 mutex 448 CALL libc_pthread_mutex_unlock(SB) 449 RET 450 451 TEXT runtime·pthread_cond_init_trampoline(SB),NOSPLIT,$0 452 MOVQ 8(DI), SI // arg 2 attr 453 MOVQ 0(DI), DI // arg 1 cond 454 CALL libc_pthread_cond_init(SB) 455 RET 456 457 TEXT runtime·pthread_cond_wait_trampoline(SB),NOSPLIT,$0 458 MOVQ 8(DI), SI // arg 2 mutex 459 MOVQ 0(DI), DI // arg 1 cond 460 CALL libc_pthread_cond_wait(SB) 461 RET 462 463 TEXT runtime·pthread_cond_timedwait_relative_np_trampoline(SB),NOSPLIT,$0 464 MOVQ 8(DI), SI // arg 2 mutex 465 MOVQ 16(DI), DX // arg 3 timeout 466 MOVQ 0(DI), DI // arg 1 cond 467 CALL libc_pthread_cond_timedwait_relative_np(SB) 468 RET 469 470 TEXT runtime·pthread_cond_signal_trampoline(SB),NOSPLIT,$0 471 MOVQ 0(DI), DI // arg 1 cond 472 CALL libc_pthread_cond_signal(SB) 473 RET 474 475 TEXT runtime·pthread_self_trampoline(SB),NOSPLIT,$0 476 MOVQ DI, BX // BX is caller-save 477 CALL libc_pthread_self(SB) 478 MOVQ AX, 0(BX) // return value 479 RET 480 481 TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0 482 MOVQ 8(DI), SI // arg 2 sig 483 MOVQ 0(DI), DI // arg 1 thread 484 CALL libc_pthread_kill(SB) 485 RET 486 487 TEXT runtime·osinit_hack_trampoline(SB),NOSPLIT,$0 488 MOVQ $0, DI // arg 1 val 489 CALL libc_notify_is_valid_token(SB) 490 CALL libc_xpc_date_create_from_current(SB) 491 RET 492 493 // syscall calls a function in libc on behalf of the syscall package. 494 // syscall takes a pointer to a struct like: 495 // struct { 496 // fn uintptr 497 // a1 uintptr 498 // a2 uintptr 499 // a3 uintptr 500 // r1 uintptr 501 // r2 uintptr 502 // err uintptr 503 // } 504 // syscall must be called on the g0 stack with the 505 // C calling convention (use libcCall). 506 // 507 // syscall expects a 32-bit result and tests for 32-bit -1 508 // to decide there was an error. 509 TEXT runtime·syscall(SB),NOSPLIT,$16 510 MOVQ (0*8)(DI), CX // fn 511 MOVQ (2*8)(DI), SI // a2 512 MOVQ (3*8)(DI), DX // a3 513 MOVQ DI, (SP) 514 MOVQ (1*8)(DI), DI // a1 515 XORL AX, AX // vararg: say "no float args" 516 517 CALL CX 518 519 MOVQ (SP), DI 520 MOVQ AX, (4*8)(DI) // r1 521 MOVQ DX, (5*8)(DI) // r2 522 523 // Standard libc functions return -1 on error 524 // and set errno. 525 CMPL AX, $-1 // Note: high 32 bits are junk 526 JNE ok 527 528 // Get error code from libc. 529 CALL libc_error(SB) 530 MOVLQSX (AX), AX 531 MOVQ (SP), DI 532 MOVQ AX, (6*8)(DI) // err 533 534 ok: 535 XORL AX, AX // no error (it's ignored anyway) 536 RET 537 538 // syscallX calls a function in libc on behalf of the syscall package. 539 // syscallX takes a pointer to a struct like: 540 // struct { 541 // fn uintptr 542 // a1 uintptr 543 // a2 uintptr 544 // a3 uintptr 545 // r1 uintptr 546 // r2 uintptr 547 // err uintptr 548 // } 549 // syscallX must be called on the g0 stack with the 550 // C calling convention (use libcCall). 551 // 552 // syscallX is like syscall but expects a 64-bit result 553 // and tests for 64-bit -1 to decide there was an error. 554 TEXT runtime·syscallX(SB),NOSPLIT,$16 555 MOVQ (0*8)(DI), CX // fn 556 MOVQ (2*8)(DI), SI // a2 557 MOVQ (3*8)(DI), DX // a3 558 MOVQ DI, (SP) 559 MOVQ (1*8)(DI), DI // a1 560 XORL AX, AX // vararg: say "no float args" 561 562 CALL CX 563 564 MOVQ (SP), DI 565 MOVQ AX, (4*8)(DI) // r1 566 MOVQ DX, (5*8)(DI) // r2 567 568 // Standard libc functions return -1 on error 569 // and set errno. 570 CMPQ AX, $-1 571 JNE ok 572 573 // Get error code from libc. 574 CALL libc_error(SB) 575 MOVLQSX (AX), AX 576 MOVQ (SP), DI 577 MOVQ AX, (6*8)(DI) // err 578 579 ok: 580 XORL AX, AX // no error (it's ignored anyway) 581 RET 582 583 // syscallPtr is like syscallX except that the libc function reports an 584 // error by returning NULL and setting errno. 585 TEXT runtime·syscallPtr(SB),NOSPLIT,$16 586 MOVQ (0*8)(DI), CX // fn 587 MOVQ (2*8)(DI), SI // a2 588 MOVQ (3*8)(DI), DX // a3 589 MOVQ DI, (SP) 590 MOVQ (1*8)(DI), DI // a1 591 XORL AX, AX // vararg: say "no float args" 592 593 CALL CX 594 595 MOVQ (SP), DI 596 MOVQ AX, (4*8)(DI) // r1 597 MOVQ DX, (5*8)(DI) // r2 598 599 // syscallPtr libc functions return NULL on error 600 // and set errno. 601 TESTQ AX, AX 602 JNE ok 603 604 // Get error code from libc. 605 CALL libc_error(SB) 606 MOVLQSX (AX), AX 607 MOVQ (SP), DI 608 MOVQ AX, (6*8)(DI) // err 609 610 ok: 611 XORL AX, AX // no error (it's ignored anyway) 612 RET 613 614 // syscall6 calls a function in libc on behalf of the syscall package. 615 // syscall6 takes a pointer to a struct like: 616 // struct { 617 // fn uintptr 618 // a1 uintptr 619 // a2 uintptr 620 // a3 uintptr 621 // a4 uintptr 622 // a5 uintptr 623 // a6 uintptr 624 // r1 uintptr 625 // r2 uintptr 626 // err uintptr 627 // } 628 // syscall6 must be called on the g0 stack with the 629 // C calling convention (use libcCall). 630 // 631 // syscall6 expects a 32-bit result and tests for 32-bit -1 632 // to decide there was an error. 633 TEXT runtime·syscall6(SB),NOSPLIT,$16 634 MOVQ (0*8)(DI), R11// fn 635 MOVQ (2*8)(DI), SI // a2 636 MOVQ (3*8)(DI), DX // a3 637 MOVQ (4*8)(DI), CX // a4 638 MOVQ (5*8)(DI), R8 // a5 639 MOVQ (6*8)(DI), R9 // a6 640 MOVQ DI, (SP) 641 MOVQ (1*8)(DI), DI // a1 642 XORL AX, AX // vararg: say "no float args" 643 644 CALL R11 645 646 MOVQ (SP), DI 647 MOVQ AX, (7*8)(DI) // r1 648 MOVQ DX, (8*8)(DI) // r2 649 650 CMPL AX, $-1 651 JNE ok 652 653 CALL libc_error(SB) 654 MOVLQSX (AX), AX 655 MOVQ (SP), DI 656 MOVQ AX, (9*8)(DI) // err 657 658 ok: 659 XORL AX, AX // no error (it's ignored anyway) 660 RET 661 662 // syscall6X calls a function in libc on behalf of the syscall package. 663 // syscall6X takes a pointer to a struct like: 664 // struct { 665 // fn uintptr 666 // a1 uintptr 667 // a2 uintptr 668 // a3 uintptr 669 // a4 uintptr 670 // a5 uintptr 671 // a6 uintptr 672 // r1 uintptr 673 // r2 uintptr 674 // err uintptr 675 // } 676 // syscall6X must be called on the g0 stack with the 677 // C calling convention (use libcCall). 678 // 679 // syscall6X is like syscall6 but expects a 64-bit result 680 // and tests for 64-bit -1 to decide there was an error. 681 TEXT runtime·syscall6X(SB),NOSPLIT,$16 682 MOVQ (0*8)(DI), R11// fn 683 MOVQ (2*8)(DI), SI // a2 684 MOVQ (3*8)(DI), DX // a3 685 MOVQ (4*8)(DI), CX // a4 686 MOVQ (5*8)(DI), R8 // a5 687 MOVQ (6*8)(DI), R9 // a6 688 MOVQ DI, (SP) 689 MOVQ (1*8)(DI), DI // a1 690 XORL AX, AX // vararg: say "no float args" 691 692 CALL R11 693 694 MOVQ (SP), DI 695 MOVQ AX, (7*8)(DI) // r1 696 MOVQ DX, (8*8)(DI) // r2 697 698 CMPQ AX, $-1 699 JNE ok 700 701 CALL libc_error(SB) 702 MOVLQSX (AX), AX 703 MOVQ (SP), DI 704 MOVQ AX, (9*8)(DI) // err 705 706 ok: 707 XORL AX, AX // no error (it's ignored anyway) 708 RET 709 710 // syscall9 calls a function in libc on behalf of the syscall package. 711 // syscall9 takes a pointer to a struct like: 712 // struct { 713 // fn uintptr 714 // a1 uintptr 715 // a2 uintptr 716 // a3 uintptr 717 // a4 uintptr 718 // a5 uintptr 719 // a6 uintptr 720 // a7 uintptr 721 // a8 uintptr 722 // a9 uintptr 723 // r1 uintptr 724 // r2 uintptr 725 // err uintptr 726 // } 727 // syscall9 must be called on the g0 stack with the 728 // C calling convention (use libcCall). 729 // 730 // syscall9 expects a 32-bit result and tests for 32-bit -1 731 // to decide there was an error. 732 TEXT runtime·syscall9(SB),NOSPLIT,$16 733 MOVQ (0*8)(DI), R13// fn 734 MOVQ (2*8)(DI), SI // a2 735 MOVQ (3*8)(DI), DX // a3 736 MOVQ (4*8)(DI), CX // a4 737 MOVQ (5*8)(DI), R8 // a5 738 MOVQ (6*8)(DI), R9 // a6 739 MOVQ (7*8)(DI), R10 // a7 740 MOVQ (8*8)(DI), R11 // a8 741 MOVQ (9*8)(DI), R12 // a9 742 MOVQ DI, (SP) 743 MOVQ (1*8)(DI), DI // a1 744 XORL AX, AX // vararg: say "no float args" 745 746 CALL R13 747 748 MOVQ (SP), DI 749 MOVQ AX, (10*8)(DI) // r1 750 MOVQ DX, (11*8)(DI) // r2 751 752 CMPL AX, $-1 753 JNE ok 754 755 CALL libc_error(SB) 756 MOVLQSX (AX), AX 757 MOVQ (SP), DI 758 MOVQ AX, (12*8)(DI) // err 759 760 ok: 761 XORL AX, AX // no error (it's ignored anyway) 762 RET 763 764 // syscall_x509 is for crypto/x509. It is like syscall6 but does not check for errors, 765 // takes 5 uintptrs and 1 float64, and only returns one value, 766 // for use with standard C ABI functions. 767 TEXT runtime·syscall_x509(SB),NOSPLIT,$16 768 MOVQ (0*8)(DI), R11// fn 769 MOVQ (2*8)(DI), SI // a2 770 MOVQ (3*8)(DI), DX // a3 771 MOVQ (4*8)(DI), CX // a4 772 MOVQ (5*8)(DI), R8 // a5 773 MOVQ (6*8)(DI), X0 // f1 774 MOVQ DI, (SP) 775 MOVQ (1*8)(DI), DI // a1 776 XORL AX, AX // vararg: say "no float args" 777 778 CALL R11 779 780 MOVQ (SP), DI 781 MOVQ AX, (7*8)(DI) // r1 782 783 XORL AX, AX // no error (it's ignored anyway) 784 RET