...
Run Format

Text file src/runtime/sys_linux_arm64.s

Documentation: runtime

     1	// Copyright 2014 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	//
     6	// System calls and other sys.stuff for arm64, Linux
     7	//
     8	
     9	#include "go_asm.h"
    10	#include "go_tls.h"
    11	#include "textflag.h"
    12	
    13	#define AT_FDCWD -100
    14	
    15	#define SYS_exit		93
    16	#define SYS_read		63
    17	#define SYS_write		64
    18	#define SYS_openat		56
    19	#define SYS_close		57
    20	#define SYS_fcntl		25
    21	#define SYS_gettimeofday	169
    22	#define SYS_pselect6		72
    23	#define SYS_mmap		222
    24	#define SYS_munmap		215
    25	#define SYS_setitimer		103
    26	#define SYS_clone		220
    27	#define SYS_sched_yield		124
    28	#define SYS_rt_sigreturn	139
    29	#define SYS_rt_sigaction	134
    30	#define SYS_rt_sigprocmask	135
    31	#define SYS_sigaltstack		132
    32	#define SYS_getrlimit		163
    33	#define SYS_madvise		233
    34	#define SYS_mincore		232
    35	#define SYS_getpid		172
    36	#define SYS_gettid		178
    37	#define SYS_kill		129
    38	#define SYS_tkill		130
    39	#define SYS_futex		98
    40	#define SYS_sched_getaffinity	123
    41	#define SYS_exit_group		94
    42	#define SYS_epoll_create1	20
    43	#define SYS_epoll_ctl		21
    44	#define SYS_epoll_pwait		22
    45	#define SYS_clock_gettime	113
    46	#define SYS_faccessat		48
    47	#define SYS_socket		198
    48	#define SYS_connect		203
    49	#define SYS_brk			214
    50	
    51	TEXT runtime·exit(SB),NOSPLIT,$-8-4
    52		MOVW	code+0(FP), R0
    53		MOVD	$SYS_exit_group, R8
    54		SVC
    55		RET
    56	
    57	TEXT runtime·exit1(SB),NOSPLIT,$-8-4
    58		MOVW	code+0(FP), R0
    59		MOVD	$SYS_exit, R8
    60		SVC
    61		RET
    62	
    63	TEXT runtime·open(SB),NOSPLIT,$-8-20
    64		MOVD	$AT_FDCWD, R0
    65		MOVD	name+0(FP), R1
    66		MOVW	mode+8(FP), R2
    67		MOVW	perm+12(FP), R3
    68		MOVD	$SYS_openat, R8
    69		SVC
    70		CMN	$4095, R0
    71		BCC	done
    72		MOVW	$-1, R0
    73	done:
    74		MOVW	R0, ret+16(FP)
    75		RET
    76	
    77	TEXT runtime·closefd(SB),NOSPLIT,$-8-12
    78		MOVW	fd+0(FP), R0
    79		MOVD	$SYS_close, R8
    80		SVC
    81		CMN	$4095, R0
    82		BCC	done
    83		MOVW	$-1, R0
    84	done:
    85		MOVW	R0, ret+8(FP)
    86		RET
    87	
    88	TEXT runtime·write(SB),NOSPLIT,$-8-28
    89		MOVD	fd+0(FP), R0
    90		MOVD	p+8(FP), R1
    91		MOVW	n+16(FP), R2
    92		MOVD	$SYS_write, R8
    93		SVC
    94		CMN	$4095, R0
    95		BCC	done
    96		MOVW	$-1, R0
    97	done:
    98		MOVW	R0, ret+24(FP)
    99		RET
   100	
   101	TEXT runtime·read(SB),NOSPLIT,$-8-28
   102		MOVW	fd+0(FP), R0
   103		MOVD	p+8(FP), R1
   104		MOVW	n+16(FP), R2
   105		MOVD	$SYS_read, R8
   106		SVC
   107		CMN	$4095, R0
   108		BCC	done
   109		MOVW	$-1, R0
   110	done:
   111		MOVW	R0, ret+24(FP)
   112		RET
   113	
   114	TEXT runtime·getrlimit(SB),NOSPLIT,$-8-20
   115		MOVW	kind+0(FP), R0
   116		MOVD	limit+8(FP), R1
   117		MOVD	$SYS_getrlimit, R8
   118		SVC
   119		MOVW	R0, ret+16(FP)
   120		RET
   121	
   122	TEXT runtime·usleep(SB),NOSPLIT,$24-4
   123		MOVWU	usec+0(FP), R3
   124		MOVD	R3, R5
   125		MOVW	$1000000, R4
   126		UDIV	R4, R3
   127		MOVD	R3, 8(RSP)
   128		MUL	R3, R4
   129		SUB	R4, R5
   130		MOVW	$1000, R4
   131		MUL	R4, R5
   132		MOVD	R5, 16(RSP)
   133	
   134		// pselect6(0, 0, 0, 0, &ts, 0)
   135		MOVD	$0, R0
   136		MOVD	R0, R1
   137		MOVD	R0, R2
   138		MOVD	R0, R3
   139		ADD	$8, RSP, R4
   140		MOVD	R0, R5
   141		MOVD	$SYS_pselect6, R8
   142		SVC
   143		RET
   144	
   145	TEXT runtime·gettid(SB),NOSPLIT,$0-4
   146		MOVD	$SYS_gettid, R8
   147		SVC
   148		MOVW	R0, ret+0(FP)
   149		RET
   150	
   151	TEXT runtime·raise(SB),NOSPLIT,$-8
   152		MOVD	$SYS_gettid, R8
   153		SVC
   154		MOVW	R0, R0	// arg 1 tid
   155		MOVW	sig+0(FP), R1	// arg 2
   156		MOVD	$SYS_tkill, R8
   157		SVC
   158		RET
   159	
   160	TEXT runtime·raiseproc(SB),NOSPLIT,$-8
   161		MOVD	$SYS_getpid, R8
   162		SVC
   163		MOVW	R0, R0		// arg 1 pid
   164		MOVW	sig+0(FP), R1	// arg 2
   165		MOVD	$SYS_kill, R8
   166		SVC
   167		RET
   168	
   169	TEXT runtime·setitimer(SB),NOSPLIT,$-8-24
   170		MOVW	mode+0(FP), R0
   171		MOVD	new+8(FP), R1
   172		MOVD	old+16(FP), R2
   173		MOVD	$SYS_setitimer, R8
   174		SVC
   175		RET
   176	
   177	TEXT runtime·mincore(SB),NOSPLIT,$-8-28
   178		MOVD	addr+0(FP), R0
   179		MOVD	n+8(FP), R1
   180		MOVD	dst+16(FP), R2
   181		MOVD	$SYS_mincore, R8
   182		SVC
   183		MOVW	R0, ret+24(FP)
   184		RET
   185	
   186	// func walltime() (sec int64, nsec int32)
   187	TEXT runtime·walltime(SB),NOSPLIT,$24-12
   188		MOVW	$0, R0 // CLOCK_REALTIME
   189		MOVD	RSP, R1
   190		MOVD	$SYS_clock_gettime, R8
   191		SVC
   192		MOVD	0(RSP), R3	// sec
   193		MOVD	8(RSP), R5	// nsec
   194		MOVD	R3, sec+0(FP)
   195		MOVW	R5, nsec+8(FP)
   196		RET
   197	
   198	TEXT runtime·nanotime(SB),NOSPLIT,$24-8
   199		MOVW	$1, R0 // CLOCK_MONOTONIC
   200		MOVD	RSP, R1
   201		MOVD	$SYS_clock_gettime, R8
   202		SVC
   203		MOVD	0(RSP), R3	// sec
   204		MOVD	8(RSP), R5	// nsec
   205		// sec is in R3, nsec in R5
   206		// return nsec in R3
   207		MOVD	$1000000000, R4
   208		MUL	R4, R3
   209		ADD	R5, R3
   210		MOVD	R3, ret+0(FP)
   211		RET
   212	
   213	TEXT runtime·rtsigprocmask(SB),NOSPLIT,$-8-28
   214		MOVW	how+0(FP), R0
   215		MOVD	new+8(FP), R1
   216		MOVD	old+16(FP), R2
   217		MOVW	size+24(FP), R3
   218		MOVD	$SYS_rt_sigprocmask, R8
   219		SVC
   220		CMN	$4095, R0
   221		BCC	done
   222		MOVD	$0, R0
   223		MOVD	R0, (R0)	// crash
   224	done:
   225		RET
   226	
   227	TEXT runtime·rt_sigaction(SB),NOSPLIT,$-8-36
   228		MOVD	sig+0(FP), R0
   229		MOVD	new+8(FP), R1
   230		MOVD	old+16(FP), R2
   231		MOVD	size+24(FP), R3
   232		MOVD	$SYS_rt_sigaction, R8
   233		SVC
   234		MOVW	R0, ret+32(FP)
   235		RET
   236	
   237	TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   238		MOVW	sig+8(FP), R0
   239		MOVD	info+16(FP), R1
   240		MOVD	ctx+24(FP), R2
   241		MOVD	fn+0(FP), R11
   242		BL	(R11)
   243		RET
   244	
   245	TEXT runtime·sigtramp(SB),NOSPLIT,$24
   246		// this might be called in external code context,
   247		// where g is not set.
   248		// first save R0, because runtime·load_g will clobber it
   249		MOVW	R0, 8(RSP)
   250		MOVBU	runtime·iscgo(SB), R0
   251		CMP	$0, R0
   252		BEQ	2(PC)
   253		BL	runtime·load_g(SB)
   254	
   255		MOVD	R1, 16(RSP)
   256		MOVD	R2, 24(RSP)
   257		MOVD	$runtime·sigtrampgo(SB), R0
   258		BL	(R0)
   259		RET
   260	
   261	TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   262		MOVD	$runtime·sigtramp(SB), R3
   263		B	(R3)
   264	
   265	TEXT runtime·mmap(SB),NOSPLIT,$-8
   266		MOVD	addr+0(FP), R0
   267		MOVD	n+8(FP), R1
   268		MOVW	prot+16(FP), R2
   269		MOVW	flags+20(FP), R3
   270		MOVW	fd+24(FP), R4
   271		MOVW	off+28(FP), R5
   272	
   273		MOVD	$SYS_mmap, R8
   274		SVC
   275		CMN	$4095, R0
   276		BCC	2(PC)
   277		NEG	R0,R0
   278		MOVD	R0, ret+32(FP)
   279		RET
   280	
   281	TEXT runtime·munmap(SB),NOSPLIT,$-8
   282		MOVD	addr+0(FP), R0
   283		MOVD	n+8(FP), R1
   284		MOVD	$SYS_munmap, R8
   285		SVC
   286		CMN	$4095, R0
   287		BCC	cool
   288		MOVD	R0, 0xf0(R0)
   289	cool:
   290		RET
   291	
   292	TEXT runtime·madvise(SB),NOSPLIT,$-8
   293		MOVD	addr+0(FP), R0
   294		MOVD	n+8(FP), R1
   295		MOVW	flags+16(FP), R2
   296		MOVD	$SYS_madvise, R8
   297		SVC
   298		// ignore failure - maybe pages are locked
   299		RET
   300	
   301	// int64 futex(int32 *uaddr, int32 op, int32 val,
   302	//	struct timespec *timeout, int32 *uaddr2, int32 val2);
   303	TEXT runtime·futex(SB),NOSPLIT,$-8
   304		MOVD	addr+0(FP), R0
   305		MOVW	op+8(FP), R1
   306		MOVW	val+12(FP), R2
   307		MOVD	ts+16(FP), R3
   308		MOVD	addr2+24(FP), R4
   309		MOVW	val3+32(FP), R5
   310		MOVD	$SYS_futex, R8
   311		SVC
   312		MOVW	R0, ret+40(FP)
   313		RET
   314	
   315	// int64 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   316	TEXT runtime·clone(SB),NOSPLIT,$-8
   317		MOVW	flags+0(FP), R0
   318		MOVD	stk+8(FP), R1
   319	
   320		// Copy mp, gp, fn off parent stack for use by child.
   321		MOVD	mp+16(FP), R10
   322		MOVD	gp+24(FP), R11
   323		MOVD	fn+32(FP), R12
   324	
   325		MOVD	R10, -8(R1)
   326		MOVD	R11, -16(R1)
   327		MOVD	R12, -24(R1)
   328		MOVD	$1234, R10
   329		MOVD	R10, -32(R1)
   330	
   331		MOVD	$SYS_clone, R8
   332		SVC
   333	
   334		// In parent, return.
   335		CMP	ZR, R0
   336		BEQ	child
   337		MOVW	R0, ret+40(FP)
   338		RET
   339	child:
   340	
   341		// In child, on new stack.
   342		MOVD	-32(RSP), R10
   343		MOVD	$1234, R0
   344		CMP	R0, R10
   345		BEQ	good
   346		MOVD	$0, R0
   347		MOVD	R0, (R0)	// crash
   348	
   349	good:
   350		// Initialize m->procid to Linux tid
   351		MOVD	$SYS_gettid, R8
   352		SVC
   353	
   354		MOVD	-24(RSP), R12     // fn
   355		MOVD	-16(RSP), R11     // g
   356		MOVD	-8(RSP), R10      // m
   357	
   358		CMP	$0, R10
   359		BEQ	nog
   360		CMP	$0, R11
   361		BEQ	nog
   362	
   363		MOVD	R0, m_procid(R10)
   364	
   365		// TODO: setup TLS.
   366	
   367		// In child, set up new stack
   368		MOVD	R10, g_m(R11)
   369		MOVD	R11, g
   370		//CALL	runtime·stackcheck(SB)
   371	
   372	nog:
   373		// Call fn
   374		MOVD	R12, R0
   375		BL	(R0)
   376	
   377		// It shouldn't return.	 If it does, exit that thread.
   378		MOVW	$111, R0
   379	again:
   380		MOVD	$SYS_exit, R8
   381		SVC
   382		B	again	// keep exiting
   383	
   384	TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   385		MOVD	new+0(FP), R0
   386		MOVD	old+8(FP), R1
   387		MOVD	$SYS_sigaltstack, R8
   388		SVC
   389		CMN	$4095, R0
   390		BCC	ok
   391		MOVD	$0, R0
   392		MOVD	R0, (R0)	// crash
   393	ok:
   394		RET
   395	
   396	TEXT runtime·osyield(SB),NOSPLIT,$-8
   397		MOVD	$SYS_sched_yield, R8
   398		SVC
   399		RET
   400	
   401	TEXT runtime·sched_getaffinity(SB),NOSPLIT,$-8
   402		MOVD	pid+0(FP), R0
   403		MOVD	len+8(FP), R1
   404		MOVD	buf+16(FP), R2
   405		MOVD	$SYS_sched_getaffinity, R8
   406		SVC
   407		MOVW	R0, ret+24(FP)
   408		RET
   409	
   410	// int32 runtime·epollcreate(int32 size);
   411	TEXT runtime·epollcreate(SB),NOSPLIT,$-8
   412		MOVW	$0, R0
   413		MOVD	$SYS_epoll_create1, R8
   414		SVC
   415		MOVW	R0, ret+8(FP)
   416		RET
   417	
   418	// int32 runtime·epollcreate1(int32 flags);
   419	TEXT runtime·epollcreate1(SB),NOSPLIT,$-8
   420		MOVW	flags+0(FP), R0
   421		MOVD	$SYS_epoll_create1, R8
   422		SVC
   423		MOVW	R0, ret+8(FP)
   424		RET
   425	
   426	// func epollctl(epfd, op, fd int32, ev *epollEvent) int
   427	TEXT runtime·epollctl(SB),NOSPLIT,$-8
   428		MOVW	epfd+0(FP), R0
   429		MOVW	op+4(FP), R1
   430		MOVW	fd+8(FP), R2
   431		MOVD	ev+16(FP), R3
   432		MOVD	$SYS_epoll_ctl, R8
   433		SVC
   434		MOVW	R0, ret+24(FP)
   435		RET
   436	
   437	// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
   438	TEXT runtime·epollwait(SB),NOSPLIT,$-8
   439		MOVW	epfd+0(FP), R0
   440		MOVD	ev+8(FP), R1
   441		MOVW	nev+16(FP), R2
   442		MOVW	timeout+20(FP), R3
   443		MOVD	$0, R4
   444		MOVD	$SYS_epoll_pwait, R8
   445		SVC
   446		MOVW	R0, ret+24(FP)
   447		RET
   448	
   449	// void runtime·closeonexec(int32 fd);
   450	TEXT runtime·closeonexec(SB),NOSPLIT,$-8
   451		MOVW	fd+0(FP), R0  // fd
   452		MOVD	$2, R1	// F_SETFD
   453		MOVD	$1, R2	// FD_CLOEXEC
   454		MOVD	$SYS_fcntl, R8
   455		SVC
   456		RET
   457	
   458	// int access(const char *name, int mode)
   459	TEXT runtime·access(SB),NOSPLIT,$0-20
   460		MOVD	$AT_FDCWD, R0
   461		MOVD	name+0(FP), R1
   462		MOVW	mode+8(FP), R2
   463		MOVD	$SYS_faccessat, R8
   464		SVC
   465		MOVW	R0, ret+16(FP)
   466		RET
   467	
   468	// int connect(int fd, const struct sockaddr *addr, socklen_t len)
   469	TEXT runtime·connect(SB),NOSPLIT,$0-28
   470		MOVW	fd+0(FP), R0
   471		MOVD	addr+8(FP), R1
   472		MOVW	len+16(FP), R2
   473		MOVD	$SYS_connect, R8
   474		SVC
   475		MOVW	R0, ret+24(FP)
   476		RET
   477	
   478	// int socket(int domain, int typ, int prot)
   479	TEXT runtime·socket(SB),NOSPLIT,$0-20
   480		MOVW	domain+0(FP), R0
   481		MOVW	typ+4(FP), R1
   482		MOVW	prot+8(FP), R2
   483		MOVD	$SYS_socket, R8
   484		SVC
   485		MOVW	R0, ret+16(FP)
   486		RET
   487	
   488	// func sbrk0() uintptr
   489	TEXT runtime·sbrk0(SB),NOSPLIT,$0-8
   490		// Implemented as brk(NULL).
   491		MOVD	$0, R0
   492		MOVD	$SYS_brk, R8
   493		SVC
   494		MOVD	R0, ret+0(FP)
   495		RET

View as plain text