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

View as plain text