Text file src/runtime/sys_linux_mipsx.s

     1  // Copyright 2016 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  //go:build linux && (mips || mipsle)
     6  
     7  //
     8  // System calls and other sys.stuff for mips, Linux
     9  //
    10  
    11  #include "go_asm.h"
    12  #include "go_tls.h"
    13  #include "textflag.h"
    14  
    15  #define SYS_exit		4001
    16  #define SYS_read		4003
    17  #define SYS_write		4004
    18  #define SYS_open		4005
    19  #define SYS_close		4006
    20  #define SYS_getpid		4020
    21  #define SYS_kill		4037
    22  #define SYS_brk			4045
    23  #define SYS_mmap		4090
    24  #define SYS_munmap		4091
    25  #define SYS_setitimer		4104
    26  #define SYS_clone		4120
    27  #define SYS_sched_yield		4162
    28  #define SYS_nanosleep		4166
    29  #define SYS_rt_sigreturn	4193
    30  #define SYS_rt_sigaction	4194
    31  #define SYS_rt_sigprocmask	4195
    32  #define SYS_sigaltstack		4206
    33  #define SYS_madvise		4218
    34  #define SYS_mincore		4217
    35  #define SYS_gettid		4222
    36  #define SYS_futex		4238
    37  #define SYS_sched_getaffinity	4240
    38  #define SYS_exit_group		4246
    39  #define SYS_timer_create	4257
    40  #define SYS_timer_settime	4258
    41  #define SYS_timer_delete	4261
    42  #define SYS_clock_gettime	4263
    43  #define SYS_tgkill		4266
    44  #define SYS_pipe2		4328
    45  
    46  TEXT runtime·exit(SB),NOSPLIT,$0-4
    47  	MOVW	code+0(FP), R4
    48  	MOVW	$SYS_exit_group, R2
    49  	SYSCALL
    50  	UNDEF
    51  	RET
    52  
    53  // func exitThread(wait *atomic.Uint32)
    54  TEXT runtime·exitThread(SB),NOSPLIT,$0-4
    55  	MOVW	wait+0(FP), R1
    56  	// We're done using the stack.
    57  	MOVW	$0, R2
    58  	SYNC
    59  	MOVW	R2, (R1)
    60  	SYNC
    61  	MOVW	$0, R4	// exit code
    62  	MOVW	$SYS_exit, R2
    63  	SYSCALL
    64  	UNDEF
    65  	JMP	0(PC)
    66  
    67  TEXT runtime·open(SB),NOSPLIT,$0-16
    68  	MOVW	name+0(FP), R4
    69  	MOVW	mode+4(FP), R5
    70  	MOVW	perm+8(FP), R6
    71  	MOVW	$SYS_open, R2
    72  	SYSCALL
    73  	BEQ	R7, 2(PC)
    74  	MOVW	$-1, R2
    75  	MOVW	R2, ret+12(FP)
    76  	RET
    77  
    78  TEXT runtime·closefd(SB),NOSPLIT,$0-8
    79  	MOVW	fd+0(FP), R4
    80  	MOVW	$SYS_close, R2
    81  	SYSCALL
    82  	BEQ	R7, 2(PC)
    83  	MOVW	$-1, R2
    84  	MOVW	R2, ret+4(FP)
    85  	RET
    86  
    87  TEXT runtime·write1(SB),NOSPLIT,$0-16
    88  	MOVW	fd+0(FP), R4
    89  	MOVW	p+4(FP), R5
    90  	MOVW	n+8(FP), R6
    91  	MOVW	$SYS_write, R2
    92  	SYSCALL
    93  	BEQ	R7, 2(PC)
    94  	SUBU	R2, R0, R2	// caller expects negative errno
    95  	MOVW	R2, ret+12(FP)
    96  	RET
    97  
    98  TEXT runtime·read(SB),NOSPLIT,$0-16
    99  	MOVW	fd+0(FP), R4
   100  	MOVW	p+4(FP), R5
   101  	MOVW	n+8(FP), R6
   102  	MOVW	$SYS_read, R2
   103  	SYSCALL
   104  	BEQ	R7, 2(PC)
   105  	SUBU	R2, R0, R2	// caller expects negative errno
   106  	MOVW	R2, ret+12(FP)
   107  	RET
   108  
   109  // func pipe2(flags int32) (r, w int32, errno int32)
   110  TEXT runtime·pipe2(SB),NOSPLIT,$0-16
   111  	MOVW	$r+4(FP), R4
   112  	MOVW	flags+0(FP), R5
   113  	MOVW	$SYS_pipe2, R2
   114  	SYSCALL
   115  	BEQ	R7, 2(PC)
   116  	SUBU	R2, R0, R2	// caller expects negative errno
   117  	MOVW	R2, errno+12(FP)
   118  	RET
   119  
   120  TEXT runtime·usleep(SB),NOSPLIT,$28-4
   121  	MOVW	usec+0(FP), R3
   122  	MOVW	R3, R5
   123  	MOVW	$1000000, R4
   124  	DIVU	R4, R3
   125  	MOVW	LO, R3
   126  	MOVW	R3, 24(R29)
   127  	MOVW	$1000, R4
   128  	MULU	R3, R4
   129  	MOVW	LO, R4
   130  	SUBU	R4, R5
   131  	MOVW	R5, 28(R29)
   132  
   133  	// nanosleep(&ts, 0)
   134  	ADDU	$24, R29, R4
   135  	MOVW	$0, R5
   136  	MOVW	$SYS_nanosleep, R2
   137  	SYSCALL
   138  	RET
   139  
   140  TEXT runtime·gettid(SB),NOSPLIT,$0-4
   141  	MOVW	$SYS_gettid, R2
   142  	SYSCALL
   143  	MOVW	R2, ret+0(FP)
   144  	RET
   145  
   146  TEXT runtime·raise(SB),NOSPLIT,$0-4
   147  	MOVW	$SYS_getpid, R2
   148  	SYSCALL
   149  	MOVW	R2, R16
   150  	MOVW	$SYS_gettid, R2
   151  	SYSCALL
   152  	MOVW	R2, R5	// arg 2 tid
   153  	MOVW	R16, R4	// arg 1 pid
   154  	MOVW	sig+0(FP), R6	// arg 3
   155  	MOVW	$SYS_tgkill, R2
   156  	SYSCALL
   157  	RET
   158  
   159  TEXT runtime·raiseproc(SB),NOSPLIT,$0
   160  	MOVW	$SYS_getpid, R2
   161  	SYSCALL
   162  	MOVW	R2, R4	// arg 1 pid
   163  	MOVW	sig+0(FP), R5	// arg 2
   164  	MOVW	$SYS_kill, R2
   165  	SYSCALL
   166  	RET
   167  
   168  TEXT ·getpid(SB),NOSPLIT,$0-4
   169  	MOVW	$SYS_getpid, R2
   170  	SYSCALL
   171  	MOVW	R2, ret+0(FP)
   172  	RET
   173  
   174  TEXT ·tgkill(SB),NOSPLIT,$0-12
   175  	MOVW	tgid+0(FP), R4
   176  	MOVW	tid+4(FP), R5
   177  	MOVW	sig+8(FP), R6
   178  	MOVW	$SYS_tgkill, R2
   179  	SYSCALL
   180  	RET
   181  
   182  TEXT runtime·setitimer(SB),NOSPLIT,$0-12
   183  	MOVW	mode+0(FP), R4
   184  	MOVW	new+4(FP), R5
   185  	MOVW	old+8(FP), R6
   186  	MOVW	$SYS_setitimer, R2
   187  	SYSCALL
   188  	RET
   189  
   190  TEXT runtime·timer_create(SB),NOSPLIT,$0-16
   191  	MOVW	clockid+0(FP), R4
   192  	MOVW	sevp+4(FP), R5
   193  	MOVW	timerid+8(FP), R6
   194  	MOVW	$SYS_timer_create, R2
   195  	SYSCALL
   196  	MOVW	R2, ret+12(FP)
   197  	RET
   198  
   199  TEXT runtime·timer_settime(SB),NOSPLIT,$0-20
   200  	MOVW	timerid+0(FP), R4
   201  	MOVW	flags+4(FP), R5
   202  	MOVW	new+8(FP), R6
   203  	MOVW	old+12(FP), R7
   204  	MOVW	$SYS_timer_settime, R2
   205  	SYSCALL
   206  	MOVW	R2, ret+16(FP)
   207  	RET
   208  
   209  TEXT runtime·timer_delete(SB),NOSPLIT,$0-8
   210  	MOVW	timerid+0(FP), R4
   211  	MOVW	$SYS_timer_delete, R2
   212  	SYSCALL
   213  	MOVW	R2, ret+4(FP)
   214  	RET
   215  
   216  TEXT runtime·mincore(SB),NOSPLIT,$0-16
   217  	MOVW	addr+0(FP), R4
   218  	MOVW	n+4(FP), R5
   219  	MOVW	dst+8(FP), R6
   220  	MOVW	$SYS_mincore, R2
   221  	SYSCALL
   222  	SUBU	R2, R0, R2	// caller expects negative errno
   223  	MOVW	R2, ret+12(FP)
   224  	RET
   225  
   226  // func walltime() (sec int64, nsec int32)
   227  TEXT runtime·walltime(SB),NOSPLIT,$8-12
   228  	MOVW	$0, R4	// CLOCK_REALTIME
   229  	MOVW	$4(R29), R5
   230  	MOVW	$SYS_clock_gettime, R2
   231  	SYSCALL
   232  	MOVW	4(R29), R3	// sec
   233  	MOVW	8(R29), R5	// nsec
   234  	MOVW	$sec+0(FP), R6
   235  #ifdef GOARCH_mips
   236  	MOVW	R3, 4(R6)
   237  	MOVW	R0, 0(R6)
   238  #else
   239  	MOVW	R3, 0(R6)
   240  	MOVW	R0, 4(R6)
   241  #endif
   242  	MOVW	R5, nsec+8(FP)
   243  	RET
   244  
   245  TEXT runtime·nanotime1(SB),NOSPLIT,$8-8
   246  	MOVW	$1, R4	// CLOCK_MONOTONIC
   247  	MOVW	$4(R29), R5
   248  	MOVW	$SYS_clock_gettime, R2
   249  	SYSCALL
   250  	MOVW	4(R29), R3	// sec
   251  	MOVW	8(R29), R5	// nsec
   252  	// sec is in R3, nsec in R5
   253  	// return nsec in R3
   254  	MOVW	$1000000000, R4
   255  	MULU	R4, R3
   256  	MOVW	LO, R3
   257  	ADDU	R5, R3
   258  	SGTU	R5, R3, R4
   259  	MOVW	$ret+0(FP), R6
   260  #ifdef GOARCH_mips
   261  	MOVW	R3, 4(R6)
   262  #else
   263  	MOVW	R3, 0(R6)
   264  #endif
   265  	MOVW	HI, R3
   266  	ADDU	R4, R3
   267  #ifdef GOARCH_mips
   268  	MOVW	R3, 0(R6)
   269  #else
   270  	MOVW	R3, 4(R6)
   271  #endif
   272  	RET
   273  
   274  TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0-16
   275  	MOVW	how+0(FP), R4
   276  	MOVW	new+4(FP), R5
   277  	MOVW	old+8(FP), R6
   278  	MOVW	size+12(FP), R7
   279  	MOVW	$SYS_rt_sigprocmask, R2
   280  	SYSCALL
   281  	BEQ	R7, 2(PC)
   282  	UNDEF	// crash
   283  	RET
   284  
   285  TEXT runtime·rt_sigaction(SB),NOSPLIT,$0-20
   286  	MOVW	sig+0(FP), R4
   287  	MOVW	new+4(FP), R5
   288  	MOVW	old+8(FP), R6
   289  	MOVW	size+12(FP), R7
   290  	MOVW	$SYS_rt_sigaction, R2
   291  	SYSCALL
   292  	BEQ	R7, 2(PC)
   293  	SUBU	R2, R0, R2	// caller expects negative errno
   294  	MOVW	R2, ret+16(FP)
   295  	RET
   296  
   297  TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
   298  	MOVW	sig+4(FP), R4
   299  	MOVW	info+8(FP), R5
   300  	MOVW	ctx+12(FP), R6
   301  	MOVW	fn+0(FP), R25
   302  	MOVW	R29, R22
   303  	SUBU	$16, R29
   304  	AND	$~7, R29	// shadow space for 4 args aligned to 8 bytes as per O32 ABI
   305  	JAL	(R25)
   306  	MOVW	R22, R29
   307  	RET
   308  
   309  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$12
   310  	// this might be called in external code context,
   311  	// where g is not set.
   312  	MOVB	runtime·iscgo(SB), R1
   313  	BEQ	R1, 2(PC)
   314  	JAL	runtime·load_g(SB)
   315  
   316  	MOVW	R4, 4(R29)
   317  	MOVW	R5, 8(R29)
   318  	MOVW	R6, 12(R29)
   319  	MOVW	$runtime·sigtrampgo(SB), R1
   320  	JAL	(R1)
   321  	RET
   322  
   323  TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   324  	JMP	runtime·sigtramp(SB)
   325  
   326  TEXT runtime·mmap(SB),NOSPLIT,$20-32
   327  	MOVW	addr+0(FP), R4
   328  	MOVW	n+4(FP), R5
   329  	MOVW	prot+8(FP), R6
   330  	MOVW	flags+12(FP), R7
   331  	MOVW	fd+16(FP), R8
   332  	MOVW	off+20(FP), R9
   333  	MOVW	R8, 16(R29)
   334  	MOVW	R9, 20(R29)
   335  
   336  	MOVW	$SYS_mmap, R2
   337  	SYSCALL
   338  	BEQ	R7, ok
   339  	MOVW	$0, p+24(FP)
   340  	MOVW	R2, err+28(FP)
   341  	RET
   342  ok:
   343  	MOVW	R2, p+24(FP)
   344  	MOVW	$0, err+28(FP)
   345  	RET
   346  
   347  TEXT runtime·munmap(SB),NOSPLIT,$0-8
   348  	MOVW	addr+0(FP), R4
   349  	MOVW	n+4(FP), R5
   350  	MOVW	$SYS_munmap, R2
   351  	SYSCALL
   352  	BEQ	R7, 2(PC)
   353  	UNDEF	// crash
   354  	RET
   355  
   356  TEXT runtime·madvise(SB),NOSPLIT,$0-16
   357  	MOVW	addr+0(FP), R4
   358  	MOVW	n+4(FP), R5
   359  	MOVW	flags+8(FP), R6
   360  	MOVW	$SYS_madvise, R2
   361  	SYSCALL
   362  	MOVW	R2, ret+12(FP)
   363  	RET
   364  
   365  // int32 futex(int32 *uaddr, int32 op, int32 val, struct timespec *timeout, int32 *uaddr2, int32 val2);
   366  TEXT runtime·futex(SB),NOSPLIT,$20-28
   367  	MOVW	addr+0(FP), R4
   368  	MOVW	op+4(FP), R5
   369  	MOVW	val+8(FP), R6
   370  	MOVW	ts+12(FP), R7
   371  
   372  	MOVW	addr2+16(FP), R8
   373  	MOVW	val3+20(FP), R9
   374  
   375  	MOVW	R8, 16(R29)
   376  	MOVW	R9, 20(R29)
   377  
   378  	MOVW	$SYS_futex, R2
   379  	SYSCALL
   380  	BEQ	R7, 2(PC)
   381  	SUBU	R2, R0, R2	// caller expects negative errno
   382  	MOVW	R2, ret+24(FP)
   383  	RET
   384  
   385  
   386  // int32 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   387  TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0-24
   388  	MOVW	flags+0(FP), R4
   389  	MOVW	stk+4(FP), R5
   390  	MOVW	R0, R6	// ptid
   391  	MOVW	R0, R7	// tls
   392  
   393  	// O32 syscall handler unconditionally copies arguments 5-8 from stack,
   394  	// even for syscalls with less than 8 arguments. Reserve 32 bytes of new
   395  	// stack so that any syscall invoked immediately in the new thread won't fail.
   396  	ADD	$-32, R5
   397  
   398  	// Copy mp, gp, fn off parent stack for use by child.
   399  	MOVW	mp+8(FP), R16
   400  	MOVW	gp+12(FP), R17
   401  	MOVW	fn+16(FP), R18
   402  
   403  	MOVW	$1234, R1
   404  
   405  	MOVW	R16, 0(R5)
   406  	MOVW	R17, 4(R5)
   407  	MOVW	R18, 8(R5)
   408  
   409  	MOVW	R1, 12(R5)
   410  
   411  	MOVW	$SYS_clone, R2
   412  	SYSCALL
   413  	BEQ	R7, 2(PC)
   414  	SUBU	R2, R0, R2	// caller expects negative errno
   415  
   416  	// In parent, return.
   417  	BEQ	R2, 3(PC)
   418  	MOVW	R2, ret+20(FP)
   419  	RET
   420  
   421  	// In child, on new stack.
   422  	// Check that SP is as we expect
   423  	NOP	R29	// tell vet R29/SP changed - stop checking offsets
   424  	MOVW	12(R29), R16
   425  	MOVW	$1234, R1
   426  	BEQ	R16, R1, 2(PC)
   427  	MOVW	(R0), R0
   428  
   429  	// Initialize m->procid to Linux tid
   430  	MOVW	$SYS_gettid, R2
   431  	SYSCALL
   432  
   433  	MOVW	0(R29), R16	// m
   434  	MOVW	4(R29), R17	// g
   435  	MOVW	8(R29), R18	// fn
   436  
   437  	BEQ	R16, nog
   438  	BEQ	R17, nog
   439  
   440  	MOVW	R2, m_procid(R16)
   441  
   442  	// In child, set up new stack
   443  	MOVW	R16, g_m(R17)
   444  	MOVW	R17, g
   445  
   446  // TODO(mips32): doesn't have runtime·stackcheck(SB)
   447  
   448  nog:
   449  	// Call fn
   450  	ADDU	$32, R29
   451  	JAL	(R18)
   452  
   453  	// It shouldn't return.	 If it does, exit that thread.
   454  	ADDU	$-32, R29
   455  	MOVW	$0xf4, R4
   456  	MOVW	$SYS_exit, R2
   457  	SYSCALL
   458  	UNDEF
   459  
   460  TEXT runtime·sigaltstack(SB),NOSPLIT,$0
   461  	MOVW	new+0(FP), R4
   462  	MOVW	old+4(FP), R5
   463  	MOVW	$SYS_sigaltstack, R2
   464  	SYSCALL
   465  	BEQ	R7, 2(PC)
   466  	UNDEF	// crash
   467  	RET
   468  
   469  TEXT runtime·osyield(SB),NOSPLIT,$0
   470  	MOVW	$SYS_sched_yield, R2
   471  	SYSCALL
   472  	RET
   473  
   474  TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0-16
   475  	MOVW	pid+0(FP), R4
   476  	MOVW	len+4(FP), R5
   477  	MOVW	buf+8(FP), R6
   478  	MOVW	$SYS_sched_getaffinity, R2
   479  	SYSCALL
   480  	BEQ	R7, 2(PC)
   481  	SUBU	R2, R0, R2	// caller expects negative errno
   482  	MOVW	R2, ret+12(FP)
   483  	RET
   484  
   485  // func sbrk0() uintptr
   486  TEXT runtime·sbrk0(SB),NOSPLIT,$0-4
   487  	// Implemented as brk(NULL).
   488  	MOVW	$0, R4
   489  	MOVW	$SYS_brk, R2
   490  	SYSCALL
   491  	MOVW	R2, ret+0(FP)
   492  	RET
   493  
   494  TEXT runtime·access(SB),$0-12
   495  	BREAK // unimplemented, only needed for android; declared in stubs_linux.go
   496  	MOVW	R0, ret+8(FP)	// for vet
   497  	RET
   498  
   499  TEXT runtime·connect(SB),$0-16
   500  	BREAK // unimplemented, only needed for android; declared in stubs_linux.go
   501  	MOVW	R0, ret+12(FP)	// for vet
   502  	RET
   503  
   504  TEXT runtime·socket(SB),$0-16
   505  	BREAK // unimplemented, only needed for android; declared in stubs_linux.go
   506  	MOVW	R0, ret+12(FP)	// for vet
   507  	RET
   508  

View as plain text