...
Run Format

Text file src/runtime/sys_netbsd_arm.s

Documentation: runtime

     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	// Exit the entire program (like C exit)
    14	TEXT runtime·exit(SB),NOSPLIT,$-4
    15		MOVW code+0(FP), R0	// arg 1 exit status
    16		SWI $0xa00001
    17		MOVW.CS $0, R8	// crash on syscall failure
    18		MOVW.CS R8, (R8)
    19		RET
    20	
    21	TEXT runtime·exit1(SB),NOSPLIT,$-4
    22		SWI $0xa00136	// sys__lwp_exit
    23		MOVW $1, R8	// crash
    24		MOVW R8, (R8)
    25		RET
    26		
    27	TEXT runtime·open(SB),NOSPLIT,$-8
    28		MOVW name+0(FP), R0
    29		MOVW mode+4(FP), R1
    30		MOVW perm+8(FP), R2
    31		SWI $0xa00005
    32		MOVW.CS	$-1, R0
    33		MOVW	R0, ret+12(FP)
    34		RET
    35	
    36	TEXT runtime·closefd(SB),NOSPLIT,$-8
    37		MOVW fd+0(FP), R0
    38		SWI $0xa00006
    39		MOVW.CS	$-1, R0
    40		MOVW	R0, ret+4(FP)
    41		RET
    42	
    43	TEXT runtime·read(SB),NOSPLIT,$-8
    44		MOVW fd+0(FP), R0
    45		MOVW p+4(FP), R1
    46		MOVW n+8(FP), R2
    47		SWI $0xa00003
    48		MOVW.CS	$-1, R0
    49		MOVW	R0, ret+12(FP)
    50		RET
    51	
    52	TEXT runtime·write(SB),NOSPLIT,$-4
    53		MOVW	fd+0(FP), R0	// arg 1 - fd
    54		MOVW	p+4(FP), R1	// arg 2 - buf
    55		MOVW	n+8(FP), R2	// arg 3 - nbyte
    56		SWI $0xa00004	// sys_write
    57		MOVW.CS	$-1, R0
    58		MOVW	R0, ret+12(FP)
    59		RET
    60	
    61	// int32 lwp_create(void *context, uintptr flags, void *lwpid)
    62	TEXT runtime·lwp_create(SB),NOSPLIT,$0
    63		MOVW ctxt+0(FP), R0
    64		MOVW flags+4(FP), R1
    65		MOVW lwpid+8(FP), R2
    66		SWI $0xa00135	// sys__lwp_create
    67		MOVW	R0, ret+12(FP)
    68		RET
    69	
    70	TEXT runtime·osyield(SB),NOSPLIT,$0
    71		SWI $0xa0015e	// sys_sched_yield
    72		RET
    73	
    74	TEXT runtime·lwp_park(SB),NOSPLIT,$0
    75		MOVW abstime+0(FP), R0	// arg 1 - abstime
    76		MOVW unpark+4(FP), R1	// arg 2 - unpark
    77		MOVW hint+8(FP), R2	// arg 3 - hint
    78		MOVW unparkhint+12(FP), R3	// arg 4 - unparkhint
    79		SWI $0xa001b2	// sys__lwp_park
    80		MOVW	R0, ret+16(FP)
    81		RET
    82	
    83	TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
    84		MOVW	lwp+0(FP), R0	// arg 1 - lwp
    85		MOVW	hint+4(FP), R1	// arg 2 - hint
    86		SWI $0xa00141 // sys__lwp_unpark
    87		MOVW	R0, ret+8(FP)
    88		RET
    89	
    90	TEXT runtime·lwp_self(SB),NOSPLIT,$0
    91		SWI $0xa00137	// sys__lwp_self
    92		MOVW	R0, ret+0(FP)
    93		RET
    94	
    95	TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
    96		MOVW R0, g_m(R1)
    97		MOVW R1, g
    98	
    99		BL runtime·emptyfunc(SB) // fault if stack check is wrong
   100		BL (R2)
   101		MOVW $2, R8  // crash (not reached)
   102		MOVW R8, (R8)
   103		RET
   104	
   105	TEXT runtime·usleep(SB),NOSPLIT,$16
   106		MOVW usec+0(FP), R0
   107		CALL runtime·usplitR0(SB)
   108		// 0(R13) is the saved LR, don't use it
   109		MOVW R0, 4(R13) // tv_sec.low
   110		MOVW $0, R0
   111		MOVW R0, 8(R13) // tv_sec.high
   112		MOVW $1000, R2
   113		MUL R1, R2
   114		MOVW R2, 12(R13) // tv_nsec
   115	
   116		MOVW $4(R13), R0 // arg 1 - rqtp
   117		MOVW $0, R1      // arg 2 - rmtp
   118		SWI $0xa001ae	// sys_nanosleep
   119		RET
   120	
   121	TEXT runtime·raise(SB),NOSPLIT,$16
   122		SWI $0xa00137	// sys__lwp_self, the returned R0 is arg 1
   123		MOVW	sig+0(FP), R1	// arg 2 - signal
   124		SWI $0xa0013e	// sys__lwp_kill
   125		RET
   126	
   127	TEXT runtime·raiseproc(SB),NOSPLIT,$16
   128		SWI $0xa00014	// sys_getpid, the returned R0 is arg 1
   129		MOVW	sig+0(FP), R1	// arg 2 - signal
   130		SWI $0xa00025	// sys_kill
   131		RET
   132	
   133	TEXT runtime·setitimer(SB),NOSPLIT,$-4
   134		MOVW mode+0(FP), R0	// arg 1 - which
   135		MOVW new+4(FP), R1	// arg 2 - itv
   136		MOVW old+8(FP), R2	// arg 3 - oitv
   137		SWI $0xa001a9	// sys_setitimer
   138		RET
   139	
   140	// func walltime() (sec int64, nsec int32)
   141	TEXT runtime·walltime(SB), NOSPLIT, $32
   142		MOVW $0, R0	// CLOCK_REALTIME
   143		MOVW $8(R13), R1
   144		SWI $0xa001ab	// clock_gettime
   145	
   146		MOVW 8(R13), R0	// sec.low
   147		MOVW 12(R13), R1 // sec.high
   148		MOVW 16(R13), R2 // nsec
   149	
   150		MOVW R0, sec_lo+0(FP)
   151		MOVW R1, sec_hi+4(FP)
   152		MOVW R2, nsec+8(FP)
   153		RET
   154	
   155	// int64 nanotime(void) so really
   156	// void nanotime(int64 *nsec)
   157	TEXT runtime·nanotime(SB), NOSPLIT, $32
   158		MOVW $0, R0 // CLOCK_REALTIME
   159		MOVW $8(R13), R1
   160		SWI $0xa001ab	// clock_gettime
   161	
   162		MOVW 8(R13), R0 // sec.low
   163		MOVW 12(R13), R4 // sec.high
   164		MOVW 16(R13), R2 // nsec
   165	
   166		MOVW $1000000000, R3
   167		MULLU R0, R3, (R1, R0)
   168		MUL R3, R4
   169		ADD.S R2, R0
   170		ADC R4, R1
   171	
   172		MOVW R0, ret_lo+0(FP)
   173		MOVW R1, ret_hi+4(FP)
   174		RET
   175	
   176	TEXT runtime·getcontext(SB),NOSPLIT,$-4
   177		MOVW ctxt+0(FP), R0	// arg 1 - context
   178		SWI $0xa00133	// sys_getcontext
   179		MOVW.CS $0, R8	// crash on syscall failure
   180		MOVW.CS R8, (R8)
   181		RET
   182	
   183	TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   184		MOVW how+0(FP), R0	// arg 1 - how
   185		MOVW new+4(FP), R1	// arg 2 - set
   186		MOVW old+8(FP), R2	// arg 3 - oset
   187		SWI $0xa00125	// sys_sigprocmask
   188		MOVW.CS $0, R8	// crash on syscall failure
   189		MOVW.CS R8, (R8)
   190		RET
   191	
   192	TEXT runtime·sigreturn_tramp(SB),NOSPLIT,$-4
   193		// on entry, SP points to siginfo, we add sizeof(ucontext)
   194		// to SP to get a pointer to ucontext.
   195		ADD $0x80, R13, R0 // 0x80 == sizeof(UcontextT)
   196		SWI $0xa00134	// sys_setcontext
   197		// something failed, we have to exit
   198		MOVW $0x4242, R0 // magic return number
   199		SWI $0xa00001	// sys_exit
   200		B -2(PC)	// continue exit
   201	
   202	TEXT runtime·sigaction(SB),NOSPLIT,$4
   203		MOVW sig+0(FP), R0	// arg 1 - signum
   204		MOVW new+4(FP), R1	// arg 2 - nsa
   205		MOVW old+8(FP), R2	// arg 3 - osa
   206		MOVW $runtime·sigreturn_tramp(SB), R3	// arg 4 - tramp
   207		MOVW $2, R4	// arg 5 - vers
   208		MOVW R4, 4(R13)
   209		ADD $4, R13	// pass arg 5 on stack
   210		SWI $0xa00154	// sys___sigaction_sigtramp
   211		SUB $4, R13
   212		MOVW.CS $3, R8	// crash on syscall failure
   213		MOVW.CS R8, (R8)
   214		RET
   215	
   216	TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
   217		MOVW	sig+4(FP), R0
   218		MOVW	info+8(FP), R1
   219		MOVW	ctx+12(FP), R2
   220		MOVW	fn+0(FP), R11
   221		MOVW	R13, R4
   222		SUB	$24, R13
   223		BIC	$0x7, R13 // alignment for ELF ABI
   224		BL	(R11)
   225		MOVW	R4, R13
   226		RET
   227	
   228	TEXT runtime·sigtramp(SB),NOSPLIT,$12
   229		// this might be called in external code context,
   230		// where g is not set.
   231		// first save R0, because runtime·load_g will clobber it
   232		MOVW	R0, 4(R13) // signum
   233		MOVB	runtime·iscgo(SB), R0
   234		CMP 	$0, R0
   235		BL.NE	runtime·load_g(SB)
   236	
   237		MOVW	R1, 8(R13)
   238		MOVW	R2, 12(R13)
   239		BL	runtime·sigtrampgo(SB)
   240		RET
   241	
   242	TEXT runtime·mmap(SB),NOSPLIT,$12
   243		MOVW addr+0(FP), R0	// arg 1 - addr
   244		MOVW n+4(FP), R1	// arg 2 - len
   245		MOVW prot+8(FP), R2	// arg 3 - prot
   246		MOVW flags+12(FP), R3	// arg 4 - flags
   247		// arg 5 (fid) and arg6 (offset_lo, offset_hi) are passed on stack
   248		// note the C runtime only passes the 32-bit offset_lo to us
   249		MOVW fd+16(FP), R4		// arg 5
   250		MOVW R4, 4(R13)
   251		MOVW off+20(FP), R5		// arg 6 lower 32-bit
   252		MOVW R5, 8(R13)
   253		MOVW $0, R6 // higher 32-bit for arg 6
   254		MOVW R6, 12(R13)
   255		ADD $4, R13 // pass arg 5 and arg 6 on stack
   256		SWI $0xa000c5	// sys_mmap
   257		SUB $4, R13
   258		MOVW	R0, ret+24(FP)
   259		RET
   260	
   261	TEXT runtime·munmap(SB),NOSPLIT,$0
   262		MOVW addr+0(FP), R0	// arg 1 - addr
   263		MOVW n+4(FP), R1	// arg 2 - len
   264		SWI $0xa00049	// sys_munmap
   265		MOVW.CS $0, R8	// crash on syscall failure
   266		MOVW.CS R8, (R8)
   267		RET
   268	
   269	TEXT runtime·madvise(SB),NOSPLIT,$0
   270		MOVW addr+0(FP), R0	// arg 1 - addr
   271		MOVW n+4(FP), R1	// arg 2 - len
   272		MOVW flags+8(FP), R2	// arg 3 - behav
   273		SWI $0xa0004b	// sys_madvise
   274		// ignore failure - maybe pages are locked
   275		RET
   276	
   277	TEXT runtime·sigaltstack(SB),NOSPLIT,$-4
   278		MOVW new+0(FP), R0	// arg 1 - nss
   279		MOVW old+4(FP), R1	// arg 2 - oss
   280		SWI $0xa00119	// sys___sigaltstack14
   281		MOVW.CS $0, R8	// crash on syscall failure
   282		MOVW.CS R8, (R8)
   283		RET
   284	
   285	TEXT runtime·sysctl(SB),NOSPLIT,$8
   286		MOVW mib+0(FP), R0	// arg 1 - name
   287		MOVW miblen+4(FP), R1	// arg 2 - namelen
   288		MOVW out+8(FP), R2	// arg 3 - oldp
   289		MOVW size+12(FP), R3	// arg 4 - oldlenp
   290		MOVW dst+16(FP), R4	// arg 5 - newp
   291		MOVW R4, 4(R13)
   292		MOVW ndst+20(FP), R4	// arg 6 - newlen
   293		MOVW R4, 8(R13)
   294		ADD $4, R13	// pass arg 5 and 6 on stack
   295		SWI $0xa000ca	// sys___sysctl
   296		SUB $4, R13
   297		MOVW	R0, ret+24(FP)
   298		RET
   299	
   300	// int32 runtime·kqueue(void)
   301	TEXT runtime·kqueue(SB),NOSPLIT,$0
   302		SWI $0xa00158	// sys_kqueue
   303		RSB.CS $0, R0
   304		MOVW	R0, ret+0(FP)
   305		RET
   306	
   307	// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   308	TEXT runtime·kevent(SB),NOSPLIT,$8
   309		MOVW kq+0(FP), R0	// kq
   310		MOVW ch+4(FP), R1	// changelist
   311		MOVW nch+8(FP), R2	// nchanges
   312		MOVW ev+12(FP), R3	// eventlist
   313		MOVW nev+16(FP), R4	// nevents
   314		MOVW R4, 4(R13)
   315		MOVW ts+20(FP), R4	// timeout
   316		MOVW R4, 8(R13)
   317		ADD $4, R13	// pass arg 5 and 6 on stack
   318		SWI $0xa001b3	// sys___kevent50
   319		RSB.CS $0, R0
   320		SUB $4, R13
   321		MOVW	R0, ret+24(FP)
   322		RET
   323	
   324	// void runtime·closeonexec(int32 fd)
   325	TEXT runtime·closeonexec(SB),NOSPLIT,$0
   326		MOVW fd+0(FP), R0	// fd
   327		MOVW $2, R1	// F_SETFD
   328		MOVW $1, R2	// FD_CLOEXEC
   329		SWI $0xa0005c	// sys_fcntl
   330		RET
   331	
   332	// TODO: this is only valid for ARMv7+
   333	TEXT ·publicationBarrier(SB),NOSPLIT,$-4-0
   334		B	runtime·armPublicationBarrier(SB)
   335	
   336	TEXT runtime·read_tls_fallback(SB),NOSPLIT,$-4
   337		MOVM.WP [R1, R2, R3, R12], (R13)
   338		SWI $0x00a0013c // _lwp_getprivate
   339		MOVM.IAW    (R13), [R1, R2, R3, R12]
   340		RET

View as plain text