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

View as plain text