...
Run Format

Text file src/runtime/sys_freebsd_arm.s

Documentation: runtime

     1	// Copyright 2012 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, FreeBSD
     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	// for EABI, as we don't support OABI
    14	#define SYS_BASE 0x0
    15	
    16	#define SYS_exit (SYS_BASE + 1)
    17	#define SYS_read (SYS_BASE + 3)
    18	#define SYS_write (SYS_BASE + 4)
    19	#define SYS_open (SYS_BASE + 5)
    20	#define SYS_close (SYS_BASE + 6)
    21	#define SYS_getpid (SYS_BASE + 20)
    22	#define SYS_kill (SYS_BASE + 37)
    23	#define SYS_sigaltstack (SYS_BASE + 53)
    24	#define SYS_munmap (SYS_BASE + 73)
    25	#define SYS_madvise (SYS_BASE + 75)
    26	#define SYS_setitimer (SYS_BASE + 83)
    27	#define SYS_fcntl (SYS_BASE + 92)
    28	#define SYS_getrlimit (SYS_BASE + 194)
    29	#define SYS___sysctl (SYS_BASE + 202)
    30	#define SYS_nanosleep (SYS_BASE + 240)
    31	#define SYS_clock_gettime (SYS_BASE + 232)
    32	#define SYS_sched_yield (SYS_BASE + 331)
    33	#define SYS_sigprocmask (SYS_BASE + 340)
    34	#define SYS_kqueue (SYS_BASE + 362)
    35	#define SYS_kevent (SYS_BASE + 363)
    36	#define SYS_sigaction (SYS_BASE + 416)
    37	#define SYS_thr_exit (SYS_BASE + 431)
    38	#define SYS_thr_self (SYS_BASE + 432)
    39	#define SYS_thr_kill (SYS_BASE + 433)
    40	#define SYS__umtx_op (SYS_BASE + 454)
    41	#define SYS_thr_new (SYS_BASE + 455)
    42	#define SYS_mmap (SYS_BASE + 477)
    43	#define SYS_cpuset_getaffinity (SYS_BASE + 487)
    44	
    45	TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
    46		MOVW addr+0(FP), R0
    47		MOVW mode+4(FP), R1
    48		MOVW val+8(FP), R2
    49		MOVW uaddr1+12(FP), R3
    50		ADD $20, R13 // arg 5 is passed on stack
    51		MOVW $SYS__umtx_op, R7
    52		SWI $0
    53		SUB $20, R13
    54		// BCS error
    55		MOVW	R0, ret+20(FP)
    56		RET
    57	
    58	TEXT runtime·thr_new(SB),NOSPLIT,$0
    59		MOVW param+0(FP), R0
    60		MOVW size+4(FP), R1
    61		MOVW $SYS_thr_new, R7
    62		SWI $0
    63		RET
    64	
    65	TEXT runtime·thr_start(SB),NOSPLIT,$0
    66		// set up g
    67		MOVW m_g0(R0), g
    68		MOVW R0, g_m(g)
    69		BL runtime·emptyfunc(SB) // fault if stack check is wrong
    70		BL runtime·mstart(SB)
    71	
    72		MOVW $2, R8  // crash (not reached)
    73		MOVW R8, (R8)
    74		RET
    75	
    76	// Exit the entire program (like C exit)
    77	TEXT runtime·exit(SB),NOSPLIT,$-8
    78		MOVW code+0(FP), R0	// arg 1 exit status
    79		MOVW $SYS_exit, R7
    80		SWI $0
    81		MOVW.CS $0, R8 // crash on syscall failure
    82		MOVW.CS R8, (R8)
    83		RET
    84	
    85	TEXT runtime·exit1(SB),NOSPLIT,$-8
    86		MOVW code+0(FP), R0	// arg 1 exit status
    87		MOVW $SYS_thr_exit, R7	
    88		SWI $0
    89		MOVW.CS $0, R8 // crash on syscall failure
    90		MOVW.CS R8, (R8)
    91		RET
    92	
    93	TEXT runtime·open(SB),NOSPLIT,$-8
    94		MOVW name+0(FP), R0	// arg 1 name
    95		MOVW mode+4(FP), R1	// arg 2 mode
    96		MOVW perm+8(FP), R2	// arg 3 perm
    97		MOVW $SYS_open, R7
    98		SWI $0
    99		MOVW.CS	$-1, R0
   100		MOVW	R0, ret+12(FP)
   101		RET
   102	
   103	TEXT runtime·read(SB),NOSPLIT,$-8
   104		MOVW fd+0(FP), R0	// arg 1 fd
   105		MOVW p+4(FP), R1	// arg 2 buf
   106		MOVW n+8(FP), R2	// arg 3 count
   107		MOVW $SYS_read, R7
   108		SWI $0
   109		MOVW.CS	$-1, R0
   110		MOVW	R0, ret+12(FP)
   111		RET
   112	
   113	TEXT runtime·write(SB),NOSPLIT,$-8
   114		MOVW fd+0(FP), R0	// arg 1 fd
   115		MOVW p+4(FP), R1	// arg 2 buf
   116		MOVW n+8(FP), R2	// arg 3 count
   117		MOVW $SYS_write, R7
   118		SWI $0
   119		MOVW.CS	$-1, R0
   120		MOVW	R0, ret+12(FP)
   121		RET
   122	
   123	TEXT runtime·closefd(SB),NOSPLIT,$-8
   124		MOVW fd+0(FP), R0	// arg 1 fd
   125		MOVW $SYS_close, R7
   126		SWI $0
   127		MOVW.CS	$-1, R0
   128		MOVW	R0, ret+4(FP)
   129		RET
   130	
   131	TEXT runtime·getrlimit(SB),NOSPLIT,$-8
   132		MOVW kind+0(FP), R0
   133		MOVW limit+4(FP), R1
   134		MOVW $SYS_getrlimit, R7
   135		SWI $0
   136		MOVW	R0, ret+8(FP)
   137		RET
   138	
   139	TEXT runtime·raise(SB),NOSPLIT,$8
   140		// thr_self(&4(R13))
   141		MOVW $4(R13), R0 // arg 1 &4(R13)
   142		MOVW $SYS_thr_self, R7
   143		SWI $0
   144		// thr_kill(self, SIGPIPE)
   145		MOVW 4(R13), R0	// arg 1 id
   146		MOVW sig+0(FP), R1	// arg 2 - signal
   147		MOVW $SYS_thr_kill, R7
   148		SWI $0
   149		RET
   150	
   151	TEXT runtime·raiseproc(SB),NOSPLIT,$0
   152		// getpid
   153		MOVW $SYS_getpid, R7
   154		SWI $0
   155		// kill(self, sig)
   156					// arg 1 - pid, now in R0
   157		MOVW sig+0(FP), R1	// arg 2 - signal
   158		MOVW $SYS_kill, R7
   159		SWI $0
   160		RET
   161	
   162	TEXT runtime·setitimer(SB), NOSPLIT, $-8
   163		MOVW mode+0(FP), R0
   164		MOVW new+4(FP), R1
   165		MOVW old+8(FP), R2
   166		MOVW $SYS_setitimer, R7
   167		SWI $0
   168		RET
   169	
   170	// func walltime() (sec int64, nsec int32)
   171	TEXT runtime·walltime(SB), NOSPLIT, $32
   172		MOVW $0, R0 // CLOCK_REALTIME
   173		MOVW $8(R13), R1
   174		MOVW $SYS_clock_gettime, R7
   175		SWI $0
   176	
   177		MOVW 8(R13), R0 // sec.low
   178		MOVW 12(R13), R1 // sec.high
   179		MOVW 16(R13), R2 // nsec
   180	
   181		MOVW R0, sec_lo+0(FP)
   182		MOVW R1, sec_hi+4(FP)
   183		MOVW R2, nsec+8(FP)
   184		RET
   185	
   186	// int64 nanotime(void) so really
   187	// void nanotime(int64 *nsec)
   188	TEXT runtime·nanotime(SB), NOSPLIT, $32
   189		// We can use CLOCK_MONOTONIC_FAST here when we drop
   190		// support for FreeBSD 8-STABLE.
   191		MOVW $4, R0 // CLOCK_MONOTONIC
   192		MOVW $8(R13), R1
   193		MOVW $SYS_clock_gettime, R7
   194		SWI $0
   195	
   196		MOVW 8(R13), R0 // sec.low
   197		MOVW 12(R13), R4 // sec.high
   198		MOVW 16(R13), R2 // nsec
   199	
   200		MOVW $1000000000, R3
   201		MULLU R0, R3, (R1, R0)
   202		MUL R3, R4
   203		ADD.S R2, R0
   204		ADC R4, R1
   205	
   206		MOVW R0, ret_lo+0(FP)
   207		MOVW R1, ret_hi+4(FP)
   208		RET
   209	
   210	TEXT runtime·sigaction(SB),NOSPLIT,$-8
   211		MOVW sig+0(FP), R0		// arg 1 sig
   212		MOVW new+4(FP), R1		// arg 2 act
   213		MOVW old+8(FP), R2		// arg 3 oact
   214		MOVW $SYS_sigaction, R7
   215		SWI $0
   216		MOVW.CS $0, R8 // crash on syscall failure
   217		MOVW.CS R8, (R8)
   218		RET
   219	
   220	TEXT runtime·sigtramp(SB),NOSPLIT,$12
   221		// this might be called in external code context,
   222		// where g is not set.
   223		// first save R0, because runtime·load_g will clobber it
   224		MOVW	R0, 4(R13) // signum
   225		MOVB	runtime·iscgo(SB), R0
   226		CMP 	$0, R0
   227		BL.NE	runtime·load_g(SB)
   228	
   229		MOVW	R1, 8(R13)
   230		MOVW	R2, 12(R13)
   231		BL	runtime·sigtrampgo(SB)
   232		RET
   233	
   234	TEXT runtime·mmap(SB),NOSPLIT,$16
   235		MOVW addr+0(FP), R0		// arg 1 addr
   236		MOVW n+4(FP), R1		// arg 2 len
   237		MOVW prot+8(FP), R2		// arg 3 prot
   238		MOVW flags+12(FP), R3		// arg 4 flags
   239		// arg 5 (fid) and arg6 (offset_lo, offset_hi) are passed on stack
   240		// note the C runtime only passes the 32-bit offset_lo to us
   241		MOVW fd+16(FP), R4		// arg 5
   242		MOVW R4, 4(R13)
   243		MOVW off+20(FP), R5		// arg 6 lower 32-bit
   244		// the word at 8(R13) is skipped due to 64-bit argument alignment.
   245		MOVW R5, 12(R13)
   246		MOVW $0, R6 		// higher 32-bit for arg 6
   247		MOVW R6, 16(R13)
   248		ADD $4, R13
   249		MOVW $SYS_mmap, R7
   250		SWI $0
   251		SUB $4, R13
   252		// TODO(dfc) error checking ?
   253		MOVW	R0, ret+24(FP)
   254		RET
   255	
   256	TEXT runtime·munmap(SB),NOSPLIT,$0
   257		MOVW addr+0(FP), R0		// arg 1 addr
   258		MOVW n+4(FP), R1		// arg 2 len
   259		MOVW $SYS_munmap, R7
   260		SWI $0
   261		MOVW.CS $0, R8 // crash on syscall failure
   262		MOVW.CS R8, (R8)
   263		RET
   264	
   265	TEXT runtime·madvise(SB),NOSPLIT,$0
   266		MOVW addr+0(FP), R0		// arg 1 addr
   267		MOVW n+4(FP), R1		// arg 2 len
   268		MOVW flags+8(FP), R2		// arg 3 flags
   269		MOVW $SYS_madvise, R7
   270		SWI $0
   271		// ignore failure - maybe pages are locked
   272		RET
   273		
   274	TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   275		MOVW new+0(FP), R0
   276		MOVW old+4(FP), R1
   277		MOVW $SYS_sigaltstack, R7
   278		SWI $0
   279		MOVW.CS $0, R8 // crash on syscall failure
   280		MOVW.CS R8, (R8)
   281		RET
   282	
   283	TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
   284		MOVW	sig+4(FP), R0
   285		MOVW	info+8(FP), R1
   286		MOVW	ctx+12(FP), R2
   287		MOVW	fn+0(FP), R11
   288		MOVW	R13, R4
   289		SUB	$24, R13
   290		BIC	$0x7, R13 // alignment for ELF ABI
   291		BL	(R11)
   292		MOVW	R4, R13
   293		RET
   294	
   295	TEXT runtime·usleep(SB),NOSPLIT,$16
   296		MOVW usec+0(FP), R0
   297		CALL runtime·usplitR0(SB)
   298		// 0(R13) is the saved LR, don't use it
   299		MOVW R0, 4(R13) // tv_sec.low
   300		MOVW $0, R0
   301		MOVW R0, 8(R13) // tv_sec.high
   302		MOVW $1000, R2
   303		MUL R1, R2
   304		MOVW R2, 12(R13) // tv_nsec
   305	
   306		MOVW $4(R13), R0 // arg 1 - rqtp
   307		MOVW $0, R1      // arg 2 - rmtp
   308		MOVW $SYS_nanosleep, R7
   309		SWI $0
   310		RET
   311	
   312	TEXT runtime·sysctl(SB),NOSPLIT,$0
   313		MOVW mib+0(FP), R0	// arg 1 - name
   314		MOVW miblen+4(FP), R1	// arg 2 - namelen
   315		MOVW out+8(FP), R2	// arg 3 - old
   316		MOVW size+12(FP), R3	// arg 4 - oldlenp
   317		// arg 5 (newp) and arg 6 (newlen) are passed on stack
   318		ADD $20, R13
   319		MOVW $SYS___sysctl, R7
   320		SWI $0
   321		SUB.CS $0, R0, R0
   322		SUB $20, R13
   323		MOVW	R0, ret+24(FP)
   324		RET
   325	
   326	TEXT runtime·osyield(SB),NOSPLIT,$-4
   327		MOVW $SYS_sched_yield, R7
   328		SWI $0
   329		RET
   330	
   331	TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   332		MOVW how+0(FP), R0	// arg 1 - how
   333		MOVW new+4(FP), R1	// arg 2 - set
   334		MOVW old+8(FP), R2	// arg 3 - oset
   335		MOVW $SYS_sigprocmask, R7
   336		SWI $0
   337		MOVW.CS $0, R8 // crash on syscall failure
   338		MOVW.CS R8, (R8)
   339		RET
   340	
   341	// int32 runtime·kqueue(void)
   342	TEXT runtime·kqueue(SB),NOSPLIT,$0
   343		MOVW $SYS_kqueue, R7
   344		SWI $0
   345		RSB.CS $0, R0
   346		MOVW	R0, ret+0(FP)
   347		RET
   348	
   349	// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   350	TEXT runtime·kevent(SB),NOSPLIT,$0
   351		MOVW kq+0(FP), R0	// kq
   352		MOVW ch+4(FP), R1	// changelist
   353		MOVW nch+8(FP), R2	// nchanges
   354		MOVW ev+12(FP), R3	// eventlist
   355		ADD $20, R13	// pass arg 5 and 6 on stack
   356		MOVW $SYS_kevent, R7
   357		SWI $0
   358		RSB.CS $0, R0
   359		SUB $20, R13
   360		MOVW	R0, ret+24(FP)
   361		RET
   362	
   363	// void runtime·closeonexec(int32 fd)
   364	TEXT runtime·closeonexec(SB),NOSPLIT,$0
   365		MOVW fd+0(FP), R0	// fd
   366		MOVW $2, R1	// F_SETFD
   367		MOVW $1, R2	// FD_CLOEXEC
   368		MOVW $SYS_fcntl, R7
   369		SWI $0
   370		RET
   371	
   372	// TODO: this is only valid for ARMv7+
   373	TEXT ·publicationBarrier(SB),NOSPLIT,$-4-0
   374		B	runtime·armPublicationBarrier(SB)
   375	
   376	// TODO(minux): this only supports ARMv6K+.
   377	TEXT runtime·read_tls_fallback(SB),NOSPLIT,$-4
   378		WORD $0xee1d0f70 // mrc p15, 0, r0, c13, c0, 3
   379		RET
   380	
   381	// func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
   382	TEXT runtime·cpuset_getaffinity(SB), NOSPLIT, $0-28
   383		MOVW	level+0(FP), R0
   384		MOVW	which+4(FP), R1
   385		MOVW	id_lo+8(FP), R2
   386		MOVW	id_hi+12(FP), R3
   387		ADD	$20, R13	// Pass size and mask on stack.
   388		MOVW	$SYS_cpuset_getaffinity, R7
   389		SWI	$0
   390		RSB.CS	$0, R0
   391		SUB	$20, R13
   392		MOVW	R0, ret+24(FP)
   393		RET

View as plain text