...
Run Format

Text file src/runtime/sys_linux_mipsx.s

Documentation: runtime

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

View as plain text