Text file src/runtime/sys_freebsd_arm64.s

     1  // Copyright 2019 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, FreeBSD
     7  // /usr/src/sys/kern/syscalls.master for syscall numbers.
     8  //
     9  
    10  #include "go_asm.h"
    11  #include "go_tls.h"
    12  #include "textflag.h"
    13  #include "cgo/abi_arm64.h"
    14  
    15  #define CLOCK_REALTIME		0
    16  #define CLOCK_MONOTONIC		4
    17  #define FD_CLOEXEC		1
    18  #define F_SETFD			2
    19  #define F_GETFL			3
    20  #define F_SETFL			4
    21  #define O_NONBLOCK		4
    22  
    23  #define SYS_exit		1
    24  #define SYS_read		3
    25  #define SYS_write		4
    26  #define SYS_open		5
    27  #define SYS_close		6
    28  #define SYS_getpid		20
    29  #define SYS_kill		37
    30  #define SYS_sigaltstack		53
    31  #define SYS_munmap		73
    32  #define SYS_madvise		75
    33  #define SYS_setitimer		83
    34  #define SYS_fcntl		92
    35  #define SYS___sysctl		202
    36  #define SYS_nanosleep		240
    37  #define SYS_clock_gettime	232
    38  #define SYS_sched_yield		331
    39  #define SYS_sigprocmask		340
    40  #define SYS_kqueue		362
    41  #define SYS_kevent		363
    42  #define SYS_sigaction		416
    43  #define SYS_thr_exit		431
    44  #define SYS_thr_self		432
    45  #define SYS_thr_kill		433
    46  #define SYS__umtx_op		454
    47  #define SYS_thr_new		455
    48  #define SYS_mmap		477
    49  #define SYS_cpuset_getaffinity	487
    50  #define SYS_pipe2 		542
    51  
    52  TEXT emptyfunc<>(SB),0,$0-0
    53  	RET
    54  
    55  // func sys_umtx_op(addr *uint32, mode int32, val uint32, uaddr1 uintptr, ut *umtx_time) int32
    56  TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
    57  	MOVD	addr+0(FP), R0
    58  	MOVW	mode+8(FP), R1
    59  	MOVW	val+12(FP), R2
    60  	MOVD	uaddr1+16(FP), R3
    61  	MOVD	ut+24(FP), R4
    62  	MOVD	$SYS__umtx_op, R8
    63  	SVC
    64  	BCC	ok
    65  	NEG	R0, R0
    66  ok:
    67  	MOVW	R0, ret+32(FP)
    68  	RET
    69  
    70  // func thr_new(param *thrparam, size int32) int32
    71  TEXT runtime·thr_new(SB),NOSPLIT,$0
    72  	MOVD	param+0(FP), R0
    73  	MOVW	size+8(FP), R1
    74  	MOVD	$SYS_thr_new, R8
    75  	SVC
    76  	BCC	ok
    77  	NEG	R0, R0
    78  ok:
    79  	MOVW	R0, ret+16(FP)
    80  	RET
    81  
    82  // func thr_start()
    83  TEXT runtime·thr_start(SB),NOSPLIT,$0
    84  	// set up g
    85  	MOVD	m_g0(R0), g
    86  	MOVD	R0, g_m(g)
    87  	BL	emptyfunc<>(SB)	 // fault if stack check is wrong
    88  	BL	runtime·mstart(SB)
    89  
    90  	MOVD	$2, R8	// crash (not reached)
    91  	MOVD	R8, (R8)
    92  	RET
    93  
    94  // func exit(code int32)
    95  TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
    96  	MOVW	code+0(FP), R0
    97  	MOVD	$SYS_exit, R8
    98  	SVC
    99  	MOVD	$0, R0
   100  	MOVD	R0, (R0)
   101  
   102  // func exitThread(wait *uint32)
   103  TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
   104  	MOVD	wait+0(FP), R0
   105  	// We're done using the stack.
   106  	MOVW	$0, R1
   107  	STLRW	R1, (R0)
   108  	MOVW	$0, R0
   109  	MOVD	$SYS_thr_exit, R8
   110  	SVC
   111  	JMP	0(PC)
   112  
   113  // func open(name *byte, mode, perm int32) int32
   114  TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
   115  	MOVD	name+0(FP), R0
   116  	MOVW	mode+8(FP), R1
   117  	MOVW	perm+12(FP), R2
   118  	MOVD	$SYS_open, R8
   119  	SVC
   120  	BCC	ok
   121  	MOVW	$-1, R0
   122  ok:
   123  	MOVW	R0, ret+16(FP)
   124  	RET
   125  
   126  // func closefd(fd int32) int32
   127  TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
   128  	MOVW	fd+0(FP), R0
   129  	MOVD	$SYS_close, R8
   130  	SVC
   131  	BCC	ok
   132  	MOVW	$-1, R0
   133  ok:
   134  	MOVW	R0, ret+8(FP)
   135  	RET
   136  
   137  // func pipe2(flags int32) (r, w int32, errno int32)
   138  TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
   139  	MOVD	$r+8(FP), R0
   140  	MOVW	flags+0(FP), R1
   141  	MOVD	$SYS_pipe2, R8
   142  	SVC
   143  	BCC	ok
   144  	NEG	R0, R0
   145  ok:
   146  	MOVW	R0, errno+16(FP)
   147  	RET
   148  
   149  // func write1(fd uintptr, p unsafe.Pointer, n int32) int32
   150  TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28
   151  	MOVD	fd+0(FP), R0
   152  	MOVD	p+8(FP), R1
   153  	MOVW	n+16(FP), R2
   154  	MOVD	$SYS_write, R8
   155  	SVC
   156  	BCC	ok
   157  	NEG	R0, R0		// caller expects negative errno
   158  ok:
   159  	MOVW	R0, ret+24(FP)
   160  	RET
   161  
   162  // func read(fd int32, p unsafe.Pointer, n int32) int32
   163  TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
   164  	MOVW	fd+0(FP), R0
   165  	MOVD	p+8(FP), R1
   166  	MOVW	n+16(FP), R2
   167  	MOVD	$SYS_read, R8
   168  	SVC
   169  	BCC	ok
   170  	NEG	R0, R0		// caller expects negative errno
   171  ok:
   172  	MOVW	R0, ret+24(FP)
   173  	RET
   174  
   175  // func usleep(usec uint32)
   176  TEXT runtime·usleep(SB),NOSPLIT,$24-4
   177  	MOVWU	usec+0(FP), R3
   178  	MOVD	R3, R5
   179  	MOVW	$1000000, R4
   180  	UDIV	R4, R3
   181  	MOVD	R3, 8(RSP)
   182  	MUL	R3, R4
   183  	SUB	R4, R5
   184  	MOVW	$1000, R4
   185  	MUL	R4, R5
   186  	MOVD	R5, 16(RSP)
   187  
   188  	// nanosleep(&ts, 0)
   189  	ADD	$8, RSP, R0
   190  	MOVD	$0, R1
   191  	MOVD	$SYS_nanosleep, R8
   192  	SVC
   193  	RET
   194  
   195  // func thr_self() thread
   196  TEXT runtime·thr_self(SB),NOSPLIT,$8-8
   197  	MOVD	$ptr-8(SP), R0	// arg 1 &8(SP)
   198  	MOVD	$SYS_thr_self, R8
   199  	SVC
   200  	MOVD	ptr-8(SP), R0
   201  	MOVD	R0, ret+0(FP)
   202  	RET
   203  
   204  // func thr_kill(t thread, sig int)
   205  TEXT runtime·thr_kill(SB),NOSPLIT,$0-16
   206  	MOVD	tid+0(FP), R0	// arg 1 pid
   207  	MOVD	sig+8(FP), R1	// arg 2 sig
   208  	MOVD	$SYS_thr_kill, R8
   209  	SVC
   210  	RET
   211  
   212  // func raiseproc(sig uint32)
   213  TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
   214  	MOVD	$SYS_getpid, R8
   215  	SVC
   216  	MOVW	sig+0(FP), R1
   217  	MOVD	$SYS_kill, R8
   218  	SVC
   219  	RET
   220  
   221  // func setitimer(mode int32, new, old *itimerval)
   222  TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
   223  	MOVW	mode+0(FP), R0
   224  	MOVD	new+8(FP), R1
   225  	MOVD	old+16(FP), R2
   226  	MOVD	$SYS_setitimer, R8
   227  	SVC
   228  	RET
   229  
   230  // func fallback_walltime() (sec int64, nsec int32)
   231  TEXT runtime·fallback_walltime(SB),NOSPLIT,$24-12
   232  	MOVW	$CLOCK_REALTIME, R0
   233  	MOVD	$8(RSP), R1
   234  	MOVD	$SYS_clock_gettime, R8
   235  	SVC
   236  	MOVD	8(RSP), R0	// sec
   237  	MOVW	16(RSP), R1	// nsec
   238  	MOVD	R0, sec+0(FP)
   239  	MOVW	R1, nsec+8(FP)
   240  	RET
   241  
   242  // func fallback_nanotime() int64
   243  TEXT runtime·fallback_nanotime(SB),NOSPLIT,$24-8
   244  	MOVD	$CLOCK_MONOTONIC, R0
   245  	MOVD	$8(RSP), R1
   246  	MOVD	$SYS_clock_gettime, R8
   247  	SVC
   248  	MOVD	8(RSP), R0	// sec
   249  	MOVW	16(RSP), R2	// nsec
   250  
   251  	// sec is in R0, nsec in R2
   252  	// return nsec in R2
   253  	MOVD	$1000000000, R3
   254  	MUL	R3, R0
   255  	ADD	R2, R0
   256  
   257  	MOVD	R0, ret+0(FP)
   258  	RET
   259  
   260  // func asmSigaction(sig uintptr, new, old *sigactiont) int32
   261  TEXT runtime·asmSigaction(SB),NOSPLIT|NOFRAME,$0
   262  	MOVD	sig+0(FP), R0		// arg 1 sig
   263  	MOVD	new+8(FP), R1		// arg 2 act
   264  	MOVD	old+16(FP), R2		// arg 3 oact
   265  	MOVD	$SYS_sigaction, R8
   266  	SVC
   267  	BCC	ok
   268  	MOVW	$-1, R0
   269  ok:
   270  	MOVW	R0, ret+24(FP)
   271  	RET
   272  
   273  // func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
   274  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   275  	MOVW	sig+8(FP), R0
   276  	MOVD	info+16(FP), R1
   277  	MOVD	ctx+24(FP), R2
   278  	MOVD	fn+0(FP), R11
   279  	BL	(R11)
   280  	RET
   281  
   282  // func sigtramp()
   283  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$176
   284  	// Save callee-save registers in the case of signal forwarding.
   285  	// Please refer to https://golang.org/issue/31827 .
   286  	SAVE_R19_TO_R28(8*4)
   287  	SAVE_F8_TO_F15(8*14)
   288  
   289  	// this might be called in external code context,
   290  	// where g is not set.
   291  	// first save R0, because runtime·load_g will clobber it
   292  	MOVW	R0, 8(RSP)
   293  	MOVBU	runtime·iscgo(SB), R0
   294  	CMP	$0, R0
   295  	BEQ	2(PC)
   296  	BL	runtime·load_g(SB)
   297  
   298  #ifdef GOEXPERIMENT_regabiargs
   299  	// Restore signum to R0.
   300  	MOVW	8(RSP), R0
   301  	// R1 and R2 already contain info and ctx, respectively.
   302  #else
   303  	MOVD	R1, 16(RSP)
   304  	MOVD	R2, 24(RSP)
   305  #endif
   306  	MOVD	$runtime·sigtrampgo<ABIInternal>(SB), R3
   307  	BL	(R3)
   308  
   309  	// Restore callee-save registers.
   310  	RESTORE_R19_TO_R28(8*4)
   311  	RESTORE_F8_TO_F15(8*14)
   312  
   313  	RET
   314  
   315  // func mmap(addr uintptr, n uintptr, prot int, flags int, fd int, off int64) (ret uintptr, err error)
   316  TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
   317  	MOVD	addr+0(FP), R0
   318  	MOVD	n+8(FP), R1
   319  	MOVW	prot+16(FP), R2
   320  	MOVW	flags+20(FP), R3
   321  	MOVW	fd+24(FP), R4
   322  	MOVW	off+28(FP), R5
   323  	MOVD	$SYS_mmap, R8
   324  	SVC
   325  	BCS	fail
   326  	MOVD	R0, p+32(FP)
   327  	MOVD	$0, err+40(FP)
   328  	RET
   329  fail:
   330  	MOVD	$0, p+32(FP)
   331  	MOVD	R0, err+40(FP)
   332  	RET
   333  
   334  // func munmap(addr uintptr, n uintptr) (err error)
   335  TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
   336  	MOVD	addr+0(FP), R0
   337  	MOVD	n+8(FP), R1
   338  	MOVD	$SYS_munmap, R8
   339  	SVC
   340  	BCS	fail
   341  	RET
   342  fail:
   343  	MOVD	$0, R0
   344  	MOVD	R0, (R0)	// crash
   345  
   346  // func madvise(addr unsafe.Pointer, n uintptr, flags int32) int32
   347  TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
   348  	MOVD	addr+0(FP), R0
   349  	MOVD	n+8(FP), R1
   350  	MOVW	flags+16(FP), R2
   351  	MOVD	$SYS_madvise, R8
   352  	SVC
   353  	BCC	ok
   354  	MOVW	$-1, R0
   355  ok:
   356  	MOVW	R0, ret+24(FP)
   357  	RET
   358  
   359  // func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32
   360  TEXT runtime·sysctl(SB),NOSPLIT,$0
   361  	MOVD	mib+0(FP), R0
   362  	MOVD	miblen+8(FP), R1
   363  	MOVD	out+16(FP), R2
   364  	MOVD	size+24(FP), R3
   365  	MOVD	dst+32(FP), R4
   366  	MOVD	ndst+40(FP), R5
   367  	MOVD	$SYS___sysctl, R8
   368  	SVC
   369  	BCC	ok
   370  	NEG	R0, R0
   371  ok:
   372  	MOVW	R0, ret+48(FP)
   373  	RET
   374  
   375  // func sigaltstack(new, old *stackt)
   376  TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
   377  	MOVD	new+0(FP), R0
   378  	MOVD	old+8(FP), R1
   379  	MOVD	$SYS_sigaltstack, R8
   380  	SVC
   381  	BCS	fail
   382  	RET
   383  fail:
   384  	MOVD	$0, R0
   385  	MOVD	R0, (R0)	// crash
   386  
   387  // func osyield()
   388  TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
   389  	MOVD	$SYS_sched_yield, R8
   390  	SVC
   391  	RET
   392  
   393  // func sigprocmask(how int32, new, old *sigset)
   394  TEXT runtime·sigprocmask(SB),NOSPLIT|NOFRAME,$0-24
   395  	MOVW	how+0(FP), R0
   396  	MOVD	new+8(FP), R1
   397  	MOVD	old+16(FP), R2
   398  	MOVD	$SYS_sigprocmask, R8
   399  	SVC
   400  	BCS	fail
   401  	RET
   402  fail:
   403  	MOVD	$0, R0
   404  	MOVD	R0, (R0)	// crash
   405  
   406  // func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
   407  TEXT runtime·cpuset_getaffinity(SB),NOSPLIT|NOFRAME,$0-44
   408  	MOVD	level+0(FP), R0
   409  	MOVD	which+8(FP), R1
   410  	MOVD	id+16(FP), R2
   411  	MOVD	size+24(FP), R3
   412  	MOVD	mask+32(FP), R4
   413  	MOVD	$SYS_cpuset_getaffinity, R8
   414  	SVC
   415  	BCC	ok
   416  	MOVW	$-1, R0
   417  ok:
   418  	MOVW	R0, ret+40(FP)
   419  	RET
   420  
   421  // func kqueue() int32
   422  TEXT runtime·kqueue(SB),NOSPLIT|NOFRAME,$0
   423  	MOVD $SYS_kqueue, R8
   424  	SVC
   425  	BCC	ok
   426  	MOVW	$-1, R0
   427  ok:
   428  	MOVW	R0, ret+0(FP)
   429  	RET
   430  
   431  // func kevent(kq int, ch unsafe.Pointer, nch int, ev unsafe.Pointer, nev int, ts *Timespec) (n int, err error)
   432  TEXT runtime·kevent(SB),NOSPLIT,$0
   433  	MOVW	kq+0(FP), R0
   434  	MOVD	ch+8(FP), R1
   435  	MOVW	nch+16(FP), R2
   436  	MOVD	ev+24(FP), R3
   437  	MOVW	nev+32(FP), R4
   438  	MOVD	ts+40(FP), R5
   439  	MOVD	$SYS_kevent, R8
   440  	SVC
   441  	BCC	ok
   442  	NEG	R0, R0
   443  ok:
   444  	MOVW	R0, ret+48(FP)
   445  	RET
   446  
   447  // func closeonexec(fd int32)
   448  TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
   449  	MOVW	fd+0(FP), R0
   450  	MOVD	$F_SETFD, R1
   451  	MOVD	$FD_CLOEXEC, R2
   452  	MOVD	$SYS_fcntl, R8
   453  	SVC
   454  	RET
   455  
   456  // func getCntxct(physical bool) uint32
   457  TEXT runtime·getCntxct(SB),NOSPLIT,$0
   458  	MOVB	physical+0(FP), R0
   459  	CMP	$0, R0
   460  	BEQ	3(PC)
   461  
   462  	// get CNTPCT (Physical Count Register) into R0
   463  	MRS	CNTPCT_EL0, R0 // SIGILL
   464  	B	2(PC)
   465  
   466  	// get CNTVCT (Virtual Count Register) into R0
   467  	MRS	CNTVCT_EL0, R0
   468  
   469  	MOVW	R0, ret+8(FP)
   470  	RET
   471  

View as plain text