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

View as plain text