Text file src/runtime/sys_linux_arm.s

     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  //
     6  // System calls and other sys.stuff for arm, Linux
     7  //
     8  
     9  #include "go_asm.h"
    10  #include "go_tls.h"
    11  #include "textflag.h"
    12  
    13  #define CLOCK_REALTIME	0
    14  #define CLOCK_MONOTONIC	1
    15  
    16  // for EABI, as we don't support OABI
    17  #define SYS_BASE 0x0
    18  
    19  #define SYS_exit (SYS_BASE + 1)
    20  #define SYS_read (SYS_BASE + 3)
    21  #define SYS_write (SYS_BASE + 4)
    22  #define SYS_open (SYS_BASE + 5)
    23  #define SYS_close (SYS_BASE + 6)
    24  #define SYS_getpid (SYS_BASE + 20)
    25  #define SYS_kill (SYS_BASE + 37)
    26  #define SYS_clone (SYS_BASE + 120)
    27  #define SYS_rt_sigreturn (SYS_BASE + 173)
    28  #define SYS_rt_sigaction (SYS_BASE + 174)
    29  #define SYS_rt_sigprocmask (SYS_BASE + 175)
    30  #define SYS_sigaltstack (SYS_BASE + 186)
    31  #define SYS_mmap2 (SYS_BASE + 192)
    32  #define SYS_futex (SYS_BASE + 240)
    33  #define SYS_exit_group (SYS_BASE + 248)
    34  #define SYS_munmap (SYS_BASE + 91)
    35  #define SYS_madvise (SYS_BASE + 220)
    36  #define SYS_setitimer (SYS_BASE + 104)
    37  #define SYS_mincore (SYS_BASE + 219)
    38  #define SYS_gettid (SYS_BASE + 224)
    39  #define SYS_tgkill (SYS_BASE + 268)
    40  #define SYS_sched_yield (SYS_BASE + 158)
    41  #define SYS_nanosleep (SYS_BASE + 162)
    42  #define SYS_sched_getaffinity (SYS_BASE + 242)
    43  #define SYS_clock_gettime (SYS_BASE + 263)
    44  #define SYS_epoll_create (SYS_BASE + 250)
    45  #define SYS_epoll_ctl (SYS_BASE + 251)
    46  #define SYS_epoll_wait (SYS_BASE + 252)
    47  #define SYS_timer_create (SYS_BASE + 257)
    48  #define SYS_timer_settime (SYS_BASE + 258)
    49  #define SYS_timer_delete (SYS_BASE + 261)
    50  #define SYS_epoll_create1 (SYS_BASE + 357)
    51  #define SYS_pipe2 (SYS_BASE + 359)
    52  #define SYS_fcntl (SYS_BASE + 55)
    53  #define SYS_access (SYS_BASE + 33)
    54  #define SYS_connect (SYS_BASE + 283)
    55  #define SYS_socket (SYS_BASE + 281)
    56  #define SYS_brk (SYS_BASE + 45)
    57  
    58  #define ARM_BASE (SYS_BASE + 0x0f0000)
    59  
    60  TEXT runtime·open(SB),NOSPLIT,$0
    61  	MOVW	name+0(FP), R0
    62  	MOVW	mode+4(FP), R1
    63  	MOVW	perm+8(FP), R2
    64  	MOVW	$SYS_open, R7
    65  	SWI	$0
    66  	MOVW	$0xfffff001, R1
    67  	CMP	R1, R0
    68  	MOVW.HI	$-1, R0
    69  	MOVW	R0, ret+12(FP)
    70  	RET
    71  
    72  TEXT runtime·closefd(SB),NOSPLIT,$0
    73  	MOVW	fd+0(FP), R0
    74  	MOVW	$SYS_close, R7
    75  	SWI	$0
    76  	MOVW	$0xfffff001, R1
    77  	CMP	R1, R0
    78  	MOVW.HI	$-1, R0
    79  	MOVW	R0, ret+4(FP)
    80  	RET
    81  
    82  TEXT runtime·write1(SB),NOSPLIT,$0
    83  	MOVW	fd+0(FP), R0
    84  	MOVW	p+4(FP), R1
    85  	MOVW	n+8(FP), R2
    86  	MOVW	$SYS_write, R7
    87  	SWI	$0
    88  	MOVW	R0, ret+12(FP)
    89  	RET
    90  
    91  TEXT runtime·read(SB),NOSPLIT,$0
    92  	MOVW	fd+0(FP), R0
    93  	MOVW	p+4(FP), R1
    94  	MOVW	n+8(FP), R2
    95  	MOVW	$SYS_read, R7
    96  	SWI	$0
    97  	MOVW	R0, ret+12(FP)
    98  	RET
    99  
   100  // func pipe2(flags int32) (r, w int32, errno int32)
   101  TEXT runtime·pipe2(SB),NOSPLIT,$0-16
   102  	MOVW	$r+4(FP), R0
   103  	MOVW	flags+0(FP), R1
   104  	MOVW	$SYS_pipe2, R7
   105  	SWI	$0
   106  	MOVW	R0, errno+12(FP)
   107  	RET
   108  
   109  TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0
   110  	MOVW	code+0(FP), R0
   111  	MOVW	$SYS_exit_group, R7
   112  	SWI	$0
   113  	MOVW	$1234, R0
   114  	MOVW	$1002, R1
   115  	MOVW	R0, (R1)	// fail hard
   116  
   117  TEXT exit1<>(SB),NOSPLIT|NOFRAME,$0
   118  	MOVW	code+0(FP), R0
   119  	MOVW	$SYS_exit, R7
   120  	SWI	$0
   121  	MOVW	$1234, R0
   122  	MOVW	$1003, R1
   123  	MOVW	R0, (R1)	// fail hard
   124  
   125  // func exitThread(wait *uint32)
   126  TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-4
   127  	MOVW	wait+0(FP), R0
   128  	// We're done using the stack.
   129  	// Alas, there's no reliable way to make this write atomic
   130  	// without potentially using the stack. So it goes.
   131  	MOVW	$0, R1
   132  	MOVW	R1, (R0)
   133  	MOVW	$0, R0	// exit code
   134  	MOVW	$SYS_exit, R7
   135  	SWI	$0
   136  	MOVW	$1234, R0
   137  	MOVW	$1004, R1
   138  	MOVW	R0, (R1)	// fail hard
   139  	JMP	0(PC)
   140  
   141  TEXT runtime·gettid(SB),NOSPLIT,$0-4
   142  	MOVW	$SYS_gettid, R7
   143  	SWI	$0
   144  	MOVW	R0, ret+0(FP)
   145  	RET
   146  
   147  TEXT	runtime·raise(SB),NOSPLIT|NOFRAME,$0
   148  	MOVW	$SYS_getpid, R7
   149  	SWI	$0
   150  	MOVW	R0, R4
   151  	MOVW	$SYS_gettid, R7
   152  	SWI	$0
   153  	MOVW	R0, R1	// arg 2 tid
   154  	MOVW	R4, R0	// arg 1 pid
   155  	MOVW	sig+0(FP), R2	// arg 3
   156  	MOVW	$SYS_tgkill, R7
   157  	SWI	$0
   158  	RET
   159  
   160  TEXT	runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
   161  	MOVW	$SYS_getpid, R7
   162  	SWI	$0
   163  	// arg 1 tid already in R0 from getpid
   164  	MOVW	sig+0(FP), R1	// arg 2 - signal
   165  	MOVW	$SYS_kill, R7
   166  	SWI	$0
   167  	RET
   168  
   169  TEXT ·getpid(SB),NOSPLIT,$0-4
   170  	MOVW	$SYS_getpid, R7
   171  	SWI	$0
   172  	MOVW	R0, ret+0(FP)
   173  	RET
   174  
   175  TEXT ·tgkill(SB),NOSPLIT,$0-12
   176  	MOVW	tgid+0(FP), R0
   177  	MOVW	tid+4(FP), R1
   178  	MOVW	sig+8(FP), R2
   179  	MOVW	$SYS_tgkill, R7
   180  	SWI	$0
   181  	RET
   182  
   183  TEXT runtime·mmap(SB),NOSPLIT,$0
   184  	MOVW	addr+0(FP), R0
   185  	MOVW	n+4(FP), R1
   186  	MOVW	prot+8(FP), R2
   187  	MOVW	flags+12(FP), R3
   188  	MOVW	fd+16(FP), R4
   189  	MOVW	off+20(FP), R5
   190  	MOVW	$SYS_mmap2, R7
   191  	SWI	$0
   192  	MOVW	$0xfffff001, R6
   193  	CMP		R6, R0
   194  	MOVW	$0, R1
   195  	RSB.HI	$0, R0
   196  	MOVW.HI	R0, R1		// if error, put in R1
   197  	MOVW.HI	$0, R0
   198  	MOVW	R0, p+24(FP)
   199  	MOVW	R1, err+28(FP)
   200  	RET
   201  
   202  TEXT runtime·munmap(SB),NOSPLIT,$0
   203  	MOVW	addr+0(FP), R0
   204  	MOVW	n+4(FP), R1
   205  	MOVW	$SYS_munmap, R7
   206  	SWI	$0
   207  	MOVW	$0xfffff001, R6
   208  	CMP 	R6, R0
   209  	MOVW.HI	$0, R8  // crash on syscall failure
   210  	MOVW.HI	R8, (R8)
   211  	RET
   212  
   213  TEXT runtime·madvise(SB),NOSPLIT,$0
   214  	MOVW	addr+0(FP), R0
   215  	MOVW	n+4(FP), R1
   216  	MOVW	flags+8(FP), R2
   217  	MOVW	$SYS_madvise, R7
   218  	SWI	$0
   219  	MOVW	R0, ret+12(FP)
   220  	RET
   221  
   222  TEXT runtime·setitimer(SB),NOSPLIT,$0
   223  	MOVW	mode+0(FP), R0
   224  	MOVW	new+4(FP), R1
   225  	MOVW	old+8(FP), R2
   226  	MOVW	$SYS_setitimer, R7
   227  	SWI	$0
   228  	RET
   229  
   230  TEXT runtime·timer_create(SB),NOSPLIT,$0-16
   231  	MOVW	clockid+0(FP), R0
   232  	MOVW	sevp+4(FP), R1
   233  	MOVW	timerid+8(FP), R2
   234  	MOVW	$SYS_timer_create, R7
   235  	SWI	$0
   236  	MOVW	R0, ret+12(FP)
   237  	RET
   238  
   239  TEXT runtime·timer_settime(SB),NOSPLIT,$0-20
   240  	MOVW	timerid+0(FP), R0
   241  	MOVW	flags+4(FP), R1
   242  	MOVW	new+8(FP), R2
   243  	MOVW	old+12(FP), R3
   244  	MOVW	$SYS_timer_settime, R7
   245  	SWI	$0
   246  	MOVW	R0, ret+16(FP)
   247  	RET
   248  
   249  TEXT runtime·timer_delete(SB),NOSPLIT,$0-8
   250  	MOVW	timerid+0(FP), R0
   251  	MOVW	$SYS_timer_delete, R7
   252  	SWI	$0
   253  	MOVW	R0, ret+4(FP)
   254  	RET
   255  
   256  TEXT runtime·mincore(SB),NOSPLIT,$0
   257  	MOVW	addr+0(FP), R0
   258  	MOVW	n+4(FP), R1
   259  	MOVW	dst+8(FP), R2
   260  	MOVW	$SYS_mincore, R7
   261  	SWI	$0
   262  	MOVW	R0, ret+12(FP)
   263  	RET
   264  
   265  TEXT runtime·walltime(SB),NOSPLIT,$8-12
   266  	// We don't know how much stack space the VDSO code will need,
   267  	// so switch to g0.
   268  
   269  	// Save old SP. Use R13 instead of SP to avoid linker rewriting the offsets.
   270  	MOVW	R13, R4	// R4 is unchanged by C code.
   271  
   272  	MOVW	g_m(g), R5 // R5 is unchanged by C code.
   273  
   274  	// Set vdsoPC and vdsoSP for SIGPROF traceback.
   275  	// Save the old values on stack and restore them on exit,
   276  	// so this function is reentrant.
   277  	MOVW	m_vdsoPC(R5), R1
   278  	MOVW	m_vdsoSP(R5), R2
   279  	MOVW	R1, 4(R13)
   280  	MOVW	R2, 8(R13)
   281  
   282  	MOVW	$ret-4(FP), R2 // caller's SP
   283  	MOVW	LR, m_vdsoPC(R5)
   284  	MOVW	R2, m_vdsoSP(R5)
   285  
   286  	MOVW	m_curg(R5), R0
   287  
   288  	CMP	g, R0		// Only switch if on curg.
   289  	B.NE	noswitch
   290  
   291  	MOVW	m_g0(R5), R0
   292  	MOVW	(g_sched+gobuf_sp)(R0), R13	 // Set SP to g0 stack
   293  
   294  noswitch:
   295  	SUB	$24, R13	// Space for results
   296  	BIC	$0x7, R13	// Align for C code
   297  
   298  	MOVW	$CLOCK_REALTIME, R0
   299  	MOVW	$8(R13), R1	// timespec
   300  	MOVW	runtime·vdsoClockgettimeSym(SB), R2
   301  	CMP	$0, R2
   302  	B.EQ	fallback
   303  
   304  	// Store g on gsignal's stack, so if we receive a signal
   305  	// during VDSO code we can find the g.
   306  	// If we don't have a signal stack, we won't receive signal,
   307  	// so don't bother saving g.
   308  	// When using cgo, we already saved g on TLS, also don't save
   309  	// g here.
   310  	// Also don't save g if we are already on the signal stack.
   311  	// We won't get a nested signal.
   312  	MOVB	runtime·iscgo(SB), R6
   313  	CMP	$0, R6
   314  	BNE	nosaveg
   315  	MOVW	m_gsignal(R5), R6          // g.m.gsignal
   316  	CMP	$0, R6
   317  	BEQ	nosaveg
   318  	CMP	g, R6
   319  	BEQ	nosaveg
   320  	MOVW	(g_stack+stack_lo)(R6), R6 // g.m.gsignal.stack.lo
   321  	MOVW	g, (R6)
   322  
   323  	BL	(R2)
   324  
   325  	MOVW	$0, R1
   326  	MOVW	R1, (R6) // clear g slot, R6 is unchanged by C code
   327  
   328  	JMP	finish
   329  
   330  nosaveg:
   331  	BL	(R2)
   332  	JMP	finish
   333  
   334  fallback:
   335  	MOVW	$SYS_clock_gettime, R7
   336  	SWI	$0
   337  
   338  finish:
   339  	MOVW	8(R13), R0  // sec
   340  	MOVW	12(R13), R2  // nsec
   341  
   342  	MOVW	R4, R13		// Restore real SP
   343  	// Restore vdsoPC, vdsoSP
   344  	// We don't worry about being signaled between the two stores.
   345  	// If we are not in a signal handler, we'll restore vdsoSP to 0,
   346  	// and no one will care about vdsoPC. If we are in a signal handler,
   347  	// we cannot receive another signal.
   348  	MOVW	8(R13), R1
   349  	MOVW	R1, m_vdsoSP(R5)
   350  	MOVW	4(R13), R1
   351  	MOVW	R1, m_vdsoPC(R5)
   352  
   353  	MOVW	R0, sec_lo+0(FP)
   354  	MOVW	$0, R1
   355  	MOVW	R1, sec_hi+4(FP)
   356  	MOVW	R2, nsec+8(FP)
   357  	RET
   358  
   359  // int64 nanotime1(void)
   360  TEXT runtime·nanotime1(SB),NOSPLIT,$8-8
   361  	// Switch to g0 stack. See comment above in runtime·walltime.
   362  
   363  	// Save old SP. Use R13 instead of SP to avoid linker rewriting the offsets.
   364  	MOVW	R13, R4	// R4 is unchanged by C code.
   365  
   366  	MOVW	g_m(g), R5 // R5 is unchanged by C code.
   367  
   368  	// Set vdsoPC and vdsoSP for SIGPROF traceback.
   369  	// Save the old values on stack and restore them on exit,
   370  	// so this function is reentrant.
   371  	MOVW	m_vdsoPC(R5), R1
   372  	MOVW	m_vdsoSP(R5), R2
   373  	MOVW	R1, 4(R13)
   374  	MOVW	R2, 8(R13)
   375  
   376  	MOVW	$ret-4(FP), R2 // caller's SP
   377  	MOVW	LR, m_vdsoPC(R5)
   378  	MOVW	R2, m_vdsoSP(R5)
   379  
   380  	MOVW	m_curg(R5), R0
   381  
   382  	CMP	g, R0		// Only switch if on curg.
   383  	B.NE	noswitch
   384  
   385  	MOVW	m_g0(R5), R0
   386  	MOVW	(g_sched+gobuf_sp)(R0), R13	// Set SP to g0 stack
   387  
   388  noswitch:
   389  	SUB	$24, R13	// Space for results
   390  	BIC	$0x7, R13	// Align for C code
   391  
   392  	MOVW	$CLOCK_MONOTONIC, R0
   393  	MOVW	$8(R13), R1	// timespec
   394  	MOVW	runtime·vdsoClockgettimeSym(SB), R2
   395  	CMP	$0, R2
   396  	B.EQ	fallback
   397  
   398  	// Store g on gsignal's stack, so if we receive a signal
   399  	// during VDSO code we can find the g.
   400  	// If we don't have a signal stack, we won't receive signal,
   401  	// so don't bother saving g.
   402  	// When using cgo, we already saved g on TLS, also don't save
   403  	// g here.
   404  	// Also don't save g if we are already on the signal stack.
   405  	// We won't get a nested signal.
   406  	MOVB	runtime·iscgo(SB), R6
   407  	CMP	$0, R6
   408  	BNE	nosaveg
   409  	MOVW	m_gsignal(R5), R6          // g.m.gsignal
   410  	CMP	$0, R6
   411  	BEQ	nosaveg
   412  	CMP	g, R6
   413  	BEQ	nosaveg
   414  	MOVW	(g_stack+stack_lo)(R6), R6 // g.m.gsignal.stack.lo
   415  	MOVW	g, (R6)
   416  
   417  	BL	(R2)
   418  
   419  	MOVW	$0, R1
   420  	MOVW	R1, (R6) // clear g slot, R6 is unchanged by C code
   421  
   422  	JMP	finish
   423  
   424  nosaveg:
   425  	BL	(R2)
   426  	JMP	finish
   427  
   428  fallback:
   429  	MOVW	$SYS_clock_gettime, R7
   430  	SWI	$0
   431  
   432  finish:
   433  	MOVW	8(R13), R0	// sec
   434  	MOVW	12(R13), R2	// nsec
   435  
   436  	MOVW	R4, R13		// Restore real SP
   437  	// Restore vdsoPC, vdsoSP
   438  	// We don't worry about being signaled between the two stores.
   439  	// If we are not in a signal handler, we'll restore vdsoSP to 0,
   440  	// and no one will care about vdsoPC. If we are in a signal handler,
   441  	// we cannot receive another signal.
   442  	MOVW	8(R13), R4
   443  	MOVW	R4, m_vdsoSP(R5)
   444  	MOVW	4(R13), R4
   445  	MOVW	R4, m_vdsoPC(R5)
   446  
   447  	MOVW	$1000000000, R3
   448  	MULLU	R0, R3, (R1, R0)
   449  	ADD.S	R2, R0
   450  	ADC	$0, R1	// Add carry bit to upper half.
   451  
   452  	MOVW	R0, ret_lo+0(FP)
   453  	MOVW	R1, ret_hi+4(FP)
   454  	RET
   455  
   456  // int32 futex(int32 *uaddr, int32 op, int32 val,
   457  //	struct timespec *timeout, int32 *uaddr2, int32 val2);
   458  TEXT runtime·futex(SB),NOSPLIT,$0
   459  	MOVW    addr+0(FP), R0
   460  	MOVW    op+4(FP), R1
   461  	MOVW    val+8(FP), R2
   462  	MOVW    ts+12(FP), R3
   463  	MOVW    addr2+16(FP), R4
   464  	MOVW    val3+20(FP), R5
   465  	MOVW	$SYS_futex, R7
   466  	SWI	$0
   467  	MOVW	R0, ret+24(FP)
   468  	RET
   469  
   470  // int32 clone(int32 flags, void *stack, M *mp, G *gp, void (*fn)(void));
   471  TEXT runtime·clone(SB),NOSPLIT,$0
   472  	MOVW	flags+0(FP), R0
   473  	MOVW	stk+4(FP), R1
   474  	MOVW	$0, R2	// parent tid ptr
   475  	MOVW	$0, R3	// tls_val
   476  	MOVW	$0, R4	// child tid ptr
   477  	MOVW	$0, R5
   478  
   479  	// Copy mp, gp, fn off parent stack for use by child.
   480  	MOVW	$-16(R1), R1
   481  	MOVW	mp+8(FP), R6
   482  	MOVW	R6, 0(R1)
   483  	MOVW	gp+12(FP), R6
   484  	MOVW	R6, 4(R1)
   485  	MOVW	fn+16(FP), R6
   486  	MOVW	R6, 8(R1)
   487  	MOVW	$1234, R6
   488  	MOVW	R6, 12(R1)
   489  
   490  	MOVW	$SYS_clone, R7
   491  	SWI	$0
   492  
   493  	// In parent, return.
   494  	CMP	$0, R0
   495  	BEQ	3(PC)
   496  	MOVW	R0, ret+20(FP)
   497  	RET
   498  
   499  	// Paranoia: check that SP is as we expect. Use R13 to avoid linker 'fixup'
   500  	NOP	R13	// tell vet SP/R13 changed - stop checking offsets
   501  	MOVW	12(R13), R0
   502  	MOVW	$1234, R1
   503  	CMP	R0, R1
   504  	BEQ	2(PC)
   505  	BL	runtime·abort(SB)
   506  
   507  	MOVW	0(R13), R8    // m
   508  	MOVW	4(R13), R0    // g
   509  
   510  	CMP	$0, R8
   511  	BEQ	nog
   512  	CMP	$0, R0
   513  	BEQ	nog
   514  
   515  	MOVW	R0, g
   516  	MOVW	R8, g_m(g)
   517  
   518  	// paranoia; check they are not nil
   519  	MOVW	0(R8), R0
   520  	MOVW	0(g), R0
   521  
   522  	BL	runtime·emptyfunc(SB)	// fault if stack check is wrong
   523  
   524  	// Initialize m->procid to Linux tid
   525  	MOVW	$SYS_gettid, R7
   526  	SWI	$0
   527  	MOVW	g_m(g), R8
   528  	MOVW	R0, m_procid(R8)
   529  
   530  nog:
   531  	// Call fn
   532  	MOVW	8(R13), R0
   533  	MOVW	$16(R13), R13
   534  	BL	(R0)
   535  
   536  	// It shouldn't return. If it does, exit that thread.
   537  	SUB	$16, R13 // restore the stack pointer to avoid memory corruption
   538  	MOVW	$0, R0
   539  	MOVW	R0, 4(R13)
   540  	BL	exit1<>(SB)
   541  
   542  	MOVW	$1234, R0
   543  	MOVW	$1005, R1
   544  	MOVW	R0, (R1)
   545  
   546  TEXT runtime·sigaltstack(SB),NOSPLIT,$0
   547  	MOVW	new+0(FP), R0
   548  	MOVW	old+4(FP), R1
   549  	MOVW	$SYS_sigaltstack, R7
   550  	SWI	$0
   551  	MOVW	$0xfffff001, R6
   552  	CMP 	R6, R0
   553  	MOVW.HI	$0, R8  // crash on syscall failure
   554  	MOVW.HI	R8, (R8)
   555  	RET
   556  
   557  TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
   558  	MOVW	sig+4(FP), R0
   559  	MOVW	info+8(FP), R1
   560  	MOVW	ctx+12(FP), R2
   561  	MOVW	fn+0(FP), R11
   562  	MOVW	R13, R4
   563  	SUB	$24, R13
   564  	BIC	$0x7, R13 // alignment for ELF ABI
   565  	BL	(R11)
   566  	MOVW	R4, R13
   567  	RET
   568  
   569  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$0
   570  	// Reserve space for callee-save registers and arguments.
   571  	MOVM.DB.W [R4-R11], (R13)
   572  	SUB	$16, R13
   573  
   574  	// this might be called in external code context,
   575  	// where g is not set.
   576  	// first save R0, because runtime·load_g will clobber it
   577  	MOVW	R0, 4(R13)
   578  	MOVB	runtime·iscgo(SB), R0
   579  	CMP 	$0, R0
   580  	BL.NE	runtime·load_g(SB)
   581  
   582  	MOVW	R1, 8(R13)
   583  	MOVW	R2, 12(R13)
   584  	MOVW  	$runtime·sigtrampgo(SB), R11
   585  	BL	(R11)
   586  
   587  	// Restore callee-save registers.
   588  	ADD	$16, R13
   589  	MOVM.IA.W (R13), [R4-R11]
   590  
   591  	RET
   592  
   593  TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   594  	MOVW  	$runtime·sigtramp(SB), R11
   595  	B	(R11)
   596  
   597  TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0
   598  	MOVW	how+0(FP), R0
   599  	MOVW	new+4(FP), R1
   600  	MOVW	old+8(FP), R2
   601  	MOVW	size+12(FP), R3
   602  	MOVW	$SYS_rt_sigprocmask, R7
   603  	SWI	$0
   604  	RET
   605  
   606  TEXT runtime·rt_sigaction(SB),NOSPLIT,$0
   607  	MOVW	sig+0(FP), R0
   608  	MOVW	new+4(FP), R1
   609  	MOVW	old+8(FP), R2
   610  	MOVW	size+12(FP), R3
   611  	MOVW	$SYS_rt_sigaction, R7
   612  	SWI	$0
   613  	MOVW	R0, ret+16(FP)
   614  	RET
   615  
   616  TEXT runtime·usleep(SB),NOSPLIT,$12
   617  	MOVW	usec+0(FP), R0
   618  	CALL	runtime·usplitR0(SB)
   619  	MOVW	R0, 4(R13)
   620  	MOVW	$1000, R0	// usec to nsec
   621  	MUL	R0, R1
   622  	MOVW	R1, 8(R13)
   623  	MOVW	$4(R13), R0
   624  	MOVW	$0, R1
   625  	MOVW	$SYS_nanosleep, R7
   626  	SWI	$0
   627  	RET
   628  
   629  // As for cas, memory barriers are complicated on ARM, but the kernel
   630  // provides a user helper. ARMv5 does not support SMP and has no
   631  // memory barrier instruction at all. ARMv6 added SMP support and has
   632  // a memory barrier, but it requires writing to a coprocessor
   633  // register. ARMv7 introduced the DMB instruction, but it's expensive
   634  // even on single-core devices. The kernel helper takes care of all of
   635  // this for us.
   636  
   637  TEXT kernelPublicationBarrier<>(SB),NOSPLIT,$0
   638  	// void __kuser_memory_barrier(void);
   639  	MOVW	$0xffff0fa0, R11
   640  	CALL	(R11)
   641  	RET
   642  
   643  TEXT ·publicationBarrier(SB),NOSPLIT,$0
   644  	MOVB	·goarm(SB), R11
   645  	CMP	$7, R11
   646  	BLT	2(PC)
   647  	JMP	·armPublicationBarrier(SB)
   648  	JMP	kernelPublicationBarrier<>(SB) // extra layer so this function is leaf and no SP adjustment on GOARM=7
   649  
   650  TEXT runtime·osyield(SB),NOSPLIT,$0
   651  	MOVW	$SYS_sched_yield, R7
   652  	SWI	$0
   653  	RET
   654  
   655  TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0
   656  	MOVW	pid+0(FP), R0
   657  	MOVW	len+4(FP), R1
   658  	MOVW	buf+8(FP), R2
   659  	MOVW	$SYS_sched_getaffinity, R7
   660  	SWI	$0
   661  	MOVW	R0, ret+12(FP)
   662  	RET
   663  
   664  // int32 runtime·epollcreate(int32 size)
   665  TEXT runtime·epollcreate(SB),NOSPLIT,$0
   666  	MOVW	size+0(FP), R0
   667  	MOVW	$SYS_epoll_create, R7
   668  	SWI	$0
   669  	MOVW	R0, ret+4(FP)
   670  	RET
   671  
   672  // int32 runtime·epollcreate1(int32 flags)
   673  TEXT runtime·epollcreate1(SB),NOSPLIT,$0
   674  	MOVW	flags+0(FP), R0
   675  	MOVW	$SYS_epoll_create1, R7
   676  	SWI	$0
   677  	MOVW	R0, ret+4(FP)
   678  	RET
   679  
   680  // func epollctl(epfd, op, fd int32, ev *epollEvent) int
   681  TEXT runtime·epollctl(SB),NOSPLIT,$0
   682  	MOVW	epfd+0(FP), R0
   683  	MOVW	op+4(FP), R1
   684  	MOVW	fd+8(FP), R2
   685  	MOVW	ev+12(FP), R3
   686  	MOVW	$SYS_epoll_ctl, R7
   687  	SWI	$0
   688  	MOVW	R0, ret+16(FP)
   689  	RET
   690  
   691  // int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout)
   692  TEXT runtime·epollwait(SB),NOSPLIT,$0
   693  	MOVW	epfd+0(FP), R0
   694  	MOVW	ev+4(FP), R1
   695  	MOVW	nev+8(FP), R2
   696  	MOVW	timeout+12(FP), R3
   697  	MOVW	$SYS_epoll_wait, R7
   698  	SWI	$0
   699  	MOVW	R0, ret+16(FP)
   700  	RET
   701  
   702  // void runtime·closeonexec(int32 fd)
   703  TEXT runtime·closeonexec(SB),NOSPLIT,$0
   704  	MOVW	fd+0(FP), R0	// fd
   705  	MOVW	$2, R1	// F_SETFD
   706  	MOVW	$1, R2	// FD_CLOEXEC
   707  	MOVW	$SYS_fcntl, R7
   708  	SWI	$0
   709  	RET
   710  
   711  // b __kuser_get_tls @ 0xffff0fe0
   712  TEXT runtime·read_tls_fallback(SB),NOSPLIT|NOFRAME,$0
   713  	MOVW	$0xffff0fe0, R0
   714  	B	(R0)
   715  
   716  TEXT runtime·access(SB),NOSPLIT,$0
   717  	MOVW	name+0(FP), R0
   718  	MOVW	mode+4(FP), R1
   719  	MOVW	$SYS_access, R7
   720  	SWI	$0
   721  	MOVW	R0, ret+8(FP)
   722  	RET
   723  
   724  TEXT runtime·connect(SB),NOSPLIT,$0
   725  	MOVW	fd+0(FP), R0
   726  	MOVW	addr+4(FP), R1
   727  	MOVW	len+8(FP), R2
   728  	MOVW	$SYS_connect, R7
   729  	SWI	$0
   730  	MOVW	R0, ret+12(FP)
   731  	RET
   732  
   733  TEXT runtime·socket(SB),NOSPLIT,$0
   734  	MOVW	domain+0(FP), R0
   735  	MOVW	typ+4(FP), R1
   736  	MOVW	prot+8(FP), R2
   737  	MOVW	$SYS_socket, R7
   738  	SWI	$0
   739  	MOVW	R0, ret+12(FP)
   740  	RET
   741  
   742  // func sbrk0() uintptr
   743  TEXT runtime·sbrk0(SB),NOSPLIT,$0-4
   744  	// Implemented as brk(NULL).
   745  	MOVW	$0, R0
   746  	MOVW	$SYS_brk, R7
   747  	SWI	$0
   748  	MOVW	R0, ret+0(FP)
   749  	RET
   750  
   751  TEXT runtime·sigreturn(SB),NOSPLIT,$0-0
   752  	RET
   753  

View as plain text