Text file src/runtime/sys_netbsd_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, 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  #include "cgo/abi_amd64.h"
    13  
    14  #define CLOCK_REALTIME		0
    15  #define CLOCK_MONOTONIC		3
    16  #define FD_CLOEXEC		1
    17  #define F_SETFD			2
    18  
    19  #define SYS_exit			1
    20  #define SYS_read			3
    21  #define SYS_write			4
    22  #define SYS_open			5
    23  #define SYS_close			6
    24  #define SYS_getpid			20
    25  #define SYS_kill			37
    26  #define SYS_munmap			73
    27  #define SYS_madvise			75
    28  #define SYS_fcntl			92
    29  #define SYS_mmap			197
    30  #define SYS___sysctl			202
    31  #define SYS___sigaltstack14		281
    32  #define SYS___sigprocmask14		293
    33  #define SYS_getcontext			307
    34  #define SYS_setcontext			308
    35  #define SYS__lwp_create			309
    36  #define SYS__lwp_exit			310
    37  #define SYS__lwp_self			311
    38  #define SYS__lwp_setprivate		317
    39  #define SYS__lwp_kill			318
    40  #define SYS__lwp_unpark			321
    41  #define SYS___sigaction_sigtramp	340
    42  #define SYS_kqueue			344
    43  #define SYS_sched_yield			350
    44  #define SYS___setitimer50		425
    45  #define SYS___clock_gettime50		427
    46  #define SYS___nanosleep50		430
    47  #define SYS___kevent50			435
    48  #define SYS____lwp_park60		478
    49  
    50  // int32 lwp_create(void *context, uintptr flags, void *lwpid)
    51  TEXT runtime·lwp_create(SB),NOSPLIT,$0
    52  	MOVQ	ctxt+0(FP), DI
    53  	MOVQ	flags+8(FP), SI
    54  	MOVQ	lwpid+16(FP), DX
    55  	MOVL	$SYS__lwp_create, AX
    56  	SYSCALL
    57  	JCC	2(PC)
    58  	NEGQ	AX
    59  	MOVL	AX, ret+24(FP)
    60  	RET
    61  
    62  TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
    63  
    64  	// Set FS to point at m->tls.
    65  	LEAQ	m_tls(R8), DI
    66  	CALL	runtime·settls(SB)
    67  
    68  	// Set up new stack.
    69  	get_tls(CX)
    70  	MOVQ	R8, g_m(R9)
    71  	MOVQ	R9, g(CX)
    72  	CALL	runtime·stackcheck(SB)
    73  
    74  	// Call fn. This is an ABI0 PC.
    75  	CALL	R12
    76  
    77  	// It shouldn't return. If it does, exit.
    78  	MOVL	$SYS__lwp_exit, AX
    79  	SYSCALL
    80  	JMP	-3(PC)			// keep exiting
    81  
    82  TEXT ·netbsdMstart(SB),NOSPLIT|TOPFRAME,$0
    83  	CALL	·netbsdMstart0(SB)
    84  	RET // not reached
    85  
    86  TEXT runtime·osyield(SB),NOSPLIT,$0
    87  	MOVL	$SYS_sched_yield, AX
    88  	SYSCALL
    89  	RET
    90  
    91  TEXT runtime·lwp_park(SB),NOSPLIT,$0
    92  	MOVL	clockid+0(FP), DI		// arg 1 - clockid
    93  	MOVL	flags+4(FP), SI			// arg 2 - flags
    94  	MOVQ	ts+8(FP), DX			// arg 3 - ts
    95  	MOVL	unpark+16(FP), R10		// arg 4 - unpark
    96  	MOVQ	hint+24(FP), R8			// arg 5 - hint
    97  	MOVQ	unparkhint+32(FP), R9		// arg 6 - unparkhint
    98  	MOVL	$SYS____lwp_park60, AX
    99  	SYSCALL
   100  	MOVL	AX, ret+40(FP)
   101  	RET
   102  
   103  TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
   104  	MOVL	lwp+0(FP), DI		// arg 1 - lwp
   105  	MOVQ	hint+8(FP), SI		// arg 2 - hint
   106  	MOVL	$SYS__lwp_unpark, AX
   107  	SYSCALL
   108  	MOVL	AX, ret+16(FP)
   109  	RET
   110  
   111  TEXT runtime·lwp_self(SB),NOSPLIT,$0
   112  	MOVL	$SYS__lwp_self, AX
   113  	SYSCALL
   114  	MOVL	AX, ret+0(FP)
   115  	RET
   116  
   117  // Exit the entire program (like C exit)
   118  TEXT runtime·exit(SB),NOSPLIT,$-8
   119  	MOVL	code+0(FP), DI		// arg 1 - exit status
   120  	MOVL	$SYS_exit, AX
   121  	SYSCALL
   122  	MOVL	$0xf1, 0xf1		// crash
   123  	RET
   124  
   125  // func exitThread(wait *uint32)
   126  TEXT runtime·exitThread(SB),NOSPLIT,$0-8
   127  	MOVQ	wait+0(FP), AX
   128  	// We're done using the stack.
   129  	MOVL	$0, (AX)
   130  	MOVL	$SYS__lwp_exit, AX
   131  	SYSCALL
   132  	MOVL	$0xf1, 0xf1		// crash
   133  	JMP	0(PC)
   134  
   135  TEXT runtime·open(SB),NOSPLIT,$-8
   136  	MOVQ	name+0(FP), DI		// arg 1 pathname
   137  	MOVL	mode+8(FP), SI		// arg 2 flags
   138  	MOVL	perm+12(FP), DX		// arg 3 mode
   139  	MOVL	$SYS_open, AX
   140  	SYSCALL
   141  	JCC	2(PC)
   142  	MOVL	$-1, AX
   143  	MOVL	AX, ret+16(FP)
   144  	RET
   145  
   146  TEXT runtime·closefd(SB),NOSPLIT,$-8
   147  	MOVL	fd+0(FP), DI		// arg 1 fd
   148  	MOVL	$SYS_close, AX
   149  	SYSCALL
   150  	JCC	2(PC)
   151  	MOVL	$-1, AX
   152  	MOVL	AX, ret+8(FP)
   153  	RET
   154  
   155  TEXT runtime·read(SB),NOSPLIT,$-8
   156  	MOVL	fd+0(FP), DI		// arg 1 fd
   157  	MOVQ	p+8(FP), SI		// arg 2 buf
   158  	MOVL	n+16(FP), DX		// arg 3 count
   159  	MOVL	$SYS_read, AX
   160  	SYSCALL
   161  	JCC	2(PC)
   162  	NEGQ	AX			// caller expects negative errno
   163  	MOVL	AX, ret+24(FP)
   164  	RET
   165  
   166  // func pipe() (r, w int32, errno int32)
   167  TEXT runtime·pipe(SB),NOSPLIT,$0-12
   168  	MOVL	$42, AX
   169  	SYSCALL
   170  	JCC	pipeok
   171  	MOVL	$-1, r+0(FP)
   172  	MOVL	$-1, w+4(FP)
   173  	MOVL	AX, errno+8(FP)
   174  	RET
   175  pipeok:
   176  	MOVL	AX, r+0(FP)
   177  	MOVL	DX, w+4(FP)
   178  	MOVL	$0, errno+8(FP)
   179  	RET
   180  
   181  // func pipe2(flags int32) (r, w int32, errno int32)
   182  TEXT runtime·pipe2(SB),NOSPLIT,$0-20
   183  	LEAQ	r+8(FP), DI
   184  	MOVL	flags+0(FP), SI
   185  	MOVL	$453, AX
   186  	SYSCALL
   187  	MOVL	AX, errno+16(FP)
   188  	RET
   189  
   190  TEXT runtime·write1(SB),NOSPLIT,$-8
   191  	MOVQ	fd+0(FP), DI		// arg 1 - fd
   192  	MOVQ	p+8(FP), SI		// arg 2 - buf
   193  	MOVL	n+16(FP), DX		// arg 3 - nbyte
   194  	MOVL	$SYS_write, AX
   195  	SYSCALL
   196  	JCC	2(PC)
   197  	NEGQ	AX			// caller expects negative errno
   198  	MOVL	AX, ret+24(FP)
   199  	RET
   200  
   201  TEXT runtime·usleep(SB),NOSPLIT,$16
   202  	MOVL	$0, DX
   203  	MOVL	usec+0(FP), AX
   204  	MOVL	$1000000, CX
   205  	DIVL	CX
   206  	MOVQ	AX, 0(SP)		// tv_sec
   207  	MOVL	$1000, AX
   208  	MULL	DX
   209  	MOVQ	AX, 8(SP)		// tv_nsec
   210  
   211  	MOVQ	SP, DI			// arg 1 - rqtp
   212  	MOVQ	$0, SI			// arg 2 - rmtp
   213  	MOVL	$SYS___nanosleep50, AX
   214  	SYSCALL
   215  	RET
   216  
   217  TEXT runtime·lwp_kill(SB),NOSPLIT,$0-16
   218  	MOVL	tid+0(FP), DI		// arg 1 - target
   219  	MOVQ	sig+8(FP), SI		// arg 2 - signo
   220  	MOVL	$SYS__lwp_kill, AX
   221  	SYSCALL
   222  	RET
   223  
   224  TEXT runtime·raiseproc(SB),NOSPLIT,$16
   225  	MOVL	$SYS_getpid, AX
   226  	SYSCALL
   227  	MOVQ	AX, DI			// arg 1 - pid
   228  	MOVL	sig+0(FP), SI		// arg 2 - signo
   229  	MOVL	$SYS_kill, AX
   230  	SYSCALL
   231  	RET
   232  
   233  TEXT runtime·setitimer(SB),NOSPLIT,$-8
   234  	MOVL	mode+0(FP), DI		// arg 1 - which
   235  	MOVQ	new+8(FP), SI		// arg 2 - itv
   236  	MOVQ	old+16(FP), DX		// arg 3 - oitv
   237  	MOVL	$SYS___setitimer50, AX
   238  	SYSCALL
   239  	RET
   240  
   241  // func walltime() (sec int64, nsec int32)
   242  TEXT runtime·walltime(SB), NOSPLIT, $32
   243  	MOVQ	$CLOCK_REALTIME, DI	// arg 1 - clock_id
   244  	LEAQ	8(SP), SI		// arg 2 - tp
   245  	MOVL	$SYS___clock_gettime50, AX
   246  	SYSCALL
   247  	MOVQ	8(SP), AX		// sec
   248  	MOVQ	16(SP), DX		// nsec
   249  
   250  	// sec is in AX, nsec in DX
   251  	MOVQ	AX, sec+0(FP)
   252  	MOVL	DX, nsec+8(FP)
   253  	RET
   254  
   255  TEXT runtime·nanotime1(SB),NOSPLIT,$32
   256  	MOVQ	$CLOCK_MONOTONIC, DI	// arg 1 - clock_id
   257  	LEAQ	8(SP), SI		// arg 2 - tp
   258  	MOVL	$SYS___clock_gettime50, AX
   259  	SYSCALL
   260  	MOVQ	8(SP), AX		// sec
   261  	MOVQ	16(SP), DX		// nsec
   262  
   263  	// sec is in AX, nsec in DX
   264  	// return nsec in AX
   265  	IMULQ	$1000000000, AX
   266  	ADDQ	DX, AX
   267  	MOVQ	AX, ret+0(FP)
   268  	RET
   269  
   270  TEXT runtime·getcontext(SB),NOSPLIT,$-8
   271  	MOVQ	ctxt+0(FP), DI		// arg 1 - context
   272  	MOVL	$SYS_getcontext, AX
   273  	SYSCALL
   274  	JCC	2(PC)
   275  	MOVL	$0xf1, 0xf1		// crash
   276  	RET
   277  
   278  TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   279  	MOVL	how+0(FP), DI		// arg 1 - how
   280  	MOVQ	new+8(FP), SI		// arg 2 - set
   281  	MOVQ	old+16(FP), DX		// arg 3 - oset
   282  	MOVL	$SYS___sigprocmask14, AX
   283  	SYSCALL
   284  	JCC	2(PC)
   285  	MOVL	$0xf1, 0xf1		// crash
   286  	RET
   287  
   288  TEXT sigreturn_tramp<>(SB),NOSPLIT,$-8
   289  	MOVQ	R15, DI			// Load address of ucontext
   290  	MOVQ	$SYS_setcontext, AX
   291  	SYSCALL
   292  	MOVQ	$-1, DI			// Something failed...
   293  	MOVL	$SYS_exit, AX
   294  	SYSCALL
   295  
   296  TEXT runtime·sigaction(SB),NOSPLIT,$-8
   297  	MOVL	sig+0(FP), DI		// arg 1 - signum
   298  	MOVQ	new+8(FP), SI		// arg 2 - nsa
   299  	MOVQ	old+16(FP), DX		// arg 3 - osa
   300  					// arg 4 - tramp
   301  	LEAQ	sigreturn_tramp<>(SB), R10
   302  	MOVQ	$2, R8			// arg 5 - vers
   303  	MOVL	$SYS___sigaction_sigtramp, AX
   304  	SYSCALL
   305  	JCC	2(PC)
   306  	MOVL	$0xf1, 0xf1		// crash
   307  	RET
   308  
   309  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   310  	MOVQ	fn+0(FP),    AX
   311  	MOVL	sig+8(FP),   DI
   312  	MOVQ	info+16(FP), SI
   313  	MOVQ	ctx+24(FP),  DX
   314  	PUSHQ	BP
   315  	MOVQ	SP, BP
   316  	ANDQ	$~15, SP     // alignment for x86_64 ABI
   317  	CALL	AX
   318  	MOVQ	BP, SP
   319  	POPQ	BP
   320  	RET
   321  
   322  // Called using C ABI.
   323  TEXT runtime·sigtramp(SB),NOSPLIT,$0
   324  	// Transition from C ABI to Go ABI.
   325  	PUSH_REGS_HOST_TO_ABI0()
   326  
   327  	// Call into the Go signal handler
   328  	NOP	SP		// disable vet stack checking
   329          ADJSP   $24
   330  	MOVQ	DI, 0(SP)	// sig
   331  	MOVQ	SI, 8(SP)	// info
   332  	MOVQ	DX, 16(SP)	// ctx
   333  	CALL	·sigtrampgo(SB)
   334  	ADJSP	$-24
   335  
   336          POP_REGS_HOST_TO_ABI0()
   337  	RET
   338  
   339  TEXT runtime·mmap(SB),NOSPLIT,$0
   340  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   341  	MOVQ	n+8(FP), SI		// arg 2 - len
   342  	MOVL	prot+16(FP), DX		// arg 3 - prot
   343  	MOVL	flags+20(FP), R10		// arg 4 - flags
   344  	MOVL	fd+24(FP), R8		// arg 5 - fd
   345  	MOVL	off+28(FP), R9
   346  	SUBQ	$16, SP
   347  	MOVQ	R9, 8(SP)		// arg 7 - offset (passed on stack)
   348  	MOVQ	$0, R9			// arg 6 - pad
   349  	MOVL	$SYS_mmap, AX
   350  	SYSCALL
   351  	JCC	ok
   352  	ADDQ	$16, SP
   353  	MOVQ	$0, p+32(FP)
   354  	MOVQ	AX, err+40(FP)
   355  	RET
   356  ok:
   357  	ADDQ	$16, SP
   358  	MOVQ	AX, p+32(FP)
   359  	MOVQ	$0, err+40(FP)
   360  	RET
   361  
   362  TEXT runtime·munmap(SB),NOSPLIT,$0
   363  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   364  	MOVQ	n+8(FP), SI		// arg 2 - len
   365  	MOVL	$SYS_munmap, AX
   366  	SYSCALL
   367  	JCC	2(PC)
   368  	MOVL	$0xf1, 0xf1		// crash
   369  	RET
   370  
   371  
   372  TEXT runtime·madvise(SB),NOSPLIT,$0
   373  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   374  	MOVQ	n+8(FP), SI		// arg 2 - len
   375  	MOVL	flags+16(FP), DX	// arg 3 - behav
   376  	MOVQ	$SYS_madvise, AX
   377  	SYSCALL
   378  	JCC	2(PC)
   379  	MOVL	$-1, AX
   380  	MOVL	AX, ret+24(FP)
   381  	RET
   382  
   383  TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   384  	MOVQ	new+0(FP), DI		// arg 1 - nss
   385  	MOVQ	old+8(FP), SI		// arg 2 - oss
   386  	MOVQ	$SYS___sigaltstack14, AX
   387  	SYSCALL
   388  	JCC	2(PC)
   389  	MOVL	$0xf1, 0xf1		// crash
   390  	RET
   391  
   392  // set tls base to DI
   393  TEXT runtime·settls(SB),NOSPLIT,$8
   394  	// adjust for ELF: wants to use -8(FS) for g
   395  	ADDQ	$8, DI			// arg 1 - ptr
   396  	MOVQ	$SYS__lwp_setprivate, AX
   397  	SYSCALL
   398  	JCC	2(PC)
   399  	MOVL	$0xf1, 0xf1		// crash
   400  	RET
   401  
   402  TEXT runtime·sysctl(SB),NOSPLIT,$0
   403  	MOVQ	mib+0(FP), DI		// arg 1 - name
   404  	MOVL	miblen+8(FP), SI		// arg 2 - namelen
   405  	MOVQ	out+16(FP), DX		// arg 3 - oldp
   406  	MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   407  	MOVQ	dst+32(FP), R8		// arg 5 - newp
   408  	MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   409  	MOVQ	$SYS___sysctl, AX
   410  	SYSCALL
   411  	JCC 4(PC)
   412  	NEGQ	AX
   413  	MOVL	AX, ret+48(FP)
   414  	RET
   415  	MOVL	$0, AX
   416  	MOVL	AX, ret+48(FP)
   417  	RET
   418  
   419  // int32 runtime·kqueue(void)
   420  TEXT runtime·kqueue(SB),NOSPLIT,$0
   421  	MOVQ	$0, DI
   422  	MOVL	$SYS_kqueue, AX
   423  	SYSCALL
   424  	JCC	2(PC)
   425  	NEGQ	AX
   426  	MOVL	AX, ret+0(FP)
   427  	RET
   428  
   429  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   430  TEXT runtime·kevent(SB),NOSPLIT,$0
   431  	MOVL	kq+0(FP), DI
   432  	MOVQ	ch+8(FP), SI
   433  	MOVL	nch+16(FP), DX
   434  	MOVQ	ev+24(FP), R10
   435  	MOVL	nev+32(FP), R8
   436  	MOVQ	ts+40(FP), R9
   437  	MOVL	$SYS___kevent50, AX
   438  	SYSCALL
   439  	JCC	2(PC)
   440  	NEGQ	AX
   441  	MOVL	AX, ret+48(FP)
   442  	RET
   443  
   444  // void runtime·closeonexec(int32 fd)
   445  TEXT runtime·closeonexec(SB),NOSPLIT,$0
   446  	MOVL	fd+0(FP), DI	// fd
   447  	MOVQ	$F_SETFD, SI
   448  	MOVQ	$FD_CLOEXEC, DX
   449  	MOVL	$SYS_fcntl, AX
   450  	SYSCALL
   451  	RET
   452  
   453  // func runtime·setNonblock(int32 fd)
   454  TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
   455  	MOVL    fd+0(FP), DI  // fd
   456  	MOVQ    $3, SI  // F_GETFL
   457  	MOVQ    $0, DX
   458  	MOVL	$92, AX // fcntl
   459  	SYSCALL
   460  	MOVL	fd+0(FP), DI // fd
   461  	MOVQ	$4, SI // F_SETFL
   462  	MOVQ	$4, DX // O_NONBLOCK
   463  	ORL	AX, DX
   464  	MOVL	$92, AX // fcntl
   465  	SYSCALL
   466  	RET
   467  

View as plain text