@@ -403,3 +403,298 @@ TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
403403 MOVD $ 0 , R0 // crash on syscall failure
404404 MOVD R0 , (R0)
405405 RET
406+
407+ // syscall calls a function in libc on behalf of the syscall package.
408+ // syscall takes a pointer to a struct like:
409+ // struct {
410+ // fn uintptr
411+ // a1 uintptr
412+ // a2 uintptr
413+ // a3 uintptr
414+ // r1 uintptr
415+ // r2 uintptr
416+ // err uintptr
417+ // }
418+ // syscall must be called on the g0 stack with the
419+ // C calling convention (use libcCall).
420+ //
421+ // syscall expects a 32 - bit result and tests for 32 - bit - 1
422+ // to decide there was an error.
423+ TEXT runtime· syscall (SB) , NOSPLIT , $ 0
424+ MOVD R0 , R19 // pointer to args
425+
426+ MOVD ( 0 * 8 )(R19) , R11 // fn
427+ MOVD ( 1 * 8 )(R19) , R0 // a1
428+ MOVD ( 2 * 8 )(R19) , R1 // a2
429+ MOVD ( 3 * 8 )(R19) , R2 // a3
430+ MOVD $ 0 , R3 // vararg
431+
432+ CALL R11
433+
434+ MOVD R0 , ( 4 * 8 )(R19) // r1
435+ MOVD R1 , ( 5 * 8 )(R19) // r2
436+
437+ // Standard libc functions return - 1 on error
438+ // and set errno.
439+ CMPW $ - 1 , R0
440+ BNE ok
441+
442+ // Get error code from libc.
443+ CALL libc_errno(SB)
444+ MOVW (R0) , R0
445+ MOVD R0 , ( 6 * 8 )(R19) // err
446+
447+ ok:
448+ RET
449+
450+ // syscallX calls a function in libc on behalf of the syscall package.
451+ // syscallX takes a pointer to a struct like:
452+ // struct {
453+ // fn uintptr
454+ // a1 uintptr
455+ // a2 uintptr
456+ // a3 uintptr
457+ // r1 uintptr
458+ // r2 uintptr
459+ // err uintptr
460+ // }
461+ // syscallX must be called on the g0 stack with the
462+ // C calling convention (use libcCall).
463+ //
464+ // syscallX is like syscall but expects a 64 - bit result
465+ // and tests for 64 - bit - 1 to decide there was an error.
466+ TEXT runtime·syscallX(SB) , NOSPLIT , $ 0
467+ MOVD R0 , R19 // pointer to args
468+
469+ MOVD ( 0 * 8 )(R19) , R11 // fn
470+ MOVD ( 1 * 8 )(R19) , R0 // a1
471+ MOVD ( 2 * 8 )(R19) , R1 // a2
472+ MOVD ( 3 * 8 )(R19) , R2 // a3
473+ MOVD $ 0 , R3 // vararg
474+
475+ CALL R11
476+
477+ MOVD R0 , ( 4 * 8 )(R19) // r1
478+ MOVD R1 , ( 5 * 8 )(R19) // r2
479+
480+ // Standard libc functions return - 1 on error
481+ // and set errno.
482+ CMP $ - 1 , R0
483+ BNE ok
484+
485+ // Get error code from libc.
486+ CALL libc_errno(SB)
487+ MOVW (R0) , R0
488+ MOVD R0 , ( 6 * 8 )(R19) // err
489+
490+ ok:
491+ RET
492+
493+ // syscall6 calls a function in libc on behalf of the syscall package.
494+ // syscall6 takes a pointer to a struct like:
495+ // struct {
496+ // fn uintptr
497+ // a1 uintptr
498+ // a2 uintptr
499+ // a3 uintptr
500+ // a4 uintptr
501+ // a5 uintptr
502+ // a6 uintptr
503+ // r1 uintptr
504+ // r2 uintptr
505+ // err uintptr
506+ // }
507+ // syscall6 must be called on the g0 stack with the
508+ // C calling convention (use libcCall).
509+ //
510+ // syscall6 expects a 32 - bit result and tests for 32 - bit - 1
511+ // to decide there was an error.
512+ TEXT runtime·syscall6(SB) , NOSPLIT , $ 0
513+ MOVD R0 , R19 // pointer to args
514+
515+ MOVD ( 0 * 8 )(R19) , R11 // fn
516+ MOVD ( 1 * 8 )(R19) , R0 // a1
517+ MOVD ( 2 * 8 )(R19) , R1 // a2
518+ MOVD ( 3 * 8 )(R19) , R2 // a3
519+ MOVD ( 4 * 8 )(R19) , R3 // a4
520+ MOVD ( 5 * 8 )(R19) , R4 // a5
521+ MOVD ( 6 * 8 )(R19) , R5 // a6
522+ MOVD $ 0 , R6 // vararg
523+
524+ CALL R11
525+
526+ MOVD R0 , ( 7 * 8 )(R19) // r1
527+ MOVD R1 , ( 8 * 8 )(R19) // r2
528+
529+ // Standard libc functions return - 1 on error
530+ // and set errno.
531+ CMPW $ - 1 , R0
532+ BNE ok
533+
534+ // Get error code from libc.
535+ CALL libc_errno(SB)
536+ MOVW (R0) , R0
537+ MOVD R0 , ( 9 * 8 )(R19) // err
538+
539+ ok:
540+ RET
541+
542+ // syscall6X calls a function in libc on behalf of the syscall package.
543+ // syscall6X takes a pointer to a struct like:
544+ // struct {
545+ // fn uintptr
546+ // a1 uintptr
547+ // a2 uintptr
548+ // a3 uintptr
549+ // a4 uintptr
550+ // a5 uintptr
551+ // a6 uintptr
552+ // r1 uintptr
553+ // r2 uintptr
554+ // err uintptr
555+ // }
556+ // syscall6X must be called on the g0 stack with the
557+ // C calling convention (use libcCall).
558+ //
559+ // syscall6X is like syscall6 but expects a 64 - bit result
560+ // and tests for 64 - bit - 1 to decide there was an error.
561+ TEXT runtime·syscall6X(SB) , NOSPLIT , $ 0
562+ MOVD R0 , R19 // pointer to args
563+
564+ MOVD ( 0 * 8 )(R19) , R11 // fn
565+ MOVD ( 1 * 8 )(R19) , R0 // a1
566+ MOVD ( 2 * 8 )(R19) , R1 // a2
567+ MOVD ( 3 * 8 )(R19) , R2 // a3
568+ MOVD ( 4 * 8 )(R19) , R3 // a4
569+ MOVD ( 5 * 8 )(R19) , R4 // a5
570+ MOVD ( 6 * 8 )(R19) , R5 // a6
571+ MOVD $ 0 , R6 // vararg
572+
573+ CALL R11
574+
575+ MOVD R0 , ( 7 * 8 )(R19) // r1
576+ MOVD R1 , ( 8 * 8 )(R19) // r2
577+
578+ // Standard libc functions return - 1 on error
579+ // and set errno.
580+ CMP $ - 1 , R0
581+ BNE ok
582+
583+ // Get error code from libc.
584+ CALL libc_errno(SB)
585+ MOVW (R0) , R0
586+ MOVD R0 , ( 9 * 8 )(R19) // err
587+
588+ ok:
589+ RET
590+
591+ // syscall10 calls a function in libc on behalf of the syscall package.
592+ // syscall10 takes a pointer to a struct like:
593+ // struct {
594+ // fn uintptr
595+ // a1 uintptr
596+ // a2 uintptr
597+ // a3 uintptr
598+ // a4 uintptr
599+ // a5 uintptr
600+ // a6 uintptr
601+ // a7 uintptr
602+ // a8 uintptr
603+ // a9 uintptr
604+ // a10 uintptr
605+ // r1 uintptr
606+ // r2 uintptr
607+ // err uintptr
608+ // }
609+ // syscall10 must be called on the g0 stack with the
610+ // C calling convention (use libcCall).
611+ TEXT runtime·syscall10(SB) , NOSPLIT , $ 0
612+ MOVD R0 , R19 // pointer to args
613+
614+ MOVD ( 0 * 8 )(R19) , R11 // fn
615+ MOVD ( 1 * 8 )(R19) , R0 // a1
616+ MOVD ( 2 * 8 )(R19) , R1 // a2
617+ MOVD ( 3 * 8 )(R19) , R2 // a3
618+ MOVD ( 4 * 8 )(R19) , R3 // a4
619+ MOVD ( 5 * 8 )(R19) , R4 // a5
620+ MOVD ( 6 * 8 )(R19) , R5 // a6
621+ MOVD ( 7 * 8 )(R19) , R6 // a7
622+ MOVD ( 8 * 8 )(R19) , R7 // a8
623+ MOVD ( 9 * 8 )(R19) , R8 // a9
624+ MOVD ( 10 * 8 )(R19) , R9 // a10
625+ MOVD $ 0 , R10 // vararg
626+
627+ CALL R11
628+
629+ MOVD R0 , ( 11 * 8 )(R19) // r1
630+ MOVD R1 , ( 12 * 8 )(R19) // r2
631+
632+ // Standard libc functions return - 1 on error
633+ // and set errno.
634+ CMPW $ - 1 , R0
635+ BNE ok
636+
637+ // Get error code from libc.
638+ CALL libc_errno(SB)
639+ MOVW (R0) , R0
640+ MOVD R0 , ( 13 * 8 )(R19) // err
641+
642+ ok:
643+ RET
644+
645+ // syscall10X calls a function in libc on behalf of the syscall package.
646+ // syscall10X takes a pointer to a struct like:
647+ // struct {
648+ // fn uintptr
649+ // a1 uintptr
650+ // a2 uintptr
651+ // a3 uintptr
652+ // a4 uintptr
653+ // a5 uintptr
654+ // a6 uintptr
655+ // a7 uintptr
656+ // a8 uintptr
657+ // a9 uintptr
658+ // a10 uintptr
659+ // r1 uintptr
660+ // r2 uintptr
661+ // err uintptr
662+ // }
663+ // syscall10X must be called on the g0 stack with the
664+ // C calling convention (use libcCall).
665+ //
666+ // syscall10X is like syscall10 but expects a 64 - bit result
667+ // and tests for 64 - bit - 1 to decide there was an error.
668+ TEXT runtime·syscall10X(SB) , NOSPLIT , $ 0
669+ MOVD R0 , R19 // pointer to args
670+
671+ MOVD ( 0 * 8 )(R19) , R11 // fn
672+ MOVD ( 1 * 8 )(R19) , R0 // a1
673+ MOVD ( 2 * 8 )(R19) , R1 // a2
674+ MOVD ( 3 * 8 )(R19) , R2 // a3
675+ MOVD ( 4 * 8 )(R19) , R3 // a4
676+ MOVD ( 5 * 8 )(R19) , R4 // a5
677+ MOVD ( 6 * 8 )(R19) , R5 // a6
678+ MOVD ( 7 * 8 )(R19) , R6 // a7
679+ MOVD ( 8 * 8 )(R19) , R7 // a8
680+ MOVD ( 9 * 8 )(R19) , R8 // a9
681+ MOVD ( 10 * 8 )(R19) , R9 // a10
682+ MOVD $ 0 , R10 // vararg
683+
684+ CALL R11
685+
686+ MOVD R0 , ( 11 * 8 )(R19) // r1
687+ MOVD R1 , ( 12 * 8 )(R19) // r2
688+
689+ // Standard libc functions return - 1 on error
690+ // and set errno.
691+ CMP $ - 1 , R0
692+ BNE ok
693+
694+ // Get error code from libc.
695+ CALL libc_errno(SB)
696+ MOVW (R0) , R0
697+ MOVD R0 , ( 13 * 8 )(R19) // err
698+
699+ ok:
700+ RET
0 commit comments