Text file src/runtime/sys_linux_loong64.s

     1  // Copyright 2022 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  //
     6  // System calls and other sys.stuff for loong64, Linux
     7  //
     8  
     9  #include "go_asm.h"
    10  #include "go_tls.h"
    11  #include "textflag.h"
    12  #include "cgo/abi_loong64.h"
    13  
    14  #define AT_FDCWD	-100
    15  #define CLOCK_REALTIME	0
    16  #define CLOCK_MONOTONIC	1
    17  
    18  #define SYS_exit		93
    19  #define SYS_read		63
    20  #define SYS_write		64
    21  #define SYS_close		57
    22  #define SYS_getpid		172
    23  #define SYS_kill		129
    24  #define SYS_mmap		222
    25  #define SYS_munmap		215
    26  #define SYS_setitimer		103
    27  #define SYS_clone		220
    28  #define SYS_nanosleep		101
    29  #define SYS_sched_yield		124
    30  #define SYS_rt_sigreturn	139
    31  #define SYS_rt_sigaction	134
    32  #define SYS_rt_sigprocmask	135
    33  #define SYS_sigaltstack		132
    34  #define SYS_madvise		233
    35  #define SYS_mincore		232
    36  #define SYS_gettid		178
    37  #define SYS_futex		98
    38  #define SYS_sched_getaffinity	123
    39  #define SYS_exit_group		94
    40  #define SYS_tgkill		131
    41  #define SYS_openat		56
    42  #define SYS_clock_gettime	113
    43  #define SYS_brk			214
    44  #define SYS_pipe2		59
    45  #define SYS_timer_create	107
    46  #define SYS_timer_settime	110
    47  #define SYS_timer_delete	111
    48  
    49  // func exit(code int32)
    50  TEXT runtime·exit<ABIInternal>(SB),NOSPLIT,$0
    51  	MOVV	$SYS_exit_group, R11
    52  	SYSCALL
    53  	RET
    54  
    55  // func exitThread(wait *atomic.Uint32)
    56  TEXT runtime·exitThread<ABIInternal>(SB),NOSPLIT|NOFRAME,$0
    57  	// We're done using the stack.
    58  	DBAR	$0x12	// StoreRelease barrier
    59  	MOVW	R0, (R4)
    60  	MOVW	$0, R4	// exit code
    61  	MOVV	$SYS_exit, R11
    62  	SYSCALL
    63  	JMP	0(PC)
    64  
    65  // func open(name *byte, mode, perm int32) int32
    66  TEXT runtime·open<ABIInternal>(SB),NOSPLIT,$0
    67  	// before:
    68  	//    R4:  name, R5: mode, R6: perm
    69  	// after:
    70  	//    R4: AT_FDCWD, R5: name, R6: mode, R7: perm
    71  	MOVW	R6, R7
    72  	MOVW	R5, R6
    73  	MOVV	R4, R5
    74  	MOVW	$AT_FDCWD, R4 // AT_FDCWD, so this acts like open
    75  
    76  	MOVV	$SYS_openat, R11
    77  	SYSCALL
    78  	MOVW	$-4096, R5
    79  	BGEU	R5, R4, 2(PC)
    80  	MOVW	$-1, R4
    81  	RET
    82  
    83  // func closefd(fd int32) int32
    84  TEXT runtime·closefd<ABIInternal>(SB),NOSPLIT,$0
    85  	MOVV	$SYS_close, R11
    86  	SYSCALL
    87  	MOVW	$-4096, R5
    88  	BGEU	R5, R4, 2(PC)
    89  	MOVW	$-1, R4
    90  	RET
    91  
    92  // func write1(fd uintptr, p unsafe.Pointer, n int32) int32
    93  TEXT runtime·write1<ABIInternal>(SB),NOSPLIT,$0
    94  	MOVV	$SYS_write, R11
    95  	SYSCALL
    96  	RET
    97  
    98  // func read(fd int32, p unsafe.Pointer, n int32) int32
    99  TEXT runtime·read<ABIInternal>(SB),NOSPLIT,$0
   100  	MOVV	$SYS_read, R11
   101  	SYSCALL
   102  	RET
   103  
   104  // func pipe2(flags int32) (r, w int32, errno int32)
   105  TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
   106  	MOVV	$r+8(FP), R4
   107  	MOVW	flags+0(FP), R5
   108  	MOVV	$SYS_pipe2, R11
   109  	SYSCALL
   110  	MOVW	R4, errno+16(FP)
   111  	RET
   112  
   113  // func usleep(usec uint32)
   114  TEXT runtime·usleep<ABIInternal>(SB),NOSPLIT,$16
   115  	MOVV	$1000, R6
   116  	MULVU	R6, R4, R4
   117  	MOVV	$1000000000, R6
   118  
   119  	DIVVU	R6, R4, R5	// ts->tv_sec
   120  	REMVU	R6, R4, R8	// ts->tv_nsec
   121  	MOVV	R5, 8(R3)
   122  	MOVV	R8, 16(R3)
   123  
   124  	// nanosleep(&ts, 0)
   125  	ADDV	$8, R3, R4
   126  	MOVV	R0, R5
   127  	MOVV	$SYS_nanosleep, R11
   128  	SYSCALL
   129  	RET
   130  
   131  // func gettid() uint32
   132  TEXT runtime·gettid<ABIInternal>(SB),NOSPLIT,$0
   133  	MOVV	$SYS_gettid, R11
   134  	SYSCALL
   135  	RET
   136  
   137  // func raise(sig uint32)
   138  TEXT runtime·raise<ABIInternal>(SB),NOSPLIT,$0
   139  	MOVW	R4, R24 // backup sig
   140  	MOVV	$SYS_getpid, R11
   141  	SYSCALL
   142  	MOVW	R4, R23
   143  	MOVV	$SYS_gettid, R11
   144  	SYSCALL
   145  	MOVW	R4, R5	// arg 2 tid
   146  	MOVW	R23, R4	// arg 1 pid
   147  	MOVW	R24, R6	// arg 3
   148  	MOVV	$SYS_tgkill, R11
   149  	SYSCALL
   150  	RET
   151  
   152  // func raiseproc(sig uint32)
   153  TEXT runtime·raiseproc<ABIInternal>(SB),NOSPLIT,$0
   154  	MOVW	R4, R24 // backup sig
   155  	MOVV	$SYS_getpid, R11
   156  	SYSCALL
   157  	//MOVW	R4, R4	// arg 1 pid
   158  	MOVW	R24, R5	// arg 2
   159  	MOVV	$SYS_kill, R11
   160  	SYSCALL
   161  	RET
   162  
   163  // func getpid() int
   164  TEXT ·getpid<ABIInternal>(SB),NOSPLIT,$0
   165  	MOVV	$SYS_getpid, R11
   166  	SYSCALL
   167  	RET
   168  
   169  // func tgkill(tgid, tid, sig int)
   170  TEXT ·tgkill<ABIInternal>(SB),NOSPLIT,$0
   171  	MOVV	$SYS_tgkill, R11
   172  	SYSCALL
   173  	RET
   174  
   175  // func setitimer(mode int32, new, old *itimerval)
   176  TEXT runtime·setitimer<ABIInternal>(SB),NOSPLIT,$0
   177  	MOVV	$SYS_setitimer, R11
   178  	SYSCALL
   179  	RET
   180  
   181  // func timer_create(clockid int32, sevp *sigevent, timerid *int32) int32
   182  TEXT runtime·timer_create<ABIInternal>(SB),NOSPLIT,$0
   183  	MOVV	$SYS_timer_create, R11
   184  	SYSCALL
   185  	RET
   186  
   187  // func timer_settime(timerid int32, flags int32, new, old *itimerspec) int32
   188  TEXT runtime·timer_settime<ABIInternal>(SB),NOSPLIT,$0
   189  	MOVV	$SYS_timer_settime, R11
   190  	SYSCALL
   191  	RET
   192  
   193  // func timer_delete(timerid int32) int32
   194  TEXT runtime·timer_delete<ABIInternal>(SB),NOSPLIT,$0
   195  	MOVV	$SYS_timer_delete, R11
   196  	SYSCALL
   197  	RET
   198  
   199  // func mincore(addr unsafe.Pointer, n uintptr, dst *byte) int32
   200  TEXT runtime·mincore<ABIInternal>(SB),NOSPLIT,$0
   201  	MOVV	$SYS_mincore, R11
   202  	SYSCALL
   203  	RET
   204  
   205  // func walltime() (sec int64, nsec int32)
   206  TEXT runtime·walltime<ABIInternal>(SB),NOSPLIT,$24
   207  	MOVV	R3, R23	// R23 is unchanged by C code
   208  
   209  	MOVV	g_m(g), R24	// R24 = m
   210  
   211  	// Set vdsoPC and vdsoSP for SIGPROF traceback.
   212  	// Save the old values on stack and restore them on exit,
   213  	// so this function is reentrant.
   214  	MOVV	m_vdsoPC(R24), R11
   215  	MOVV	m_vdsoSP(R24), R7
   216  	MOVV	R11, 8(R3)
   217  	MOVV	R7, 16(R3)
   218  
   219  	MOVV    $ret-8(FP), R11 // caller's SP
   220  	MOVV	R1, m_vdsoPC(R24)
   221  	MOVV	R11, m_vdsoSP(R24)
   222  
   223  	MOVV	m_curg(R24), R4
   224  	BNE	R4, g, noswitch
   225  
   226  	MOVV	m_g0(R24), R4
   227  	MOVV	(g_sched+gobuf_sp)(R4), R3	// Set SP to g0 stack
   228  
   229  noswitch:
   230  	SUBV	$16, R3
   231  	AND	$~15, R3	// Align for C code
   232  
   233  	MOVW	$CLOCK_REALTIME, R4
   234  	MOVV	$0(R3), R5
   235  
   236  	MOVV	runtime·vdsoClockgettimeSym(SB), R20
   237  	BEQ	R20, fallback
   238  
   239  	// Store g on gsignal's stack, see sys_linux_arm64.s for detail
   240  	MOVBU	runtime·iscgo(SB), R25
   241  	BNE	R25, nosaveg
   242  
   243  	MOVV	m_gsignal(R24), R25	// g.m.gsignal
   244  	BEQ	R25, nosaveg
   245  	BEQ	g, R25, nosaveg
   246  
   247  	MOVV	(g_stack+stack_lo)(R25), R25	// g.m.gsignal.stack.lo
   248  	MOVV	g, (R25)
   249  
   250  	JAL	(R20)
   251  
   252  	MOVV	R0, (R25)
   253  	JMP	finish
   254  
   255  nosaveg:
   256  	JAL	(R20)
   257  
   258  finish:
   259  	MOVV	0(R3), R4	// sec
   260  	MOVV	8(R3), R5	// nsec
   261  
   262  	MOVV	R23, R3	// restore SP
   263  	// Restore vdsoPC, vdsoSP
   264  	// We don't worry about being signaled between the two stores.
   265  	// If we are not in a signal handler, we'll restore vdsoSP to 0,
   266  	// and no one will care about vdsoPC. If we are in a signal handler,
   267  	// we cannot receive another signal.
   268  	MOVV	16(R3), R25
   269  	MOVV	R25, m_vdsoSP(R24)
   270  	MOVV	8(R3), R25
   271  	MOVV	R25, m_vdsoPC(R24)
   272  
   273  	RET
   274  
   275  fallback:
   276  	MOVV	$SYS_clock_gettime, R11
   277  	SYSCALL
   278  	JMP finish
   279  
   280  // func nanotime1() int64
   281  TEXT runtime·nanotime1<ABIInternal>(SB),NOSPLIT,$24
   282  	MOVV	R3, R23	// R23 is unchanged by C code
   283  
   284  	MOVV	g_m(g), R24	// R24 = m
   285  
   286  	// Set vdsoPC and vdsoSP for SIGPROF traceback.
   287  	// Save the old values on stack and restore them on exit,
   288  	// so this function is reentrant.
   289  	MOVV	m_vdsoPC(R24), R11
   290  	MOVV	m_vdsoSP(R24), R7
   291  	MOVV	R11, 8(R3)
   292  	MOVV	R7, 16(R3)
   293  
   294  	MOVV    $ret-8(FP), R11 // caller's SP
   295  	MOVV	R1, m_vdsoPC(R24)
   296  	MOVV	R11, m_vdsoSP(R24)
   297  
   298  	MOVV	m_curg(R24), R4
   299  	BNE	R4, g, noswitch
   300  
   301  	MOVV	m_g0(R24), R4
   302  	MOVV	(g_sched+gobuf_sp)(R4), R3	// Set SP to g0 stack
   303  
   304  noswitch:
   305  	SUBV	$16, R3
   306  	AND	$~15, R3	// Align for C code
   307  
   308  	MOVW	$CLOCK_MONOTONIC, R4
   309  	MOVV	$0(R3), R5
   310  
   311  	MOVV	runtime·vdsoClockgettimeSym(SB), R20
   312  	BEQ	R20, fallback
   313  
   314  	// Store g on gsignal's stack, see sys_linux_arm64.s for detail
   315  	MOVBU	runtime·iscgo(SB), R25
   316  	BNE	R25, nosaveg
   317  
   318  	MOVV	m_gsignal(R24), R25	// g.m.gsignal
   319  	BEQ	R25, nosaveg
   320  	BEQ	g, R25, nosaveg
   321  
   322  	MOVV	(g_stack+stack_lo)(R25), R25	// g.m.gsignal.stack.lo
   323  	MOVV	g, (R25)
   324  
   325  	JAL	(R20)
   326  
   327  	MOVV	R0, (R25)
   328  	JMP	finish
   329  
   330  nosaveg:
   331  	JAL	(R20)
   332  
   333  finish:
   334  	MOVV	0(R3), R7	// sec
   335  	MOVV	8(R3), R5	// nsec
   336  
   337  	MOVV	R23, R3	// restore SP
   338  	// Restore vdsoPC, vdsoSP
   339  	// We don't worry about being signaled between the two stores.
   340  	// If we are not in a signal handler, we'll restore vdsoSP to 0,
   341  	// and no one will care about vdsoPC. If we are in a signal handler,
   342  	// we cannot receive another signal.
   343  	MOVV	16(R3), R25
   344  	MOVV	R25, m_vdsoSP(R24)
   345  	MOVV	8(R3), R25
   346  	MOVV	R25, m_vdsoPC(R24)
   347  
   348  	// sec is in R7, nsec in R5
   349  	// return nsec in R7
   350  	MOVV	$1000000000, R4
   351  	MULVU	R4, R7, R7
   352  	ADDVU	R5, R7, R4
   353  	RET
   354  
   355  fallback:
   356  	MOVV	$SYS_clock_gettime, R11
   357  	SYSCALL
   358  	JMP	finish
   359  
   360  // func rtsigprocmask(how int32, new, old *sigset, size int32)
   361  TEXT runtime·rtsigprocmask<ABIInternal>(SB),NOSPLIT,$0
   362  	MOVV	$SYS_rt_sigprocmask, R11
   363  	SYSCALL
   364  	MOVW	$-4096, R5
   365  	BGEU	R5, R4, 2(PC)
   366  	MOVV	R0, 0xf1(R0)	// crash
   367  	RET
   368  
   369  // func rt_sigaction(sig uintptr, new, old *sigactiont, size uintptr) int32
   370  TEXT runtime·rt_sigaction<ABIInternal>(SB),NOSPLIT,$0
   371  	MOVV	$SYS_rt_sigaction, R11
   372  	SYSCALL
   373  	RET
   374  
   375  // Call the function stored in _cgo_sigaction using the GCC calling convention.
   376  TEXT runtime·callCgoSigaction<ABIInternal>(SB),NOSPLIT,$0
   377  	// R4: sig, R5: new, R6: old
   378  	MOVV    _cgo_sigaction(SB), R7
   379  	SUBV    $16, R3 // reserve 16 bytes for sp-8 where fp may be saved.
   380  	JAL     (R7)
   381  	ADDV    $16, R3
   382  	MOVW    R4, R4
   383  	RET
   384  
   385  // func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
   386  TEXT runtime·sigfwd<ABIInternal>(SB),NOSPLIT,$0
   387  	// before:
   388  	//    R4:  fn, R5: sig, R6: info, R7: ctx
   389  	// after:
   390  	//    R20: fn, R4: sig, R5: info, R6: ctx
   391  	MOVV	R4, R20
   392  	MOVV	R5, R4
   393  	MOVV	R6, R5
   394  	MOVV	R7, R6
   395  	JAL	(R20)
   396  	RET
   397  
   398  // Called from c-abi, R4: sig, R5: info, R6: cxt
   399  // func sigtramp(signo, ureg, ctxt unsafe.Pointer)
   400  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$168
   401  	// Save callee-save registers in the case of signal forwarding.
   402  	// Please refer to https://golang.org/issue/31827 .
   403  	SAVE_R22_TO_R31((4*8))
   404  	SAVE_F24_TO_F31((14*8))
   405  
   406  	// this might be called in external code context,
   407  	// where g is not set.
   408  	MOVB	runtime·iscgo(SB), R7
   409  	BEQ	R7, 2(PC)
   410  	JAL	runtime·load_g(SB)
   411  
   412  	// R5 and R6 already contain info and ctx, respectively.
   413  	MOVV	$runtime·sigtrampgo<ABIInternal>(SB), R7
   414  	JAL	(R7)
   415  
   416  	// Restore callee-save registers.
   417  	RESTORE_R22_TO_R31((4*8))
   418  	RESTORE_F24_TO_F31((14*8))
   419  
   420  	RET
   421  
   422  // Called from c-abi, R4: sig, R5: info, R6: cxt
   423  TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$168
   424  	// Save callee-save registers because it's a callback from c code.
   425  	SAVE_R22_TO_R31((4*8))
   426  	SAVE_F24_TO_F31((14*8))
   427  
   428  	// R4, R5 and R6 already contain sig, info and ctx, respectively.
   429  	CALL	runtime·sigprofNonGo<ABIInternal>(SB)
   430  
   431  	// Restore callee-save registers.
   432  	RESTORE_R22_TO_R31((4*8))
   433  	RESTORE_F24_TO_F31((14*8))
   434  	RET
   435  
   436  // Called from c-abi, R4: sig, R5: info, R6: cxt
   437  TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
   438  	// The stack unwinder, presumably written in C, may not be able to
   439  	// handle Go frame correctly. So, this function is NOFRAME, and we
   440  	// save/restore LR manually.
   441  	MOVV	R1, R12
   442  	// Save R30, g because they will be clobbered,
   443  	// we need to restore them before jump to sigtramp.
   444  	MOVV	R30, R13
   445  	MOVV	g, R14
   446  
   447  	// If no traceback function, do usual sigtramp.
   448  	MOVV	runtime·cgoTraceback(SB), R15
   449  	BEQ	R15, sigtramp
   450  
   451  	// If no traceback support function, which means that
   452  	// runtime/cgo was not linked in, do usual sigtramp.
   453  	MOVV	_cgo_callers(SB), R15
   454  	BEQ	R15, sigtramp
   455  
   456  	// Figure out if we are currently in a cgo call.
   457  	// If not, just do usual sigtramp.
   458  	CALL	runtime·load_g(SB)
   459  	BEQ	g, sigtrampnog // g == nil
   460  
   461  	MOVV	g_m(g), R15
   462  	BEQ	R15, sigtramp    // g.m == nil
   463  	MOVW	m_ncgo(R15), R16
   464  	BEQ	R16, sigtramp    // g.m.ncgo = 0
   465  	MOVV	m_curg(R15), R16
   466  	BEQ	R16, sigtramp    // g.m.curg == nil
   467  	MOVV	g_syscallsp(R16), R17
   468  	BEQ     R17, sigtramp    // g.m.curg.syscallsp == 0
   469  	MOVV	m_cgoCallers(R15), R8 // R8 is the fifth arg in C calling convention.
   470  	BEQ	R8, sigtramp    // g.m.cgoCallers == nil
   471  	MOVW	m_cgoCallersUse(R15), R16
   472  	BNE	R16, sigtramp    // g.m.cgoCallersUse != 0
   473  
   474  	// Jump to a function in runtime/cgo.
   475  	// That function, written in C, will call the user's traceback
   476  	// function with proper unwind info, and will then call back here.
   477  	// The first three arguments, and the fifth, are already in registers.
   478  	// Set the two remaining arguments now.
   479  	MOVV	runtime·cgoTraceback(SB), R7
   480  	MOVV	$runtime·sigtramp(SB), R9
   481  	MOVV	_cgo_callers(SB), R15
   482  	MOVV	R12, R1 // restore
   483  	MOVV	R13, R30
   484  	MOVV	R14, g
   485  	JMP	(R15)
   486  
   487  sigtramp:
   488  	MOVV	R12, R1 // restore
   489  	MOVV	R13, R30
   490  	MOVV	R14, g
   491  	JMP	runtime·sigtramp(SB)
   492  
   493  sigtrampnog:
   494  	// Signal arrived on a non-Go thread. If this is SIGPROF, get a
   495  	// stack trace.
   496  	MOVW    $27, R15 // 27 == SIGPROF
   497  	BNE     R4, R15, sigtramp
   498  
   499  	MOVV    $runtime·sigprofCallersUse(SB), R16
   500  	DBAR	$0x14
   501  cas_again:
   502  	MOVV    $1, R15
   503  	LL	(R16), R17
   504  	BNE	R17, fail
   505  	SC	R15, (R16)
   506  	BEQ	R15, cas_again
   507  	DBAR    $0x14
   508  
   509  	// Jump to the traceback function in runtime/cgo.
   510  	// It will call back to sigprofNonGo, which will ignore the
   511  	// arguments passed in registers.
   512  	// First three arguments to traceback function are in registers already.
   513  	MOVV	runtime·cgoTraceback(SB), R7
   514  	MOVV	$runtime·sigprofCallers(SB), R8
   515  	MOVV	$runtime·sigprofNonGoWrapper<>(SB), R9
   516  	MOVV	_cgo_callers(SB), R15
   517  	MOVV	R12, R1 // restore
   518  	MOVV	R13, R30
   519  	MOVV	R14, g
   520  	JMP	(R15)
   521  
   522  fail:
   523  	DBAR    $0x14
   524  	JMP     sigtramp
   525  
   526  // func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (p unsafe.Pointer, err int)
   527  TEXT runtime·sysMmap<ABIInternal>(SB),NOSPLIT,$0
   528  	MOVV	$SYS_mmap, R11
   529  	SYSCALL
   530  	MOVW	$-4096, R5
   531  	BGEU	R5, R4, ok
   532  	SUBVU	R4, R0, R5
   533  	MOVV	$0, R4
   534  	RET
   535  ok:
   536  	MOVV	$0, R5
   537  	RET
   538  
   539  // Call the function stored in _cgo_mmap using the GCC calling convention.
   540  // This must be called on the system stack.
   541  // func callCgoMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) uintptr
   542  TEXT runtime·callCgoMmap<ABIInternal>(SB),NOSPLIT,$0
   543  	MOVV	_cgo_mmap(SB), R13
   544  	SUBV	$16, R3		// reserve 16 bytes for sp-8 where fp may be saved.
   545  	JAL	(R13)
   546  	ADDV	$16, R3
   547  	MOVV	R4, R4
   548  	RET
   549  
   550  // func sysMunmap(addr unsafe.Pointer, n uintptr)
   551  TEXT runtime·sysMunmap<ABIInternal>(SB),NOSPLIT,$0
   552  	MOVV	$SYS_munmap, R11
   553  	SYSCALL
   554  	MOVW	$-4096, R5
   555  	BGEU	R5, R4, 2(PC)
   556  	MOVV	R0, 0xf3(R0)	// crash
   557  	RET
   558  
   559  // Call the function stored in _cgo_munmap using the GCC calling convention.
   560  // This must be called on the system stack.
   561  // func callCgoMunmap(addr unsafe.Pointer, n uintptr)
   562  TEXT runtime·callCgoMunmap<ABIInternal>(SB),NOSPLIT,$0
   563  	MOVV	_cgo_munmap(SB), R13
   564  	SUBV	$16, R3		// reserve 16 bytes for sp-8 where fp may be saved.
   565  	JAL	(R13)
   566  	ADDV	$16, R3
   567  	RET
   568  
   569  // func madvise(addr unsafe.Pointer, n uintptr, flags int32)
   570  TEXT runtime·madvise<ABIInternal>(SB),NOSPLIT,$0
   571  	MOVV	$SYS_madvise, R11
   572  	SYSCALL
   573  	RET
   574  
   575  // func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32
   576  TEXT runtime·futex<ABIInternal>(SB),NOSPLIT,$0
   577  	MOVV	$SYS_futex, R11
   578  	SYSCALL
   579  	RET
   580  
   581  // int64 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   582  TEXT runtime·clone<ABIInternal>(SB),NOSPLIT,$0
   583  	// Copy mp, gp, fn off parent stack for use by child.
   584  	// Careful: Linux system call clobbers ???.
   585  	MOVV	R6, R23
   586  	MOVV	R7, R24
   587  	MOVV	R8, R25
   588  
   589  	MOVV	R23, -8(R5)
   590  	MOVV	R24, -16(R5)
   591  	MOVV	R25, -24(R5)
   592  	MOVV	$1234, R23
   593  	MOVV	R23, -32(R5)
   594  
   595  	MOVV	$SYS_clone, R11
   596  	SYSCALL
   597  
   598  	// In parent, return.
   599  	BEQ	R4, 2(PC)
   600  	RET
   601  
   602  	// In child, on new stack.
   603  	MOVV	-32(R3), R23
   604  	MOVV	$1234, R19
   605  	BEQ	R23, R19, 2(PC)
   606  	MOVV	R0, 0(R0)
   607  
   608  	// Initialize m->procid to Linux tid
   609  	MOVV	$SYS_gettid, R11
   610  	SYSCALL
   611  
   612  	MOVV	-24(R3), R25		// fn
   613  	MOVV	-16(R3), R24		// g
   614  	MOVV	-8(R3), R23		// m
   615  
   616  	BEQ	R23, nog
   617  	BEQ	R24, nog
   618  
   619  	MOVV	R4, m_procid(R23)
   620  
   621  	// TODO: setup TLS.
   622  
   623  	// In child, set up new stack
   624  	MOVV	R23, g_m(R24)
   625  	MOVV	R24, g
   626  	//CALL	runtime·stackcheck(SB)
   627  
   628  nog:
   629  	// Call fn
   630  	JAL	(R25)
   631  
   632  	// It shouldn't return.	 If it does, exit that thread.
   633  	MOVW	$111, R4
   634  	MOVV	$SYS_exit, R11
   635  	SYSCALL
   636  	JMP	-3(PC)	// keep exiting
   637  
   638  // func sigaltstack(new, old *stackt)
   639  TEXT runtime·sigaltstack<ABIInternal>(SB),NOSPLIT,$0
   640  	MOVV	$SYS_sigaltstack, R11
   641  	SYSCALL
   642  	MOVW	$-4096, R5
   643  	BGEU	R5, R4, 2(PC)
   644  	MOVV	R0, 0xf1(R0)	// crash
   645  	RET
   646  
   647  // func osyield()
   648  TEXT runtime·osyield<ABIInternal>(SB),NOSPLIT,$0
   649  	MOVV	$SYS_sched_yield, R11
   650  	SYSCALL
   651  	RET
   652  
   653  // func sched_getaffinity(pid, len uintptr, buf *uintptr) int32
   654  TEXT runtime·sched_getaffinity<ABIInternal>(SB),NOSPLIT,$0
   655  	MOVV	$SYS_sched_getaffinity, R11
   656  	SYSCALL
   657  	RET
   658  
   659  // func sbrk0() uintptr
   660  TEXT runtime·sbrk0<ABIInternal>(SB),NOSPLIT,$0
   661  	// Implemented as brk(NULL).
   662  	MOVV	$0, R4
   663  	MOVV	$SYS_brk, R11
   664  	SYSCALL
   665  	RET
   666  
   667  // unimplemented, only needed for android; declared in stubs_linux.go
   668  TEXT runtime·access(SB),$0-20
   669  	MOVV	R0, 2(R0)
   670  	MOVW	R0, ret+16(FP) // for vet
   671  	RET
   672  
   673  // unimplemented, only needed for android; declared in stubs_linux.go
   674  TEXT runtime·connect(SB),$0-28
   675  	MOVV	R0, 2(R0)
   676  	MOVW	R0, ret+24(FP) // for vet
   677  	RET
   678  
   679  // unimplemented, only needed for android; declared in stubs_linux.go
   680  TEXT runtime·socket(SB),$0-20
   681  	MOVV	R0, 2(R0)
   682  	MOVW	R0, ret+16(FP) // for vet
   683  	RET
   684  
   685  // func vgetrandom1(buf *byte, length uintptr, flags uint32, state uintptr, stateSize uintptr) int
   686  TEXT runtime·vgetrandom1<ABIInternal>(SB),NOSPLIT,$16
   687  	MOVV	R3, R23
   688  
   689  	MOVV	runtime·vdsoGetrandomSym(SB), R12
   690  
   691  	MOVV	g_m(g), R24
   692  
   693  	MOVV	m_vdsoPC(R24), R13
   694  	MOVV	R13, 8(R3)
   695  	MOVV	m_vdsoSP(R24), R13
   696  	MOVV	R13, 16(R3)
   697  	MOVV	R1, m_vdsoPC(R24)
   698  	MOVV    $buf-8(FP), R13
   699  	MOVV	R13, m_vdsoSP(R24)
   700  
   701  	AND	$~15, R3
   702  
   703  	MOVBU	runtime·iscgo(SB), R13
   704  	BNE	R13, nosaveg
   705  	MOVV	m_gsignal(R24), R13
   706  	BEQ	R13, nosaveg
   707  	BEQ	g, R13, nosaveg
   708  	MOVV	(g_stack+stack_lo)(R13), R25
   709  	MOVV	g, (R25)
   710  
   711  	JAL	(R12)
   712  
   713  	MOVV	R0, (R25)
   714  	JMP	restore
   715  
   716  nosaveg:
   717  	JAL	(R12)
   718  
   719  restore:
   720  	MOVV	R23, R3
   721  	MOVV	16(R3), R25
   722  	MOVV	R25, m_vdsoSP(R24)
   723  	MOVV	8(R3), R25
   724  	MOVV	R25, m_vdsoPC(R24)
   725  	NOP	R4 // Satisfy go vet, since the return value comes from the vDSO function.
   726  	RET
   727  

View as plain text