...
Run Format

Text file src/runtime/sys_openbsd_arm.s

Documentation: runtime

     1	// Copyright 2009 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, OpenBSD
     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	// Exit the entire program (like C exit)
    17	TEXT runtime·exit(SB),NOSPLIT,$-4
    18		MOVW	code+0(FP), R0	// arg 1 - status
    19		MOVW	$1, R12			// sys_exit
    20		SWI	$0
    21		MOVW.CS	$0, R8			// crash on syscall failure
    22		MOVW.CS	R8, (R8)
    23		RET
    24	
    25	TEXT runtime·exit1(SB),NOSPLIT,$-4
    26		MOVW	$0, R0			// arg 1 - notdead
    27		MOVW	$302, R12		// sys___threxit
    28		SWI	$0
    29		MOVW.CS	$1, R8			// crash on syscall failure
    30		MOVW.CS	R8, (R8)
    31		RET
    32	
    33	TEXT runtime·open(SB),NOSPLIT,$-4
    34		MOVW	name+0(FP), R0		// arg 1 - path
    35		MOVW	mode+4(FP), R1		// arg 2 - mode
    36		MOVW	perm+8(FP), R2		// arg 3 - perm
    37		MOVW	$5, R12			// sys_open
    38		SWI	$0
    39		MOVW.CS	$-1, R0
    40		MOVW	R0, ret+12(FP)
    41		RET
    42	
    43	TEXT runtime·closefd(SB),NOSPLIT,$-4
    44		MOVW	fd+0(FP), R0		// arg 1 - fd
    45		MOVW	$6, R12			// sys_close
    46		SWI	$0
    47		MOVW.CS	$-1, R0
    48		MOVW	R0, ret+4(FP)
    49		RET
    50	
    51	TEXT runtime·read(SB),NOSPLIT,$-4
    52		MOVW	fd+0(FP), R0		// arg 1 - fd
    53		MOVW	p+4(FP), R1		// arg 2 - buf
    54		MOVW	n+8(FP), R2		// arg 3 - nbyte
    55		MOVW	$3, R12			// sys_read
    56		SWI	$0
    57		MOVW.CS	$-1, R0
    58		MOVW	R0, ret+12(FP)
    59		RET
    60	
    61	TEXT runtime·write(SB),NOSPLIT,$-4
    62		MOVW	fd+0(FP), R0		// arg 1 - fd
    63		MOVW	p+4(FP), R1		// arg 2 - buf
    64		MOVW	n+8(FP), R2		// arg 3 - nbyte
    65		MOVW	$4, R12			// sys_write
    66		SWI	$0
    67		MOVW.CS	$-1, R0
    68		MOVW	R0, ret+12(FP)
    69		RET
    70	
    71	TEXT runtime·usleep(SB),NOSPLIT,$16
    72		MOVW	usec+0(FP), R0
    73		CALL	runtime·usplitR0(SB)
    74		MOVW	R0, 4(R13)		// tv_sec - l32
    75		MOVW	$0, R0
    76		MOVW	R0, 8(R13)		// tv_sec - h32
    77		MOVW	$1000, R2
    78		MUL	R1, R2
    79		MOVW	R2, 12(R13)		// tv_nsec
    80	
    81		MOVW	$4(R13), R0		// arg 1 - rqtp
    82		MOVW	$0, R1			// arg 2 - rmtp
    83		MOVW	$91, R12		// sys_nanosleep
    84		SWI	$0
    85		RET
    86	
    87	TEXT runtime·raise(SB),NOSPLIT,$12
    88		MOVW	$0x12B, R12
    89		SWI	$0			// sys_getthrid
    90						// arg 1 - tid, already in R0
    91		MOVW	sig+0(FP), R1		// arg 2 - signum
    92		MOVW	$0, R2			// arg 3 - tcb
    93		MOVW	$119, R12		// sys_thrkill
    94		SWI	$0
    95		RET
    96	
    97	TEXT runtime·raiseproc(SB),NOSPLIT,$12
    98		MOVW	$20, R12
    99		SWI	$0			// sys_getpid
   100						// arg 1 - pid, already in R0
   101		MOVW	sig+0(FP), R1		// arg 2 - signum
   102		MOVW	$122, R12		// sys_kill
   103		SWI	$0
   104		RET
   105	
   106	TEXT runtime·mmap(SB),NOSPLIT,$16
   107		MOVW	addr+0(FP), R0		// arg 1 - addr
   108		MOVW	n+4(FP), R1		// arg 2 - len
   109		MOVW	prot+8(FP), R2		// arg 3 - prot
   110		MOVW	flags+12(FP), R3	// arg 4 - flags
   111		MOVW	fd+16(FP), R4		// arg 5 - fd (on stack)
   112		MOVW	R4, 4(R13)
   113		MOVW	$0, R5			// arg 6 - pad (on stack)
   114		MOVW	R5, 8(R13)
   115		MOVW	off+20(FP), R6		// arg 7 - offset (on stack)
   116		MOVW	R6, 12(R13)		// lower 32 bits (from Go runtime)
   117		MOVW	$0, R7
   118		MOVW	R7, 16(R13)		// high 32 bits
   119		ADD	$4, R13
   120		MOVW	$197, R12		// sys_mmap
   121		SWI	$0
   122		SUB	$4, R13
   123		MOVW	R0, ret+24(FP)
   124		RET
   125	
   126	TEXT runtime·munmap(SB),NOSPLIT,$0
   127		MOVW	addr+0(FP), R0		// arg 1 - addr
   128		MOVW	n+4(FP), R1		// arg 2 - len
   129		MOVW	$73, R12		// sys_munmap
   130		SWI	$0
   131		MOVW.CS	$0, R8			// crash on syscall failure
   132		MOVW.CS	R8, (R8)
   133		RET
   134	
   135	TEXT runtime·madvise(SB),NOSPLIT,$0
   136		MOVW	addr+0(FP), R0		// arg 1 - addr
   137		MOVW	n+4(FP), R1		// arg 2 - len
   138		MOVW	flags+8(FP), R2		// arg 2 - flags
   139		MOVW	$75, R12		// sys_madvise
   140		SWI	$0
   141		MOVW.CS	$0, R8			// crash on syscall failure
   142		MOVW.CS	R8, (R8)
   143		RET
   144	
   145	TEXT runtime·setitimer(SB),NOSPLIT,$0
   146		MOVW	mode+0(FP), R0		// arg 1 - mode
   147		MOVW	new+4(FP), R1		// arg 2 - new value
   148		MOVW	old+8(FP), R2		// arg 3 - old value
   149		MOVW	$69, R12		// sys_setitimer
   150		SWI	$0
   151		RET
   152	
   153	// func walltime() (sec int64, nsec int32)
   154	TEXT runtime·walltime(SB), NOSPLIT, $32
   155		MOVW	CLOCK_REALTIME, R0	// arg 1 - clock_id
   156		MOVW	$8(R13), R1		// arg 2 - tp
   157		MOVW	$87, R12		// sys_clock_gettime
   158		SWI	$0
   159	
   160		MOVW	8(R13), R0		// sec - l32
   161		MOVW	12(R13), R1		// sec - h32
   162		MOVW	16(R13), R2		// nsec
   163	
   164		MOVW	R0, sec_lo+0(FP)
   165		MOVW	R1, sec_hi+4(FP)
   166		MOVW	R2, nsec+8(FP)
   167	
   168		RET
   169	
   170	// int64 nanotime(void) so really
   171	// void nanotime(int64 *nsec)
   172	TEXT runtime·nanotime(SB),NOSPLIT,$32
   173		MOVW	CLOCK_MONOTONIC, R0	// arg 1 - clock_id
   174		MOVW	$8(R13), R1		// arg 2 - tp
   175		MOVW	$87, R12		// sys_clock_gettime
   176		SWI	$0
   177	
   178		MOVW	8(R13), R0		// sec - l32
   179		MOVW	12(R13), R4		// sec - h32
   180		MOVW	16(R13), R2		// nsec
   181	
   182		MOVW	$1000000000, R3
   183		MULLU	R0, R3, (R1, R0)
   184		MUL	R3, R4
   185		ADD.S	R2, R0
   186		ADC	R4, R1
   187	
   188		MOVW	R0, ret_lo+0(FP)
   189		MOVW	R1, ret_hi+4(FP)
   190		RET
   191	
   192	TEXT runtime·sigaction(SB),NOSPLIT,$0
   193		MOVW	sig+0(FP), R0		// arg 1 - signum
   194		MOVW	new+4(FP), R1		// arg 2 - new sigaction
   195		MOVW	old+8(FP), R2		// arg 3 - old sigaction
   196		MOVW	$46, R12		// sys_sigaction
   197		SWI	$0
   198		MOVW.CS	$3, R8			// crash on syscall failure
   199		MOVW.CS	R8, (R8)
   200		RET
   201	
   202	TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0
   203		MOVW	how+0(FP), R0		// arg 1 - mode
   204		MOVW	new+4(FP), R1		// arg 2 - new
   205		MOVW	$48, R12		// sys_sigprocmask
   206		SWI	$0
   207		MOVW.CS	$3, R8			// crash on syscall failure
   208		MOVW.CS	R8, (R8)
   209		MOVW	R0, ret+8(FP)
   210		RET
   211	
   212	TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
   213		MOVW	sig+4(FP), R0
   214		MOVW	info+8(FP), R1
   215		MOVW	ctx+12(FP), R2
   216		MOVW	fn+0(FP), R11
   217		MOVW	R13, R4
   218		SUB	$24, R13
   219		BIC	$0x7, R13 // alignment for ELF ABI
   220		BL	(R11)
   221		MOVW	R4, R13
   222		RET
   223	
   224	TEXT runtime·sigtramp(SB),NOSPLIT,$12
   225		// If called from an external code context, g will not be set.
   226		// Save R0, since runtime·load_g will clobber it.
   227		MOVW	R0, 4(R13)		// signum
   228		MOVB	runtime·iscgo(SB), R0
   229		CMP	$0, R0
   230		BL.NE	runtime·load_g(SB)
   231	
   232		MOVW	R1, 8(R13)
   233		MOVW	R2, 12(R13)
   234		BL	runtime·sigtrampgo(SB)
   235		RET
   236	
   237	// int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
   238	TEXT runtime·tfork(SB),NOSPLIT,$0
   239	
   240		// Copy mp, gp and fn off parent stack for use by child.
   241		MOVW	mm+8(FP), R4
   242		MOVW	gg+12(FP), R5
   243		MOVW	fn+16(FP), R6
   244	
   245		MOVW	param+0(FP), R0		// arg 1 - param
   246		MOVW	psize+4(FP), R1		// arg 2 - psize
   247		MOVW	$8, R12			// sys___tfork
   248		SWI	$0
   249	
   250		// Return if syscall failed.
   251		B.CC	4(PC)
   252		RSB	$0, R0
   253		MOVW	R0, ret+20(FP)
   254		RET
   255	
   256		// In parent, return.
   257		CMP	$0, R0
   258		BEQ	3(PC)
   259		MOVW	R0, ret+20(FP)
   260		RET
   261	
   262		// Initialise m, g.
   263		MOVW	R5, g
   264		MOVW	R4, g_m(g)
   265	
   266		// Paranoia; check that stack splitting code works.
   267		BL	runtime·emptyfunc(SB)
   268	
   269		// Call fn.
   270		BL	(R6)
   271	
   272		BL	runtime·exit1(SB)
   273		MOVW	$2, R8			// crash if reached
   274		MOVW	R8, (R8)
   275		RET
   276	
   277	TEXT runtime·sigaltstack(SB),NOSPLIT,$0
   278		MOVW	new+0(FP), R0		// arg 1 - new sigaltstack
   279		MOVW	old+4(FP), R1		// arg 2 - old sigaltstack
   280		MOVW	$288, R12		// sys_sigaltstack
   281		SWI	$0
   282		MOVW.CS	$0, R8			// crash on syscall failure
   283		MOVW.CS	R8, (R8)
   284		RET
   285	
   286	TEXT runtime·osyield(SB),NOSPLIT,$0
   287		MOVW	$298, R12		// sys_sched_yield
   288		SWI	$0
   289		RET
   290	
   291	TEXT runtime·thrsleep(SB),NOSPLIT,$4
   292		MOVW	ident+0(FP), R0		// arg 1 - ident
   293		MOVW	clock_id+4(FP), R1	// arg 2 - clock_id
   294		MOVW	tsp+8(FP), R2		// arg 3 - tsp
   295		MOVW	lock+12(FP), R3		// arg 4 - lock
   296		MOVW	abort+16(FP), R4	// arg 5 - abort (on stack)
   297		MOVW	R4, 4(R13)
   298		ADD	$4, R13
   299		MOVW	$94, R12		// sys___thrsleep
   300		SWI	$0
   301		SUB	$4, R13
   302		MOVW	R0, ret+20(FP)
   303		RET
   304	
   305	TEXT runtime·thrwakeup(SB),NOSPLIT,$0
   306		MOVW	ident+0(FP), R0		// arg 1 - ident
   307		MOVW	n+4(FP), R1		// arg 2 - n
   308		MOVW	$301, R12		// sys___thrwakeup
   309		SWI	$0
   310		MOVW	R0, ret+8(FP)
   311		RET
   312	
   313	TEXT runtime·sysctl(SB),NOSPLIT,$8
   314		MOVW	mib+0(FP), R0		// arg 1 - mib
   315		MOVW	miblen+4(FP), R1	// arg 2 - miblen
   316		MOVW	out+8(FP), R2		// arg 3 - out
   317		MOVW	size+12(FP), R3		// arg 4 - size
   318		MOVW	dst+16(FP), R4		// arg 5 - dest (on stack)
   319		MOVW	R4, 4(R13)
   320		MOVW	ndst+20(FP), R5		// arg 6 - newlen (on stack)
   321		MOVW	R5, 8(R13)
   322		ADD	$4, R13
   323		MOVW	$202, R12		// sys___sysctl
   324		SWI	$0
   325		SUB	$4, R13
   326		MOVW.CC	$0, R0
   327		RSB.CS	$0, R0
   328		MOVW	R0, ret+24(FP)
   329		RET
   330	
   331	// int32 runtime·kqueue(void);
   332	TEXT runtime·kqueue(SB),NOSPLIT,$0
   333		MOVW	$269, R12		// sys_kqueue
   334		SWI	$0
   335		RSB.CS	$0, R0
   336		MOVW	R0, ret+0(FP)
   337		RET
   338	
   339	// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   340	TEXT runtime·kevent(SB),NOSPLIT,$8
   341		MOVW	kq+0(FP), R0		// arg 1 - kq
   342		MOVW	ch+4(FP), R1		// arg 2 - changelist
   343		MOVW	nch+8(FP), R2		// arg 3 - nchanges
   344		MOVW	ev+12(FP), R3		// arg 4 - eventlist
   345		MOVW	nev+16(FP), R4		// arg 5 - nevents (on stack)
   346		MOVW	R4, 4(R13)
   347		MOVW	ts+20(FP), R5		// arg 6 - timeout (on stack)
   348		MOVW	R5, 8(R13)
   349		ADD	$4, R13
   350		MOVW	$72, R12		// sys_kevent
   351		SWI	$0
   352		RSB.CS	$0, R0
   353		SUB	$4, R13
   354		MOVW	R0, ret+24(FP)
   355		RET
   356	
   357	// func closeonexec(fd int32)
   358	TEXT runtime·closeonexec(SB),NOSPLIT,$0
   359		MOVW	fd+0(FP), R0		// arg 1 - fd
   360		MOVW	$2, R1			// arg 2 - cmd (F_SETFD)
   361		MOVW	$1, R2			// arg 3 - arg (FD_CLOEXEC)
   362		MOVW	$92, R12		// sys_fcntl
   363		SWI	$0
   364		RET
   365	
   366	TEXT ·publicationBarrier(SB),NOSPLIT,$-4-0
   367		B	runtime·armPublicationBarrier(SB)
   368	
   369	// TODO(jsing): Implement.
   370	TEXT runtime·read_tls_fallback(SB),NOSPLIT,$-4
   371		MOVW	$5, R0
   372		MOVW	R0, (R0)
   373		RET

View as plain text