...
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_futex		5194
    39#define SYS_sched_getaffinity	5196
    40#define SYS_exit_group		5205
    41#define SYS_epoll_create	5207
    42#define SYS_epoll_ctl		5208
    43#define SYS_tgkill		5225
    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
    50TEXT 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)
    57TEXT 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
    69TEXT 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
    82TEXT 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
    91TEXT 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
   102TEXT 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
   113TEXT 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
   133TEXT runtime·gettid(SB),NOSPLIT,$0-4
   134	MOVV	$SYS_gettid, R2
   135	SYSCALL
   136	MOVW	R2, ret+0(FP)
   137	RET
   138
   139TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
   140	MOVV	$SYS_getpid, R2
   141	SYSCALL
   142	MOVW	R2, R16
   143	MOVV	$SYS_gettid, R2
   144	SYSCALL
   145	MOVW	R2, R5	// arg 2 tid
   146	MOVW	R16, R4	// arg 1 pid
   147	MOVW	sig+0(FP), R6	// arg 3
   148	MOVV	$SYS_tgkill, R2
   149	SYSCALL
   150	RET
   151
   152TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
   153	MOVV	$SYS_getpid, R2
   154	SYSCALL
   155	MOVW	R2, R4	// arg 1 pid
   156	MOVW	sig+0(FP), R5	// arg 2
   157	MOVV	$SYS_kill, R2
   158	SYSCALL
   159	RET
   160
   161TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
   162	MOVW	mode+0(FP), R4
   163	MOVV	new+8(FP), R5
   164	MOVV	old+16(FP), R6
   165	MOVV	$SYS_setitimer, R2
   166	SYSCALL
   167	RET
   168
   169TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28
   170	MOVV	addr+0(FP), R4
   171	MOVV	n+8(FP), R5
   172	MOVV	dst+16(FP), R6
   173	MOVV	$SYS_mincore, R2
   174	SYSCALL
   175	SUBVU	R2, R0, R2	// caller expects negative errno
   176	MOVW	R2, ret+24(FP)
   177	RET
   178
   179// func walltime() (sec int64, nsec int32)
   180TEXT runtime·walltime(SB),NOSPLIT,$16
   181	MOVW	$0, R4 // CLOCK_REALTIME
   182	MOVV	$0(R29), R5
   183	MOVV	$SYS_clock_gettime, R2
   184	SYSCALL
   185	MOVV	0(R29), R3	// sec
   186	MOVV	8(R29), R5	// nsec
   187	MOVV	R3, sec+0(FP)
   188	MOVW	R5, nsec+8(FP)
   189	RET
   190
   191TEXT runtime·nanotime(SB),NOSPLIT,$16
   192	MOVW	$1, R4 // CLOCK_MONOTONIC
   193	MOVV	$0(R29), R5
   194	MOVV	$SYS_clock_gettime, R2
   195	SYSCALL
   196	MOVV	0(R29), R3	// sec
   197	MOVV	8(R29), R5	// nsec
   198	// sec is in R3, nsec in R5
   199	// return nsec in R3
   200	MOVV	$1000000000, R4
   201	MULVU	R4, R3
   202	MOVV	LO, R3
   203	ADDVU	R5, R3
   204	MOVV	R3, ret+0(FP)
   205	RET
   206
   207TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
   208	MOVW	how+0(FP), R4
   209	MOVV	new+8(FP), R5
   210	MOVV	old+16(FP), R6
   211	MOVW	size+24(FP), R7
   212	MOVV	$SYS_rt_sigprocmask, R2
   213	SYSCALL
   214	BEQ	R7, 2(PC)
   215	MOVV	R0, 0xf1(R0)	// crash
   216	RET
   217
   218TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
   219	MOVV	sig+0(FP), R4
   220	MOVV	new+8(FP), R5
   221	MOVV	old+16(FP), R6
   222	MOVV	size+24(FP), R7
   223	MOVV	$SYS_rt_sigaction, R2
   224	SYSCALL
   225	BEQ	R7, 2(PC)
   226	SUBVU	R2, R0, R2	// caller expects negative errno
   227	MOVW	R2, ret+32(FP)
   228	RET
   229
   230TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   231	MOVW	sig+8(FP), R4
   232	MOVV	info+16(FP), R5
   233	MOVV	ctx+24(FP), R6
   234	MOVV	fn+0(FP), R25
   235	JAL	(R25)
   236	RET
   237
   238TEXT runtime·sigtramp(SB),NOSPLIT,$64
   239	// initialize REGSB = PC&0xffffffff00000000
   240	BGEZAL	R0, 1(PC)
   241	SRLV	$32, R31, RSB
   242	SLLV	$32, RSB
   243
   244	// this might be called in external code context,
   245	// where g is not set.
   246	MOVB	runtime·iscgo(SB), R1
   247	BEQ	R1, 2(PC)
   248	JAL	runtime·load_g(SB)
   249
   250	MOVW	R4, 8(R29)
   251	MOVV	R5, 16(R29)
   252	MOVV	R6, 24(R29)
   253	MOVV	$runtime·sigtrampgo(SB), R1
   254	JAL	(R1)
   255	RET
   256
   257TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   258	JMP	runtime·sigtramp(SB)
   259
   260TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
   261	MOVV	addr+0(FP), R4
   262	MOVV	n+8(FP), R5
   263	MOVW	prot+16(FP), R6
   264	MOVW	flags+20(FP), R7
   265	MOVW	fd+24(FP), R8
   266	MOVW	off+28(FP), R9
   267
   268	MOVV	$SYS_mmap, R2
   269	SYSCALL
   270	BEQ	R7, ok
   271	MOVV	$0, p+32(FP)
   272	MOVV	R2, err+40(FP)
   273	RET
   274ok:
   275	MOVV	R2, p+32(FP)
   276	MOVV	$0, err+40(FP)
   277	RET
   278
   279TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
   280	MOVV	addr+0(FP), R4
   281	MOVV	n+8(FP), R5
   282	MOVV	$SYS_munmap, R2
   283	SYSCALL
   284	BEQ	R7, 2(PC)
   285	MOVV	R0, 0xf3(R0)	// crash
   286	RET
   287
   288TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
   289	MOVV	addr+0(FP), R4
   290	MOVV	n+8(FP), R5
   291	MOVW	flags+16(FP), R6
   292	MOVV	$SYS_madvise, R2
   293	SYSCALL
   294	MOVW	R2, ret+24(FP)
   295	RET
   296
   297// int64 futex(int32 *uaddr, int32 op, int32 val,
   298//	struct timespec *timeout, int32 *uaddr2, int32 val2);
   299TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
   300	MOVV	addr+0(FP), R4
   301	MOVW	op+8(FP), R5
   302	MOVW	val+12(FP), R6
   303	MOVV	ts+16(FP), R7
   304	MOVV	addr2+24(FP), R8
   305	MOVW	val3+32(FP), R9
   306	MOVV	$SYS_futex, R2
   307	SYSCALL
   308	BEQ	R7, 2(PC)
   309	SUBVU	R2, R0, R2	// caller expects negative errno
   310	MOVW	R2, ret+40(FP)
   311	RET
   312
   313// int64 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   314TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
   315	MOVW	flags+0(FP), R4
   316	MOVV	stk+8(FP), R5
   317
   318	// Copy mp, gp, fn off parent stack for use by child.
   319	// Careful: Linux system call clobbers ???.
   320	MOVV	mp+16(FP), R16
   321	MOVV	gp+24(FP), R17
   322	MOVV	fn+32(FP), R18
   323
   324	MOVV	R16, -8(R5)
   325	MOVV	R17, -16(R5)
   326	MOVV	R18, -24(R5)
   327	MOVV	$1234, R16
   328	MOVV	R16, -32(R5)
   329
   330	MOVV	$SYS_clone, R2
   331	SYSCALL
   332	BEQ	R7, 2(PC)
   333	SUBVU	R2, R0, R2	// caller expects negative errno
   334
   335	// In parent, return.
   336	BEQ	R2, 3(PC)
   337	MOVW	R2, ret+40(FP)
   338	RET
   339
   340	// In child, on new stack.
   341	MOVV	-32(R29), R16
   342	MOVV	$1234, R1
   343	BEQ	R16, R1, 2(PC)
   344	MOVV	R0, 0(R0)
   345
   346	// Initialize m->procid to Linux tid
   347	MOVV	$SYS_gettid, R2
   348	SYSCALL
   349
   350	MOVV	-24(R29), R18		// fn
   351	MOVV	-16(R29), R17		// g
   352	MOVV	-8(R29), R16		// m
   353
   354	BEQ	R16, nog
   355	BEQ	R17, nog
   356
   357	MOVV	R2, m_procid(R16)
   358
   359	// TODO: setup TLS.
   360
   361	// In child, set up new stack
   362	MOVV	R16, g_m(R17)
   363	MOVV	R17, g
   364	//CALL	runtime·stackcheck(SB)
   365
   366nog:
   367	// Call fn
   368	JAL	(R18)
   369
   370	// It shouldn't return.	 If it does, exit that thread.
   371	MOVW	$111, R4
   372	MOVV	$SYS_exit, R2
   373	SYSCALL
   374	JMP	-3(PC)	// keep exiting
   375
   376TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
   377	MOVV	new+0(FP), R4
   378	MOVV	old+8(FP), R5
   379	MOVV	$SYS_sigaltstack, R2
   380	SYSCALL
   381	BEQ	R7, 2(PC)
   382	MOVV	R0, 0xf1(R0)	// crash
   383	RET
   384
   385TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
   386	MOVV	$SYS_sched_yield, R2
   387	SYSCALL
   388	RET
   389
   390TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
   391	MOVV	pid+0(FP), R4
   392	MOVV	len+8(FP), R5
   393	MOVV	buf+16(FP), R6
   394	MOVV	$SYS_sched_getaffinity, R2
   395	SYSCALL
   396	BEQ	R7, 2(PC)
   397	SUBVU	R2, R0, R2	// caller expects negative errno
   398	MOVW	R2, ret+24(FP)
   399	RET
   400
   401// int32 runtime·epollcreate(int32 size);
   402TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
   403	MOVW    size+0(FP), R4
   404	MOVV	$SYS_epoll_create, R2
   405	SYSCALL
   406	BEQ	R7, 2(PC)
   407	SUBVU	R2, R0, R2	// caller expects negative errno
   408	MOVW	R2, ret+8(FP)
   409	RET
   410
   411// int32 runtime·epollcreate1(int32 flags);
   412TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
   413	MOVW	flags+0(FP), R4
   414	MOVV	$SYS_epoll_create1, R2
   415	SYSCALL
   416	BEQ	R7, 2(PC)
   417	SUBVU	R2, R0, R2	// caller expects negative errno
   418	MOVW	R2, ret+8(FP)
   419	RET
   420
   421// func epollctl(epfd, op, fd int32, ev *epollEvent) int
   422TEXT runtime·epollctl(SB),NOSPLIT|NOFRAME,$0
   423	MOVW	epfd+0(FP), R4
   424	MOVW	op+4(FP), R5
   425	MOVW	fd+8(FP), R6
   426	MOVV	ev+16(FP), R7
   427	MOVV	$SYS_epoll_ctl, R2
   428	SYSCALL
   429	SUBVU	R2, R0, R2	// caller expects negative errno
   430	MOVW	R2, ret+24(FP)
   431	RET
   432
   433// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
   434TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
   435	// This uses pwait instead of wait, because Android O blocks wait.
   436	MOVW	epfd+0(FP), R4
   437	MOVV	ev+8(FP), R5
   438	MOVW	nev+16(FP), R6
   439	MOVW	timeout+20(FP), R7
   440	MOVV	$0, R8
   441	MOVV	$SYS_epoll_pwait, R2
   442	SYSCALL
   443	BEQ	R7, 2(PC)
   444	SUBVU	R2, R0, R2	// caller expects negative errno
   445	MOVW	R2, ret+24(FP)
   446	RET
   447
   448// void runtime·closeonexec(int32 fd);
   449TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
   450	MOVW    fd+0(FP), R4  // fd
   451	MOVV    $2, R5  // F_SETFD
   452	MOVV    $1, R6  // FD_CLOEXEC
   453	MOVV	$SYS_fcntl, R2
   454	SYSCALL
   455	RET
   456
   457// func sbrk0() uintptr
   458TEXT runtime·sbrk0(SB),NOSPLIT|NOFRAME,$0-8
   459	// Implemented as brk(NULL).
   460	MOVV	$0, R4
   461	MOVV	$SYS_brk, R2
   462	SYSCALL
   463	MOVV	R2, ret+0(FP)
   464	RET

View as plain text