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

View as plain text