...
Run Format

Text file src/runtime/sys_linux_mips64x.s

Documentation: runtime

     1	// Copyright 2015 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 mips64 mips64le
     7	
     8	//
     9	// System calls and other sys.stuff for mips64, Linux
    10	//
    11	
    12	#include "go_asm.h"
    13	#include "go_tls.h"
    14	#include "textflag.h"
    15	
    16	#define AT_FDCWD -100
    17	
    18	#define SYS_exit		5058
    19	#define SYS_read		5000
    20	#define SYS_write		5001
    21	#define SYS_close		5003
    22	#define SYS_getpid		5038
    23	#define SYS_kill		5060
    24	#define SYS_fcntl		5080
    25	#define SYS_gettimeofday	5094
    26	#define SYS_mmap		5009
    27	#define SYS_munmap		5011
    28	#define SYS_setitimer		5036
    29	#define SYS_clone		5055
    30	#define SYS_newselect		5022
    31	#define SYS_sched_yield		5023
    32	#define SYS_rt_sigreturn	5211
    33	#define SYS_rt_sigaction	5013
    34	#define SYS_rt_sigprocmask	5014
    35	#define SYS_sigaltstack		5129
    36	#define SYS_getrlimit		5095
    37	#define SYS_madvise		5027
    38	#define SYS_mincore		5026
    39	#define SYS_gettid		5178
    40	#define SYS_tkill		5192
    41	#define SYS_futex		5194
    42	#define SYS_sched_getaffinity	5196
    43	#define SYS_exit_group		5205
    44	#define SYS_epoll_create	5207
    45	#define SYS_epoll_ctl		5208
    46	#define SYS_openat		5247
    47	#define SYS_epoll_pwait		5272
    48	#define SYS_clock_gettime	5222
    49	#define SYS_epoll_create1	5285
    50	#define SYS_brk			5012
    51	
    52	TEXT runtime·exit(SB),NOSPLIT,$-8-4
    53		MOVW	code+0(FP), R4
    54		MOVV	$SYS_exit_group, R2
    55		SYSCALL
    56		RET
    57	
    58	// func exitThread(wait *uint32)
    59	TEXT runtime·exitThread(SB),NOSPLIT,$-8-8
    60		MOVV	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		MOVV	$SYS_exit, R2
    68		SYSCALL
    69		JMP	0(PC)
    70	
    71	TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
    72		// This uses openat instead of open, because Android O blocks open.
    73		MOVW	$AT_FDCWD, R4 // AT_FDCWD, so this acts like open
    74		MOVV	name+0(FP), R5
    75		MOVW	mode+8(FP), R6
    76		MOVW	perm+12(FP), R7
    77		MOVV	$SYS_openat, R2
    78		SYSCALL
    79		BEQ	R7, 2(PC)
    80		MOVW	$-1, R2
    81		MOVW	R2, ret+16(FP)
    82		RET
    83	
    84	TEXT runtime·closefd(SB),NOSPLIT,$-8-12
    85		MOVW	fd+0(FP), R4
    86		MOVV	$SYS_close, R2
    87		SYSCALL
    88		BEQ	R7, 2(PC)
    89		MOVW	$-1, R2
    90		MOVW	R2, ret+8(FP)
    91		RET
    92	
    93	TEXT runtime·write(SB),NOSPLIT,$-8-28
    94		MOVV	fd+0(FP), R4
    95		MOVV	p+8(FP), R5
    96		MOVW	n+16(FP), R6
    97		MOVV	$SYS_write, R2
    98		SYSCALL
    99		BEQ	R7, 2(PC)
   100		MOVW	$-1, R2
   101		MOVW	R2, ret+24(FP)
   102		RET
   103	
   104	TEXT runtime·read(SB),NOSPLIT,$-8-28
   105		MOVW	fd+0(FP), R4
   106		MOVV	p+8(FP), R5
   107		MOVW	n+16(FP), R6
   108		MOVV	$SYS_read, R2
   109		SYSCALL
   110		BEQ	R7, 2(PC)
   111		MOVW	$-1, R2
   112		MOVW	R2, ret+24(FP)
   113		RET
   114	
   115	TEXT runtime·getrlimit(SB),NOSPLIT,$-8-20
   116		MOVW	kind+0(FP), R4	// _RLIMIT_AS = 6 on linux/mips
   117		MOVV	limit+8(FP), R5
   118		MOVV	$SYS_getrlimit, R2
   119		SYSCALL
   120		MOVW	R2, ret+16(FP)
   121		RET
   122	
   123	TEXT runtime·usleep(SB),NOSPLIT,$16-4
   124		MOVWU	usec+0(FP), R3
   125		MOVV	R3, R5
   126		MOVW	$1000000, R4
   127		DIVVU	R4, R3
   128		MOVV	LO, R3
   129		MOVV	R3, 8(R29)
   130		MULVU	R3, R4
   131		MOVV	LO, R4
   132		SUBVU	R4, R5
   133		MOVV	R5, 16(R29)
   134	
   135		// select(0, 0, 0, 0, &tv)
   136		MOVW	$0, R4
   137		MOVW	$0, R5
   138		MOVW	$0, R6
   139		MOVW	$0, R7
   140		ADDV	$8, R29, R8
   141		MOVV	$SYS_newselect, R2
   142		SYSCALL
   143		RET
   144	
   145	TEXT runtime·gettid(SB),NOSPLIT,$0-4
   146		MOVV	$SYS_gettid, R2
   147		SYSCALL
   148		MOVW	R2, ret+0(FP)
   149		RET
   150	
   151	TEXT runtime·raise(SB),NOSPLIT,$-8
   152		MOVV	$SYS_gettid, R2
   153		SYSCALL
   154		MOVW	R2, R4	// arg 1 tid
   155		MOVW	sig+0(FP), R5	// arg 2
   156		MOVV	$SYS_tkill, R2
   157		SYSCALL
   158		RET
   159	
   160	TEXT runtime·raiseproc(SB),NOSPLIT,$-8
   161		MOVV	$SYS_getpid, R2
   162		SYSCALL
   163		MOVW	R2, R4	// arg 1 pid
   164		MOVW	sig+0(FP), R5	// arg 2
   165		MOVV	$SYS_kill, R2
   166		SYSCALL
   167		RET
   168	
   169	TEXT runtime·setitimer(SB),NOSPLIT,$-8-24
   170		MOVW	mode+0(FP), R4
   171		MOVV	new+8(FP), R5
   172		MOVV	old+16(FP), R6
   173		MOVV	$SYS_setitimer, R2
   174		SYSCALL
   175		RET
   176	
   177	TEXT runtime·mincore(SB),NOSPLIT,$-8-28
   178		MOVV	addr+0(FP), R4
   179		MOVV	n+8(FP), R5
   180		MOVV	dst+16(FP), R6
   181		MOVV	$SYS_mincore, R2
   182		SYSCALL
   183		SUBVU	R2, R0, R2	// caller expects negative errno
   184		MOVW	R2, ret+24(FP)
   185		RET
   186	
   187	// func walltime() (sec int64, nsec int32)
   188	TEXT runtime·walltime(SB),NOSPLIT,$16
   189		MOVW	$0, R4 // CLOCK_REALTIME
   190		MOVV	$0(R29), R5
   191		MOVV	$SYS_clock_gettime, R2
   192		SYSCALL
   193		MOVV	0(R29), R3	// sec
   194		MOVV	8(R29), R5	// nsec
   195		MOVV	R3, sec+0(FP)
   196		MOVW	R5, nsec+8(FP)
   197		RET
   198	
   199	TEXT runtime·nanotime(SB),NOSPLIT,$16
   200		MOVW	$1, R4 // CLOCK_MONOTONIC
   201		MOVV	$0(R29), R5
   202		MOVV	$SYS_clock_gettime, R2
   203		SYSCALL
   204		MOVV	0(R29), R3	// sec
   205		MOVV	8(R29), R5	// nsec
   206		// sec is in R3, nsec in R5
   207		// return nsec in R3
   208		MOVV	$1000000000, R4
   209		MULVU	R4, R3
   210		MOVV	LO, R3
   211		ADDVU	R5, R3
   212		MOVV	R3, ret+0(FP)
   213		RET
   214	
   215	TEXT runtime·rtsigprocmask(SB),NOSPLIT,$-8-28
   216		MOVW	how+0(FP), R4
   217		MOVV	new+8(FP), R5
   218		MOVV	old+16(FP), R6
   219		MOVW	size+24(FP), R7
   220		MOVV	$SYS_rt_sigprocmask, R2
   221		SYSCALL
   222		BEQ	R7, 2(PC)
   223		MOVV	R0, 0xf1(R0)	// crash
   224		RET
   225	
   226	TEXT runtime·rt_sigaction(SB),NOSPLIT,$-8-36
   227		MOVV	sig+0(FP), R4
   228		MOVV	new+8(FP), R5
   229		MOVV	old+16(FP), R6
   230		MOVV	size+24(FP), R7
   231		MOVV	$SYS_rt_sigaction, R2
   232		SYSCALL
   233		MOVW	R2, ret+32(FP)
   234		RET
   235	
   236	TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   237		MOVW	sig+8(FP), R4
   238		MOVV	info+16(FP), R5
   239		MOVV	ctx+24(FP), R6
   240		MOVV	fn+0(FP), R25
   241		JAL	(R25)
   242		RET
   243	
   244	TEXT runtime·sigtramp(SB),NOSPLIT,$64
   245		// initialize REGSB = PC&0xffffffff00000000
   246		BGEZAL	R0, 1(PC)
   247		SRLV	$32, R31, RSB
   248		SLLV	$32, RSB
   249	
   250		// this might be called in external code context,
   251		// where g is not set.
   252		MOVB	runtime·iscgo(SB), R1
   253		BEQ	R1, 2(PC)
   254		JAL	runtime·load_g(SB)
   255	
   256		MOVW	R4, 8(R29)
   257		MOVV	R5, 16(R29)
   258		MOVV	R6, 24(R29)
   259		MOVV	$runtime·sigtrampgo(SB), R1
   260		JAL	(R1)
   261		RET
   262	
   263	TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   264		JMP	runtime·sigtramp(SB)
   265	
   266	TEXT runtime·mmap(SB),NOSPLIT,$-8
   267		MOVV	addr+0(FP), R4
   268		MOVV	n+8(FP), R5
   269		MOVW	prot+16(FP), R6
   270		MOVW	flags+20(FP), R7
   271		MOVW	fd+24(FP), R8
   272		MOVW	off+28(FP), R9
   273	
   274		MOVV	$SYS_mmap, R2
   275		SYSCALL
   276		BEQ	R7, ok
   277		MOVV	$0, p+32(FP)
   278		MOVV	R2, err+40(FP)
   279		RET
   280	ok:
   281		MOVV	R2, p+32(FP)
   282		MOVV	$0, err+40(FP)
   283		RET
   284	
   285	TEXT runtime·munmap(SB),NOSPLIT,$-8
   286		MOVV	addr+0(FP), R4
   287		MOVV	n+8(FP), R5
   288		MOVV	$SYS_munmap, R2
   289		SYSCALL
   290		BEQ	R7, 2(PC)
   291		MOVV	R0, 0xf3(R0)	// crash
   292		RET
   293	
   294	TEXT runtime·madvise(SB),NOSPLIT,$-8
   295		MOVV	addr+0(FP), R4
   296		MOVV	n+8(FP), R5
   297		MOVW	flags+16(FP), R6
   298		MOVV	$SYS_madvise, R2
   299		SYSCALL
   300		// ignore failure - maybe pages are locked
   301		RET
   302	
   303	// int64 futex(int32 *uaddr, int32 op, int32 val,
   304	//	struct timespec *timeout, int32 *uaddr2, int32 val2);
   305	TEXT runtime·futex(SB),NOSPLIT,$-8
   306		MOVV	addr+0(FP), R4
   307		MOVW	op+8(FP), R5
   308		MOVW	val+12(FP), R6
   309		MOVV	ts+16(FP), R7
   310		MOVV	addr2+24(FP), R8
   311		MOVW	val3+32(FP), R9
   312		MOVV	$SYS_futex, R2
   313		SYSCALL
   314		MOVW	R2, ret+40(FP)
   315		RET
   316	
   317	// int64 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   318	TEXT runtime·clone(SB),NOSPLIT,$-8
   319		MOVW	flags+0(FP), R4
   320		MOVV	stk+8(FP), R5
   321	
   322		// Copy mp, gp, fn off parent stack for use by child.
   323		// Careful: Linux system call clobbers ???.
   324		MOVV	mp+16(FP), R16
   325		MOVV	gp+24(FP), R17
   326		MOVV	fn+32(FP), R18
   327	
   328		MOVV	R16, -8(R5)
   329		MOVV	R17, -16(R5)
   330		MOVV	R18, -24(R5)
   331		MOVV	$1234, R16
   332		MOVV	R16, -32(R5)
   333	
   334		MOVV	$SYS_clone, R2
   335		SYSCALL
   336	
   337		// In parent, return.
   338		BEQ	R2, 3(PC)
   339		MOVW	R2, ret+40(FP)
   340		RET
   341	
   342		// In child, on new stack.
   343		MOVV	-32(R29), R16
   344		MOVV	$1234, R1
   345		BEQ	R16, R1, 2(PC)
   346		MOVV	R0, 0(R0)
   347	
   348		// Initialize m->procid to Linux tid
   349		MOVV	$SYS_gettid, R2
   350		SYSCALL
   351	
   352		MOVV	-24(R29), R18		// fn
   353		MOVV	-16(R29), R17		// g
   354		MOVV	-8(R29), R16		// m
   355	
   356		BEQ	R16, nog
   357		BEQ	R17, nog
   358	
   359		MOVV	R2, m_procid(R16)
   360	
   361		// TODO: setup TLS.
   362	
   363		// In child, set up new stack
   364		MOVV	R16, g_m(R17)
   365		MOVV	R17, g
   366		//CALL	runtime·stackcheck(SB)
   367	
   368	nog:
   369		// Call fn
   370		JAL	(R18)
   371	
   372		// It shouldn't return.	 If it does, exit that thread.
   373		MOVW	$111, R4
   374		MOVV	$SYS_exit, R2
   375		SYSCALL
   376		JMP	-3(PC)	// keep exiting
   377	
   378	TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   379		MOVV	new+0(FP), R4
   380		MOVV	old+8(FP), R5
   381		MOVV	$SYS_sigaltstack, R2
   382		SYSCALL
   383		BEQ	R7, 2(PC)
   384		MOVV	R0, 0xf1(R0)	// crash
   385		RET
   386	
   387	TEXT runtime·osyield(SB),NOSPLIT,$-8
   388		MOVV	$SYS_sched_yield, R2
   389		SYSCALL
   390		RET
   391	
   392	TEXT runtime·sched_getaffinity(SB),NOSPLIT,$-8
   393		MOVV	pid+0(FP), R4
   394		MOVV	len+8(FP), R5
   395		MOVV	buf+16(FP), R6
   396		MOVV	$SYS_sched_getaffinity, R2
   397		SYSCALL
   398		MOVW	R2, ret+24(FP)
   399		RET
   400	
   401	// int32 runtime·epollcreate(int32 size);
   402	TEXT runtime·epollcreate(SB),NOSPLIT,$-8
   403		MOVW    size+0(FP), R4
   404		MOVV	$SYS_epoll_create, R2
   405		SYSCALL
   406		MOVW	R2, ret+8(FP)
   407		RET
   408	
   409	// int32 runtime·epollcreate1(int32 flags);
   410	TEXT runtime·epollcreate1(SB),NOSPLIT,$-8
   411		MOVW	flags+0(FP), R4
   412		MOVV	$SYS_epoll_create1, R2
   413		SYSCALL
   414		MOVW	R2, ret+8(FP)
   415		RET
   416	
   417	// func epollctl(epfd, op, fd int32, ev *epollEvent) int
   418	TEXT runtime·epollctl(SB),NOSPLIT,$-8
   419		MOVW	epfd+0(FP), R4
   420		MOVW	op+4(FP), R5
   421		MOVW	fd+8(FP), R6
   422		MOVV	ev+16(FP), R7
   423		MOVV	$SYS_epoll_ctl, R2
   424		SYSCALL
   425		MOVW	R2, ret+24(FP)
   426		RET
   427	
   428	// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
   429	TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
   430		// This uses pwait instead of wait, because Android O blocks wait.
   431		MOVW	epfd+0(FP), R4
   432		MOVV	ev+8(FP), R5
   433		MOVW	nev+16(FP), R6
   434		MOVW	timeout+20(FP), R7
   435		MOVV	$0, R8
   436		MOVV	$SYS_epoll_pwait, R2
   437		SYSCALL
   438		MOVW	R2, ret+24(FP)
   439		RET
   440	
   441	// void runtime·closeonexec(int32 fd);
   442	TEXT runtime·closeonexec(SB),NOSPLIT,$-8
   443		MOVW    fd+0(FP), R4  // fd
   444		MOVV    $2, R5  // F_SETFD
   445		MOVV    $1, R6  // FD_CLOEXEC
   446		MOVV	$SYS_fcntl, R2
   447		SYSCALL
   448		RET
   449	
   450	// func sbrk0() uintptr
   451	TEXT runtime·sbrk0(SB),NOSPLIT,$-8-8
   452		// Implemented as brk(NULL).
   453		MOVV	$0, R4
   454		MOVV	$SYS_brk, R2
   455		SYSCALL
   456		MOVV	R2, ret+0(FP)
   457		RET

View as plain text