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

View as plain text