...
Run Format

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

View as plain text