github.com/aloncn/graphics-go@v0.0.1/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  	MOVQ	abstime+0(FP), DI		// arg 1 - abstime
    52  	MOVL	unpark+8(FP), SI		// arg 2 - unpark
    53  	MOVQ	hint+16(FP), DX		// arg 3 - hint
    54  	MOVQ	unparkhint+24(FP), R10		// arg 4 - unparkhint
    55  	MOVL	$434, AX		// sys__lwp_park
    56  	SYSCALL
    57  	MOVL	AX, ret+32(FP)
    58  	RET
    59  
    60  TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
    61  	MOVL	lwp+0(FP), DI		// arg 1 - lwp
    62  	MOVQ	hint+8(FP), SI		// arg 2 - hint
    63  	MOVL	$321, AX		// sys__lwp_unpark
    64  	SYSCALL
    65  	MOVL	AX, ret+16(FP)
    66  	RET
    67  
    68  TEXT runtime·lwp_self(SB),NOSPLIT,$0
    69  	MOVL	$311, AX		// sys__lwp_self
    70  	SYSCALL
    71  	MOVL	AX, ret+0(FP)
    72  	RET
    73  
    74  // Exit the entire program (like C exit)
    75  TEXT runtime·exit(SB),NOSPLIT,$-8
    76  	MOVL	code+0(FP), DI		// arg 1 - exit status
    77  	MOVL	$1, AX			// sys_exit
    78  	SYSCALL
    79  	MOVL	$0xf1, 0xf1		// crash
    80  	RET
    81  
    82  TEXT runtime·exit1(SB),NOSPLIT,$-8
    83  	MOVL	$310, AX		// sys__lwp_exit
    84  	SYSCALL
    85  	MOVL	$0xf1, 0xf1		// crash
    86  	RET
    87  
    88  TEXT runtime·open(SB),NOSPLIT,$-8
    89  	MOVQ	name+0(FP), DI		// arg 1 pathname
    90  	MOVL	mode+8(FP), SI		// arg 2 flags
    91  	MOVL	perm+12(FP), DX		// arg 3 mode
    92  	MOVL	$5, AX
    93  	SYSCALL
    94  	JCC	2(PC)
    95  	MOVL	$-1, AX
    96  	MOVL	AX, ret+16(FP)
    97  	RET
    98  
    99  TEXT runtime·closefd(SB),NOSPLIT,$-8
   100  	MOVL	fd+0(FP), DI		// arg 1 fd
   101  	MOVL	$6, AX
   102  	SYSCALL
   103  	JCC	2(PC)
   104  	MOVL	$-1, AX
   105  	MOVL	AX, ret+8(FP)
   106  	RET
   107  
   108  TEXT runtime·read(SB),NOSPLIT,$-8
   109  	MOVL	fd+0(FP), DI		// arg 1 fd
   110  	MOVQ	p+8(FP), SI		// arg 2 buf
   111  	MOVL	n+16(FP), DX		// arg 3 count
   112  	MOVL	$3, AX
   113  	SYSCALL
   114  	JCC	2(PC)
   115  	MOVL	$-1, AX
   116  	MOVL	AX, ret+24(FP)
   117  	RET
   118  
   119  TEXT runtime·write(SB),NOSPLIT,$-8
   120  	MOVQ	fd+0(FP), DI		// arg 1 - fd
   121  	MOVQ	p+8(FP), SI		// arg 2 - buf
   122  	MOVL	n+16(FP), DX		// arg 3 - nbyte
   123  	MOVL	$4, AX			// sys_write
   124  	SYSCALL
   125  	JCC	2(PC)
   126  	MOVL	$-1, AX
   127  	MOVL	AX, ret+24(FP)
   128  	RET
   129  
   130  TEXT runtime·usleep(SB),NOSPLIT,$16
   131  	MOVL	$0, DX
   132  	MOVL	usec+0(FP), AX
   133  	MOVL	$1000000, CX
   134  	DIVL	CX
   135  	MOVQ	AX, 0(SP)		// tv_sec
   136  	MOVL	$1000, AX
   137  	MULL	DX
   138  	MOVQ	AX, 8(SP)		// tv_nsec
   139  
   140  	MOVQ	SP, DI			// arg 1 - rqtp
   141  	MOVQ	$0, SI			// arg 2 - rmtp
   142  	MOVL	$430, AX		// sys_nanosleep
   143  	SYSCALL
   144  	RET
   145  
   146  TEXT runtime·raise(SB),NOSPLIT,$16
   147  	MOVL	$311, AX		// sys__lwp_self
   148  	SYSCALL
   149  	MOVQ	AX, DI			// arg 1 - target
   150  	MOVL	sig+0(FP), SI		// arg 2 - signo
   151  	MOVL	$318, AX		// sys__lwp_kill
   152  	SYSCALL
   153  	RET
   154  
   155  TEXT runtime·raiseproc(SB),NOSPLIT,$16
   156  	MOVL	$20, AX			// sys_getpid
   157  	SYSCALL
   158  	MOVQ	AX, DI			// arg 1 - pid
   159  	MOVL	sig+0(FP), SI		// arg 2 - signo
   160  	MOVL	$37, AX			// sys_kill
   161  	SYSCALL
   162  	RET
   163  
   164  TEXT runtime·setitimer(SB),NOSPLIT,$-8
   165  	MOVL	mode+0(FP), DI		// arg 1 - which
   166  	MOVQ	new+8(FP), SI		// arg 2 - itv
   167  	MOVQ	old+16(FP), DX		// arg 3 - oitv
   168  	MOVL	$425, AX		// sys_setitimer
   169  	SYSCALL
   170  	RET
   171  
   172  // func now() (sec int64, nsec int32)
   173  TEXT time·now(SB), NOSPLIT, $32
   174  	MOVQ	$0, DI			// arg 1 - clock_id
   175  	LEAQ	8(SP), SI		// arg 2 - tp
   176  	MOVL	$427, AX		// sys_clock_gettime
   177  	SYSCALL
   178  	MOVQ	8(SP), AX		// sec
   179  	MOVL	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·nanotime(SB),NOSPLIT,$32
   187  	MOVQ	$0, DI			// arg 1 - clock_id
   188  	LEAQ	8(SP), SI		// arg 2 - tp
   189  	MOVL	$427, AX		// sys_clock_gettime
   190  	SYSCALL
   191  	MOVQ	8(SP), AX		// sec
   192  	MOVL	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·getcontext(SB),NOSPLIT,$-8
   202  	MOVQ	ctxt+0(FP), DI		// arg 1 - context
   203  	MOVL	$307, AX		// sys_getcontext
   204  	SYSCALL
   205  	JCC	2(PC)
   206  	MOVL	$0xf1, 0xf1		// crash
   207  	RET
   208  
   209  TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   210  	MOVL	mode+0(FP), DI		// arg 1 - how
   211  	MOVQ	new+8(FP), SI		// arg 2 - set
   212  	MOVQ	old+16(FP), DX		// arg 3 - oset
   213  	MOVL	$293, AX		// sys_sigprocmask
   214  	SYSCALL
   215  	JCC	2(PC)
   216  	MOVL	$0xf1, 0xf1		// crash
   217  	RET
   218  
   219  TEXT runtime·sigreturn_tramp(SB),NOSPLIT,$-8
   220  	MOVQ	R15, DI			// Load address of ucontext
   221  	MOVQ	$308, AX		// sys_setcontext
   222  	SYSCALL
   223  	MOVQ	$-1, DI			// Something failed...
   224  	MOVL	$1, AX			// sys_exit
   225  	SYSCALL
   226  
   227  TEXT runtime·sigaction(SB),NOSPLIT,$-8
   228  	MOVL	sig+0(FP), DI		// arg 1 - signum
   229  	MOVQ	new+8(FP), SI		// arg 2 - nsa
   230  	MOVQ	old+16(FP), DX		// arg 3 - osa
   231  					// arg 4 - tramp
   232  	LEAQ	runtime·sigreturn_tramp(SB), R10
   233  	MOVQ	$2, R8			// arg 5 - vers
   234  	MOVL	$340, AX		// sys___sigaction_sigtramp
   235  	SYSCALL
   236  	JCC	2(PC)
   237  	MOVL	$0xf1, 0xf1		// crash
   238  	RET
   239  
   240  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   241  	MOVL	sig+8(FP), DI
   242  	MOVQ	info+16(FP), SI
   243  	MOVQ	ctx+24(FP), DX
   244  	MOVQ	fn+0(FP), AX
   245  	CALL	AX
   246  	RET
   247  
   248  TEXT runtime·sigtramp(SB),NOSPLIT,$32
   249  	MOVQ	DI, 0(SP)   // signum
   250  	MOVQ	SI, 8(SP)   // info
   251  	MOVQ	DX, 16(SP)  // ctx
   252  	MOVQ	R15, 24(SP) // for sigreturn
   253  	CALL	runtime·sigtrampgo(SB)
   254  	MOVQ	24(SP), R15
   255  	RET
   256  
   257  TEXT runtime·mmap(SB),NOSPLIT,$0
   258  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   259  	MOVQ	n+8(FP), SI		// arg 2 - len
   260  	MOVL	prot+16(FP), DX		// arg 3 - prot
   261  	MOVL	flags+20(FP), R10		// arg 4 - flags
   262  	MOVL	fd+24(FP), R8		// arg 5 - fd
   263  	MOVL	off+28(FP), R9
   264  	SUBQ	$16, SP
   265  	MOVQ	R9, 8(SP)		// arg 7 - offset (passed on stack)
   266  	MOVQ	$0, R9			// arg 6 - pad
   267  	MOVL	$197, AX		// sys_mmap
   268  	SYSCALL
   269  	ADDQ	$16, SP
   270  	MOVQ	AX, ret+32(FP)
   271  	RET
   272  
   273  TEXT runtime·munmap(SB),NOSPLIT,$0
   274  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   275  	MOVQ	n+8(FP), SI		// arg 2 - len
   276  	MOVL	$73, AX			// sys_munmap
   277  	SYSCALL
   278  	JCC	2(PC)
   279  	MOVL	$0xf1, 0xf1		// crash
   280  	RET
   281  
   282  
   283  TEXT runtime·madvise(SB),NOSPLIT,$0
   284  	MOVQ	addr+0(FP), DI		// arg 1 - addr
   285  	MOVQ	n+8(FP), SI		// arg 2 - len
   286  	MOVL	flags+16(FP), DX	// arg 3 - behav
   287  	MOVQ	$75, AX			// sys_madvise
   288  	SYSCALL
   289  	// ignore failure - maybe pages are locked
   290  	RET
   291  
   292  TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   293  	MOVQ	new+8(SP), DI		// arg 1 - nss
   294  	MOVQ	old+16(SP), SI		// arg 2 - oss
   295  	MOVQ	$281, AX		// sys___sigaltstack14
   296  	SYSCALL
   297  	JCC	2(PC)
   298  	MOVL	$0xf1, 0xf1		// crash
   299  	RET
   300  
   301  // set tls base to DI
   302  TEXT runtime·settls(SB),NOSPLIT,$8
   303  	// adjust for ELF: wants to use -8(FS) for g
   304  	ADDQ	$8, DI			// arg 1 - ptr
   305  	MOVQ	$317, AX		// sys__lwp_setprivate
   306  	SYSCALL
   307  	JCC	2(PC)
   308  	MOVL	$0xf1, 0xf1		// crash
   309  	RET
   310  
   311  TEXT runtime·sysctl(SB),NOSPLIT,$0
   312  	MOVQ	mib+0(FP), DI		// arg 1 - name
   313  	MOVL	miblen+8(FP), SI		// arg 2 - namelen
   314  	MOVQ	out+16(FP), DX		// arg 3 - oldp
   315  	MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   316  	MOVQ	dst+32(FP), R8		// arg 5 - newp
   317  	MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   318  	MOVQ	$202, AX		// sys___sysctl
   319  	SYSCALL
   320  	JCC 4(PC)
   321  	NEGQ	AX
   322  	MOVL	AX, ret+48(FP)
   323  	RET
   324  	MOVL	$0, AX
   325  	MOVL	AX, ret+48(FP)
   326  	RET
   327  
   328  // int32 runtime·kqueue(void)
   329  TEXT runtime·kqueue(SB),NOSPLIT,$0
   330  	MOVQ	$0, DI
   331  	MOVL	$344, AX
   332  	SYSCALL
   333  	JCC	2(PC)
   334  	NEGQ	AX
   335  	MOVL	AX, ret+0(FP)
   336  	RET
   337  
   338  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   339  TEXT runtime·kevent(SB),NOSPLIT,$0
   340  	MOVL	fd+0(FP), DI
   341  	MOVQ	ev1+8(FP), SI
   342  	MOVL	nev1+16(FP), DX
   343  	MOVQ	ev2+24(FP), R10
   344  	MOVL	nev2+32(FP), R8
   345  	MOVQ	ts+40(FP), R9
   346  	MOVL	$435, AX
   347  	SYSCALL
   348  	JCC	2(PC)
   349  	NEGQ	AX
   350  	MOVL	AX, ret+48(FP)
   351  	RET
   352  
   353  // void runtime·closeonexec(int32 fd)
   354  TEXT runtime·closeonexec(SB),NOSPLIT,$0
   355  	MOVL	fd+0(FP), DI	// fd
   356  	MOVQ	$2, SI		// F_SETFD
   357  	MOVQ	$1, DX		// FD_CLOEXEC
   358  	MOVL	$92, AX		// fcntl
   359  	SYSCALL
   360  	RET