Text file src/runtime/sys_netbsd_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, NetBSD
     7  //
     8  
     9  #include "go_asm.h"
    10  #include "go_tls.h"
    11  #include "textflag.h"
    12  
    13  #define CLOCK_REALTIME		0
    14  #define CLOCK_MONOTONIC		3
    15  #define FD_CLOEXEC		1
    16  #define F_SETFD			2
    17  #define F_GETFL			3
    18  #define F_SETFL			4
    19  #define O_NONBLOCK		4
    20  
    21  #define SYS_exit			1
    22  #define SYS_read			3
    23  #define SYS_write			4
    24  #define SYS_open			5
    25  #define SYS_close			6
    26  #define SYS_getpid			20
    27  #define SYS_kill			37
    28  #define SYS_munmap			73
    29  #define SYS_madvise			75
    30  #define SYS_fcntl			92
    31  #define SYS_mmap			197
    32  #define SYS___sysctl			202
    33  #define SYS___sigaltstack14		281
    34  #define SYS___sigprocmask14		293
    35  #define SYS_getcontext			307
    36  #define SYS_setcontext			308
    37  #define SYS__lwp_create			309
    38  #define SYS__lwp_exit			310
    39  #define SYS__lwp_self			311
    40  #define SYS__lwp_kill			318
    41  #define SYS__lwp_unpark			321
    42  #define SYS___sigaction_sigtramp	340
    43  #define SYS_kqueue			344
    44  #define SYS_sched_yield			350
    45  #define SYS___setitimer50		425
    46  #define SYS___clock_gettime50		427
    47  #define SYS___nanosleep50		430
    48  #define SYS___kevent50			435
    49  #define SYS_pipe2			453
    50  #define SYS_openat			468
    51  #define SYS____lwp_park60		478
    52  
    53  // int32 lwp_create(void *context, uintptr flags, void *lwpid)
    54  TEXT runtime·lwp_create(SB),NOSPLIT,$0
    55  	MOVD	ctxt+0(FP), R0
    56  	MOVD	flags+8(FP), R1
    57  	MOVD	lwpid+16(FP), R2
    58  	SVC	$SYS__lwp_create
    59  	BCC	ok
    60  	NEG	R0, R0
    61  ok:
    62  	MOVW	R0, ret+24(FP)
    63  	RET
    64  
    65  TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
    66  	CMP	$0, R1
    67  	BEQ	nog
    68  	CMP	$0, R2
    69  	BEQ	nog
    70  
    71  	MOVD	R0, g_m(R1)
    72  	MOVD	R1, g
    73  nog:
    74  	CALL	(R2)
    75  
    76  	MOVD	$0, R0  // crash (not reached)
    77  	MOVD	R0, (R8)
    78  
    79  TEXT ·netbsdMstart(SB),NOSPLIT|TOPFRAME,$0
    80  	CALL	·netbsdMstart0(SB)
    81  	RET // not reached
    82  
    83  TEXT runtime·osyield(SB),NOSPLIT,$0
    84  	SVC	$SYS_sched_yield
    85  	RET
    86  
    87  TEXT runtime·lwp_park(SB),NOSPLIT,$0
    88  	MOVW	clockid+0(FP), R0	// arg 1 - clockid
    89  	MOVW	flags+4(FP), R1		// arg 2 - flags
    90  	MOVD	ts+8(FP), R2		// arg 3 - ts
    91  	MOVW	unpark+16(FP), R3	// arg 4 - unpark
    92  	MOVD	hint+24(FP), R4		// arg 5 - hint
    93  	MOVD	unparkhint+32(FP), R5	// arg 6 - unparkhint
    94  	SVC	$SYS____lwp_park60
    95  	MOVW	R0, ret+40(FP)
    96  	RET
    97  
    98  TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
    99  	MOVW	lwp+0(FP), R0		// arg 1 - lwp
   100  	MOVD	hint+8(FP), R1		// arg 2 - hint
   101  	SVC	$SYS__lwp_unpark
   102  	MOVW	R0, ret+16(FP)
   103  	RET
   104  
   105  TEXT runtime·lwp_self(SB),NOSPLIT,$0
   106  	SVC	$SYS__lwp_self
   107  	MOVW	R0, ret+0(FP)
   108  	RET
   109  
   110  // Exit the entire program (like C exit)
   111  TEXT runtime·exit(SB),NOSPLIT,$-8
   112  	MOVW	code+0(FP), R0		// arg 1 - exit status
   113  	SVC	$SYS_exit
   114  	MOVD	$0, R0			// If we're still running,
   115  	MOVD	R0, (R0)		// crash
   116  
   117  // func exitThread(wait *uint32)
   118  TEXT runtime·exitThread(SB),NOSPLIT,$0-8
   119  	MOVD	wait+0(FP), R0
   120  	// We're done using the stack.
   121  	MOVW	$0, R1
   122  	STLRW	R1, (R0)
   123  	SVC	$SYS__lwp_exit
   124  	JMP	0(PC)
   125  
   126  TEXT runtime·open(SB),NOSPLIT|NOFRAME,$-8
   127  	MOVD	name+0(FP), R0		// arg 1 - pathname
   128  	MOVW	mode+8(FP), R1		// arg 2 - flags
   129  	MOVW	perm+12(FP), R2		// arg 3 - mode
   130  	SVC	$SYS_open
   131  	BCC	ok
   132  	MOVW	$-1, R0
   133  ok:
   134  	MOVW	R0, ret+16(FP)
   135  	RET
   136  
   137  TEXT runtime·closefd(SB),NOSPLIT,$-8
   138  	MOVW	fd+0(FP), R0		// arg 1 - fd
   139  	SVC	$SYS_close
   140  	BCC	ok
   141  	MOVW	$-1, R0
   142  ok:
   143  	MOVW	R0, ret+8(FP)
   144  	RET
   145  
   146  TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
   147  	MOVW	fd+0(FP), R0		// arg 1 - fd
   148  	MOVD	p+8(FP), R1		// arg 2 - buf
   149  	MOVW	n+16(FP), R2		// arg 3 - count
   150  	SVC	$SYS_read
   151  	BCC	ok
   152  	NEG	R0, R0
   153  ok:
   154  	MOVW	R0, ret+24(FP)
   155  	RET
   156  
   157  // func pipe() (r, w int32, errno int32)
   158  TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
   159  	ADD	$8, RSP, R0
   160  	MOVW	$0, R1
   161  	SVC	$SYS_pipe2
   162  	BCC	pipeok
   163  	NEG	R0, R0
   164  pipeok:
   165  	MOVW	R0, errno+8(FP)
   166  	RET
   167  
   168  // func pipe2(flags int32) (r, w int32, errno int32)
   169  TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
   170  	ADD	$16, RSP, R0
   171  	MOVW	flags+0(FP), R1
   172  	SVC	$SYS_pipe2
   173  	BCC	pipe2ok
   174  	NEG	R0, R0
   175  pipe2ok:
   176  	MOVW	R0, errno+16(FP)
   177  	RET
   178  
   179  TEXT runtime·write1(SB),NOSPLIT,$-8
   180  	MOVD	fd+0(FP), R0		// arg 1 - fd
   181  	MOVD	p+8(FP), R1		// arg 2 - buf
   182  	MOVW	n+16(FP), R2		// arg 3 - nbyte
   183  	SVC	$SYS_write
   184  	BCC	ok
   185  	NEG	R0, R0
   186  ok:
   187  	MOVW	R0, ret+24(FP)
   188  	RET
   189  
   190  TEXT runtime·usleep(SB),NOSPLIT,$24-4
   191  	MOVWU	usec+0(FP), R3
   192  	MOVD	R3, R5
   193  	MOVW	$1000000, R4
   194  	UDIV	R4, R3
   195  	MOVD	R3, 8(RSP)		// sec
   196  	MUL	R3, R4
   197  	SUB	R4, R5
   198  	MOVW	$1000, R4
   199  	MUL	R4, R5
   200  	MOVD	R5, 16(RSP)		// nsec
   201  
   202  	MOVD	$8(RSP), R0		// arg 1 - rqtp
   203  	MOVD	$0, R1			// arg 2 - rmtp
   204  	SVC	$SYS___nanosleep50
   205  	RET
   206  
   207  TEXT runtime·lwp_kill(SB),NOSPLIT,$0-16
   208  	MOVW	tid+0(FP), R0		// arg 1 - target
   209  	MOVD	sig+8(FP), R1		// arg 2 - signo
   210  	SVC	$SYS__lwp_kill
   211  	RET
   212  
   213  TEXT runtime·raiseproc(SB),NOSPLIT,$16
   214  	SVC	$SYS_getpid
   215  					// arg 1 - pid (from getpid)
   216  	MOVD	sig+0(FP), R1		// arg 2 - signo
   217  	SVC	$SYS_kill
   218  	RET
   219  
   220  TEXT runtime·setitimer(SB),NOSPLIT,$-8
   221  	MOVW	mode+0(FP), R0		// arg 1 - which
   222  	MOVD	new+8(FP), R1		// arg 2 - itv
   223  	MOVD	old+16(FP), R2		// arg 3 - oitv
   224  	SVC	$SYS___setitimer50
   225  	RET
   226  
   227  // func walltime() (sec int64, nsec int32)
   228  TEXT runtime·walltime(SB), NOSPLIT, $32
   229  	MOVW	$CLOCK_REALTIME, R0	// arg 1 - clock_id
   230  	MOVD	$8(RSP), R1		// arg 2 - tp
   231  	SVC	$SYS___clock_gettime50
   232  
   233  	MOVD	8(RSP), R0		// sec
   234  	MOVD	16(RSP), R1		// nsec
   235  
   236  	// sec is in R0, nsec in R1
   237  	MOVD	R0, sec+0(FP)
   238  	MOVW	R1, nsec+8(FP)
   239  	RET
   240  
   241  // int64 nanotime1(void) so really
   242  // void nanotime1(int64 *nsec)
   243  TEXT runtime·nanotime1(SB), NOSPLIT, $32
   244  	MOVD	$CLOCK_MONOTONIC, R0	// arg 1 - clock_id
   245  	MOVD	$8(RSP), R1		// arg 2 - tp
   246  	SVC	$SYS___clock_gettime50
   247  	MOVD	8(RSP), R0		// sec
   248  	MOVD	16(RSP), R2		// nsec
   249  
   250  	// sec is in R0, nsec in R2
   251  	// return nsec in R2
   252  	MOVD	$1000000000, R3
   253  	MUL	R3, R0
   254  	ADD	R2, R0
   255  
   256  	MOVD	R0, ret+0(FP)
   257  	RET
   258  
   259  TEXT runtime·getcontext(SB),NOSPLIT,$-8
   260  	MOVD	ctxt+0(FP), R0		// arg 1 - context
   261  	SVC	$SYS_getcontext
   262  	BCS	fail
   263  	RET
   264  fail:
   265  	MOVD	$0, R0
   266  	MOVD	R0, (R0)		// crash
   267  
   268  TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   269  	MOVW	how+0(FP), R0		// arg 1 - how
   270  	MOVD	new+8(FP), R1		// arg 2 - set
   271  	MOVD	old+16(FP), R2		// arg 3 - oset
   272  	SVC	$SYS___sigprocmask14
   273  	BCS	fail
   274  	RET
   275  fail:
   276  	MOVD	$0, R0
   277  	MOVD	R0, (R0)		// crash
   278  
   279  TEXT sigreturn_tramp<>(SB),NOSPLIT,$-8
   280  	MOVD	g, R0
   281  	SVC	$SYS_setcontext
   282  	MOVD	$0, R0
   283  	MOVD	R0, (R0)		// crash
   284  
   285  TEXT runtime·sigaction(SB),NOSPLIT,$-8
   286  	MOVW	sig+0(FP), R0		// arg 1 - signum
   287  	MOVD	new+8(FP), R1		// arg 2 - nsa
   288  	MOVD	old+16(FP), R2		// arg 3 - osa
   289  					// arg 4 - tramp
   290  	MOVD	$sigreturn_tramp<>(SB), R3
   291  	MOVW	$2, R4			// arg 5 - vers
   292  	SVC	$SYS___sigaction_sigtramp
   293  	BCS	fail
   294  	RET
   295  fail:
   296  	MOVD	$0, R0
   297  	MOVD	R0, (R0)		// crash
   298  
   299  // XXX ???
   300  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   301  	MOVW	sig+8(FP), R0
   302  	MOVD	info+16(FP), R1
   303  	MOVD	ctx+24(FP), R2
   304  	MOVD	fn+0(FP), R11
   305  	BL	(R11)
   306  	RET
   307  
   308  TEXT runtime·sigtramp(SB),NOSPLIT,$192
   309  	// Save callee-save registers in the case of signal forwarding.
   310  	// Please refer to https://golang.org/issue/31827 .
   311  	MOVD	R19, 8*4(RSP)
   312  	MOVD	R20, 8*5(RSP)
   313  	MOVD	R21, 8*6(RSP)
   314  	MOVD	R22, 8*7(RSP)
   315  	MOVD	R23, 8*8(RSP)
   316  	MOVD	R24, 8*9(RSP)
   317  	MOVD	R25, 8*10(RSP)
   318  	MOVD	R26, 8*11(RSP)
   319  	MOVD	R27, 8*12(RSP)
   320  	MOVD	g, 8*13(RSP)
   321  	// Unclobber g for now (kernel uses it as ucontext ptr)
   322  	// See https://github.com/golang/go/issues/30824#issuecomment-492772426
   323  	// This is only correct in the non-cgo case.
   324  	// XXX should use lwp_getprivate as suggested.
   325  	// 8*36 is ucontext.uc_mcontext.__gregs[_REG_X28]
   326  	MOVD	8*36(g), g
   327  	MOVD	R29, 8*14(RSP)
   328  	FMOVD	F8, 8*15(RSP)
   329  	FMOVD	F9, 8*16(RSP)
   330  	FMOVD	F10, 8*17(RSP)
   331  	FMOVD	F11, 8*18(RSP)
   332  	FMOVD	F12, 8*19(RSP)
   333  	FMOVD	F13, 8*20(RSP)
   334  	FMOVD	F14, 8*21(RSP)
   335  	FMOVD	F15, 8*22(RSP)
   336  
   337  	// this might be called in external code context,
   338  	// where g is not set.
   339  	// first save R0, because runtime·load_g will clobber it
   340  	MOVD	R0, 8(RSP)		// signum
   341  	MOVB	runtime·iscgo(SB), R0
   342  	CMP 	$0, R0
   343  	// XXX branch destination
   344  	BEQ	2(PC)
   345  	BL	runtime·load_g(SB)
   346  
   347  	MOVD	R1, 16(RSP)
   348  	MOVD	R2, 24(RSP)
   349  	BL	runtime·sigtrampgo(SB)
   350  
   351  	// Restore callee-save registers.
   352  	MOVD	8*4(RSP), R19
   353  	MOVD	8*5(RSP), R20
   354  	MOVD	8*6(RSP), R21
   355  	MOVD	8*7(RSP), R22
   356  	MOVD	8*8(RSP), R23
   357  	MOVD	8*9(RSP), R24
   358  	MOVD	8*10(RSP), R25
   359  	MOVD	8*11(RSP), R26
   360  	MOVD	8*12(RSP), R27
   361  	MOVD	8*13(RSP), g
   362  	MOVD	8*14(RSP), R29
   363  	FMOVD	8*15(RSP), F8
   364  	FMOVD	8*16(RSP), F9
   365  	FMOVD	8*17(RSP), F10
   366  	FMOVD	8*18(RSP), F11
   367  	FMOVD	8*19(RSP), F12
   368  	FMOVD	8*20(RSP), F13
   369  	FMOVD	8*21(RSP), F14
   370  	FMOVD	8*22(RSP), F15
   371  
   372  	RET
   373  
   374  TEXT runtime·mmap(SB),NOSPLIT,$0
   375  	MOVD	addr+0(FP), R0		// arg 1 - addr
   376  	MOVD	n+8(FP), R1		// arg 2 - len
   377  	MOVW	prot+16(FP), R2		// arg 3 - prot
   378  	MOVW	flags+20(FP), R3	// arg 4 - flags
   379  	MOVW	fd+24(FP), R4		// arg 5 - fd
   380  	MOVW	$0, R5			// arg 6 - pad
   381  	MOVD	off+28(FP), R6		// arg 7 - offset
   382  	SVC	$SYS_mmap
   383  	BCS	fail
   384  	MOVD	R0, p+32(FP)
   385  	MOVD	$0, err+40(FP)
   386  	RET
   387  fail:
   388  	MOVD	$0, p+32(FP)
   389  	MOVD	R0, err+40(FP)
   390  	RET
   391  
   392  TEXT runtime·munmap(SB),NOSPLIT,$0
   393  	MOVD	addr+0(FP), R0	// arg 1 - addr
   394  	MOVD	n+8(FP), R1	// arg 2 - len
   395  	SVC	$SYS_munmap
   396  	BCS	fail
   397  	RET
   398  fail:
   399  	MOVD	$0, R0
   400  	MOVD	R0, (R0)	// crash
   401  
   402  TEXT runtime·madvise(SB),NOSPLIT,$0
   403  	MOVD	addr+0(FP), R0		// arg 1 - addr
   404  	MOVD	n+8(FP), R1		// arg 2 - len
   405  	MOVW	flags+16(FP), R2	// arg 3 - behav
   406  	SVC	$SYS_madvise
   407  	BCC	ok
   408  	MOVD	$-1, R0
   409  ok:
   410  	MOVD	R0, ret+24(FP)
   411  	RET
   412  
   413  TEXT runtime·sigaltstack(SB),NOSPLIT,$0
   414  	MOVD	new+0(FP), R0		// arg 1 - nss
   415  	MOVD	old+8(FP), R1		// arg 2 - oss
   416  	SVC	$SYS___sigaltstack14
   417  	BCS	fail
   418  	RET
   419  fail:
   420  	MOVD	$0, R0
   421  	MOVD	R0, (R0)		// crash
   422  
   423  TEXT runtime·sysctl(SB),NOSPLIT,$0
   424  	MOVD	mib+0(FP), R0		// arg 1 - name
   425  	MOVW	miblen+8(FP), R1	// arg 2 - namelen
   426  	MOVD	out+16(FP), R2		// arg 3 - oldp
   427  	MOVD	size+24(FP), R3		// arg 4 - oldlenp
   428  	MOVD	dst+32(FP), R4		// arg 5 - newp
   429  	MOVD	ndst+40(FP), R5		// arg 6 - newlen
   430  	SVC	$SYS___sysctl
   431  	BCC	ok
   432  	NEG	R0, R0
   433  ok:
   434  	MOVW	R0, ret+48(FP)
   435  	RET
   436  
   437  // int32 runtime·kqueue(void)
   438  TEXT runtime·kqueue(SB),NOSPLIT,$0
   439  	MOVD	$0, R0
   440  	SVC	$SYS_kqueue
   441  	BCC	ok
   442  	NEG	R0, R0
   443  ok:
   444  	MOVW	R0, ret+0(FP)
   445  	RET
   446  
   447  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   448  TEXT runtime·kevent(SB),NOSPLIT,$0
   449  	MOVW	kq+0(FP), R0	// arg 1 - kq
   450  	MOVD	ch+8(FP), R1	// arg 2 - changelist
   451  	MOVW	nch+16(FP), R2	// arg 3 - nchanges
   452  	MOVD	ev+24(FP), R3	// arg 4 - eventlist
   453  	MOVW	nev+32(FP), R4	// arg 5 - nevents
   454  	MOVD	ts+40(FP), R5	// arg 6 - timeout
   455  	SVC	$SYS___kevent50
   456  	BCC	ok
   457  	NEG	R0, R0
   458  ok:
   459  	MOVW	R0, ret+48(FP)
   460  	RET
   461  
   462  // void runtime·closeonexec(int32 fd)
   463  TEXT runtime·closeonexec(SB),NOSPLIT,$0
   464  	MOVW	fd+0(FP), R0		// arg 1 - fd
   465  	MOVW	$F_SETFD, R1
   466  	MOVW	$FD_CLOEXEC, R2
   467  	SVC	$SYS_fcntl
   468  	RET
   469  
   470  // func runtime·setNonblock(int32 fd)
   471  TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
   472  	MOVW	fd+0(FP), R0		// arg 1 - fd
   473  	MOVD	$F_GETFL, R1		// arg 2 - cmd
   474  	MOVD	$0, R2			// arg 3
   475  	SVC	$SYS_fcntl
   476  	MOVD	$O_NONBLOCK, R2
   477  	EOR	R0, R2			// arg 3 - flags
   478  	MOVW	fd+0(FP), R0		// arg 1 - fd
   479  	MOVD	$F_SETFL, R1		// arg 2 - cmd
   480  	SVC	$SYS_fcntl
   481  	RET
   482  

View as plain text