...
Run Format

Text file src/runtime/sys_linux_ppc64x.s

Documentation: runtime

     1	// Copyright 2014 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	// +build linux
     6	// +build ppc64 ppc64le
     7	
     8	//
     9	// System calls and other sys.stuff for ppc64, Linux
    10	//
    11	
    12	#include "go_asm.h"
    13	#include "go_tls.h"
    14	#include "textflag.h"
    15	#include "asm_ppc64x.h"
    16	
    17	#define SYS_exit		  1
    18	#define SYS_read		  3
    19	#define SYS_write		  4
    20	#define SYS_open		  5
    21	#define SYS_close		  6
    22	#define SYS_getpid		 20
    23	#define SYS_kill		 37
    24	#define SYS_brk			 45
    25	#define SYS_fcntl		 55
    26	#define SYS_gettimeofday	 78
    27	#define SYS_select		 82	// always return -ENOSYS
    28	#define SYS_mmap		 90
    29	#define SYS_munmap		 91
    30	#define SYS_setitimer		104
    31	#define SYS_clone		120
    32	#define SYS_newselect		142
    33	#define SYS_sched_yield		158
    34	#define SYS_rt_sigreturn	172
    35	#define SYS_rt_sigaction	173
    36	#define SYS_rt_sigprocmask	174
    37	#define SYS_sigaltstack		185
    38	#define SYS_ugetrlimit		190
    39	#define SYS_madvise		205
    40	#define SYS_mincore		206
    41	#define SYS_gettid		207
    42	#define SYS_tkill		208
    43	#define SYS_futex		221
    44	#define SYS_sched_getaffinity	223
    45	#define SYS_exit_group		234
    46	#define SYS_epoll_create	236
    47	#define SYS_epoll_ctl		237
    48	#define SYS_epoll_wait		238
    49	#define SYS_clock_gettime	246
    50	#define SYS_epoll_create1	315
    51	
    52	TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
    53		MOVW	code+0(FP), R3
    54		SYSCALL	$SYS_exit_group
    55		RET
    56	
    57	TEXT runtime·exit1(SB),NOSPLIT|NOFRAME,$0-4
    58		MOVW	code+0(FP), R3
    59		SYSCALL	$SYS_exit
    60		RET
    61	
    62	TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
    63		MOVD	name+0(FP), R3
    64		MOVW	mode+8(FP), R4
    65		MOVW	perm+12(FP), R5
    66		SYSCALL	$SYS_open
    67		BVC	2(PC)
    68		MOVW	$-1, R3
    69		MOVW	R3, ret+16(FP)
    70		RET
    71	
    72	TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
    73		MOVW	fd+0(FP), R3
    74		SYSCALL	$SYS_close
    75		BVC	2(PC)
    76		MOVW	$-1, R3
    77		MOVW	R3, ret+8(FP)
    78		RET
    79	
    80	TEXT runtime·write(SB),NOSPLIT|NOFRAME,$0-28
    81		MOVD	fd+0(FP), R3
    82		MOVD	p+8(FP), R4
    83		MOVW	n+16(FP), R5
    84		SYSCALL	$SYS_write
    85		BVC	2(PC)
    86		MOVW	$-1, R3
    87		MOVW	R3, ret+24(FP)
    88		RET
    89	
    90	TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
    91		MOVW	fd+0(FP), R3
    92		MOVD	p+8(FP), R4
    93		MOVW	n+16(FP), R5
    94		SYSCALL	$SYS_read
    95		BVC	2(PC)
    96		MOVW	$-1, R3
    97		MOVW	R3, ret+24(FP)
    98		RET
    99	
   100	TEXT runtime·getrlimit(SB),NOSPLIT|NOFRAME,$0-20
   101		MOVW	kind+0(FP), R3
   102		MOVD	limit+8(FP), R4
   103		SYSCALL	$SYS_ugetrlimit
   104		MOVW	R3, ret+16(FP)
   105		RET
   106	
   107	TEXT runtime·usleep(SB),NOSPLIT,$16-4
   108		MOVW	usec+0(FP), R3
   109		MOVD	R3, R5
   110		MOVW	$1000000, R4
   111		DIVD	R4, R3
   112		MOVD	R3, 8(R1)
   113		MULLD	R3, R4
   114		SUB	R4, R5
   115		MOVD	R5, 16(R1)
   116	
   117		// select(0, 0, 0, 0, &tv)
   118		MOVW	$0, R3
   119		MOVW	$0, R4
   120		MOVW	$0, R5
   121		MOVW	$0, R6
   122		ADD	$8, R1, R7
   123		SYSCALL	$SYS_newselect
   124		RET
   125	
   126	TEXT runtime·gettid(SB),NOSPLIT,$0-4
   127		SYSCALL	$SYS_gettid
   128		MOVW	R3, ret+0(FP)
   129		RET
   130	
   131	TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
   132		SYSCALL	$SYS_gettid
   133		MOVW	R3, R3	// arg 1 tid
   134		MOVW	sig+0(FP), R4	// arg 2
   135		SYSCALL	$SYS_tkill
   136		RET
   137	
   138	TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
   139		SYSCALL	$SYS_getpid
   140		MOVW	R3, R3	// arg 1 pid
   141		MOVW	sig+0(FP), R4	// arg 2
   142		SYSCALL	$SYS_kill
   143		RET
   144	
   145	TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
   146		MOVW	mode+0(FP), R3
   147		MOVD	new+8(FP), R4
   148		MOVD	old+16(FP), R5
   149		SYSCALL	$SYS_setitimer
   150		RET
   151	
   152	TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28
   153		MOVD	addr+0(FP), R3
   154		MOVD	n+8(FP), R4
   155		MOVD	dst+16(FP), R5
   156		SYSCALL	$SYS_mincore
   157		NEG	R3		// caller expects negative errno
   158		MOVW	R3, ret+24(FP)
   159		RET
   160	
   161	// func walltime() (sec int64, nsec int32)
   162	TEXT runtime·walltime(SB),NOSPLIT,$16
   163		MOVD	$0, R3 // CLOCK_REALTIME
   164		MOVD	$0(R1), R4
   165		SYSCALL	$SYS_clock_gettime
   166		MOVD	0(R1), R3	// sec
   167		MOVD	8(R1), R5	// nsec
   168		MOVD	R3, sec+0(FP)
   169		MOVW	R5, nsec+8(FP)
   170		RET
   171	
   172	TEXT runtime·nanotime(SB),NOSPLIT,$16
   173		MOVW	$1, R3 // CLOCK_MONOTONIC
   174		MOVD	$0(R1), R4
   175		SYSCALL	$SYS_clock_gettime
   176		MOVD	0(R1), R3	// sec
   177		MOVD	8(R1), R5	// nsec
   178		// sec is in R3, nsec in R5
   179		// return nsec in R3
   180		MOVD	$1000000000, R4
   181		MULLD	R4, R3
   182		ADD	R5, R3
   183		MOVD	R3, ret+0(FP)
   184		RET
   185	
   186	TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
   187		MOVW	how+0(FP), R3
   188		MOVD	new+8(FP), R4
   189		MOVD	old+16(FP), R5
   190		MOVW	size+24(FP), R6
   191		SYSCALL	$SYS_rt_sigprocmask
   192		BVC	2(PC)
   193		MOVD	R0, 0xf0(R0)	// crash
   194		RET
   195	
   196	TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
   197		MOVD	sig+0(FP), R3
   198		MOVD	new+8(FP), R4
   199		MOVD	old+16(FP), R5
   200		MOVD	size+24(FP), R6
   201		SYSCALL	$SYS_rt_sigaction
   202		MOVW	R3, ret+32(FP)
   203		RET
   204	
   205	TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   206		MOVW	sig+8(FP), R3
   207		MOVD	info+16(FP), R4
   208		MOVD	ctx+24(FP), R5
   209		MOVD	fn+0(FP), R12
   210		MOVD	R12, CTR
   211		BL	(CTR)
   212		MOVD	24(R1), R2
   213		RET
   214	
   215	#ifdef GOARCH_ppc64le
   216	// ppc64le doesn't need function descriptors
   217	TEXT runtime·sigtramp(SB),NOSPLIT,$64
   218	#else
   219	// function descriptor for the real sigtramp
   220	TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0
   221		DWORD	$runtime·_sigtramp(SB)
   222		DWORD	$0
   223		DWORD	$0
   224	TEXT runtime·_sigtramp(SB),NOSPLIT,$64
   225	#endif
   226		// initialize essential registers (just in case)
   227		BL	runtime·reginit(SB)
   228	
   229		// this might be called in external code context,
   230		// where g is not set.
   231		MOVB	runtime·iscgo(SB), R6
   232		CMP 	R6, $0
   233		BEQ	2(PC)
   234		BL	runtime·load_g(SB)
   235	
   236		MOVW	R3, FIXED_FRAME+0(R1)
   237		MOVD	R4, FIXED_FRAME+8(R1)
   238		MOVD	R5, FIXED_FRAME+16(R1)
   239		MOVD	$runtime·sigtrampgo(SB), R12
   240		MOVD	R12, CTR
   241		BL	(CTR)
   242		MOVD	24(R1), R2
   243		RET
   244	
   245	#ifdef GOARCH_ppc64le
   246	// ppc64le doesn't need function descriptors
   247	TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   248	#else
   249	// function descriptor for the real sigtramp
   250	TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
   251		DWORD	$runtime·_cgoSigtramp(SB)
   252		DWORD	$0
   253		DWORD	$0
   254	TEXT runtime·_cgoSigtramp(SB),NOSPLIT,$0
   255	#endif
   256		MOVD	$runtime·sigtramp(SB), R12
   257		MOVD	R12, CTR
   258		JMP	(CTR)
   259	
   260	TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
   261		MOVD	addr+0(FP), R3
   262		MOVD	n+8(FP), R4
   263		MOVW	prot+16(FP), R5
   264		MOVW	flags+20(FP), R6
   265		MOVW	fd+24(FP), R7
   266		MOVW	off+28(FP), R8
   267	
   268		SYSCALL	$SYS_mmap
   269		MOVD	R3, ret+32(FP)
   270		RET
   271	
   272	TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
   273		MOVD	addr+0(FP), R3
   274		MOVD	n+8(FP), R4
   275		SYSCALL	$SYS_munmap
   276		BVC	2(PC)
   277		MOVD	R0, 0xf0(R0)
   278		RET
   279	
   280	TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
   281		MOVD	addr+0(FP), R3
   282		MOVD	n+8(FP), R4
   283		MOVW	flags+16(FP), R5
   284		SYSCALL	$SYS_madvise
   285		// ignore failure - maybe pages are locked
   286		RET
   287	
   288	// int64 futex(int32 *uaddr, int32 op, int32 val,
   289	//	struct timespec *timeout, int32 *uaddr2, int32 val2);
   290	TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
   291		MOVD	addr+0(FP), R3
   292		MOVW	op+8(FP), R4
   293		MOVW	val+12(FP), R5
   294		MOVD	ts+16(FP), R6
   295		MOVD	addr2+24(FP), R7
   296		MOVW	val3+32(FP), R8
   297		SYSCALL	$SYS_futex
   298		MOVW	R3, ret+40(FP)
   299		RET
   300	
   301	// int64 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   302	TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
   303		MOVW	flags+0(FP), R3
   304		MOVD	stk+8(FP), R4
   305	
   306		// Copy mp, gp, fn off parent stack for use by child.
   307		// Careful: Linux system call clobbers ???.
   308		MOVD	mp+16(FP), R7
   309		MOVD	gp+24(FP), R8
   310		MOVD	fn+32(FP), R12
   311	
   312		MOVD	R7, -8(R4)
   313		MOVD	R8, -16(R4)
   314		MOVD	R12, -24(R4)
   315		MOVD	$1234, R7
   316		MOVD	R7, -32(R4)
   317	
   318		SYSCALL $SYS_clone
   319	
   320		// In parent, return.
   321		CMP	R3, $0
   322		BEQ	3(PC)
   323		MOVW	R3, ret+40(FP)
   324		RET
   325	
   326		// In child, on new stack.
   327		// initialize essential registers
   328		BL	runtime·reginit(SB)
   329		MOVD	-32(R1), R7
   330		CMP	R7, $1234
   331		BEQ	2(PC)
   332		MOVD	R0, 0(R0)
   333	
   334		// Initialize m->procid to Linux tid
   335		SYSCALL $SYS_gettid
   336	
   337		MOVD	-24(R1), R12       // fn
   338		MOVD	-16(R1), R8        // g
   339		MOVD	-8(R1), R7         // m
   340	
   341		CMP	R7, $0
   342		BEQ	nog
   343		CMP	R8, $0
   344		BEQ	nog
   345	
   346		MOVD	R3, m_procid(R7)
   347	
   348		// TODO: setup TLS.
   349	
   350		// In child, set up new stack
   351		MOVD	R7, g_m(R8)
   352		MOVD	R8, g
   353		//CALL	runtime·stackcheck(SB)
   354	
   355	nog:
   356		// Call fn
   357		MOVD	R12, CTR
   358		BL	(CTR)
   359	
   360		// It shouldn't return.	 If it does, exit that thread.
   361		MOVW	$111, R3
   362		SYSCALL	$SYS_exit
   363		BR	-2(PC)	// keep exiting
   364	
   365	TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
   366		MOVD	new+0(FP), R3
   367		MOVD	old+8(FP), R4
   368		SYSCALL	$SYS_sigaltstack
   369		BVC	2(PC)
   370		MOVD	R0, 0xf0(R0)  // crash
   371		RET
   372	
   373	TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
   374		SYSCALL	$SYS_sched_yield
   375		RET
   376	
   377	TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
   378		MOVD	pid+0(FP), R3
   379		MOVD	len+8(FP), R4
   380		MOVD	buf+16(FP), R5
   381		SYSCALL	$SYS_sched_getaffinity
   382		MOVW	R3, ret+24(FP)
   383		RET
   384	
   385	// int32 runtime·epollcreate(int32 size);
   386	TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
   387		MOVW    size+0(FP), R3
   388		SYSCALL	$SYS_epoll_create
   389		MOVW	R3, ret+8(FP)
   390		RET
   391	
   392	// int32 runtime·epollcreate1(int32 flags);
   393	TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
   394		MOVW	flags+0(FP), R3
   395		SYSCALL	$SYS_epoll_create1
   396		MOVW	R3, ret+8(FP)
   397		RET
   398	
   399	// func epollctl(epfd, op, fd int32, ev *epollEvent) int
   400	TEXT runtime·epollctl(SB),NOSPLIT|NOFRAME,$0
   401		MOVW	epfd+0(FP), R3
   402		MOVW	op+4(FP), R4
   403		MOVW	fd+8(FP), R5
   404		MOVD	ev+16(FP), R6
   405		SYSCALL	$SYS_epoll_ctl
   406		MOVW	R3, ret+24(FP)
   407		RET
   408	
   409	// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
   410	TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
   411		MOVW	epfd+0(FP), R3
   412		MOVD	ev+8(FP), R4
   413		MOVW	nev+16(FP), R5
   414		MOVW	timeout+20(FP), R6
   415		SYSCALL	$SYS_epoll_wait
   416		MOVW	R3, ret+24(FP)
   417		RET
   418	
   419	// void runtime·closeonexec(int32 fd);
   420	TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
   421		MOVW    fd+0(FP), R3  // fd
   422		MOVD    $2, R4  // F_SETFD
   423		MOVD    $1, R5  // FD_CLOEXEC
   424		SYSCALL	$SYS_fcntl
   425		RET
   426	
   427	// func sbrk0() uintptr
   428	TEXT runtime·sbrk0(SB),NOSPLIT|NOFRAME,$0
   429		// Implemented as brk(NULL).
   430		MOVD	$0, R3
   431		SYSCALL	$SYS_brk
   432		MOVD	R3, ret+0(FP)
   433		RET

View as plain text