...
Run Format

Text file src/runtime/sys_freebsd_amd64.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 AMD64, FreeBSD
     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	TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
    14		MOVQ addr+0(FP), DI
    15		MOVL mode+8(FP), SI
    16		MOVL val+12(FP), DX
    17		MOVQ uaddr1+16(FP), R10
    18		MOVQ ut+24(FP), R8
    19		MOVL $454, AX
    20		SYSCALL
    21		MOVL	AX, ret+32(FP)
    22		RET
    23	
    24	TEXT runtime·thr_new(SB),NOSPLIT,$0
    25		MOVQ param+0(FP), DI
    26		MOVL size+8(FP), SI
    27		MOVL $455, AX
    28		SYSCALL
    29		RET
    30	
    31	TEXT runtime·thr_start(SB),NOSPLIT,$0
    32		MOVQ	DI, R13 // m
    33	
    34		// set up FS to point at m->tls
    35		LEAQ	m_tls(R13), DI
    36		CALL	runtime·settls(SB)	// smashes DI
    37	
    38		// set up m, g
    39		get_tls(CX)
    40		MOVQ	m_g0(R13), DI
    41		MOVQ	R13, g_m(DI)
    42		MOVQ	DI, g(CX)
    43	
    44		CALL	runtime·stackcheck(SB)
    45		CALL	runtime·mstart(SB)
    46	
    47		MOVQ 0, AX			// crash (not reached)
    48	
    49	// Exit the entire program (like C exit)
    50	TEXT runtime·exit(SB),NOSPLIT,$-8
    51		MOVL	code+0(FP), DI		// arg 1 exit status
    52		MOVL	$1, AX
    53		SYSCALL
    54		MOVL	$0xf1, 0xf1  // crash
    55		RET
    56	
    57	TEXT runtime·exit1(SB),NOSPLIT,$-8
    58		MOVL	code+0(FP), DI		// arg 1 exit status
    59		MOVL	$431, AX
    60		SYSCALL
    61		MOVL	$0xf1, 0xf1  // crash
    62		RET
    63	
    64	TEXT runtime·open(SB),NOSPLIT,$-8
    65		MOVQ	name+0(FP), DI		// arg 1 pathname
    66		MOVL	mode+8(FP), SI		// arg 2 flags
    67		MOVL	perm+12(FP), DX		// arg 3 mode
    68		MOVL	$5, AX
    69		SYSCALL
    70		JCC	2(PC)
    71		MOVL	$-1, AX
    72		MOVL	AX, ret+16(FP)
    73		RET
    74	
    75	TEXT runtime·closefd(SB),NOSPLIT,$-8
    76		MOVL	fd+0(FP), DI		// arg 1 fd
    77		MOVL	$6, AX
    78		SYSCALL
    79		JCC	2(PC)
    80		MOVL	$-1, AX
    81		MOVL	AX, ret+8(FP)
    82		RET
    83	
    84	TEXT runtime·read(SB),NOSPLIT,$-8
    85		MOVL	fd+0(FP), DI		// arg 1 fd
    86		MOVQ	p+8(FP), SI		// arg 2 buf
    87		MOVL	n+16(FP), DX		// arg 3 count
    88		MOVL	$3, AX
    89		SYSCALL
    90		JCC	2(PC)
    91		MOVL	$-1, AX
    92		MOVL	AX, ret+24(FP)
    93		RET
    94	
    95	TEXT runtime·write(SB),NOSPLIT,$-8
    96		MOVQ	fd+0(FP), DI		// arg 1 fd
    97		MOVQ	p+8(FP), SI		// arg 2 buf
    98		MOVL	n+16(FP), DX		// arg 3 count
    99		MOVL	$4, AX
   100		SYSCALL
   101		JCC	2(PC)
   102		MOVL	$-1, AX
   103		MOVL	AX, ret+24(FP)
   104		RET
   105	
   106	TEXT runtime·getrlimit(SB),NOSPLIT,$-8
   107		MOVL	kind+0(FP), DI
   108		MOVQ	limit+8(FP), SI
   109		MOVL	$194, AX
   110		SYSCALL
   111		MOVL	AX, ret+16(FP)
   112		RET
   113	
   114	TEXT runtime·raise(SB),NOSPLIT,$16
   115		// thr_self(&8(SP))
   116		LEAQ	8(SP), DI	// arg 1 &8(SP)
   117		MOVL	$432, AX
   118		SYSCALL
   119		// thr_kill(self, SIGPIPE)
   120		MOVQ	8(SP), DI	// arg 1 id
   121		MOVL	sig+0(FP), SI	// arg 2
   122		MOVL	$433, AX
   123		SYSCALL
   124		RET
   125	
   126	TEXT runtime·raiseproc(SB),NOSPLIT,$0
   127		// getpid
   128		MOVL	$20, AX
   129		SYSCALL
   130		// kill(self, sig)
   131		MOVQ	AX, DI		// arg 1 pid
   132		MOVL	sig+0(FP), SI	// arg 2 sig
   133		MOVL	$37, AX
   134		SYSCALL
   135		RET
   136	
   137	TEXT runtime·setitimer(SB), NOSPLIT, $-8
   138		MOVL	mode+0(FP), DI
   139		MOVQ	new+8(FP), SI
   140		MOVQ	old+16(FP), DX
   141		MOVL	$83, AX
   142		SYSCALL
   143		RET
   144	
   145	// func walltime() (sec int64, nsec int32)
   146	TEXT runtime·walltime(SB), NOSPLIT, $32
   147		MOVL	$232, AX // clock_gettime
   148		MOVQ	$0, DI		// CLOCK_REALTIME
   149		LEAQ	8(SP), SI
   150		SYSCALL
   151		MOVQ	8(SP), AX	// sec
   152		MOVQ	16(SP), DX	// nsec
   153	
   154		// sec is in AX, nsec in DX
   155		MOVQ	AX, sec+0(FP)
   156		MOVL	DX, nsec+8(FP)
   157		RET
   158	
   159	TEXT runtime·nanotime(SB), NOSPLIT, $32
   160		MOVL	$232, AX
   161		// We can use CLOCK_MONOTONIC_FAST here when we drop
   162		// support for FreeBSD 8-STABLE.
   163		MOVQ	$4, DI		// CLOCK_MONOTONIC
   164		LEAQ	8(SP), SI
   165		SYSCALL
   166		MOVQ	8(SP), AX	// sec
   167		MOVQ	16(SP), DX	// nsec
   168	
   169		// sec is in AX, nsec in DX
   170		// return nsec in AX
   171		IMULQ	$1000000000, AX
   172		ADDQ	DX, AX
   173		MOVQ	AX, ret+0(FP)
   174		RET
   175	
   176	TEXT runtime·sigaction(SB),NOSPLIT,$-8
   177		MOVL	sig+0(FP), DI		// arg 1 sig
   178		MOVQ	new+8(FP), SI		// arg 2 act
   179		MOVQ	old+16(FP), DX		// arg 3 oact
   180		MOVL	$416, AX
   181		SYSCALL
   182		JCC	2(PC)
   183		MOVL	$0xf1, 0xf1  // crash
   184		RET
   185	
   186	TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   187		MOVQ	fn+0(FP),    AX
   188		MOVL	sig+8(FP),   DI
   189		MOVQ	info+16(FP), SI
   190		MOVQ	ctx+24(FP),  DX
   191		PUSHQ	BP
   192		MOVQ	SP, BP
   193		ANDQ	$~15, SP     // alignment for x86_64 ABI
   194		CALL	AX
   195		MOVQ	BP, SP
   196		POPQ	BP
   197		RET
   198	
   199	TEXT runtime·sigtramp(SB),NOSPLIT,$72
   200		// Save callee-saved C registers, since the caller may be a C signal handler.
   201		MOVQ	BX, bx-8(SP)
   202		MOVQ	BP, bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
   203		MOVQ	R12, r12-24(SP)
   204		MOVQ	R13, r13-32(SP)
   205		MOVQ	R14, r14-40(SP)
   206		MOVQ	R15, r15-48(SP)
   207		// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   208		// modify them.
   209	
   210		MOVQ	DX, ctx-56(SP)
   211		MOVQ	SI, info-64(SP)
   212		MOVQ	DI, signum-72(SP)
   213		CALL	runtime·sigtrampgo(SB)
   214	
   215		MOVQ	r15-48(SP), R15
   216		MOVQ	r14-40(SP), R14
   217		MOVQ	r13-32(SP), R13
   218		MOVQ	r12-24(SP), R12
   219		MOVQ	bp-16(SP),  BP
   220		MOVQ	bx-8(SP),   BX
   221		RET
   222	
   223	TEXT runtime·mmap(SB),NOSPLIT,$0
   224		MOVQ	addr+0(FP), DI		// arg 1 addr
   225		MOVQ	n+8(FP), SI		// arg 2 len
   226		MOVL	prot+16(FP), DX		// arg 3 prot
   227		MOVL	flags+20(FP), R10		// arg 4 flags
   228		MOVL	fd+24(FP), R8		// arg 5 fid
   229		MOVL	off+28(FP), R9		// arg 6 offset
   230		MOVL	$477, AX
   231		SYSCALL
   232		MOVQ	AX, ret+32(FP)
   233		RET
   234	
   235	TEXT runtime·munmap(SB),NOSPLIT,$0
   236		MOVQ	addr+0(FP), DI		// arg 1 addr
   237		MOVQ	n+8(FP), SI		// arg 2 len
   238		MOVL	$73, AX
   239		SYSCALL
   240		JCC	2(PC)
   241		MOVL	$0xf1, 0xf1  // crash
   242		RET
   243	
   244	TEXT runtime·madvise(SB),NOSPLIT,$0
   245		MOVQ	addr+0(FP), DI
   246		MOVQ	n+8(FP), SI
   247		MOVL	flags+16(FP), DX
   248		MOVQ	$75, AX	// madvise
   249		SYSCALL
   250		// ignore failure - maybe pages are locked
   251		RET
   252		
   253	TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   254		MOVQ	new+0(FP), DI
   255		MOVQ	old+8(FP), SI
   256		MOVQ	$53, AX
   257		SYSCALL
   258		JCC	2(PC)
   259		MOVL	$0xf1, 0xf1  // crash
   260		RET
   261	
   262	TEXT runtime·usleep(SB),NOSPLIT,$16
   263		MOVL	$0, DX
   264		MOVL	usec+0(FP), AX
   265		MOVL	$1000000, CX
   266		DIVL	CX
   267		MOVQ	AX, 0(SP)		// tv_sec
   268		MOVL	$1000, AX
   269		MULL	DX
   270		MOVQ	AX, 8(SP)		// tv_nsec
   271	
   272		MOVQ	SP, DI			// arg 1 - rqtp
   273		MOVQ	$0, SI			// arg 2 - rmtp
   274		MOVL	$240, AX		// sys_nanosleep
   275		SYSCALL
   276		RET
   277	
   278	// set tls base to DI
   279	TEXT runtime·settls(SB),NOSPLIT,$8
   280		ADDQ	$8, DI	// adjust for ELF: wants to use -8(FS) for g and m
   281		MOVQ	DI, 0(SP)
   282		MOVQ	SP, SI
   283		MOVQ	$129, DI	// AMD64_SET_FSBASE
   284		MOVQ	$165, AX	// sysarch
   285		SYSCALL
   286		JCC	2(PC)
   287		MOVL	$0xf1, 0xf1  // crash
   288		RET
   289	
   290	TEXT runtime·sysctl(SB),NOSPLIT,$0
   291		MOVQ	mib+0(FP), DI		// arg 1 - name
   292		MOVL	miblen+8(FP), SI		// arg 2 - namelen
   293		MOVQ	out+16(FP), DX		// arg 3 - oldp
   294		MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   295		MOVQ	dst+32(FP), R8		// arg 5 - newp
   296		MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   297		MOVQ	$202, AX		// sys___sysctl
   298		SYSCALL
   299		JCC 4(PC)
   300		NEGQ	AX
   301		MOVL	AX, ret+48(FP)
   302		RET
   303		MOVL	$0, AX
   304		MOVL	AX, ret+48(FP)
   305		RET
   306	
   307	TEXT runtime·osyield(SB),NOSPLIT,$-4
   308		MOVL	$331, AX		// sys_sched_yield
   309		SYSCALL
   310		RET
   311	
   312	TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   313		MOVL	how+0(FP), DI		// arg 1 - how
   314		MOVQ	new+8(FP), SI		// arg 2 - set
   315		MOVQ	old+16(FP), DX		// arg 3 - oset
   316		MOVL	$340, AX		// sys_sigprocmask
   317		SYSCALL
   318		JAE	2(PC)
   319		MOVL	$0xf1, 0xf1  // crash
   320		RET
   321	
   322	// int32 runtime·kqueue(void);
   323	TEXT runtime·kqueue(SB),NOSPLIT,$0
   324		MOVQ	$0, DI
   325		MOVQ	$0, SI
   326		MOVQ	$0, DX
   327		MOVL	$362, AX
   328		SYSCALL
   329		JCC	2(PC)
   330		NEGQ	AX
   331		MOVL	AX, ret+0(FP)
   332		RET
   333	
   334	// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   335	TEXT runtime·kevent(SB),NOSPLIT,$0
   336		MOVL	kq+0(FP), DI
   337		MOVQ	ch+8(FP), SI
   338		MOVL	nch+16(FP), DX
   339		MOVQ	ev+24(FP), R10
   340		MOVL	nev+32(FP), R8
   341		MOVQ	ts+40(FP), R9
   342		MOVL	$363, AX
   343		SYSCALL
   344		JCC	2(PC)
   345		NEGQ	AX
   346		MOVL	AX, ret+48(FP)
   347		RET
   348	
   349	// void runtime·closeonexec(int32 fd);
   350	TEXT runtime·closeonexec(SB),NOSPLIT,$0
   351		MOVL	fd+0(FP), DI	// fd
   352		MOVQ	$2, SI		// F_SETFD
   353		MOVQ	$1, DX		// FD_CLOEXEC
   354		MOVL	$92, AX		// fcntl
   355		SYSCALL
   356		RET
   357	
   358	// func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
   359	TEXT runtime·cpuset_getaffinity(SB), NOSPLIT, $0-44
   360		MOVQ	level+0(FP), DI
   361		MOVQ	which+8(FP), SI
   362		MOVQ	id+16(FP), DX
   363		MOVQ	size+24(FP), R10
   364		MOVQ	mask+32(FP), R8
   365		MOVL	$487, AX
   366		SYSCALL
   367		JCC	2(PC)
   368		NEGQ	AX
   369		MOVL	AX, ret+40(FP)
   370		RET

View as plain text