Text file src/runtime/sys_dragonfly_amd64.s

     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  #include "cgo/abi_amd64.h"
    13  
    14  TEXT runtime·sys_umtx_sleep(SB),NOSPLIT,$0
    15  	MOVQ addr+0(FP), DI		// arg 1 - ptr
    16  	MOVL val+8(FP), SI		// arg 2 - value
    17  	MOVL timeout+12(FP), DX		// arg 3 - timeout
    18  	MOVL $469, AX		// umtx_sleep
    19  	SYSCALL
    20  	JCC	2(PC)
    21  	NEGQ	AX
    22  	MOVL	AX, ret+16(FP)
    23  	RET
    24  
    25  TEXT runtime·sys_umtx_wakeup(SB),NOSPLIT,$0
    26  	MOVQ addr+0(FP), DI		// arg 1 - ptr
    27  	MOVL val+8(FP), SI		// arg 2 - count
    28  	MOVL $470, AX		// umtx_wakeup
    29  	SYSCALL
    30  	JCC	2(PC)
    31  	NEGQ	AX
    32  	MOVL	AX, ret+16(FP)
    33  	RET
    34  
    35  TEXT runtime·lwp_create(SB),NOSPLIT,$0
    36  	MOVQ param+0(FP), DI		// arg 1 - params
    37  	MOVL $495, AX		// lwp_create
    38  	SYSCALL
    39  	MOVL	AX, ret+8(FP)
    40  	RET
    41  
    42  TEXT runtime·lwp_start(SB),NOSPLIT,$0
    43  	MOVQ	DI, R13 // m
    44  
    45  	// set up FS to point at m->tls
    46  	LEAQ	m_tls(R13), DI
    47  	CALL	runtime·settls(SB)	// smashes DI
    48  
    49  	// set up m, g
    50  	get_tls(CX)
    51  	MOVQ	m_g0(R13), DI
    52  	MOVQ	R13, g_m(DI)
    53  	MOVQ	DI, g(CX)
    54  
    55  	CALL	runtime·stackcheck(SB)
    56  	CALL	runtime·mstart(SB)
    57  
    58  	MOVQ 0, AX			// crash (not reached)
    59  
    60  // Exit the entire program (like C exit)
    61  TEXT runtime·exit(SB),NOSPLIT,$-8
    62  	MOVL	code+0(FP), DI		// arg 1 exit status
    63  	MOVL	$1, AX
    64  	SYSCALL
    65  	MOVL	$0xf1, 0xf1  // crash
    66  	RET
    67  
    68  // func exitThread(wait *uint32)
    69  TEXT runtime·exitThread(SB),NOSPLIT,$0-8
    70  	MOVQ	wait+0(FP), AX
    71  	// We're done using the stack.
    72  	MOVL	$0, (AX)
    73  	MOVL	$0x10000, DI	// arg 1 how - EXTEXIT_LWP
    74  	MOVL	$0, SI		// arg 2 status
    75  	MOVL	$0, DX		// arg 3 addr
    76  	MOVL	$494, AX	// extexit
    77  	SYSCALL
    78  	MOVL	$0xf1, 0xf1  // crash
    79  	JMP	0(PC)
    80  
    81  TEXT runtime·open(SB),NOSPLIT,$-8
    82  	MOVQ	name+0(FP), DI		// arg 1 pathname
    83  	MOVL	mode+8(FP), SI		// arg 2 flags
    84  	MOVL	perm+12(FP), DX		// arg 3 mode
    85  	MOVL	$5, AX
    86  	SYSCALL
    87  	JCC	2(PC)
    88  	MOVL	$-1, AX
    89  	MOVL	AX, ret+16(FP)
    90  	RET
    91  
    92  TEXT runtime·closefd(SB),NOSPLIT,$-8
    93  	MOVL	fd+0(FP), DI		// arg 1 fd
    94  	MOVL	$6, AX
    95  	SYSCALL
    96  	JCC	2(PC)
    97  	MOVL	$-1, AX
    98  	MOVL	AX, ret+8(FP)
    99  	RET
   100  
   101  TEXT runtime·read(SB),NOSPLIT,$-8
   102  	MOVL	fd+0(FP), DI		// arg 1 fd
   103  	MOVQ	p+8(FP), SI		// arg 2 buf
   104  	MOVL	n+16(FP), DX		// arg 3 count
   105  	MOVL	$3, AX
   106  	SYSCALL
   107  	JCC	2(PC)
   108  	NEGL	AX			// caller expects negative errno
   109  	MOVL	AX, ret+24(FP)
   110  	RET
   111  
   112  // func pipe2(flags int32) (r, w int32, errno int32)
   113  TEXT runtime·pipe2(SB),NOSPLIT,$0-20
   114  	MOVL	$0, DI
   115  	// dragonfly expects flags as the 2nd argument
   116  	MOVL	flags+0(FP), SI
   117  	MOVL	$538, AX
   118  	SYSCALL
   119  	JCC	pipe2ok
   120  	MOVL	$-1,r+8(FP)
   121  	MOVL	$-1,w+12(FP)
   122  	MOVL	AX, errno+16(FP)
   123  	RET
   124  pipe2ok:
   125  	MOVL	AX, r+8(FP)
   126  	MOVL	DX, w+12(FP)
   127  	MOVL	$0, errno+16(FP)
   128  	RET
   129  
   130  TEXT runtime·write1(SB),NOSPLIT,$-8
   131  	MOVQ	fd+0(FP), DI		// arg 1 fd
   132  	MOVQ	p+8(FP), SI		// arg 2 buf
   133  	MOVL	n+16(FP), DX		// arg 3 count
   134  	MOVL	$4, AX
   135  	SYSCALL
   136  	JCC	2(PC)
   137  	NEGL	AX			// caller expects negative errno
   138  	MOVL	AX, ret+24(FP)
   139  	RET
   140  
   141  TEXT runtime·lwp_gettid(SB),NOSPLIT,$0-4
   142  	MOVL	$496, AX	// lwp_gettid
   143  	SYSCALL
   144  	MOVL	AX, ret+0(FP)
   145  	RET
   146  
   147  TEXT runtime·lwp_kill(SB),NOSPLIT,$0-16
   148  	MOVL	pid+0(FP), DI	// arg 1 - pid
   149  	MOVL	tid+4(FP), SI	// arg 2 - tid
   150  	MOVQ	sig+8(FP), DX	// arg 3 - signum
   151  	MOVL	$497, AX	// lwp_kill
   152  	SYSCALL
   153  	RET
   154  
   155  TEXT runtime·raiseproc(SB),NOSPLIT,$0
   156  	MOVL	$20, AX		// getpid
   157  	SYSCALL
   158  	MOVQ	AX, DI		// arg 1 - pid
   159  	MOVL	sig+0(FP), SI	// arg 2 - signum
   160  	MOVL	$37, AX		// kill
   161  	SYSCALL
   162  	RET
   163  
   164  TEXT runtime·setitimer(SB), NOSPLIT, $-8
   165  	MOVL	mode+0(FP), DI
   166  	MOVQ	new+8(FP), SI
   167  	MOVQ	old+16(FP), DX
   168  	MOVL	$83, AX
   169  	SYSCALL
   170  	RET
   171  
   172  // func walltime() (sec int64, nsec int32)
   173  TEXT runtime·walltime(SB), NOSPLIT, $32
   174  	MOVL	$232, AX // clock_gettime
   175  	MOVQ	$0, DI  	// CLOCK_REALTIME
   176  	LEAQ	8(SP), SI
   177  	SYSCALL
   178  	MOVQ	8(SP), AX	// sec
   179  	MOVQ	16(SP), DX	// nsec
   180  
   181  	// sec is in AX, nsec in DX
   182  	MOVQ	AX, sec+0(FP)
   183  	MOVL	DX, nsec+8(FP)
   184  	RET
   185  
   186  TEXT runtime·nanotime1(SB), NOSPLIT, $32
   187  	MOVL	$232, AX
   188  	MOVQ	$4, DI  	// CLOCK_MONOTONIC
   189  	LEAQ	8(SP), SI
   190  	SYSCALL
   191  	MOVQ	8(SP), AX	// sec
   192  	MOVQ	16(SP), DX	// nsec
   193  
   194  	// sec is in AX, nsec in DX
   195  	// return nsec in AX
   196  	IMULQ	$1000000000, AX
   197  	ADDQ	DX, AX
   198  	MOVQ	AX, ret+0(FP)
   199  	RET
   200  
   201  TEXT runtime·sigaction(SB),NOSPLIT,$-8
   202  	MOVL	sig+0(FP), DI		// arg 1 sig
   203  	MOVQ	new+8(FP), SI		// arg 2 act
   204  	MOVQ	old+16(FP), DX		// arg 3 oact
   205  	MOVL	$342, AX
   206  	SYSCALL
   207  	JCC	2(PC)
   208  	MOVL	$0xf1, 0xf1  // crash
   209  	RET
   210  
   211  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   212  	MOVQ	fn+0(FP),    AX
   213  	MOVL	sig+8(FP),   DI
   214  	MOVQ	info+16(FP), SI
   215  	MOVQ	ctx+24(FP),  DX
   216  	PUSHQ	BP
   217  	MOVQ	SP, BP
   218  	ANDQ	$~15, SP     // alignment for x86_64 ABI
   219  	CALL	AX
   220  	MOVQ	BP, SP
   221  	POPQ	BP
   222  	RET
   223  
   224  // Called using C ABI.
   225  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$0
   226  	// Transition from C ABI to Go ABI.
   227  	PUSH_REGS_HOST_TO_ABI0()
   228  
   229  	// Set up ABIInternal environment: g in R14, cleared X15.
   230  	get_tls(R12)
   231  	MOVQ	g(R12), R14
   232  	PXOR	X15, X15
   233  
   234  	// Reserve space for spill slots.
   235  	NOP	SP		// disable vet stack checking
   236  	ADJSP   $24
   237  
   238  	// Call into the Go signal handler
   239  	MOVQ	DI, AX	// sig
   240  	MOVQ	SI, BX	// info
   241  	MOVQ	DX, CX	// ctx
   242  	CALL	·sigtrampgo<ABIInternal>(SB)
   243  
   244  	ADJSP	$-24
   245  
   246  	POP_REGS_HOST_TO_ABI0()
   247  	RET
   248  
   249  TEXT runtime·mmap(SB),NOSPLIT,$0
   250  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   251  	MOVQ	n+8(FP), SI		// arg 2 - len
   252  	MOVL	prot+16(FP), DX		// arg 3 - prot
   253  	MOVL	flags+20(FP), R10		// arg 4 - flags
   254  	MOVL	fd+24(FP), R8		// arg 5 - fd
   255  	MOVL	off+28(FP), R9
   256  	SUBQ	$16, SP
   257  	MOVQ	R9, 8(SP)		// arg 7 - offset (passed on stack)
   258  	MOVQ	$0, R9			// arg 6 - pad
   259  	MOVL	$197, AX
   260  	SYSCALL
   261  	JCC	ok
   262  	ADDQ	$16, SP
   263  	MOVQ	$0, p+32(FP)
   264  	MOVQ	AX, err+40(FP)
   265  	RET
   266  ok:
   267  	ADDQ	$16, SP
   268  	MOVQ	AX, p+32(FP)
   269  	MOVQ	$0, err+40(FP)
   270  	RET
   271  
   272  TEXT runtime·munmap(SB),NOSPLIT,$0
   273  	MOVQ	addr+0(FP), DI		// arg 1 addr
   274  	MOVQ	n+8(FP), SI		// arg 2 len
   275  	MOVL	$73, AX
   276  	SYSCALL
   277  	JCC	2(PC)
   278  	MOVL	$0xf1, 0xf1  // crash
   279  	RET
   280  
   281  TEXT runtime·madvise(SB),NOSPLIT,$0
   282  	MOVQ	addr+0(FP), DI
   283  	MOVQ	n+8(FP), SI
   284  	MOVL	flags+16(FP), DX
   285  	MOVQ	$75, AX	// madvise
   286  	SYSCALL
   287  	JCC	2(PC)
   288  	MOVL	$-1, AX
   289  	MOVL	AX, ret+24(FP)
   290  	RET
   291  
   292  TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   293  	MOVQ	new+0(FP), DI
   294  	MOVQ	old+8(FP), SI
   295  	MOVQ	$53, AX
   296  	SYSCALL
   297  	JCC	2(PC)
   298  	MOVL	$0xf1, 0xf1  // crash
   299  	RET
   300  
   301  TEXT runtime·usleep(SB),NOSPLIT,$16
   302  	MOVL	$0, DX
   303  	MOVL	usec+0(FP), AX
   304  	MOVL	$1000000, CX
   305  	DIVL	CX
   306  	MOVQ	AX, 0(SP)		// tv_sec
   307  	MOVL	$1000, AX
   308  	MULL	DX
   309  	MOVQ	AX, 8(SP)		// tv_nsec
   310  
   311  	MOVQ	SP, DI			// arg 1 - rqtp
   312  	MOVQ	$0, SI			// arg 2 - rmtp
   313  	MOVL	$240, AX		// sys_nanosleep
   314  	SYSCALL
   315  	RET
   316  
   317  // set tls base to DI
   318  TEXT runtime·settls(SB),NOSPLIT,$16
   319  	ADDQ	$8, DI	// adjust for ELF: wants to use -8(FS) for g
   320  	MOVQ	DI, 0(SP)
   321  	MOVQ	$16, 8(SP)
   322  	MOVQ	$0, DI			// arg 1 - which
   323  	MOVQ	SP, SI			// arg 2 - tls_info
   324  	MOVQ	$16, DX			// arg 3 - infosize
   325  	MOVQ	$472, AX		// set_tls_area
   326  	SYSCALL
   327  	JCC	2(PC)
   328  	MOVL	$0xf1, 0xf1  // crash
   329  	RET
   330  
   331  TEXT runtime·sysctl(SB),NOSPLIT,$0
   332  	MOVQ	mib+0(FP), DI		// arg 1 - name
   333  	MOVL	miblen+8(FP), SI		// arg 2 - namelen
   334  	MOVQ	out+16(FP), DX		// arg 3 - oldp
   335  	MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   336  	MOVQ	dst+32(FP), R8		// arg 5 - newp
   337  	MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   338  	MOVQ	$202, AX		// sys___sysctl
   339  	SYSCALL
   340  	JCC 4(PC)
   341  	NEGQ	AX
   342  	MOVL	AX, ret+48(FP)
   343  	RET
   344  	MOVL	$0, AX
   345  	MOVL	AX, ret+48(FP)
   346  	RET
   347  
   348  TEXT runtime·osyield(SB),NOSPLIT,$-4
   349  	MOVL	$331, AX		// sys_sched_yield
   350  	SYSCALL
   351  	RET
   352  
   353  TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   354  	MOVL	how+0(FP), DI		// arg 1 - how
   355  	MOVQ	new+8(FP), SI		// arg 2 - set
   356  	MOVQ	old+16(FP), DX		// arg 3 - oset
   357  	MOVL	$340, AX		// sys_sigprocmask
   358  	SYSCALL
   359  	JAE	2(PC)
   360  	MOVL	$0xf1, 0xf1  // crash
   361  	RET
   362  
   363  // int32 runtime·kqueue(void);
   364  TEXT runtime·kqueue(SB),NOSPLIT,$0
   365  	MOVQ	$0, DI
   366  	MOVQ	$0, SI
   367  	MOVQ	$0, DX
   368  	MOVL	$362, AX
   369  	SYSCALL
   370  	JCC	2(PC)
   371  	NEGQ	AX
   372  	MOVL	AX, ret+0(FP)
   373  	RET
   374  
   375  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   376  TEXT runtime·kevent(SB),NOSPLIT,$0
   377  	MOVL	kq+0(FP), DI
   378  	MOVQ	ch+8(FP), SI
   379  	MOVL	nch+16(FP), DX
   380  	MOVQ	ev+24(FP), R10
   381  	MOVL	nev+32(FP), R8
   382  	MOVQ	ts+40(FP), R9
   383  	MOVL	$363, AX
   384  	SYSCALL
   385  	JCC	2(PC)
   386  	NEGQ	AX
   387  	MOVL	AX, ret+48(FP)
   388  	RET
   389  
   390  // void runtime·closeonexec(int32 fd);
   391  TEXT runtime·closeonexec(SB),NOSPLIT,$0
   392  	MOVL	fd+0(FP), DI	// fd
   393  	MOVQ	$2, SI		// F_SETFD
   394  	MOVQ	$1, DX		// FD_CLOEXEC
   395  	MOVL	$92, AX		// fcntl
   396  	SYSCALL
   397  	RET
   398  

View as plain text