github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/src/runtime/sys_netbsd_amd64.s (about)

     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, NetBSD
     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  // int32 lwp_create(void *context, uintptr flags, void *lwpid)
    14  TEXT runtime·lwp_create(SB),NOSPLIT,$0
    15  	MOVQ	ctxt+0(FP), DI
    16  	MOVQ	flags+8(FP), SI
    17  	MOVQ	lwpid+16(FP), DX
    18  	MOVL	$309, AX		// sys__lwp_create
    19  	SYSCALL
    20  	JCC	2(PC)
    21  	NEGQ	AX
    22  	MOVL	AX, ret+24(FP)
    23  	RET
    24  
    25  TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
    26  	
    27  	// Set FS to point at m->tls.
    28  	LEAQ	m_tls(R8), DI
    29  	CALL	runtime·settls(SB)
    30  
    31  	// Set up new stack.
    32  	get_tls(CX)
    33  	MOVQ	R8, g_m(R9)
    34  	MOVQ	R9, g(CX)
    35  	CALL	runtime·stackcheck(SB)
    36  
    37  	// Call fn
    38  	CALL	R12
    39  
    40  	// It shouldn't return. If it does, exit.
    41  	MOVL	$310, AX		// sys__lwp_exit
    42  	SYSCALL
    43  	JMP	-3(PC)			// keep exiting
    44  
    45  TEXT runtime·osyield(SB),NOSPLIT,$0
    46  	MOVL	$350, AX		// sys_sched_yield
    47  	SYSCALL
    48  	RET
    49  
    50  TEXT runtime·lwp_park(SB),NOSPLIT,$0
    51  	MOVL	clockid+0(FP), DI		// arg 1 - clockid
    52  	MOVL	flags+4(FP), SI			// arg 2 - flags
    53  	MOVQ	ts+8(FP), DX			// arg 3 - ts
    54  	MOVL	unpark+16(FP), R10		// arg 4 - unpark
    55  	MOVQ	hint+24(FP), R8			// arg 5 - hint
    56  	MOVQ	unparkhint+32(FP), R9		// arg 6 - unparkhint
    57  	MOVL	$478, AX			// sys__lwp_park
    58  	SYSCALL
    59  	MOVL	AX, ret+40(FP)
    60  	RET
    61  
    62  TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
    63  	MOVL	lwp+0(FP), DI		// arg 1 - lwp
    64  	MOVQ	hint+8(FP), SI		// arg 2 - hint
    65  	MOVL	$321, AX		// sys__lwp_unpark
    66  	SYSCALL
    67  	MOVL	AX, ret+16(FP)
    68  	RET
    69  
    70  TEXT runtime·lwp_self(SB),NOSPLIT,$0
    71  	MOVL	$311, AX		// sys__lwp_self
    72  	SYSCALL
    73  	MOVL	AX, ret+0(FP)
    74  	RET
    75  
    76  // Exit the entire program (like C exit)
    77  TEXT runtime·exit(SB),NOSPLIT,$-8
    78  	MOVL	code+0(FP), DI		// arg 1 - exit status
    79  	MOVL	$1, AX			// sys_exit
    80  	SYSCALL
    81  	MOVL	$0xf1, 0xf1		// crash
    82  	RET
    83  
    84  // func exitThread(wait *uint32)
    85  TEXT runtime·exitThread(SB),NOSPLIT,$0-8
    86  	MOVQ	wait+0(FP), AX
    87  	// We're done using the stack.
    88  	MOVL	$0, (AX)
    89  	MOVL	$310, AX		// sys__lwp_exit
    90  	SYSCALL
    91  	MOVL	$0xf1, 0xf1		// crash
    92  	JMP	0(PC)
    93  
    94  TEXT runtime·open(SB),NOSPLIT,$-8
    95  	MOVQ	name+0(FP), DI		// arg 1 pathname
    96  	MOVL	mode+8(FP), SI		// arg 2 flags
    97  	MOVL	perm+12(FP), DX		// arg 3 mode
    98  	MOVL	$5, AX
    99  	SYSCALL
   100  	JCC	2(PC)
   101  	MOVL	$-1, AX
   102  	MOVL	AX, ret+16(FP)
   103  	RET
   104  
   105  TEXT runtime·closefd(SB),NOSPLIT,$-8
   106  	MOVL	fd+0(FP), DI		// arg 1 fd
   107  	MOVL	$6, AX
   108  	SYSCALL
   109  	JCC	2(PC)
   110  	MOVL	$-1, AX
   111  	MOVL	AX, ret+8(FP)
   112  	RET
   113  
   114  TEXT runtime·read(SB),NOSPLIT,$-8
   115  	MOVL	fd+0(FP), DI		// arg 1 fd
   116  	MOVQ	p+8(FP), SI		// arg 2 buf
   117  	MOVL	n+16(FP), DX		// arg 3 count
   118  	MOVL	$3, AX
   119  	SYSCALL
   120  	JCC	2(PC)
   121  	MOVL	$-1, AX
   122  	MOVL	AX, ret+24(FP)
   123  	RET
   124  
   125  TEXT runtime·write(SB),NOSPLIT,$-8
   126  	MOVQ	fd+0(FP), DI		// arg 1 - fd
   127  	MOVQ	p+8(FP), SI		// arg 2 - buf
   128  	MOVL	n+16(FP), DX		// arg 3 - nbyte
   129  	MOVL	$4, AX			// sys_write
   130  	SYSCALL
   131  	JCC	2(PC)
   132  	MOVL	$-1, AX
   133  	MOVL	AX, ret+24(FP)
   134  	RET
   135  
   136  TEXT runtime·usleep(SB),NOSPLIT,$16
   137  	MOVL	$0, DX
   138  	MOVL	usec+0(FP), AX
   139  	MOVL	$1000000, CX
   140  	DIVL	CX
   141  	MOVQ	AX, 0(SP)		// tv_sec
   142  	MOVL	$1000, AX
   143  	MULL	DX
   144  	MOVQ	AX, 8(SP)		// tv_nsec
   145  
   146  	MOVQ	SP, DI			// arg 1 - rqtp
   147  	MOVQ	$0, SI			// arg 2 - rmtp
   148  	MOVL	$430, AX		// sys_nanosleep
   149  	SYSCALL
   150  	RET
   151  
   152  TEXT runtime·raise(SB),NOSPLIT,$16
   153  	MOVL	$311, AX		// sys__lwp_self
   154  	SYSCALL
   155  	MOVQ	AX, DI			// arg 1 - target
   156  	MOVL	sig+0(FP), SI		// arg 2 - signo
   157  	MOVL	$318, AX		// sys__lwp_kill
   158  	SYSCALL
   159  	RET
   160  
   161  TEXT runtime·raiseproc(SB),NOSPLIT,$16
   162  	MOVL	$20, AX			// sys_getpid
   163  	SYSCALL
   164  	MOVQ	AX, DI			// arg 1 - pid
   165  	MOVL	sig+0(FP), SI		// arg 2 - signo
   166  	MOVL	$37, AX			// sys_kill
   167  	SYSCALL
   168  	RET
   169  
   170  TEXT runtime·setitimer(SB),NOSPLIT,$-8
   171  	MOVL	mode+0(FP), DI		// arg 1 - which
   172  	MOVQ	new+8(FP), SI		// arg 2 - itv
   173  	MOVQ	old+16(FP), DX		// arg 3 - oitv
   174  	MOVL	$425, AX		// sys_setitimer
   175  	SYSCALL
   176  	RET
   177  
   178  // func walltime() (sec int64, nsec int32)
   179  TEXT runtime·walltime(SB), NOSPLIT, $32
   180  	MOVQ	$0, DI			// arg 1 - clock_id
   181  	LEAQ	8(SP), SI		// arg 2 - tp
   182  	MOVL	$427, AX		// sys_clock_gettime
   183  	SYSCALL
   184  	MOVQ	8(SP), AX		// sec
   185  	MOVL	16(SP), DX		// nsec
   186  
   187  	// sec is in AX, nsec in DX
   188  	MOVQ	AX, sec+0(FP)
   189  	MOVL	DX, nsec+8(FP)
   190  	RET
   191  
   192  TEXT runtime·nanotime(SB),NOSPLIT,$32
   193  	MOVQ	$3, DI			// arg 1 - clock_id CLOCK_MONOTONIC
   194  	LEAQ	8(SP), SI		// arg 2 - tp
   195  	MOVL	$427, AX		// sys_clock_gettime
   196  	SYSCALL
   197  	MOVQ	8(SP), AX		// sec
   198  	MOVL	16(SP), DX		// nsec
   199  
   200  	// sec is in AX, nsec in DX
   201  	// return nsec in AX
   202  	IMULQ	$1000000000, AX
   203  	ADDQ	DX, AX
   204  	MOVQ	AX, ret+0(FP)
   205  	RET
   206  
   207  TEXT runtime·getcontext(SB),NOSPLIT,$-8
   208  	MOVQ	ctxt+0(FP), DI		// arg 1 - context
   209  	MOVL	$307, AX		// sys_getcontext
   210  	SYSCALL
   211  	JCC	2(PC)
   212  	MOVL	$0xf1, 0xf1		// crash
   213  	RET
   214  
   215  TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   216  	MOVL	how+0(FP), DI		// arg 1 - how
   217  	MOVQ	new+8(FP), SI		// arg 2 - set
   218  	MOVQ	old+16(FP), DX		// arg 3 - oset
   219  	MOVL	$293, AX		// sys_sigprocmask
   220  	SYSCALL
   221  	JCC	2(PC)
   222  	MOVL	$0xf1, 0xf1		// crash
   223  	RET
   224  
   225  TEXT runtime·sigreturn_tramp(SB),NOSPLIT,$-8
   226  	MOVQ	R15, DI			// Load address of ucontext
   227  	MOVQ	$308, AX		// sys_setcontext
   228  	SYSCALL
   229  	MOVQ	$-1, DI			// Something failed...
   230  	MOVL	$1, AX			// sys_exit
   231  	SYSCALL
   232  
   233  TEXT runtime·sigaction(SB),NOSPLIT,$-8
   234  	MOVL	sig+0(FP), DI		// arg 1 - signum
   235  	MOVQ	new+8(FP), SI		// arg 2 - nsa
   236  	MOVQ	old+16(FP), DX		// arg 3 - osa
   237  					// arg 4 - tramp
   238  	LEAQ	runtime·sigreturn_tramp(SB), R10
   239  	MOVQ	$2, R8			// arg 5 - vers
   240  	MOVL	$340, AX		// sys___sigaction_sigtramp
   241  	SYSCALL
   242  	JCC	2(PC)
   243  	MOVL	$0xf1, 0xf1		// crash
   244  	RET
   245  
   246  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   247  	MOVQ	fn+0(FP),    AX
   248  	MOVL	sig+8(FP),   DI
   249  	MOVQ	info+16(FP), SI
   250  	MOVQ	ctx+24(FP),  DX
   251  	PUSHQ	BP
   252  	MOVQ	SP, BP
   253  	ANDQ	$~15, SP     // alignment for x86_64 ABI
   254  	CALL	AX
   255  	MOVQ	BP, SP
   256  	POPQ	BP
   257  	RET
   258  
   259  TEXT runtime·sigtramp(SB),NOSPLIT,$72
   260  	// Save callee-saved C registers, since the caller may be a C signal handler.
   261  	MOVQ	BX,  bx-8(SP)
   262  	MOVQ	BP,  bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
   263  	MOVQ	R12, r12-24(SP)
   264  	MOVQ	R13, r13-32(SP)
   265  	MOVQ	R14, r14-40(SP)
   266  	MOVQ	R15, r15-48(SP)
   267  	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   268  	// modify them.
   269  
   270  	MOVQ	DX, ctx-56(SP)
   271  	MOVQ	SI, info-64(SP)
   272  	MOVQ	DI, signum-72(SP)
   273  	CALL	runtime·sigtrampgo(SB)
   274  
   275  	MOVQ	r15-48(SP), R15
   276  	MOVQ	r14-40(SP), R14
   277  	MOVQ	r13-32(SP), R13
   278  	MOVQ	r12-24(SP), R12
   279  	MOVQ	bp-16(SP),  BP
   280  	MOVQ	bx-8(SP),   BX
   281  	RET
   282  
   283  TEXT runtime·mmap(SB),NOSPLIT,$0
   284  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   285  	MOVQ	n+8(FP), SI		// arg 2 - len
   286  	MOVL	prot+16(FP), DX		// arg 3 - prot
   287  	MOVL	flags+20(FP), R10		// arg 4 - flags
   288  	MOVL	fd+24(FP), R8		// arg 5 - fd
   289  	MOVL	off+28(FP), R9
   290  	SUBQ	$16, SP
   291  	MOVQ	R9, 8(SP)		// arg 7 - offset (passed on stack)
   292  	MOVQ	$0, R9			// arg 6 - pad
   293  	MOVL	$197, AX		// sys_mmap
   294  	SYSCALL
   295  	JCC	ok
   296  	ADDQ	$16, SP
   297  	MOVQ	$0, p+32(FP)
   298  	MOVQ	AX, err+40(FP)
   299  	RET
   300  ok:
   301  	ADDQ	$16, SP
   302  	MOVQ	AX, p+32(FP)
   303  	MOVQ	$0, err+40(FP)
   304  	RET
   305  
   306  TEXT runtime·munmap(SB),NOSPLIT,$0
   307  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   308  	MOVQ	n+8(FP), SI		// arg 2 - len
   309  	MOVL	$73, AX			// sys_munmap
   310  	SYSCALL
   311  	JCC	2(PC)
   312  	MOVL	$0xf1, 0xf1		// crash
   313  	RET
   314  
   315  
   316  TEXT runtime·madvise(SB),NOSPLIT,$0
   317  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   318  	MOVQ	n+8(FP), SI		// arg 2 - len
   319  	MOVL	flags+16(FP), DX	// arg 3 - behav
   320  	MOVQ	$75, AX			// sys_madvise
   321  	SYSCALL
   322  	// ignore failure - maybe pages are locked
   323  	RET
   324  
   325  TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   326  	MOVQ	new+0(FP), DI		// arg 1 - nss
   327  	MOVQ	old+8(FP), SI		// arg 2 - oss
   328  	MOVQ	$281, AX		// sys___sigaltstack14
   329  	SYSCALL
   330  	JCC	2(PC)
   331  	MOVL	$0xf1, 0xf1		// crash
   332  	RET
   333  
   334  // set tls base to DI
   335  TEXT runtime·settls(SB),NOSPLIT,$8
   336  	// adjust for ELF: wants to use -8(FS) for g
   337  	ADDQ	$8, DI			// arg 1 - ptr
   338  	MOVQ	$317, AX		// sys__lwp_setprivate
   339  	SYSCALL
   340  	JCC	2(PC)
   341  	MOVL	$0xf1, 0xf1		// crash
   342  	RET
   343  
   344  TEXT runtime·sysctl(SB),NOSPLIT,$0
   345  	MOVQ	mib+0(FP), DI		// arg 1 - name
   346  	MOVL	miblen+8(FP), SI		// arg 2 - namelen
   347  	MOVQ	out+16(FP), DX		// arg 3 - oldp
   348  	MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   349  	MOVQ	dst+32(FP), R8		// arg 5 - newp
   350  	MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   351  	MOVQ	$202, AX		// sys___sysctl
   352  	SYSCALL
   353  	JCC 4(PC)
   354  	NEGQ	AX
   355  	MOVL	AX, ret+48(FP)
   356  	RET
   357  	MOVL	$0, AX
   358  	MOVL	AX, ret+48(FP)
   359  	RET
   360  
   361  // int32 runtime·kqueue(void)
   362  TEXT runtime·kqueue(SB),NOSPLIT,$0
   363  	MOVQ	$0, DI
   364  	MOVL	$344, AX
   365  	SYSCALL
   366  	JCC	2(PC)
   367  	NEGQ	AX
   368  	MOVL	AX, ret+0(FP)
   369  	RET
   370  
   371  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   372  TEXT runtime·kevent(SB),NOSPLIT,$0
   373  	MOVL	kq+0(FP), DI
   374  	MOVQ	ch+8(FP), SI
   375  	MOVL	nch+16(FP), DX
   376  	MOVQ	ev+24(FP), R10
   377  	MOVL	nev+32(FP), R8
   378  	MOVQ	ts+40(FP), R9
   379  	MOVL	$435, AX
   380  	SYSCALL
   381  	JCC	2(PC)
   382  	NEGQ	AX
   383  	MOVL	AX, ret+48(FP)
   384  	RET
   385  
   386  // void runtime·closeonexec(int32 fd)
   387  TEXT runtime·closeonexec(SB),NOSPLIT,$0
   388  	MOVL	fd+0(FP), DI	// fd
   389  	MOVQ	$2, SI		// F_SETFD
   390  	MOVQ	$1, DX		// FD_CLOEXEC
   391  	MOVL	$92, AX		// fcntl
   392  	SYSCALL
   393  	RET