Text file src/runtime/sys_netbsd_arm.s

     1  // Copyright 2013 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  // System calls and other sys.stuff for ARM, NetBSD
     6  // /usr/src/sys/kern/syscalls.master for syscall numbers.
     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  
    16  #define SWI_OS_NETBSD			0xa00000
    17  #define SYS_exit			SWI_OS_NETBSD | 1
    18  #define SYS_read			SWI_OS_NETBSD | 3
    19  #define SYS_write			SWI_OS_NETBSD | 4
    20  #define SYS_open			SWI_OS_NETBSD | 5
    21  #define SYS_close			SWI_OS_NETBSD | 6
    22  #define SYS_getpid			SWI_OS_NETBSD | 20
    23  #define SYS_kill			SWI_OS_NETBSD | 37
    24  #define SYS_munmap			SWI_OS_NETBSD | 73
    25  #define SYS_madvise			SWI_OS_NETBSD | 75
    26  #define SYS_fcntl			SWI_OS_NETBSD | 92
    27  #define SYS_mmap			SWI_OS_NETBSD | 197
    28  #define SYS___sysctl			SWI_OS_NETBSD | 202
    29  #define SYS___sigaltstack14		SWI_OS_NETBSD | 281
    30  #define SYS___sigprocmask14		SWI_OS_NETBSD | 293
    31  #define SYS_issetugid			SWI_OS_NETBSD | 305
    32  #define SYS_getcontext			SWI_OS_NETBSD | 307
    33  #define SYS_setcontext			SWI_OS_NETBSD | 308
    34  #define SYS__lwp_create			SWI_OS_NETBSD | 309
    35  #define SYS__lwp_exit			SWI_OS_NETBSD | 310
    36  #define SYS__lwp_self			SWI_OS_NETBSD | 311
    37  #define SYS__lwp_getprivate		SWI_OS_NETBSD | 316
    38  #define SYS__lwp_setprivate		SWI_OS_NETBSD | 317
    39  #define SYS__lwp_kill			SWI_OS_NETBSD | 318
    40  #define SYS__lwp_unpark			SWI_OS_NETBSD | 321
    41  #define SYS___sigaction_sigtramp	SWI_OS_NETBSD | 340
    42  #define SYS_kqueue			SWI_OS_NETBSD | 344
    43  #define SYS_sched_yield			SWI_OS_NETBSD | 350
    44  #define SYS___setitimer50		SWI_OS_NETBSD | 425
    45  #define SYS___clock_gettime50		SWI_OS_NETBSD | 427
    46  #define SYS___nanosleep50		SWI_OS_NETBSD | 430
    47  #define SYS___kevent50			SWI_OS_NETBSD | 435
    48  #define SYS____lwp_park60		SWI_OS_NETBSD | 478
    49  
    50  // Exit the entire program (like C exit)
    51  TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0
    52  	MOVW code+0(FP), R0	// arg 1 exit status
    53  	SWI $SYS_exit
    54  	MOVW.CS $0, R8	// crash on syscall failure
    55  	MOVW.CS R8, (R8)
    56  	RET
    57  
    58  // func exitThread(wait *atomic.Uint32)
    59  TEXT runtime·exitThread(SB),NOSPLIT,$0-4
    60  	MOVW wait+0(FP), R0
    61  	// We're done using the stack.
    62  	MOVW $0, R2
    63  storeloop:
    64  	LDREX (R0), R4          // loads R4
    65  	STREX R2, (R0), R1      // stores R2
    66  	CMP $0, R1
    67  	BNE storeloop
    68  	SWI $SYS__lwp_exit
    69  	MOVW $1, R8	// crash
    70  	MOVW R8, (R8)
    71  	JMP 0(PC)
    72  
    73  TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0
    74  	MOVW name+0(FP), R0
    75  	MOVW mode+4(FP), R1
    76  	MOVW perm+8(FP), R2
    77  	SWI $SYS_open
    78  	MOVW.CS	$-1, R0
    79  	MOVW	R0, ret+12(FP)
    80  	RET
    81  
    82  TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0
    83  	MOVW fd+0(FP), R0
    84  	SWI $SYS_close
    85  	MOVW.CS	$-1, R0
    86  	MOVW	R0, ret+4(FP)
    87  	RET
    88  
    89  TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
    90  	MOVW fd+0(FP), R0
    91  	MOVW p+4(FP), R1
    92  	MOVW n+8(FP), R2
    93  	SWI $SYS_read
    94  	RSB.CS	$0, R0		// caller expects negative errno
    95  	MOVW	R0, ret+12(FP)
    96  	RET
    97  
    98  // func pipe2(flags int32) (r, w int32, errno int32)
    99  TEXT runtime·pipe2(SB),NOSPLIT,$0-16
   100  	MOVW $r+4(FP), R0
   101  	MOVW flags+0(FP), R1
   102  	SWI $0xa001c5
   103  	MOVW R0, errno+12(FP)
   104  	RET
   105  
   106  TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0
   107  	MOVW	fd+0(FP), R0	// arg 1 - fd
   108  	MOVW	p+4(FP), R1	// arg 2 - buf
   109  	MOVW	n+8(FP), R2	// arg 3 - nbyte
   110  	SWI $SYS_write
   111  	RSB.CS	$0, R0		// caller expects negative errno
   112  	MOVW	R0, ret+12(FP)
   113  	RET
   114  
   115  // int32 lwp_create(void *context, uintptr flags, void *lwpid)
   116  TEXT runtime·lwp_create(SB),NOSPLIT,$0
   117  	MOVW ctxt+0(FP), R0
   118  	MOVW flags+4(FP), R1
   119  	MOVW lwpid+8(FP), R2
   120  	SWI $SYS__lwp_create
   121  	MOVW	R0, ret+12(FP)
   122  	RET
   123  
   124  TEXT runtime·osyield(SB),NOSPLIT,$0
   125  	SWI $SYS_sched_yield
   126  	RET
   127  
   128  TEXT runtime·lwp_park(SB),NOSPLIT,$8
   129  	MOVW clockid+0(FP), R0		// arg 1 - clock_id
   130  	MOVW flags+4(FP), R1		// arg 2 - flags
   131  	MOVW ts+8(FP), R2		// arg 3 - ts
   132  	MOVW unpark+12(FP), R3		// arg 4 - unpark
   133  	MOVW hint+16(FP), R4		// arg 5 - hint
   134  	MOVW R4, 4(R13)
   135  	MOVW unparkhint+20(FP), R5	// arg 6 - unparkhint
   136  	MOVW R5, 8(R13)
   137  	SWI $SYS____lwp_park60
   138  	MOVW	R0, ret+24(FP)
   139  	RET
   140  
   141  TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
   142  	MOVW	lwp+0(FP), R0	// arg 1 - lwp
   143  	MOVW	hint+4(FP), R1	// arg 2 - hint
   144  	SWI	$SYS__lwp_unpark
   145  	MOVW	R0, ret+8(FP)
   146  	RET
   147  
   148  TEXT runtime·lwp_self(SB),NOSPLIT,$0
   149  	SWI	$SYS__lwp_self
   150  	MOVW	R0, ret+0(FP)
   151  	RET
   152  
   153  TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
   154  	MOVW R0, g_m(R1)
   155  	MOVW R1, g
   156  
   157  	BL runtime·emptyfunc(SB) // fault if stack check is wrong
   158  	BL (R2)
   159  	MOVW $2, R8  // crash (not reached)
   160  	MOVW R8, (R8)
   161  	RET
   162  
   163  TEXT ·netbsdMstart(SB),NOSPLIT|TOPFRAME,$0
   164  	BL ·netbsdMstart0(SB)
   165  	RET // not reached
   166  
   167  TEXT runtime·usleep(SB),NOSPLIT,$16
   168  	MOVW usec+0(FP), R0
   169  	CALL runtime·usplitR0(SB)
   170  	// 0(R13) is the saved LR, don't use it
   171  	MOVW R0, 4(R13) // tv_sec.low
   172  	MOVW $0, R0
   173  	MOVW R0, 8(R13) // tv_sec.high
   174  	MOVW $1000, R2
   175  	MUL R1, R2
   176  	MOVW R2, 12(R13) // tv_nsec
   177  
   178  	MOVW $4(R13), R0 // arg 1 - rqtp
   179  	MOVW $0, R1      // arg 2 - rmtp
   180  	SWI $SYS___nanosleep50
   181  	RET
   182  
   183  TEXT runtime·lwp_kill(SB),NOSPLIT,$0-8
   184  	MOVW	tid+0(FP), R0	// arg 1 - tid
   185  	MOVW	sig+4(FP), R1	// arg 2 - signal
   186  	SWI	$SYS__lwp_kill
   187  	RET
   188  
   189  TEXT runtime·raiseproc(SB),NOSPLIT,$16
   190  	SWI	$SYS_getpid	// the returned R0 is arg 1
   191  	MOVW	sig+0(FP), R1	// arg 2 - signal
   192  	SWI	$SYS_kill
   193  	RET
   194  
   195  TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0
   196  	MOVW mode+0(FP), R0	// arg 1 - which
   197  	MOVW new+4(FP), R1	// arg 2 - itv
   198  	MOVW old+8(FP), R2	// arg 3 - oitv
   199  	SWI $SYS___setitimer50
   200  	RET
   201  
   202  // func walltime() (sec int64, nsec int32)
   203  TEXT runtime·walltime(SB), NOSPLIT, $32
   204  	MOVW $0, R0	// CLOCK_REALTIME
   205  	MOVW $8(R13), R1
   206  	SWI $SYS___clock_gettime50
   207  
   208  	MOVW 8(R13), R0	// sec.low
   209  	MOVW 12(R13), R1 // sec.high
   210  	MOVW 16(R13), R2 // nsec
   211  
   212  	MOVW R0, sec_lo+0(FP)
   213  	MOVW R1, sec_hi+4(FP)
   214  	MOVW R2, nsec+8(FP)
   215  	RET
   216  
   217  // int64 nanotime1(void) so really
   218  // void nanotime1(int64 *nsec)
   219  TEXT runtime·nanotime1(SB), NOSPLIT, $32
   220  	MOVW $3, R0 // CLOCK_MONOTONIC
   221  	MOVW $8(R13), R1
   222  	SWI $SYS___clock_gettime50
   223  
   224  	MOVW 8(R13), R0 // sec.low
   225  	MOVW 12(R13), R4 // sec.high
   226  	MOVW 16(R13), R2 // nsec
   227  
   228  	MOVW $1000000000, R3
   229  	MULLU R0, R3, (R1, R0)
   230  	MUL R3, R4
   231  	ADD.S R2, R0
   232  	ADC R4, R1
   233  
   234  	MOVW R0, ret_lo+0(FP)
   235  	MOVW R1, ret_hi+4(FP)
   236  	RET
   237  
   238  TEXT runtime·getcontext(SB),NOSPLIT|NOFRAME,$0
   239  	MOVW ctxt+0(FP), R0	// arg 1 - context
   240  	SWI $SYS_getcontext
   241  	MOVW.CS $0, R8	// crash on syscall failure
   242  	MOVW.CS R8, (R8)
   243  	RET
   244  
   245  TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   246  	MOVW how+0(FP), R0	// arg 1 - how
   247  	MOVW new+4(FP), R1	// arg 2 - set
   248  	MOVW old+8(FP), R2	// arg 3 - oset
   249  	SWI $SYS___sigprocmask14
   250  	MOVW.CS $0, R8	// crash on syscall failure
   251  	MOVW.CS R8, (R8)
   252  	RET
   253  
   254  TEXT sigreturn_tramp<>(SB),NOSPLIT|NOFRAME,$0
   255  	// on entry, SP points to siginfo, we add sizeof(ucontext)
   256  	// to SP to get a pointer to ucontext.
   257  	ADD $0x80, R13, R0 // 0x80 == sizeof(UcontextT)
   258  	SWI $SYS_setcontext
   259  	// something failed, we have to exit
   260  	MOVW $0x4242, R0 // magic return number
   261  	SWI $SYS_exit
   262  	B -2(PC)	// continue exit
   263  
   264  TEXT runtime·sigaction(SB),NOSPLIT,$4
   265  	MOVW sig+0(FP), R0	// arg 1 - signum
   266  	MOVW new+4(FP), R1	// arg 2 - nsa
   267  	MOVW old+8(FP), R2	// arg 3 - osa
   268  	MOVW $sigreturn_tramp<>(SB), R3	// arg 4 - tramp
   269  	MOVW $2, R4	// arg 5 - vers
   270  	MOVW R4, 4(R13)
   271  	ADD $4, R13	// pass arg 5 on stack
   272  	SWI $SYS___sigaction_sigtramp
   273  	SUB $4, R13
   274  	MOVW.CS $3, R8	// crash on syscall failure
   275  	MOVW.CS R8, (R8)
   276  	RET
   277  
   278  TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
   279  	MOVW	sig+4(FP), R0
   280  	MOVW	info+8(FP), R1
   281  	MOVW	ctx+12(FP), R2
   282  	MOVW	fn+0(FP), R11
   283  	MOVW	R13, R4
   284  	SUB	$24, R13
   285  	BIC	$0x7, R13 // alignment for ELF ABI
   286  	BL	(R11)
   287  	MOVW	R4, R13
   288  	RET
   289  
   290  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$0
   291  	// Reserve space for callee-save registers and arguments.
   292  	MOVM.DB.W [R4-R11], (R13)
   293  	SUB	$16, R13
   294  
   295  	// this might be called in external code context,
   296  	// where g is not set.
   297  	// first save R0, because runtime·load_g will clobber it
   298  	MOVW	R0, 4(R13) // signum
   299  	MOVB	runtime·iscgo(SB), R0
   300  	CMP 	$0, R0
   301  	BL.NE	runtime·load_g(SB)
   302  
   303  	MOVW	R1, 8(R13)
   304  	MOVW	R2, 12(R13)
   305  	BL	runtime·sigtrampgo(SB)
   306  
   307  	// Restore callee-save registers.
   308  	ADD	$16, R13
   309  	MOVM.IA.W (R13), [R4-R11]
   310  
   311  	RET
   312  
   313  TEXT runtime·mmap(SB),NOSPLIT,$12
   314  	MOVW addr+0(FP), R0	// arg 1 - addr
   315  	MOVW n+4(FP), R1	// arg 2 - len
   316  	MOVW prot+8(FP), R2	// arg 3 - prot
   317  	MOVW flags+12(FP), R3	// arg 4 - flags
   318  	// arg 5 (fid) and arg6 (offset_lo, offset_hi) are passed on stack
   319  	// note the C runtime only passes the 32-bit offset_lo to us
   320  	MOVW fd+16(FP), R4		// arg 5
   321  	MOVW R4, 4(R13)
   322  	MOVW off+20(FP), R5		// arg 6 lower 32-bit
   323  	MOVW R5, 8(R13)
   324  	MOVW $0, R6 // higher 32-bit for arg 6
   325  	MOVW R6, 12(R13)
   326  	ADD $4, R13 // pass arg 5 and arg 6 on stack
   327  	SWI $SYS_mmap
   328  	SUB $4, R13
   329  	MOVW	$0, R1
   330  	MOVW.CS R0, R1	// if error, move to R1
   331  	MOVW.CS $0, R0
   332  	MOVW	R0, p+24(FP)
   333  	MOVW	R1, err+28(FP)
   334  	RET
   335  
   336  TEXT runtime·munmap(SB),NOSPLIT,$0
   337  	MOVW addr+0(FP), R0	// arg 1 - addr
   338  	MOVW n+4(FP), R1	// arg 2 - len
   339  	SWI $SYS_munmap
   340  	MOVW.CS $0, R8	// crash on syscall failure
   341  	MOVW.CS R8, (R8)
   342  	RET
   343  
   344  TEXT runtime·madvise(SB),NOSPLIT,$0
   345  	MOVW	addr+0(FP), R0	// arg 1 - addr
   346  	MOVW	n+4(FP), R1	// arg 2 - len
   347  	MOVW	flags+8(FP), R2	// arg 3 - behav
   348  	SWI	$SYS_madvise
   349  	MOVW.CS	$-1, R0
   350  	MOVW	R0, ret+12(FP)
   351  	RET
   352  
   353  TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
   354  	MOVW new+0(FP), R0	// arg 1 - nss
   355  	MOVW old+4(FP), R1	// arg 2 - oss
   356  	SWI $SYS___sigaltstack14
   357  	MOVW.CS $0, R8	// crash on syscall failure
   358  	MOVW.CS R8, (R8)
   359  	RET
   360  
   361  TEXT runtime·sysctl(SB),NOSPLIT,$8
   362  	MOVW mib+0(FP), R0	// arg 1 - name
   363  	MOVW miblen+4(FP), R1	// arg 2 - namelen
   364  	MOVW out+8(FP), R2	// arg 3 - oldp
   365  	MOVW size+12(FP), R3	// arg 4 - oldlenp
   366  	MOVW dst+16(FP), R4	// arg 5 - newp
   367  	MOVW R4, 4(R13)
   368  	MOVW ndst+20(FP), R4	// arg 6 - newlen
   369  	MOVW R4, 8(R13)
   370  	ADD $4, R13	// pass arg 5 and 6 on stack
   371  	SWI $SYS___sysctl
   372  	SUB $4, R13
   373  	MOVW	R0, ret+24(FP)
   374  	RET
   375  
   376  // int32 runtime·kqueue(void)
   377  TEXT runtime·kqueue(SB),NOSPLIT,$0
   378  	SWI	$SYS_kqueue
   379  	RSB.CS	$0, R0
   380  	MOVW	R0, ret+0(FP)
   381  	RET
   382  
   383  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   384  TEXT runtime·kevent(SB),NOSPLIT,$8
   385  	MOVW kq+0(FP), R0	// kq
   386  	MOVW ch+4(FP), R1	// changelist
   387  	MOVW nch+8(FP), R2	// nchanges
   388  	MOVW ev+12(FP), R3	// eventlist
   389  	MOVW nev+16(FP), R4	// nevents
   390  	MOVW R4, 4(R13)
   391  	MOVW ts+20(FP), R4	// timeout
   392  	MOVW R4, 8(R13)
   393  	ADD $4, R13	// pass arg 5 and 6 on stack
   394  	SWI $SYS___kevent50
   395  	RSB.CS $0, R0
   396  	SUB $4, R13
   397  	MOVW	R0, ret+24(FP)
   398  	RET
   399  
   400  // func fcntl(fd, cmd, args int32) int32
   401  TEXT runtime·fcntl(SB),NOSPLIT,$0
   402  	MOVW fd+0(FP), R0
   403  	MOVW cmd+4(FP), R1
   404  	MOVW arg+8(FP), R2
   405  	SWI $SYS_fcntl
   406  	MOVW $0, R1
   407  	MOVW.CS R0, R1
   408  	MOVW.CS $-1, R0
   409  	MOVW R0, ret+12(FP)
   410  	MOVW R1, errno+16(FP)
   411  	RET
   412  
   413  // TODO: this is only valid for ARMv7+
   414  TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
   415  	B	runtime·armPublicationBarrier(SB)
   416  
   417  TEXT runtime·read_tls_fallback(SB),NOSPLIT|NOFRAME,$0
   418  	MOVM.WP [R1, R2, R3, R12], (R13)
   419  	SWI $SYS__lwp_getprivate
   420  	MOVM.IAW    (R13), [R1, R2, R3, R12]
   421  	RET
   422  
   423  // func issetugid() int32
   424  TEXT runtime·issetugid(SB),NOSPLIT,$0
   425  	SWI $SYS_issetugid
   426  	MOVW	R0, ret+0(FP)
   427  	RET
   428  

View as plain text