...
Run Format

Text file src/runtime/sys_linux_s390x.s

Documentation: runtime

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

View as plain text