Text file src/runtime/sys_linux_arm64.s

     1  // Copyright 2014 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 arm64, Linux
     7  //
     8  
     9  #include "go_asm.h"
    10  #include "go_tls.h"
    11  #include "textflag.h"
    12  
    13  #define AT_FDCWD -100
    14  
    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_openat		56
    22  #define SYS_close		57
    23  #define SYS_pipe2		59
    24  #define SYS_fcntl		25
    25  #define SYS_nanosleep		101
    26  #define SYS_mmap		222
    27  #define SYS_munmap		215
    28  #define SYS_setitimer		103
    29  #define SYS_clone		220
    30  #define SYS_sched_yield		124
    31  #define SYS_rt_sigreturn	139
    32  #define SYS_rt_sigaction	134
    33  #define SYS_rt_sigprocmask	135
    34  #define SYS_sigaltstack		132
    35  #define SYS_madvise		233
    36  #define SYS_mincore		232
    37  #define SYS_getpid		172
    38  #define SYS_gettid		178
    39  #define SYS_kill		129
    40  #define SYS_tgkill		131
    41  #define SYS_futex		98
    42  #define SYS_sched_getaffinity	123
    43  #define SYS_exit_group		94
    44  #define SYS_epoll_create1	20
    45  #define SYS_epoll_ctl		21
    46  #define SYS_epoll_pwait		22
    47  #define SYS_clock_gettime	113
    48  #define SYS_faccessat		48
    49  #define SYS_socket		198
    50  #define SYS_connect		203
    51  #define SYS_brk			214
    52  #define SYS_timer_create	107
    53  #define SYS_timer_settime	110
    54  #define SYS_timer_delete	111
    55  
    56  TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
    57  	MOVW	code+0(FP), R0
    58  	MOVD	$SYS_exit_group, R8
    59  	SVC
    60  	RET
    61  
    62  // func exitThread(wait *uint32)
    63  TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
    64  	MOVD	wait+0(FP), R0
    65  	// We're done using the stack.
    66  	MOVW	$0, R1
    67  	STLRW	R1, (R0)
    68  	MOVW	$0, R0	// exit code
    69  	MOVD	$SYS_exit, R8
    70  	SVC
    71  	JMP	0(PC)
    72  
    73  TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
    74  	MOVD	$AT_FDCWD, R0
    75  	MOVD	name+0(FP), R1
    76  	MOVW	mode+8(FP), R2
    77  	MOVW	perm+12(FP), R3
    78  	MOVD	$SYS_openat, R8
    79  	SVC
    80  	CMN	$4095, R0
    81  	BCC	done
    82  	MOVW	$-1, R0
    83  done:
    84  	MOVW	R0, ret+16(FP)
    85  	RET
    86  
    87  TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
    88  	MOVW	fd+0(FP), R0
    89  	MOVD	$SYS_close, R8
    90  	SVC
    91  	CMN	$4095, R0
    92  	BCC	done
    93  	MOVW	$-1, R0
    94  done:
    95  	MOVW	R0, ret+8(FP)
    96  	RET
    97  
    98  TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28
    99  	MOVD	fd+0(FP), R0
   100  	MOVD	p+8(FP), R1
   101  	MOVW	n+16(FP), R2
   102  	MOVD	$SYS_write, R8
   103  	SVC
   104  	MOVW	R0, ret+24(FP)
   105  	RET
   106  
   107  TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
   108  	MOVW	fd+0(FP), R0
   109  	MOVD	p+8(FP), R1
   110  	MOVW	n+16(FP), R2
   111  	MOVD	$SYS_read, R8
   112  	SVC
   113  	MOVW	R0, ret+24(FP)
   114  	RET
   115  
   116  // func pipe() (r, w int32, errno int32)
   117  TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
   118  	MOVD	$r+0(FP), R0
   119  	MOVW	$0, R1
   120  	MOVW	$SYS_pipe2, R8
   121  	SVC
   122  	MOVW	R0, errno+8(FP)
   123  	RET
   124  
   125  // func pipe2(flags int32) (r, w int32, errno int32)
   126  TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
   127  	MOVD	$r+8(FP), R0
   128  	MOVW	flags+0(FP), R1
   129  	MOVW	$SYS_pipe2, R8
   130  	SVC
   131  	MOVW	R0, errno+16(FP)
   132  	RET
   133  
   134  TEXT runtime·usleep(SB),NOSPLIT,$24-4
   135  	MOVWU	usec+0(FP), R3
   136  	MOVD	R3, R5
   137  	MOVW	$1000000, R4
   138  	UDIV	R4, R3
   139  	MOVD	R3, 8(RSP)
   140  	MUL	R3, R4
   141  	SUB	R4, R5
   142  	MOVW	$1000, R4
   143  	MUL	R4, R5
   144  	MOVD	R5, 16(RSP)
   145  
   146  	// nanosleep(&ts, 0)
   147  	ADD	$8, RSP, R0
   148  	MOVD	$0, R1
   149  	MOVD	$SYS_nanosleep, R8
   150  	SVC
   151  	RET
   152  
   153  TEXT runtime·gettid(SB),NOSPLIT,$0-4
   154  	MOVD	$SYS_gettid, R8
   155  	SVC
   156  	MOVW	R0, ret+0(FP)
   157  	RET
   158  
   159  TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
   160  	MOVD	$SYS_getpid, R8
   161  	SVC
   162  	MOVW	R0, R19
   163  	MOVD	$SYS_gettid, R8
   164  	SVC
   165  	MOVW	R0, R1	// arg 2 tid
   166  	MOVW	R19, R0	// arg 1 pid
   167  	MOVW	sig+0(FP), R2	// arg 3
   168  	MOVD	$SYS_tgkill, R8
   169  	SVC
   170  	RET
   171  
   172  TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
   173  	MOVD	$SYS_getpid, R8
   174  	SVC
   175  	MOVW	R0, R0		// arg 1 pid
   176  	MOVW	sig+0(FP), R1	// arg 2
   177  	MOVD	$SYS_kill, R8
   178  	SVC
   179  	RET
   180  
   181  TEXT ·getpid(SB),NOSPLIT|NOFRAME,$0-8
   182  	MOVD	$SYS_getpid, R8
   183  	SVC
   184  	MOVD	R0, ret+0(FP)
   185  	RET
   186  
   187  TEXT ·tgkill(SB),NOSPLIT,$0-24
   188  	MOVD	tgid+0(FP), R0
   189  	MOVD	tid+8(FP), R1
   190  	MOVD	sig+16(FP), R2
   191  	MOVD	$SYS_tgkill, R8
   192  	SVC
   193  	RET
   194  
   195  TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
   196  	MOVW	mode+0(FP), R0
   197  	MOVD	new+8(FP), R1
   198  	MOVD	old+16(FP), R2
   199  	MOVD	$SYS_setitimer, R8
   200  	SVC
   201  	RET
   202  
   203  TEXT runtime·timer_create(SB),NOSPLIT,$0-28
   204  	MOVW	clockid+0(FP), R0
   205  	MOVD	sevp+8(FP), R1
   206  	MOVD	timerid+16(FP), R2
   207  	MOVD	$SYS_timer_create, R8
   208  	SVC
   209  	MOVW	R0, ret+24(FP)
   210  	RET
   211  
   212  TEXT runtime·timer_settime(SB),NOSPLIT,$0-28
   213  	MOVW	timerid+0(FP), R0
   214  	MOVW	flags+4(FP), R1
   215  	MOVD	new+8(FP), R2
   216  	MOVD	old+16(FP), R3
   217  	MOVD	$SYS_timer_settime, R8
   218  	SVC
   219  	MOVW	R0, ret+24(FP)
   220  	RET
   221  
   222  TEXT runtime·timer_delete(SB),NOSPLIT,$0-12
   223  	MOVW	timerid+0(FP), R0
   224  	MOVD	$SYS_timer_delete, R8
   225  	SVC
   226  	MOVW	R0, ret+8(FP)
   227  	RET
   228  
   229  TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28
   230  	MOVD	addr+0(FP), R0
   231  	MOVD	n+8(FP), R1
   232  	MOVD	dst+16(FP), R2
   233  	MOVD	$SYS_mincore, R8
   234  	SVC
   235  	MOVW	R0, ret+24(FP)
   236  	RET
   237  
   238  // func walltime() (sec int64, nsec int32)
   239  TEXT runtime·walltime(SB),NOSPLIT,$24-12
   240  	MOVD	RSP, R20	// R20 is unchanged by C code
   241  	MOVD	RSP, R1
   242  
   243  	MOVD	g_m(g), R21	// R21 = m
   244  
   245  	// Set vdsoPC and vdsoSP for SIGPROF traceback.
   246  	// Save the old values on stack and restore them on exit,
   247  	// so this function is reentrant.
   248  	MOVD	m_vdsoPC(R21), R2
   249  	MOVD	m_vdsoSP(R21), R3
   250  	MOVD	R2, 8(RSP)
   251  	MOVD	R3, 16(RSP)
   252  
   253  	MOVD	$ret-8(FP), R2 // caller's SP
   254  	MOVD	LR, m_vdsoPC(R21)
   255  	MOVD	R2, m_vdsoSP(R21)
   256  
   257  	MOVD	m_curg(R21), R0
   258  	CMP	g, R0
   259  	BNE	noswitch
   260  
   261  	MOVD	m_g0(R21), R3
   262  	MOVD	(g_sched+gobuf_sp)(R3), R1	// Set RSP to g0 stack
   263  
   264  noswitch:
   265  	SUB	$16, R1
   266  	BIC	$15, R1	// Align for C code
   267  	MOVD	R1, RSP
   268  
   269  	MOVW	$CLOCK_REALTIME, R0
   270  	MOVD	runtime·vdsoClockgettimeSym(SB), R2
   271  	CBZ	R2, fallback
   272  
   273  	// Store g on gsignal's stack, so if we receive a signal
   274  	// during VDSO code we can find the g.
   275  	// If we don't have a signal stack, we won't receive signal,
   276  	// so don't bother saving g.
   277  	// When using cgo, we already saved g on TLS, also don't save
   278  	// g here.
   279  	// Also don't save g if we are already on the signal stack.
   280  	// We won't get a nested signal.
   281  	MOVBU	runtime·iscgo(SB), R22
   282  	CBNZ	R22, nosaveg
   283  	MOVD	m_gsignal(R21), R22          // g.m.gsignal
   284  	CBZ	R22, nosaveg
   285  	CMP	g, R22
   286  	BEQ	nosaveg
   287  	MOVD	(g_stack+stack_lo)(R22), R22 // g.m.gsignal.stack.lo
   288  	MOVD	g, (R22)
   289  
   290  	BL	(R2)
   291  
   292  	MOVD	ZR, (R22)  // clear g slot, R22 is unchanged by C code
   293  
   294  	B	finish
   295  
   296  nosaveg:
   297  	BL	(R2)
   298  	B	finish
   299  
   300  fallback:
   301  	MOVD	$SYS_clock_gettime, R8
   302  	SVC
   303  
   304  finish:
   305  	MOVD	0(RSP), R3	// sec
   306  	MOVD	8(RSP), R5	// nsec
   307  
   308  	MOVD	R20, RSP	// restore SP
   309  	// Restore vdsoPC, vdsoSP
   310  	// We don't worry about being signaled between the two stores.
   311  	// If we are not in a signal handler, we'll restore vdsoSP to 0,
   312  	// and no one will care about vdsoPC. If we are in a signal handler,
   313  	// we cannot receive another signal.
   314  	MOVD	16(RSP), R1
   315  	MOVD	R1, m_vdsoSP(R21)
   316  	MOVD	8(RSP), R1
   317  	MOVD	R1, m_vdsoPC(R21)
   318  
   319  	MOVD	R3, sec+0(FP)
   320  	MOVW	R5, nsec+8(FP)
   321  	RET
   322  
   323  TEXT runtime·nanotime1(SB),NOSPLIT,$24-8
   324  	MOVD	RSP, R20	// R20 is unchanged by C code
   325  	MOVD	RSP, R1
   326  
   327  	MOVD	g_m(g), R21	// R21 = m
   328  
   329  	// Set vdsoPC and vdsoSP for SIGPROF traceback.
   330  	// Save the old values on stack and restore them on exit,
   331  	// so this function is reentrant.
   332  	MOVD	m_vdsoPC(R21), R2
   333  	MOVD	m_vdsoSP(R21), R3
   334  	MOVD	R2, 8(RSP)
   335  	MOVD	R3, 16(RSP)
   336  
   337  	MOVD	$ret-8(FP), R2 // caller's SP
   338  	MOVD	LR, m_vdsoPC(R21)
   339  	MOVD	R2, m_vdsoSP(R21)
   340  
   341  	MOVD	m_curg(R21), R0
   342  	CMP	g, R0
   343  	BNE	noswitch
   344  
   345  	MOVD	m_g0(R21), R3
   346  	MOVD	(g_sched+gobuf_sp)(R3), R1	// Set RSP to g0 stack
   347  
   348  noswitch:
   349  	SUB	$32, R1
   350  	BIC	$15, R1
   351  	MOVD	R1, RSP
   352  
   353  	MOVW	$CLOCK_MONOTONIC, R0
   354  	MOVD	runtime·vdsoClockgettimeSym(SB), R2
   355  	CBZ	R2, fallback
   356  
   357  	// Store g on gsignal's stack, so if we receive a signal
   358  	// during VDSO code we can find the g.
   359  	// If we don't have a signal stack, we won't receive signal,
   360  	// so don't bother saving g.
   361  	// When using cgo, we already saved g on TLS, also don't save
   362  	// g here.
   363  	// Also don't save g if we are already on the signal stack.
   364  	// We won't get a nested signal.
   365  	MOVBU	runtime·iscgo(SB), R22
   366  	CBNZ	R22, nosaveg
   367  	MOVD	m_gsignal(R21), R22          // g.m.gsignal
   368  	CBZ	R22, nosaveg
   369  	CMP	g, R22
   370  	BEQ	nosaveg
   371  	MOVD	(g_stack+stack_lo)(R22), R22 // g.m.gsignal.stack.lo
   372  	MOVD	g, (R22)
   373  
   374  	BL	(R2)
   375  
   376  	MOVD	ZR, (R22)  // clear g slot, R22 is unchanged by C code
   377  
   378  	B	finish
   379  
   380  nosaveg:
   381  	BL	(R2)
   382  	B	finish
   383  
   384  fallback:
   385  	MOVD	$SYS_clock_gettime, R8
   386  	SVC
   387  
   388  finish:
   389  	MOVD	0(RSP), R3	// sec
   390  	MOVD	8(RSP), R5	// nsec
   391  
   392  	MOVD	R20, RSP	// restore SP
   393  	// Restore vdsoPC, vdsoSP
   394  	// We don't worry about being signaled between the two stores.
   395  	// If we are not in a signal handler, we'll restore vdsoSP to 0,
   396  	// and no one will care about vdsoPC. If we are in a signal handler,
   397  	// we cannot receive another signal.
   398  	MOVD	16(RSP), R1
   399  	MOVD	R1, m_vdsoSP(R21)
   400  	MOVD	8(RSP), R1
   401  	MOVD	R1, m_vdsoPC(R21)
   402  
   403  	// sec is in R3, nsec in R5
   404  	// return nsec in R3
   405  	MOVD	$1000000000, R4
   406  	MUL	R4, R3
   407  	ADD	R5, R3
   408  	MOVD	R3, ret+0(FP)
   409  	RET
   410  
   411  TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
   412  	MOVW	how+0(FP), R0
   413  	MOVD	new+8(FP), R1
   414  	MOVD	old+16(FP), R2
   415  	MOVW	size+24(FP), R3
   416  	MOVD	$SYS_rt_sigprocmask, R8
   417  	SVC
   418  	CMN	$4095, R0
   419  	BCC	done
   420  	MOVD	$0, R0
   421  	MOVD	R0, (R0)	// crash
   422  done:
   423  	RET
   424  
   425  TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
   426  	MOVD	sig+0(FP), R0
   427  	MOVD	new+8(FP), R1
   428  	MOVD	old+16(FP), R2
   429  	MOVD	size+24(FP), R3
   430  	MOVD	$SYS_rt_sigaction, R8
   431  	SVC
   432  	MOVW	R0, ret+32(FP)
   433  	RET
   434  
   435  // Call the function stored in _cgo_sigaction using the GCC calling convention.
   436  TEXT runtime·callCgoSigaction(SB),NOSPLIT,$0
   437  	MOVD	sig+0(FP), R0
   438  	MOVD	new+8(FP), R1
   439  	MOVD	old+16(FP), R2
   440  	MOVD	 _cgo_sigaction(SB), R3
   441  	SUB	$16, RSP		// reserve 16 bytes for sp-8 where fp may be saved.
   442  	BL	R3
   443  	ADD	$16, RSP
   444  	MOVW	R0, ret+24(FP)
   445  	RET
   446  
   447  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   448  	MOVW	sig+8(FP), R0
   449  	MOVD	info+16(FP), R1
   450  	MOVD	ctx+24(FP), R2
   451  	MOVD	fn+0(FP), R11
   452  	BL	(R11)
   453  	RET
   454  
   455  TEXT runtime·sigtramp(SB),NOSPLIT,$192
   456  	// Save callee-save registers in the case of signal forwarding.
   457  	// Please refer to https://golang.org/issue/31827 .
   458  	MOVD	R19, 8*4(RSP)
   459  	MOVD	R20, 8*5(RSP)
   460  	MOVD	R21, 8*6(RSP)
   461  	MOVD	R22, 8*7(RSP)
   462  	MOVD	R23, 8*8(RSP)
   463  	MOVD	R24, 8*9(RSP)
   464  	MOVD	R25, 8*10(RSP)
   465  	MOVD	R26, 8*11(RSP)
   466  	MOVD	R27, 8*12(RSP)
   467  	MOVD	g, 8*13(RSP)
   468  	MOVD	R29, 8*14(RSP)
   469  	FMOVD	F8, 8*15(RSP)
   470  	FMOVD	F9, 8*16(RSP)
   471  	FMOVD	F10, 8*17(RSP)
   472  	FMOVD	F11, 8*18(RSP)
   473  	FMOVD	F12, 8*19(RSP)
   474  	FMOVD	F13, 8*20(RSP)
   475  	FMOVD	F14, 8*21(RSP)
   476  	FMOVD	F15, 8*22(RSP)
   477  
   478  	// this might be called in external code context,
   479  	// where g is not set.
   480  	// first save R0, because runtime·load_g will clobber it
   481  	MOVW	R0, 8(RSP)
   482  	MOVBU	runtime·iscgo(SB), R0
   483  	CBZ	R0, 2(PC)
   484  	BL	runtime·load_g(SB)
   485  
   486  	MOVD	R1, 16(RSP)
   487  	MOVD	R2, 24(RSP)
   488  	MOVD	$runtime·sigtrampgo(SB), R0
   489  	BL	(R0)
   490  
   491  	// Restore callee-save registers.
   492  	MOVD	8*4(RSP), R19
   493  	MOVD	8*5(RSP), R20
   494  	MOVD	8*6(RSP), R21
   495  	MOVD	8*7(RSP), R22
   496  	MOVD	8*8(RSP), R23
   497  	MOVD	8*9(RSP), R24
   498  	MOVD	8*10(RSP), R25
   499  	MOVD	8*11(RSP), R26
   500  	MOVD	8*12(RSP), R27
   501  	MOVD	8*13(RSP), g
   502  	MOVD	8*14(RSP), R29
   503  	FMOVD	8*15(RSP), F8
   504  	FMOVD	8*16(RSP), F9
   505  	FMOVD	8*17(RSP), F10
   506  	FMOVD	8*18(RSP), F11
   507  	FMOVD	8*19(RSP), F12
   508  	FMOVD	8*20(RSP), F13
   509  	FMOVD	8*21(RSP), F14
   510  	FMOVD	8*22(RSP), F15
   511  
   512  	RET
   513  
   514  TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   515  	MOVD	$runtime·sigtramp(SB), R3
   516  	B	(R3)
   517  
   518  TEXT runtime·sysMmap(SB),NOSPLIT|NOFRAME,$0
   519  	MOVD	addr+0(FP), R0
   520  	MOVD	n+8(FP), R1
   521  	MOVW	prot+16(FP), R2
   522  	MOVW	flags+20(FP), R3
   523  	MOVW	fd+24(FP), R4
   524  	MOVW	off+28(FP), R5
   525  
   526  	MOVD	$SYS_mmap, R8
   527  	SVC
   528  	CMN	$4095, R0
   529  	BCC	ok
   530  	NEG	R0,R0
   531  	MOVD	$0, p+32(FP)
   532  	MOVD	R0, err+40(FP)
   533  	RET
   534  ok:
   535  	MOVD	R0, p+32(FP)
   536  	MOVD	$0, err+40(FP)
   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  TEXT runtime·callCgoMmap(SB),NOSPLIT,$0
   542  	MOVD	addr+0(FP), R0
   543  	MOVD	n+8(FP), R1
   544  	MOVW	prot+16(FP), R2
   545  	MOVW	flags+20(FP), R3
   546  	MOVW	fd+24(FP), R4
   547  	MOVW	off+28(FP), R5
   548  	MOVD	_cgo_mmap(SB), R9
   549  	SUB	$16, RSP		// reserve 16 bytes for sp-8 where fp may be saved.
   550  	BL	R9
   551  	ADD	$16, RSP
   552  	MOVD	R0, ret+32(FP)
   553  	RET
   554  
   555  TEXT runtime·sysMunmap(SB),NOSPLIT|NOFRAME,$0
   556  	MOVD	addr+0(FP), R0
   557  	MOVD	n+8(FP), R1
   558  	MOVD	$SYS_munmap, R8
   559  	SVC
   560  	CMN	$4095, R0
   561  	BCC	cool
   562  	MOVD	R0, 0xf0(R0)
   563  cool:
   564  	RET
   565  
   566  // Call the function stored in _cgo_munmap using the GCC calling convention.
   567  // This must be called on the system stack.
   568  TEXT runtime·callCgoMunmap(SB),NOSPLIT,$0
   569  	MOVD	addr+0(FP), R0
   570  	MOVD	n+8(FP), R1
   571  	MOVD	_cgo_munmap(SB), R9
   572  	SUB	$16, RSP		// reserve 16 bytes for sp-8 where fp may be saved.
   573  	BL	R9
   574  	ADD	$16, RSP
   575  	RET
   576  
   577  TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
   578  	MOVD	addr+0(FP), R0
   579  	MOVD	n+8(FP), R1
   580  	MOVW	flags+16(FP), R2
   581  	MOVD	$SYS_madvise, R8
   582  	SVC
   583  	MOVW	R0, ret+24(FP)
   584  	RET
   585  
   586  // int64 futex(int32 *uaddr, int32 op, int32 val,
   587  //	struct timespec *timeout, int32 *uaddr2, int32 val2);
   588  TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
   589  	MOVD	addr+0(FP), R0
   590  	MOVW	op+8(FP), R1
   591  	MOVW	val+12(FP), R2
   592  	MOVD	ts+16(FP), R3
   593  	MOVD	addr2+24(FP), R4
   594  	MOVW	val3+32(FP), R5
   595  	MOVD	$SYS_futex, R8
   596  	SVC
   597  	MOVW	R0, ret+40(FP)
   598  	RET
   599  
   600  // int64 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   601  TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
   602  	MOVW	flags+0(FP), R0
   603  	MOVD	stk+8(FP), R1
   604  
   605  	// Copy mp, gp, fn off parent stack for use by child.
   606  	MOVD	mp+16(FP), R10
   607  	MOVD	gp+24(FP), R11
   608  	MOVD	fn+32(FP), R12
   609  
   610  	MOVD	R10, -8(R1)
   611  	MOVD	R11, -16(R1)
   612  	MOVD	R12, -24(R1)
   613  	MOVD	$1234, R10
   614  	MOVD	R10, -32(R1)
   615  
   616  	MOVD	$SYS_clone, R8
   617  	SVC
   618  
   619  	// In parent, return.
   620  	CMP	ZR, R0
   621  	BEQ	child
   622  	MOVW	R0, ret+40(FP)
   623  	RET
   624  child:
   625  
   626  	// In child, on new stack.
   627  	MOVD	-32(RSP), R10
   628  	MOVD	$1234, R0
   629  	CMP	R0, R10
   630  	BEQ	good
   631  	MOVD	$0, R0
   632  	MOVD	R0, (R0)	// crash
   633  
   634  good:
   635  	// Initialize m->procid to Linux tid
   636  	MOVD	$SYS_gettid, R8
   637  	SVC
   638  
   639  	MOVD	-24(RSP), R12     // fn
   640  	MOVD	-16(RSP), R11     // g
   641  	MOVD	-8(RSP), R10      // m
   642  
   643  	CMP	$0, R10
   644  	BEQ	nog
   645  	CMP	$0, R11
   646  	BEQ	nog
   647  
   648  	MOVD	R0, m_procid(R10)
   649  
   650  	// TODO: setup TLS.
   651  
   652  	// In child, set up new stack
   653  	MOVD	R10, g_m(R11)
   654  	MOVD	R11, g
   655  	//CALL	runtime·stackcheck(SB)
   656  
   657  nog:
   658  	// Call fn
   659  	MOVD	R12, R0
   660  	BL	(R0)
   661  
   662  	// It shouldn't return.	 If it does, exit that thread.
   663  	MOVW	$111, R0
   664  again:
   665  	MOVD	$SYS_exit, R8
   666  	SVC
   667  	B	again	// keep exiting
   668  
   669  TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
   670  	MOVD	new+0(FP), R0
   671  	MOVD	old+8(FP), R1
   672  	MOVD	$SYS_sigaltstack, R8
   673  	SVC
   674  	CMN	$4095, R0
   675  	BCC	ok
   676  	MOVD	$0, R0
   677  	MOVD	R0, (R0)	// crash
   678  ok:
   679  	RET
   680  
   681  TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
   682  	MOVD	$SYS_sched_yield, R8
   683  	SVC
   684  	RET
   685  
   686  TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
   687  	MOVD	pid+0(FP), R0
   688  	MOVD	len+8(FP), R1
   689  	MOVD	buf+16(FP), R2
   690  	MOVD	$SYS_sched_getaffinity, R8
   691  	SVC
   692  	MOVW	R0, ret+24(FP)
   693  	RET
   694  
   695  // int32 runtime·epollcreate(int32 size);
   696  TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
   697  	MOVW	$0, R0
   698  	MOVD	$SYS_epoll_create1, R8
   699  	SVC
   700  	MOVW	R0, ret+8(FP)
   701  	RET
   702  
   703  // int32 runtime·epollcreate1(int32 flags);
   704  TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
   705  	MOVW	flags+0(FP), R0
   706  	MOVD	$SYS_epoll_create1, R8
   707  	SVC
   708  	MOVW	R0, ret+8(FP)
   709  	RET
   710  
   711  // func epollctl(epfd, op, fd int32, ev *epollEvent) int
   712  TEXT runtime·epollctl(SB),NOSPLIT|NOFRAME,$0
   713  	MOVW	epfd+0(FP), R0
   714  	MOVW	op+4(FP), R1
   715  	MOVW	fd+8(FP), R2
   716  	MOVD	ev+16(FP), R3
   717  	MOVD	$SYS_epoll_ctl, R8
   718  	SVC
   719  	MOVW	R0, ret+24(FP)
   720  	RET
   721  
   722  // int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
   723  TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
   724  	MOVW	epfd+0(FP), R0
   725  	MOVD	ev+8(FP), R1
   726  	MOVW	nev+16(FP), R2
   727  	MOVW	timeout+20(FP), R3
   728  	MOVD	$0, R4
   729  	MOVD	$SYS_epoll_pwait, R8
   730  	SVC
   731  	MOVW	R0, ret+24(FP)
   732  	RET
   733  
   734  // void runtime·closeonexec(int32 fd);
   735  TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
   736  	MOVW	fd+0(FP), R0  // fd
   737  	MOVD	$2, R1	// F_SETFD
   738  	MOVD	$1, R2	// FD_CLOEXEC
   739  	MOVD	$SYS_fcntl, R8
   740  	SVC
   741  	RET
   742  
   743  // func runtime·setNonblock(int32 fd)
   744  TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
   745  	MOVW	fd+0(FP), R0 // fd
   746  	MOVD	$3, R1	// F_GETFL
   747  	MOVD	$0, R2
   748  	MOVD	$SYS_fcntl, R8
   749  	SVC
   750  	MOVD	$0x800, R2 // O_NONBLOCK
   751  	ORR	R0, R2
   752  	MOVW	fd+0(FP), R0 // fd
   753  	MOVD	$4, R1	// F_SETFL
   754  	MOVD	$SYS_fcntl, R8
   755  	SVC
   756  	RET
   757  
   758  // int access(const char *name, int mode)
   759  TEXT runtime·access(SB),NOSPLIT,$0-20
   760  	MOVD	$AT_FDCWD, R0
   761  	MOVD	name+0(FP), R1
   762  	MOVW	mode+8(FP), R2
   763  	MOVD	$SYS_faccessat, R8
   764  	SVC
   765  	MOVW	R0, ret+16(FP)
   766  	RET
   767  
   768  // int connect(int fd, const struct sockaddr *addr, socklen_t len)
   769  TEXT runtime·connect(SB),NOSPLIT,$0-28
   770  	MOVW	fd+0(FP), R0
   771  	MOVD	addr+8(FP), R1
   772  	MOVW	len+16(FP), R2
   773  	MOVD	$SYS_connect, R8
   774  	SVC
   775  	MOVW	R0, ret+24(FP)
   776  	RET
   777  
   778  // int socket(int domain, int typ, int prot)
   779  TEXT runtime·socket(SB),NOSPLIT,$0-20
   780  	MOVW	domain+0(FP), R0
   781  	MOVW	typ+4(FP), R1
   782  	MOVW	prot+8(FP), R2
   783  	MOVD	$SYS_socket, R8
   784  	SVC
   785  	MOVW	R0, ret+16(FP)
   786  	RET
   787  
   788  // func sbrk0() uintptr
   789  TEXT runtime·sbrk0(SB),NOSPLIT,$0-8
   790  	// Implemented as brk(NULL).
   791  	MOVD	$0, R0
   792  	MOVD	$SYS_brk, R8
   793  	SVC
   794  	MOVD	R0, ret+0(FP)
   795  	RET
   796  
   797  TEXT runtime·sigreturn(SB),NOSPLIT,$0-0
   798  	RET
   799  

View as plain text