...
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_mmap		 90
    27	#define SYS_munmap		 91
    28	#define SYS_setitimer		104
    29	#define SYS_clone		120
    30	#define SYS_sched_yield		158
    31	#define SYS_nanosleep		162
    32	#define SYS_rt_sigreturn	172
    33	#define SYS_rt_sigaction	173
    34	#define SYS_rt_sigprocmask	174
    35	#define SYS_sigaltstack		185
    36	#define SYS_madvise		205
    37	#define SYS_mincore		206
    38	#define SYS_gettid		207
    39	#define SYS_tkill		208
    40	#define SYS_futex		221
    41	#define SYS_sched_getaffinity	223
    42	#define SYS_exit_group		234
    43	#define SYS_epoll_create	236
    44	#define SYS_epoll_ctl		237
    45	#define SYS_epoll_wait		238
    46	#define SYS_clock_gettime	246
    47	#define SYS_epoll_create1	315
    48	
    49	TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
    50		MOVW	code+0(FP), R3
    51		SYSCALL	$SYS_exit_group
    52		RET
    53	
    54	// func exitThread(wait *uint32)
    55	TEXT runtime·exitThread(SB),NOSPLIT|NOFRAME,$0-8
    56		MOVD	wait+0(FP), R1
    57		// We're done using the stack.
    58		MOVW	$0, R2
    59		SYNC
    60		MOVW	R2, (R1)
    61		MOVW	$0, R3	// exit code
    62		SYSCALL	$SYS_exit
    63		JMP	0(PC)
    64	
    65	TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
    66		MOVD	name+0(FP), R3
    67		MOVW	mode+8(FP), R4
    68		MOVW	perm+12(FP), R5
    69		SYSCALL	$SYS_open
    70		BVC	2(PC)
    71		MOVW	$-1, R3
    72		MOVW	R3, ret+16(FP)
    73		RET
    74	
    75	TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12
    76		MOVW	fd+0(FP), R3
    77		SYSCALL	$SYS_close
    78		BVC	2(PC)
    79		MOVW	$-1, R3
    80		MOVW	R3, ret+8(FP)
    81		RET
    82	
    83	TEXT runtime·write(SB),NOSPLIT|NOFRAME,$0-28
    84		MOVD	fd+0(FP), R3
    85		MOVD	p+8(FP), R4
    86		MOVW	n+16(FP), R5
    87		SYSCALL	$SYS_write
    88		BVC	2(PC)
    89		MOVW	$-1, R3
    90		MOVW	R3, ret+24(FP)
    91		RET
    92	
    93	TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
    94		MOVW	fd+0(FP), R3
    95		MOVD	p+8(FP), R4
    96		MOVW	n+16(FP), R5
    97		SYSCALL	$SYS_read
    98		BVC	2(PC)
    99		MOVW	$-1, R3
   100		MOVW	R3, ret+24(FP)
   101		RET
   102	
   103	TEXT runtime·usleep(SB),NOSPLIT,$16-4
   104		MOVW	usec+0(FP), R3
   105		MOVD	R3, R5
   106		MOVW	$1000000, R4
   107		DIVD	R4, R3
   108		MOVD	R3, 8(R1)
   109		MOVW	$1000, R4
   110		MULLD	R3, R4
   111		SUB	R4, R5
   112		MOVD	R5, 16(R1)
   113	
   114		// nanosleep(&ts, 0)
   115		ADD	$8, R1, R3
   116		MOVW	$0, R4
   117		SYSCALL	$SYS_nanosleep
   118		RET
   119	
   120	TEXT runtime·gettid(SB),NOSPLIT,$0-4
   121		SYSCALL	$SYS_gettid
   122		MOVW	R3, ret+0(FP)
   123		RET
   124	
   125	TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0
   126		SYSCALL	$SYS_gettid
   127		MOVW	R3, R3	// arg 1 tid
   128		MOVW	sig+0(FP), R4	// arg 2
   129		SYSCALL	$SYS_tkill
   130		RET
   131	
   132	TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0
   133		SYSCALL	$SYS_getpid
   134		MOVW	R3, R3	// arg 1 pid
   135		MOVW	sig+0(FP), R4	// arg 2
   136		SYSCALL	$SYS_kill
   137		RET
   138	
   139	TEXT runtime·setitimer(SB),NOSPLIT|NOFRAME,$0-24
   140		MOVW	mode+0(FP), R3
   141		MOVD	new+8(FP), R4
   142		MOVD	old+16(FP), R5
   143		SYSCALL	$SYS_setitimer
   144		RET
   145	
   146	TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28
   147		MOVD	addr+0(FP), R3
   148		MOVD	n+8(FP), R4
   149		MOVD	dst+16(FP), R5
   150		SYSCALL	$SYS_mincore
   151		NEG	R3		// caller expects negative errno
   152		MOVW	R3, ret+24(FP)
   153		RET
   154	
   155	// func walltime() (sec int64, nsec int32)
   156	TEXT runtime·walltime(SB),NOSPLIT,$16
   157		MOVD	$0, R3 // CLOCK_REALTIME
   158		MOVD	$0(R1), R4
   159		SYSCALL	$SYS_clock_gettime
   160		MOVD	0(R1), R3	// sec
   161		MOVD	8(R1), R5	// nsec
   162		MOVD	R3, sec+0(FP)
   163		MOVW	R5, nsec+8(FP)
   164		RET
   165	
   166	TEXT runtime·nanotime(SB),NOSPLIT,$16
   167		MOVW	$1, R3 // CLOCK_MONOTONIC
   168		MOVD	$0(R1), R4
   169		SYSCALL	$SYS_clock_gettime
   170		MOVD	0(R1), R3	// sec
   171		MOVD	8(R1), R5	// nsec
   172		// sec is in R3, nsec in R5
   173		// return nsec in R3
   174		MOVD	$1000000000, R4
   175		MULLD	R4, R3
   176		ADD	R5, R3
   177		MOVD	R3, ret+0(FP)
   178		RET
   179	
   180	TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
   181		MOVW	how+0(FP), R3
   182		MOVD	new+8(FP), R4
   183		MOVD	old+16(FP), R5
   184		MOVW	size+24(FP), R6
   185		SYSCALL	$SYS_rt_sigprocmask
   186		BVC	2(PC)
   187		MOVD	R0, 0xf0(R0)	// crash
   188		RET
   189	
   190	TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
   191		MOVD	sig+0(FP), R3
   192		MOVD	new+8(FP), R4
   193		MOVD	old+16(FP), R5
   194		MOVD	size+24(FP), R6
   195		SYSCALL	$SYS_rt_sigaction
   196		BVC	2(PC)
   197		NEG	R3	// caller expects negative errno
   198		MOVW	R3, ret+32(FP)
   199		RET
   200	
   201	TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   202		MOVW	sig+8(FP), R3
   203		MOVD	info+16(FP), R4
   204		MOVD	ctx+24(FP), R5
   205		MOVD	fn+0(FP), R12
   206		MOVD	R12, CTR
   207		BL	(CTR)
   208		MOVD	24(R1), R2
   209		RET
   210	
   211	#ifdef GOARCH_ppc64le
   212	// ppc64le doesn't need function descriptors
   213	TEXT runtime·sigtramp(SB),NOSPLIT,$64
   214	#else
   215	// function descriptor for the real sigtramp
   216	TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0
   217		DWORD	$runtime·_sigtramp(SB)
   218		DWORD	$0
   219		DWORD	$0
   220	TEXT runtime·_sigtramp(SB),NOSPLIT,$64
   221	#endif
   222		// initialize essential registers (just in case)
   223		BL	runtime·reginit(SB)
   224	
   225		// this might be called in external code context,
   226		// where g is not set.
   227		MOVB	runtime·iscgo(SB), R6
   228		CMP 	R6, $0
   229		BEQ	2(PC)
   230		BL	runtime·load_g(SB)
   231	
   232		MOVW	R3, FIXED_FRAME+0(R1)
   233		MOVD	R4, FIXED_FRAME+8(R1)
   234		MOVD	R5, FIXED_FRAME+16(R1)
   235		MOVD	$runtime·sigtrampgo(SB), R12
   236		MOVD	R12, CTR
   237		BL	(CTR)
   238		MOVD	24(R1), R2
   239		RET
   240	
   241	#ifdef GOARCH_ppc64le
   242	// ppc64le doesn't need function descriptors
   243	TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
   244		// The stack unwinder, presumably written in C, may not be able to
   245		// handle Go frame correctly. So, this function is NOFRAME, and we
   246		// we save/restore LR manually.
   247		MOVD	LR, R10
   248	
   249		// We're coming from C code, initialize essential registers.
   250		CALL	runtime·reginit(SB)
   251	
   252		// If no traceback function, do usual sigtramp.
   253		MOVD	runtime·cgoTraceback(SB), R6
   254		CMP	$0, R6
   255		BEQ	sigtramp
   256	
   257		// If no traceback support function, which means that
   258		// runtime/cgo was not linked in, do usual sigtramp.
   259		MOVD	_cgo_callers(SB), R6
   260		CMP	$0, R6
   261		BEQ	sigtramp
   262	
   263		// Set up g register.
   264		CALL	runtime·load_g(SB)
   265	
   266		// Figure out if we are currently in a cgo call.
   267		// If not, just do usual sigtramp.
   268		CMP	$0, g
   269		BEQ	sigtrampnog // g == nil
   270		MOVD	g_m(g), R6
   271		CMP	$0, R6
   272		BEQ	sigtramp    // g.m == nil
   273		MOVW	m_ncgo(R6), R7
   274		CMPW	$0, R7
   275		BEQ	sigtramp    // g.m.ncgo = 0
   276		MOVD	m_curg(R6), R7
   277		CMP	$0, R7
   278		BEQ	sigtramp    // g.m.curg == nil
   279		MOVD	g_syscallsp(R7), R7
   280		CMP	$0, R7
   281		BEQ	sigtramp    // g.m.curg.syscallsp == 0
   282		MOVD	m_cgoCallers(R6), R7 // R7 is the fifth arg in C calling convention.
   283		CMP	$0, R7
   284		BEQ	sigtramp    // g.m.cgoCallers == nil
   285		MOVW	m_cgoCallersUse(R6), R8
   286		CMPW	$0, R8
   287		BNE	sigtramp    // g.m.cgoCallersUse != 0
   288	
   289		// Jump to a function in runtime/cgo.
   290		// That function, written in C, will call the user's traceback
   291		// function with proper unwind info, and will then call back here.
   292		// The first three arguments, and the fifth, are already in registers.
   293		// Set the two remaining arguments now.
   294		MOVD	runtime·cgoTraceback(SB), R6
   295		MOVD	$runtime·sigtramp(SB), R8
   296		MOVD	_cgo_callers(SB), R12
   297		MOVD	R12, CTR
   298		MOVD	R10, LR // restore LR
   299		JMP	(CTR)
   300	
   301	sigtramp:
   302		MOVD	R10, LR // restore LR
   303		JMP	runtime·sigtramp(SB)
   304	
   305	sigtrampnog:
   306		// Signal arrived on a non-Go thread. If this is SIGPROF, get a
   307		// stack trace.
   308		CMPW	R3, $27 // 27 == SIGPROF
   309		BNE	sigtramp
   310	
   311		// Lock sigprofCallersUse (cas from 0 to 1).
   312		MOVW	$1, R7
   313		MOVD	$runtime·sigprofCallersUse(SB), R8
   314		SYNC
   315		LWAR    (R8), R6
   316		CMPW    $0, R6
   317		BNE     sigtramp
   318		STWCCC  R7, (R8)
   319		BNE     -4(PC)
   320		ISYNC
   321	
   322		// Jump to the traceback function in runtime/cgo.
   323		// It will call back to sigprofNonGo, which will ignore the
   324		// arguments passed in registers.
   325		// First three arguments to traceback function are in registers already.
   326		MOVD	runtime·cgoTraceback(SB), R6
   327		MOVD	$runtime·sigprofCallers(SB), R7
   328		MOVD	$runtime·sigprofNonGoWrapper<>(SB), R8
   329		MOVD	_cgo_callers(SB), R12
   330		MOVD	R12, CTR
   331		MOVD	R10, LR // restore LR
   332		JMP	(CTR)
   333	#else
   334	// function descriptor for the real sigtramp
   335	TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
   336		DWORD	$runtime·_cgoSigtramp(SB)
   337		DWORD	$0
   338		DWORD	$0
   339	TEXT runtime·_cgoSigtramp(SB),NOSPLIT,$0
   340		JMP	runtime·sigtramp(SB)
   341	#endif
   342	
   343	TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$0
   344		// We're coming from C code, set up essential register, then call sigprofNonGo.
   345		CALL	runtime·reginit(SB)
   346		CALL	runtime·sigprofNonGo(SB)
   347		RET
   348	
   349	TEXT runtime·mmap(SB),NOSPLIT|NOFRAME,$0
   350		MOVD	addr+0(FP), R3
   351		MOVD	n+8(FP), R4
   352		MOVW	prot+16(FP), R5
   353		MOVW	flags+20(FP), R6
   354		MOVW	fd+24(FP), R7
   355		MOVW	off+28(FP), R8
   356	
   357		SYSCALL	$SYS_mmap
   358		BVC	ok
   359		MOVD	$0, p+32(FP)
   360		MOVD	R3, err+40(FP)
   361		RET
   362	ok:
   363		MOVD	R3, p+32(FP)
   364		MOVD	$0, err+40(FP)
   365		RET
   366	
   367	TEXT runtime·munmap(SB),NOSPLIT|NOFRAME,$0
   368		MOVD	addr+0(FP), R3
   369		MOVD	n+8(FP), R4
   370		SYSCALL	$SYS_munmap
   371		BVC	2(PC)
   372		MOVD	R0, 0xf0(R0)
   373		RET
   374	
   375	TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0
   376		MOVD	addr+0(FP), R3
   377		MOVD	n+8(FP), R4
   378		MOVW	flags+16(FP), R5
   379		SYSCALL	$SYS_madvise
   380		// ignore failure - maybe pages are locked
   381		RET
   382	
   383	// int64 futex(int32 *uaddr, int32 op, int32 val,
   384	//	struct timespec *timeout, int32 *uaddr2, int32 val2);
   385	TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
   386		MOVD	addr+0(FP), R3
   387		MOVW	op+8(FP), R4
   388		MOVW	val+12(FP), R5
   389		MOVD	ts+16(FP), R6
   390		MOVD	addr2+24(FP), R7
   391		MOVW	val3+32(FP), R8
   392		SYSCALL	$SYS_futex
   393		BVC	2(PC)
   394		NEG	R3	// caller expects negative errno
   395		MOVW	R3, ret+40(FP)
   396		RET
   397	
   398	// int64 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   399	TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
   400		MOVW	flags+0(FP), R3
   401		MOVD	stk+8(FP), R4
   402	
   403		// Copy mp, gp, fn off parent stack for use by child.
   404		// Careful: Linux system call clobbers ???.
   405		MOVD	mp+16(FP), R7
   406		MOVD	gp+24(FP), R8
   407		MOVD	fn+32(FP), R12
   408	
   409		MOVD	R7, -8(R4)
   410		MOVD	R8, -16(R4)
   411		MOVD	R12, -24(R4)
   412		MOVD	$1234, R7
   413		MOVD	R7, -32(R4)
   414	
   415		SYSCALL $SYS_clone
   416		BVC	2(PC)
   417		NEG	R3	// caller expects negative errno
   418	
   419		// In parent, return.
   420		CMP	R3, $0
   421		BEQ	3(PC)
   422		MOVW	R3, ret+40(FP)
   423		RET
   424	
   425		// In child, on new stack.
   426		// initialize essential registers
   427		BL	runtime·reginit(SB)
   428		MOVD	-32(R1), R7
   429		CMP	R7, $1234
   430		BEQ	2(PC)
   431		MOVD	R0, 0(R0)
   432	
   433		// Initialize m->procid to Linux tid
   434		SYSCALL $SYS_gettid
   435	
   436		MOVD	-24(R1), R12       // fn
   437		MOVD	-16(R1), R8        // g
   438		MOVD	-8(R1), R7         // m
   439	
   440		CMP	R7, $0
   441		BEQ	nog
   442		CMP	R8, $0
   443		BEQ	nog
   444	
   445		MOVD	R3, m_procid(R7)
   446	
   447		// TODO: setup TLS.
   448	
   449		// In child, set up new stack
   450		MOVD	R7, g_m(R8)
   451		MOVD	R8, g
   452		//CALL	runtime·stackcheck(SB)
   453	
   454	nog:
   455		// Call fn
   456		MOVD	R12, CTR
   457		BL	(CTR)
   458	
   459		// It shouldn't return.	 If it does, exit that thread.
   460		MOVW	$111, R3
   461		SYSCALL	$SYS_exit
   462		BR	-2(PC)	// keep exiting
   463	
   464	TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0
   465		MOVD	new+0(FP), R3
   466		MOVD	old+8(FP), R4
   467		SYSCALL	$SYS_sigaltstack
   468		BVC	2(PC)
   469		MOVD	R0, 0xf0(R0)  // crash
   470		RET
   471	
   472	TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0
   473		SYSCALL	$SYS_sched_yield
   474		RET
   475	
   476	TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
   477		MOVD	pid+0(FP), R3
   478		MOVD	len+8(FP), R4
   479		MOVD	buf+16(FP), R5
   480		SYSCALL	$SYS_sched_getaffinity
   481		BVC	2(PC)
   482		NEG	R3	// caller expects negative errno
   483		MOVW	R3, ret+24(FP)
   484		RET
   485	
   486	// int32 runtime·epollcreate(int32 size);
   487	TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
   488		MOVW    size+0(FP), R3
   489		SYSCALL	$SYS_epoll_create
   490		BVC	2(PC)
   491		NEG	R3	// caller expects negative errno
   492		MOVW	R3, ret+8(FP)
   493		RET
   494	
   495	// int32 runtime·epollcreate1(int32 flags);
   496	TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
   497		MOVW	flags+0(FP), R3
   498		SYSCALL	$SYS_epoll_create1
   499		BVC	2(PC)
   500		NEG	R3	// caller expects negative errno
   501		MOVW	R3, ret+8(FP)
   502		RET
   503	
   504	// func epollctl(epfd, op, fd int32, ev *epollEvent) int
   505	TEXT runtime·epollctl(SB),NOSPLIT|NOFRAME,$0
   506		MOVW	epfd+0(FP), R3
   507		MOVW	op+4(FP), R4
   508		MOVW	fd+8(FP), R5
   509		MOVD	ev+16(FP), R6
   510		SYSCALL	$SYS_epoll_ctl
   511		NEG	R3	// caller expects negative errno
   512		MOVW	R3, ret+24(FP)
   513		RET
   514	
   515	// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
   516	TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
   517		MOVW	epfd+0(FP), R3
   518		MOVD	ev+8(FP), R4
   519		MOVW	nev+16(FP), R5
   520		MOVW	timeout+20(FP), R6
   521		SYSCALL	$SYS_epoll_wait
   522		BVC	2(PC)
   523		NEG	R3	// caller expects negative errno
   524		MOVW	R3, ret+24(FP)
   525		RET
   526	
   527	// void runtime·closeonexec(int32 fd);
   528	TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
   529		MOVW    fd+0(FP), R3  // fd
   530		MOVD    $2, R4  // F_SETFD
   531		MOVD    $1, R5  // FD_CLOEXEC
   532		SYSCALL	$SYS_fcntl
   533		RET
   534	
   535	// func sbrk0() uintptr
   536	TEXT runtime·sbrk0(SB),NOSPLIT|NOFRAME,$0
   537		// Implemented as brk(NULL).
   538		MOVD	$0, R3
   539		SYSCALL	$SYS_brk
   540		MOVD	R3, ret+0(FP)
   541		RET

View as plain text