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

View as plain text