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 pipe2(flags int32) (r, w int32, errno int32)
   167  TEXT runtime·pipe2(SB),NOSPLIT,$0-20
   168  	LEAQ	r+8(FP), DI
   169  	MOVL	flags+0(FP), SI
   170  	MOVL	$453, AX
   171  	SYSCALL
   172  	MOVL	AX, errno+16(FP)
   173  	RET
   174  
   175  TEXT runtime·write1(SB),NOSPLIT,$-8
   176  	MOVQ	fd+0(FP), DI		// arg 1 - fd
   177  	MOVQ	p+8(FP), SI		// arg 2 - buf
   178  	MOVL	n+16(FP), DX		// arg 3 - nbyte
   179  	MOVL	$SYS_write, AX
   180  	SYSCALL
   181  	JCC	2(PC)
   182  	NEGQ	AX			// caller expects negative errno
   183  	MOVL	AX, ret+24(FP)
   184  	RET
   185  
   186  TEXT runtime·usleep(SB),NOSPLIT,$16
   187  	MOVL	$0, DX
   188  	MOVL	usec+0(FP), AX
   189  	MOVL	$1000000, CX
   190  	DIVL	CX
   191  	MOVQ	AX, 0(SP)		// tv_sec
   192  	MOVL	$1000, AX
   193  	MULL	DX
   194  	MOVQ	AX, 8(SP)		// tv_nsec
   195  
   196  	MOVQ	SP, DI			// arg 1 - rqtp
   197  	MOVQ	$0, SI			// arg 2 - rmtp
   198  	MOVL	$SYS___nanosleep50, AX
   199  	SYSCALL
   200  	RET
   201  
   202  TEXT runtime·lwp_kill(SB),NOSPLIT,$0-16
   203  	MOVL	tid+0(FP), DI		// arg 1 - target
   204  	MOVQ	sig+8(FP), SI		// arg 2 - signo
   205  	MOVL	$SYS__lwp_kill, AX
   206  	SYSCALL
   207  	RET
   208  
   209  TEXT runtime·raiseproc(SB),NOSPLIT,$16
   210  	MOVL	$SYS_getpid, AX
   211  	SYSCALL
   212  	MOVQ	AX, DI			// arg 1 - pid
   213  	MOVL	sig+0(FP), SI		// arg 2 - signo
   214  	MOVL	$SYS_kill, AX
   215  	SYSCALL
   216  	RET
   217  
   218  TEXT runtime·setitimer(SB),NOSPLIT,$-8
   219  	MOVL	mode+0(FP), DI		// arg 1 - which
   220  	MOVQ	new+8(FP), SI		// arg 2 - itv
   221  	MOVQ	old+16(FP), DX		// arg 3 - oitv
   222  	MOVL	$SYS___setitimer50, AX
   223  	SYSCALL
   224  	RET
   225  
   226  // func walltime() (sec int64, nsec int32)
   227  TEXT runtime·walltime(SB), NOSPLIT, $32
   228  	MOVQ	$CLOCK_REALTIME, DI	// arg 1 - clock_id
   229  	LEAQ	8(SP), SI		// arg 2 - tp
   230  	MOVL	$SYS___clock_gettime50, AX
   231  	SYSCALL
   232  	MOVQ	8(SP), AX		// sec
   233  	MOVQ	16(SP), DX		// nsec
   234  
   235  	// sec is in AX, nsec in DX
   236  	MOVQ	AX, sec+0(FP)
   237  	MOVL	DX, nsec+8(FP)
   238  	RET
   239  
   240  TEXT runtime·nanotime1(SB),NOSPLIT,$32
   241  	MOVQ	$CLOCK_MONOTONIC, DI	// arg 1 - clock_id
   242  	LEAQ	8(SP), SI		// arg 2 - tp
   243  	MOVL	$SYS___clock_gettime50, AX
   244  	SYSCALL
   245  	MOVQ	8(SP), AX		// sec
   246  	MOVQ	16(SP), DX		// nsec
   247  
   248  	// sec is in AX, nsec in DX
   249  	// return nsec in AX
   250  	IMULQ	$1000000000, AX
   251  	ADDQ	DX, AX
   252  	MOVQ	AX, ret+0(FP)
   253  	RET
   254  
   255  TEXT runtime·getcontext(SB),NOSPLIT,$-8
   256  	MOVQ	ctxt+0(FP), DI		// arg 1 - context
   257  	MOVL	$SYS_getcontext, AX
   258  	SYSCALL
   259  	JCC	2(PC)
   260  	MOVL	$0xf1, 0xf1		// crash
   261  	RET
   262  
   263  TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   264  	MOVL	how+0(FP), DI		// arg 1 - how
   265  	MOVQ	new+8(FP), SI		// arg 2 - set
   266  	MOVQ	old+16(FP), DX		// arg 3 - oset
   267  	MOVL	$SYS___sigprocmask14, AX
   268  	SYSCALL
   269  	JCC	2(PC)
   270  	MOVL	$0xf1, 0xf1		// crash
   271  	RET
   272  
   273  TEXT sigreturn_tramp<>(SB),NOSPLIT,$-8
   274  	MOVQ	R15, DI			// Load address of ucontext
   275  	MOVQ	$SYS_setcontext, AX
   276  	SYSCALL
   277  	MOVQ	$-1, DI			// Something failed...
   278  	MOVL	$SYS_exit, AX
   279  	SYSCALL
   280  
   281  TEXT runtime·sigaction(SB),NOSPLIT,$-8
   282  	MOVL	sig+0(FP), DI		// arg 1 - signum
   283  	MOVQ	new+8(FP), SI		// arg 2 - nsa
   284  	MOVQ	old+16(FP), DX		// arg 3 - osa
   285  					// arg 4 - tramp
   286  	LEAQ	sigreturn_tramp<>(SB), R10
   287  	MOVQ	$2, R8			// arg 5 - vers
   288  	MOVL	$SYS___sigaction_sigtramp, AX
   289  	SYSCALL
   290  	JCC	2(PC)
   291  	MOVL	$0xf1, 0xf1		// crash
   292  	RET
   293  
   294  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   295  	MOVQ	fn+0(FP),    AX
   296  	MOVL	sig+8(FP),   DI
   297  	MOVQ	info+16(FP), SI
   298  	MOVQ	ctx+24(FP),  DX
   299  	PUSHQ	BP
   300  	MOVQ	SP, BP
   301  	ANDQ	$~15, SP     // alignment for x86_64 ABI
   302  	CALL	AX
   303  	MOVQ	BP, SP
   304  	POPQ	BP
   305  	RET
   306  
   307  // Called using C ABI.
   308  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$0
   309  	// Transition from C ABI to Go ABI.
   310  	PUSH_REGS_HOST_TO_ABI0()
   311  
   312  	// Set up ABIInternal environment: g in R14, cleared X15.
   313  	get_tls(R12)
   314  	MOVQ	g(R12), R14
   315  	PXOR	X15, X15
   316  
   317  	// Reserve space for spill slots.
   318  	NOP	SP		// disable vet stack checking
   319  	ADJSP   $24
   320  
   321  	// Call into the Go signal handler
   322  	MOVQ	DI, AX	// sig
   323  	MOVQ	SI, BX	// info
   324  	MOVQ	DX, CX	// ctx
   325  	CALL	·sigtrampgo<ABIInternal>(SB)
   326  
   327  	ADJSP	$-24
   328  
   329          POP_REGS_HOST_TO_ABI0()
   330  	RET
   331  
   332  TEXT runtime·mmap(SB),NOSPLIT,$0
   333  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   334  	MOVQ	n+8(FP), SI		// arg 2 - len
   335  	MOVL	prot+16(FP), DX		// arg 3 - prot
   336  	MOVL	flags+20(FP), R10		// arg 4 - flags
   337  	MOVL	fd+24(FP), R8		// arg 5 - fd
   338  	MOVL	off+28(FP), R9
   339  	SUBQ	$16, SP
   340  	MOVQ	R9, 8(SP)		// arg 7 - offset (passed on stack)
   341  	MOVQ	$0, R9			// arg 6 - pad
   342  	MOVL	$SYS_mmap, AX
   343  	SYSCALL
   344  	JCC	ok
   345  	ADDQ	$16, SP
   346  	MOVQ	$0, p+32(FP)
   347  	MOVQ	AX, err+40(FP)
   348  	RET
   349  ok:
   350  	ADDQ	$16, SP
   351  	MOVQ	AX, p+32(FP)
   352  	MOVQ	$0, err+40(FP)
   353  	RET
   354  
   355  TEXT runtime·munmap(SB),NOSPLIT,$0
   356  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   357  	MOVQ	n+8(FP), SI		// arg 2 - len
   358  	MOVL	$SYS_munmap, AX
   359  	SYSCALL
   360  	JCC	2(PC)
   361  	MOVL	$0xf1, 0xf1		// crash
   362  	RET
   363  
   364  
   365  TEXT runtime·madvise(SB),NOSPLIT,$0
   366  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   367  	MOVQ	n+8(FP), SI		// arg 2 - len
   368  	MOVL	flags+16(FP), DX	// arg 3 - behav
   369  	MOVQ	$SYS_madvise, AX
   370  	SYSCALL
   371  	JCC	2(PC)
   372  	MOVL	$-1, AX
   373  	MOVL	AX, ret+24(FP)
   374  	RET
   375  
   376  TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   377  	MOVQ	new+0(FP), DI		// arg 1 - nss
   378  	MOVQ	old+8(FP), SI		// arg 2 - oss
   379  	MOVQ	$SYS___sigaltstack14, AX
   380  	SYSCALL
   381  	JCC	2(PC)
   382  	MOVL	$0xf1, 0xf1		// crash
   383  	RET
   384  
   385  // set tls base to DI
   386  TEXT runtime·settls(SB),NOSPLIT,$8
   387  	// adjust for ELF: wants to use -8(FS) for g
   388  	ADDQ	$8, DI			// arg 1 - ptr
   389  	MOVQ	$SYS__lwp_setprivate, AX
   390  	SYSCALL
   391  	JCC	2(PC)
   392  	MOVL	$0xf1, 0xf1		// crash
   393  	RET
   394  
   395  TEXT runtime·sysctl(SB),NOSPLIT,$0
   396  	MOVQ	mib+0(FP), DI		// arg 1 - name
   397  	MOVL	miblen+8(FP), SI		// arg 2 - namelen
   398  	MOVQ	out+16(FP), DX		// arg 3 - oldp
   399  	MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   400  	MOVQ	dst+32(FP), R8		// arg 5 - newp
   401  	MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   402  	MOVQ	$SYS___sysctl, AX
   403  	SYSCALL
   404  	JCC 4(PC)
   405  	NEGQ	AX
   406  	MOVL	AX, ret+48(FP)
   407  	RET
   408  	MOVL	$0, AX
   409  	MOVL	AX, ret+48(FP)
   410  	RET
   411  
   412  // int32 runtime·kqueue(void)
   413  TEXT runtime·kqueue(SB),NOSPLIT,$0
   414  	MOVQ	$0, DI
   415  	MOVL	$SYS_kqueue, AX
   416  	SYSCALL
   417  	JCC	2(PC)
   418  	NEGQ	AX
   419  	MOVL	AX, ret+0(FP)
   420  	RET
   421  
   422  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   423  TEXT runtime·kevent(SB),NOSPLIT,$0
   424  	MOVL	kq+0(FP), DI
   425  	MOVQ	ch+8(FP), SI
   426  	MOVL	nch+16(FP), DX
   427  	MOVQ	ev+24(FP), R10
   428  	MOVL	nev+32(FP), R8
   429  	MOVQ	ts+40(FP), R9
   430  	MOVL	$SYS___kevent50, AX
   431  	SYSCALL
   432  	JCC	2(PC)
   433  	NEGQ	AX
   434  	MOVL	AX, ret+48(FP)
   435  	RET
   436  
   437  // void runtime·closeonexec(int32 fd)
   438  TEXT runtime·closeonexec(SB),NOSPLIT,$0
   439  	MOVL	fd+0(FP), DI	// fd
   440  	MOVQ	$F_SETFD, SI
   441  	MOVQ	$FD_CLOEXEC, DX
   442  	MOVL	$SYS_fcntl, AX
   443  	SYSCALL
   444  	RET
   445  

View as plain text