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

View as plain text