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

View as plain text