github.com/aloncn/graphics-go@v0.0.1/src/runtime/sys_freebsd_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, 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  
    13  TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
    14  	MOVQ addr+0(FP), DI
    15  	MOVL mode+8(FP), SI
    16  	MOVL val+12(FP), DX
    17  	MOVQ ptr2+16(FP), R10
    18  	MOVQ ts+24(FP), R8
    19  	MOVL $454, AX
    20  	SYSCALL
    21  	MOVL	AX, ret+32(FP)
    22  	RET
    23  
    24  TEXT runtime·thr_new(SB),NOSPLIT,$0
    25  	MOVQ param+0(FP), DI
    26  	MOVL size+8(FP), SI
    27  	MOVL $455, AX
    28  	SYSCALL
    29  	RET
    30  
    31  TEXT runtime·thr_start(SB),NOSPLIT,$0
    32  	MOVQ	DI, R13 // m
    33  
    34  	// set up FS to point at m->tls
    35  	LEAQ	m_tls(R13), DI
    36  	CALL	runtime·settls(SB)	// smashes DI
    37  
    38  	// set up m, g
    39  	get_tls(CX)
    40  	MOVQ	m_g0(R13), DI
    41  	MOVQ	R13, g_m(DI)
    42  	MOVQ	DI, g(CX)
    43  
    44  	CALL	runtime·stackcheck(SB)
    45  	CALL	runtime·mstart(SB)
    46  
    47  	MOVQ 0, AX			// crash (not reached)
    48  
    49  // Exit the entire program (like C exit)
    50  TEXT runtime·exit(SB),NOSPLIT,$-8
    51  	MOVL	code+0(FP), DI		// arg 1 exit status
    52  	MOVL	$1, AX
    53  	SYSCALL
    54  	MOVL	$0xf1, 0xf1  // crash
    55  	RET
    56  
    57  TEXT runtime·exit1(SB),NOSPLIT,$-8
    58  	MOVL	code+0(FP), DI		// arg 1 exit status
    59  	MOVL	$431, AX
    60  	SYSCALL
    61  	MOVL	$0xf1, 0xf1  // crash
    62  	RET
    63  
    64  TEXT runtime·open(SB),NOSPLIT,$-8
    65  	MOVQ	name+0(FP), DI		// arg 1 pathname
    66  	MOVL	mode+8(FP), SI		// arg 2 flags
    67  	MOVL	perm+12(FP), DX		// arg 3 mode
    68  	MOVL	$5, AX
    69  	SYSCALL
    70  	JCC	2(PC)
    71  	MOVL	$-1, AX
    72  	MOVL	AX, ret+16(FP)
    73  	RET
    74  
    75  TEXT runtime·closefd(SB),NOSPLIT,$-8
    76  	MOVL	fd+0(FP), DI		// arg 1 fd
    77  	MOVL	$6, AX
    78  	SYSCALL
    79  	JCC	2(PC)
    80  	MOVL	$-1, AX
    81  	MOVL	AX, ret+8(FP)
    82  	RET
    83  
    84  TEXT runtime·read(SB),NOSPLIT,$-8
    85  	MOVL	fd+0(FP), DI		// arg 1 fd
    86  	MOVQ	p+8(FP), SI		// arg 2 buf
    87  	MOVL	n+16(FP), DX		// arg 3 count
    88  	MOVL	$3, AX
    89  	SYSCALL
    90  	JCC	2(PC)
    91  	MOVL	$-1, AX
    92  	MOVL	AX, ret+24(FP)
    93  	RET
    94  
    95  TEXT runtime·write(SB),NOSPLIT,$-8
    96  	MOVQ	fd+0(FP), DI		// arg 1 fd
    97  	MOVQ	p+8(FP), SI		// arg 2 buf
    98  	MOVL	n+16(FP), DX		// arg 3 count
    99  	MOVL	$4, AX
   100  	SYSCALL
   101  	JCC	2(PC)
   102  	MOVL	$-1, AX
   103  	MOVL	AX, ret+24(FP)
   104  	RET
   105  
   106  TEXT runtime·getrlimit(SB),NOSPLIT,$-8
   107  	MOVL	kind+0(FP), DI
   108  	MOVQ	limit+8(FP), SI
   109  	MOVL	$194, AX
   110  	SYSCALL
   111  	MOVL	AX, ret+16(FP)
   112  	RET
   113  
   114  TEXT runtime·raise(SB),NOSPLIT,$16
   115  	// thr_self(&8(SP))
   116  	LEAQ	8(SP), DI	// arg 1 &8(SP)
   117  	MOVL	$432, AX
   118  	SYSCALL
   119  	// thr_kill(self, SIGPIPE)
   120  	MOVQ	8(SP), DI	// arg 1 id
   121  	MOVL	sig+0(FP), SI	// arg 2
   122  	MOVL	$433, AX
   123  	SYSCALL
   124  	RET
   125  
   126  TEXT runtime·raiseproc(SB),NOSPLIT,$0
   127  	// getpid
   128  	MOVL	$20, AX
   129  	SYSCALL
   130  	// kill(self, sig)
   131  	MOVQ	AX, DI		// arg 1 pid
   132  	MOVL	sig+0(FP), SI	// arg 2 sig
   133  	MOVL	$37, AX
   134  	SYSCALL
   135  	RET
   136  
   137  TEXT runtime·setitimer(SB), NOSPLIT, $-8
   138  	MOVL	mode+0(FP), DI
   139  	MOVQ	new+8(FP), SI
   140  	MOVQ	old+16(FP), DX
   141  	MOVL	$83, AX
   142  	SYSCALL
   143  	RET
   144  
   145  // func now() (sec int64, nsec int32)
   146  TEXT time·now(SB), NOSPLIT, $32
   147  	MOVL	$232, AX
   148  	MOVQ	$0, DI		// CLOCK_REALTIME
   149  	LEAQ	8(SP), SI
   150  	SYSCALL
   151  	MOVQ	8(SP), AX	// sec
   152  	MOVQ	16(SP), DX	// nsec
   153  
   154  	// sec is in AX, nsec in DX
   155  	MOVQ	AX, sec+0(FP)
   156  	MOVL	DX, nsec+8(FP)
   157  	RET
   158  
   159  TEXT runtime·nanotime(SB), NOSPLIT, $32
   160  	MOVL	$232, AX
   161  	// We can use CLOCK_MONOTONIC_FAST here when we drop
   162  	// support for FreeBSD 8-STABLE.
   163  	MOVQ	$4, DI		// CLOCK_MONOTONIC
   164  	LEAQ	8(SP), SI
   165  	SYSCALL
   166  	MOVQ	8(SP), AX	// sec
   167  	MOVQ	16(SP), DX	// nsec
   168  
   169  	// sec is in AX, nsec in DX
   170  	// return nsec in AX
   171  	IMULQ	$1000000000, AX
   172  	ADDQ	DX, AX
   173  	MOVQ	AX, ret+0(FP)
   174  	RET
   175  
   176  TEXT runtime·sigaction(SB),NOSPLIT,$-8
   177  	MOVL	sig+0(FP), DI		// arg 1 sig
   178  	MOVQ	new+8(FP), SI		// arg 2 act
   179  	MOVQ	old+16(FP), DX		// arg 3 oact
   180  	MOVL	$416, AX
   181  	SYSCALL
   182  	JCC	2(PC)
   183  	MOVL	$0xf1, 0xf1  // crash
   184  	RET
   185  
   186  TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   187  	MOVL	sig+8(FP), DI
   188  	MOVQ	info+16(FP), SI
   189  	MOVQ	ctx+24(FP), DX
   190  	MOVQ	fn+0(FP), AX
   191  	CALL	AX
   192  	RET
   193  
   194  TEXT runtime·sigtramp(SB),NOSPLIT,$24
   195  	MOVQ	DI, 0(SP)
   196  	MOVQ	SI, 8(SP)
   197  	MOVQ	DX, 16(SP)
   198  	CALL	runtime·sigtrampgo(SB)
   199  	RET
   200  
   201  TEXT runtime·mmap(SB),NOSPLIT,$0
   202  	MOVQ	addr+0(FP), DI		// arg 1 addr
   203  	MOVQ	n+8(FP), SI		// arg 2 len
   204  	MOVL	prot+16(FP), DX		// arg 3 prot
   205  	MOVL	flags+20(FP), R10		// arg 4 flags
   206  	MOVL	fd+24(FP), R8		// arg 5 fid
   207  	MOVL	off+28(FP), R9		// arg 6 offset
   208  	MOVL	$477, AX
   209  	SYSCALL
   210  	MOVQ	AX, ret+32(FP)
   211  	RET
   212  
   213  TEXT runtime·munmap(SB),NOSPLIT,$0
   214  	MOVQ	addr+0(FP), DI		// arg 1 addr
   215  	MOVQ	n+8(FP), SI		// arg 2 len
   216  	MOVL	$73, AX
   217  	SYSCALL
   218  	JCC	2(PC)
   219  	MOVL	$0xf1, 0xf1  // crash
   220  	RET
   221  
   222  TEXT runtime·madvise(SB),NOSPLIT,$0
   223  	MOVQ	addr+0(FP), DI
   224  	MOVQ	n+8(FP), SI
   225  	MOVL	flags+16(FP), DX
   226  	MOVQ	$75, AX	// madvise
   227  	SYSCALL
   228  	// ignore failure - maybe pages are locked
   229  	RET
   230  	
   231  TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   232  	MOVQ	new+8(SP), DI
   233  	MOVQ	old+16(SP), SI
   234  	MOVQ	$53, AX
   235  	SYSCALL
   236  	JCC	2(PC)
   237  	MOVL	$0xf1, 0xf1  // crash
   238  	RET
   239  
   240  TEXT runtime·usleep(SB),NOSPLIT,$16
   241  	MOVL	$0, DX
   242  	MOVL	usec+0(FP), AX
   243  	MOVL	$1000000, CX
   244  	DIVL	CX
   245  	MOVQ	AX, 0(SP)		// tv_sec
   246  	MOVL	$1000, AX
   247  	MULL	DX
   248  	MOVQ	AX, 8(SP)		// tv_nsec
   249  
   250  	MOVQ	SP, DI			// arg 1 - rqtp
   251  	MOVQ	$0, SI			// arg 2 - rmtp
   252  	MOVL	$240, AX		// sys_nanosleep
   253  	SYSCALL
   254  	RET
   255  
   256  // set tls base to DI
   257  TEXT runtime·settls(SB),NOSPLIT,$8
   258  	ADDQ	$8, DI	// adjust for ELF: wants to use -8(FS) for g and m
   259  	MOVQ	DI, 0(SP)
   260  	MOVQ	SP, SI
   261  	MOVQ	$129, DI	// AMD64_SET_FSBASE
   262  	MOVQ	$165, AX	// sysarch
   263  	SYSCALL
   264  	JCC	2(PC)
   265  	MOVL	$0xf1, 0xf1  // crash
   266  	RET
   267  
   268  TEXT runtime·sysctl(SB),NOSPLIT,$0
   269  	MOVQ	mib+0(FP), DI		// arg 1 - name
   270  	MOVL	miblen+8(FP), SI		// arg 2 - namelen
   271  	MOVQ	out+16(FP), DX		// arg 3 - oldp
   272  	MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   273  	MOVQ	dst+32(FP), R8		// arg 5 - newp
   274  	MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   275  	MOVQ	$202, AX		// sys___sysctl
   276  	SYSCALL
   277  	JCC 4(PC)
   278  	NEGQ	AX
   279  	MOVL	AX, ret+48(FP)
   280  	RET
   281  	MOVL	$0, AX
   282  	MOVL	AX, ret+48(FP)
   283  	RET
   284  
   285  TEXT runtime·osyield(SB),NOSPLIT,$-4
   286  	MOVL	$331, AX		// sys_sched_yield
   287  	SYSCALL
   288  	RET
   289  
   290  TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   291  	MOVL	how+0(FP), DI		// arg 1 - how
   292  	MOVQ	new+8(FP), SI		// arg 2 - set
   293  	MOVQ	old+16(FP), DX		// arg 3 - oset
   294  	MOVL	$340, AX		// sys_sigprocmask
   295  	SYSCALL
   296  	JAE	2(PC)
   297  	MOVL	$0xf1, 0xf1  // crash
   298  	RET
   299  
   300  // int32 runtime·kqueue(void);
   301  TEXT runtime·kqueue(SB),NOSPLIT,$0
   302  	MOVQ	$0, DI
   303  	MOVQ	$0, SI
   304  	MOVQ	$0, DX
   305  	MOVL	$362, AX
   306  	SYSCALL
   307  	JCC	2(PC)
   308  	NEGQ	AX
   309  	MOVL	AX, ret+0(FP)
   310  	RET
   311  
   312  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   313  TEXT runtime·kevent(SB),NOSPLIT,$0
   314  	MOVL	fd+0(FP), DI
   315  	MOVQ	ev1+8(FP), SI
   316  	MOVL	nev1+16(FP), DX
   317  	MOVQ	ev2+24(FP), R10
   318  	MOVL	nev2+32(FP), R8
   319  	MOVQ	ts+40(FP), R9
   320  	MOVL	$363, AX
   321  	SYSCALL
   322  	JCC	2(PC)
   323  	NEGQ	AX
   324  	MOVL	AX, ret+48(FP)
   325  	RET
   326  
   327  // void runtime·closeonexec(int32 fd);
   328  TEXT runtime·closeonexec(SB),NOSPLIT,$0
   329  	MOVL	fd+0(FP), DI	// fd
   330  	MOVQ	$2, SI		// F_SETFD
   331  	MOVQ	$1, DX		// FD_CLOEXEC
   332  	MOVL	$92, AX		// fcntl
   333  	SYSCALL
   334  	RET