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

View as plain text