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

View as plain text