github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/src/runtime/sys_freebsd_386.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 386, 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,$-4
    14  	MOVL	$454, AX
    15  	INT	$0x80
    16  	MOVL	AX, ret+20(FP)
    17  	RET
    18  
    19  TEXT runtime·thr_new(SB),NOSPLIT,$-4
    20  	MOVL	$455, AX
    21  	INT	$0x80
    22  	RET
    23  
    24  TEXT runtime·thr_start(SB),NOSPLIT,$0
    25  	MOVL	mm+0(FP), AX
    26  	MOVL	m_g0(AX), BX
    27  	LEAL	m_tls(AX), BP
    28  	MOVL	0(BP), DI
    29  	ADDL	$7, DI
    30  	PUSHAL
    31  	PUSHL	$32
    32  	PUSHL	BP
    33  	PUSHL	DI
    34  	CALL	runtime·setldt(SB)
    35  	POPL	AX
    36  	POPL	AX
    37  	POPL	AX
    38  	POPAL
    39  	get_tls(CX)
    40  	MOVL	BX, g(CX)
    41  	
    42  	MOVL	AX, g_m(BX)
    43  	CALL	runtime·stackcheck(SB)		// smashes AX
    44  	CALL	runtime·mstart(SB)
    45  
    46  	MOVL	0, AX			// crash (not reached)
    47  
    48  // Exit the entire program (like C exit)
    49  TEXT runtime·exit(SB),NOSPLIT,$-4
    50  	MOVL	$1, AX
    51  	INT	$0x80
    52  	MOVL	$0xf1, 0xf1  // crash
    53  	RET
    54  
    55  TEXT runtime·exit1(SB),NOSPLIT,$-4
    56  	MOVL	$431, AX
    57  	INT	$0x80
    58  	JAE	2(PC)
    59  	MOVL	$0xf1, 0xf1  // crash
    60  	RET
    61  
    62  TEXT runtime·open(SB),NOSPLIT,$-4
    63  	MOVL	$5, AX
    64  	INT	$0x80
    65  	JAE	2(PC)
    66  	MOVL	$-1, AX
    67  	MOVL	AX, ret+12(FP)
    68  	RET
    69  
    70  TEXT runtime·closefd(SB),NOSPLIT,$-4
    71  	MOVL	$6, AX
    72  	INT	$0x80
    73  	JAE	2(PC)
    74  	MOVL	$-1, AX
    75  	MOVL	AX, ret+4(FP)
    76  	RET
    77  
    78  TEXT runtime·read(SB),NOSPLIT,$-4
    79  	MOVL	$3, AX
    80  	INT	$0x80
    81  	JAE	2(PC)
    82  	MOVL	$-1, AX
    83  	MOVL	AX, ret+12(FP)
    84  	RET
    85  
    86  TEXT runtime·write(SB),NOSPLIT,$-4
    87  	MOVL	$4, AX
    88  	INT	$0x80
    89  	JAE	2(PC)
    90  	MOVL	$-1, AX
    91  	MOVL	AX, ret+12(FP)
    92  	RET
    93  
    94  TEXT runtime·getrlimit(SB),NOSPLIT,$-4
    95  	MOVL	$194, AX
    96  	INT	$0x80
    97  	MOVL	AX, ret+8(FP)
    98  	RET
    99  
   100  TEXT runtime·raise(SB),NOSPLIT,$16
   101  	// thr_self(&8(SP))
   102  	LEAL	8(SP), AX
   103  	MOVL	AX, 4(SP)
   104  	MOVL	$432, AX
   105  	INT	$0x80
   106  	// thr_kill(self, SIGPIPE)
   107  	MOVL	8(SP), AX
   108  	MOVL	AX, 4(SP)
   109  	MOVL	sig+0(FP), AX
   110  	MOVL	AX, 8(SP)
   111  	MOVL	$433, AX
   112  	INT	$0x80
   113  	RET
   114  
   115  TEXT runtime·mmap(SB),NOSPLIT,$32
   116  	LEAL addr+0(FP), SI
   117  	LEAL	4(SP), DI
   118  	CLD
   119  	MOVSL
   120  	MOVSL
   121  	MOVSL
   122  	MOVSL
   123  	MOVSL
   124  	MOVSL
   125  	MOVL	$0, AX	// top 32 bits of file offset
   126  	STOSL
   127  	MOVL	$477, AX
   128  	INT	$0x80
   129  	MOVL	AX, ret+24(FP)
   130  	RET
   131  
   132  TEXT runtime·munmap(SB),NOSPLIT,$-4
   133  	MOVL	$73, AX
   134  	INT	$0x80
   135  	JAE	2(PC)
   136  	MOVL	$0xf1, 0xf1  // crash
   137  	RET
   138  
   139  TEXT runtime·madvise(SB),NOSPLIT,$-4
   140  	MOVL	$75, AX	// madvise
   141  	INT	$0x80
   142  	// ignore failure - maybe pages are locked
   143  	RET
   144  
   145  TEXT runtime·setitimer(SB), NOSPLIT, $-4
   146  	MOVL	$83, AX
   147  	INT	$0x80
   148  	RET
   149  
   150  // func now() (sec int64, nsec int32)
   151  TEXT time·now(SB), NOSPLIT, $32
   152  	MOVL	$232, AX
   153  	LEAL	12(SP), BX
   154  	MOVL	$0, 4(SP)	// CLOCK_REALTIME
   155  	MOVL	BX, 8(SP)
   156  	INT	$0x80
   157  	MOVL	12(SP), AX	// sec
   158  	MOVL	16(SP), BX	// nsec
   159  
   160  	// sec is in AX, nsec in BX
   161  	MOVL	AX, sec+0(FP)
   162  	MOVL	$0, sec+4(FP)
   163  	MOVL	BX, nsec+8(FP)
   164  	RET
   165  
   166  // int64 nanotime(void) so really
   167  // void nanotime(int64 *nsec)
   168  TEXT runtime·nanotime(SB), NOSPLIT, $32
   169  	MOVL	$232, AX
   170  	LEAL	12(SP), BX
   171  	// We can use CLOCK_MONOTONIC_FAST here when we drop
   172  	// support for FreeBSD 8-STABLE.
   173  	MOVL	$4, 4(SP)	// CLOCK_MONOTONIC
   174  	MOVL	BX, 8(SP)
   175  	INT	$0x80
   176  	MOVL	12(SP), AX	// sec
   177  	MOVL	16(SP), BX	// nsec
   178  
   179  	// sec is in AX, nsec in BX
   180  	// convert to DX:AX nsec
   181  	MOVL	$1000000000, CX
   182  	MULL	CX
   183  	ADDL	BX, AX
   184  	ADCL	$0, DX
   185  
   186  	MOVL	AX, ret_lo+0(FP)
   187  	MOVL	DX, ret_hi+4(FP)
   188  	RET
   189  
   190  
   191  TEXT runtime·sigaction(SB),NOSPLIT,$-4
   192  	MOVL	$416, AX
   193  	INT	$0x80
   194  	JAE	2(PC)
   195  	MOVL	$0xf1, 0xf1  // crash
   196  	RET
   197  
   198  TEXT runtime·sigtramp(SB),NOSPLIT,$44
   199  	get_tls(CX)
   200  
   201  	// check that g exists
   202  	MOVL	g(CX), DI
   203  	CMPL	DI, $0
   204  	JNE	6(PC)
   205  	MOVL	signo+0(FP), BX
   206  	MOVL	BX, 0(SP)
   207  	MOVL	$runtime·badsignal(SB), AX
   208  	CALL	AX
   209  	JMP 	ret
   210  
   211  	// save g
   212  	MOVL	DI, 20(SP)
   213  	
   214  	// g = m->gsignal
   215  	MOVL	g_m(DI), BX
   216  	MOVL	m_gsignal(BX), BX
   217  	MOVL	BX, g(CX)
   218  
   219  	// copy arguments for call to sighandler
   220  	MOVL	signo+0(FP), BX
   221  	MOVL	BX, 0(SP)
   222  	MOVL	info+4(FP), BX
   223  	MOVL	BX, 4(SP)
   224  	MOVL	context+8(FP), BX
   225  	MOVL	BX, 8(SP)
   226  	MOVL	DI, 12(SP)
   227  
   228  	CALL	runtime·sighandler(SB)
   229  
   230  	// restore g
   231  	get_tls(CX)
   232  	MOVL	20(SP), BX
   233  	MOVL	BX, g(CX)
   234  
   235  ret:
   236  	// call sigreturn
   237  	MOVL	context+8(FP), AX
   238  	MOVL	$0, 0(SP)	// syscall gap
   239  	MOVL	AX, 4(SP)
   240  	MOVL	$417, AX	// sigreturn(ucontext)
   241  	INT	$0x80
   242  	MOVL	$0xf1, 0xf1  // crash
   243  	RET
   244  
   245  TEXT runtime·sigaltstack(SB),NOSPLIT,$0
   246  	MOVL	$53, AX
   247  	INT	$0x80
   248  	JAE	2(PC)
   249  	MOVL	$0xf1, 0xf1  // crash
   250  	RET
   251  
   252  TEXT runtime·usleep(SB),NOSPLIT,$20
   253  	MOVL	$0, DX
   254  	MOVL	usec+0(FP), AX
   255  	MOVL	$1000000, CX
   256  	DIVL	CX
   257  	MOVL	AX, 12(SP)		// tv_sec
   258  	MOVL	$1000, AX
   259  	MULL	DX
   260  	MOVL	AX, 16(SP)		// tv_nsec
   261  
   262  	MOVL	$0, 0(SP)
   263  	LEAL	12(SP), AX
   264  	MOVL	AX, 4(SP)		// arg 1 - rqtp
   265  	MOVL	$0, 8(SP)		// arg 2 - rmtp
   266  	MOVL	$240, AX		// sys_nanosleep
   267  	INT	$0x80
   268  	RET
   269  
   270  /*
   271  descriptor entry format for system call
   272  is the native machine format, ugly as it is:
   273  
   274  	2-byte limit
   275  	3-byte base
   276  	1-byte: 0x80=present, 0x60=dpl<<5, 0x1F=type
   277  	1-byte: 0x80=limit is *4k, 0x40=32-bit operand size,
   278  		0x0F=4 more bits of limit
   279  	1 byte: 8 more bits of base
   280  
   281  int i386_get_ldt(int, union ldt_entry *, int);
   282  int i386_set_ldt(int, const union ldt_entry *, int);
   283  
   284  */
   285  
   286  // setldt(int entry, int address, int limit)
   287  TEXT runtime·setldt(SB),NOSPLIT,$32
   288  	MOVL	address+4(FP), BX	// aka base
   289  	// see comment in sys_linux_386.s; freebsd is similar
   290  	ADDL	$0x4, BX
   291  
   292  	// set up data_desc
   293  	LEAL	16(SP), AX	// struct data_desc
   294  	MOVL	$0, 0(AX)
   295  	MOVL	$0, 4(AX)
   296  
   297  	MOVW	BX, 2(AX)
   298  	SHRL	$16, BX
   299  	MOVB	BX, 4(AX)
   300  	SHRL	$8, BX
   301  	MOVB	BX, 7(AX)
   302  
   303  	MOVW	$0xffff, 0(AX)
   304  	MOVB	$0xCF, 6(AX)	// 32-bit operand, 4k limit unit, 4 more bits of limit
   305  
   306  	MOVB	$0xF2, 5(AX)	// r/w data descriptor, dpl=3, present
   307  
   308  	// call i386_set_ldt(entry, desc, 1)
   309  	MOVL	$0xffffffff, 0(SP)	// auto-allocate entry and return in AX
   310  	MOVL	AX, 4(SP)
   311  	MOVL	$1, 8(SP)
   312  	CALL	runtime·i386_set_ldt(SB)
   313  
   314  	// compute segment selector - (entry*8+7)
   315  	SHLL	$3, AX
   316  	ADDL	$7, AX
   317  	MOVW	AX, GS
   318  	RET
   319  
   320  TEXT runtime·i386_set_ldt(SB),NOSPLIT,$16
   321  	LEAL	args+0(FP), AX	// 0(FP) == 4(SP) before SP got moved
   322  	MOVL	$0, 0(SP)	// syscall gap
   323  	MOVL	$1, 4(SP)
   324  	MOVL	AX, 8(SP)
   325  	MOVL	$165, AX
   326  	INT	$0x80
   327  	JAE	2(PC)
   328  	INT	$3
   329  	RET
   330  
   331  TEXT runtime·sysctl(SB),NOSPLIT,$28
   332  	LEAL	mib+0(FP), SI
   333  	LEAL	4(SP), DI
   334  	CLD
   335  	MOVSL				// arg 1 - name
   336  	MOVSL				// arg 2 - namelen
   337  	MOVSL				// arg 3 - oldp
   338  	MOVSL				// arg 4 - oldlenp
   339  	MOVSL				// arg 5 - newp
   340  	MOVSL				// arg 6 - newlen
   341  	MOVL	$202, AX		// sys___sysctl
   342  	INT	$0x80
   343  	JAE	4(PC)
   344  	NEGL	AX
   345  	MOVL	AX, ret+24(FP)
   346  	RET
   347  	MOVL	$0, AX
   348  	MOVL	AX, ret+24(FP)
   349  	RET
   350  
   351  TEXT runtime·osyield(SB),NOSPLIT,$-4
   352  	MOVL	$331, AX		// sys_sched_yield
   353  	INT	$0x80
   354  	RET
   355  
   356  TEXT runtime·sigprocmask(SB),NOSPLIT,$16
   357  	MOVL	$0, 0(SP)		// syscall gap
   358  	MOVL	$3, 4(SP)		// arg 1 - how (SIG_SETMASK)
   359  	MOVL	new+0(FP), AX
   360  	MOVL	AX, 8(SP)		// arg 2 - set
   361  	MOVL	old+4(FP), AX
   362  	MOVL	AX, 12(SP)		// arg 3 - oset
   363  	MOVL	$340, AX		// sys_sigprocmask
   364  	INT	$0x80
   365  	JAE	2(PC)
   366  	MOVL	$0xf1, 0xf1  // crash
   367  	RET
   368  
   369  // int32 runtime·kqueue(void);
   370  TEXT runtime·kqueue(SB),NOSPLIT,$0
   371  	MOVL	$362, AX
   372  	INT	$0x80
   373  	JAE	2(PC)
   374  	NEGL	AX
   375  	MOVL	AX, ret+0(FP)
   376  	RET
   377  
   378  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   379  TEXT runtime·kevent(SB),NOSPLIT,$0
   380  	MOVL	$363, AX
   381  	INT	$0x80
   382  	JAE	2(PC)
   383  	NEGL	AX
   384  	MOVL	AX, ret+24(FP)
   385  	RET
   386  
   387  // int32 runtime·closeonexec(int32 fd);
   388  TEXT runtime·closeonexec(SB),NOSPLIT,$32
   389  	MOVL	$92, AX		// fcntl
   390  	// 0(SP) is where the caller PC would be; kernel skips it
   391  	MOVL	fd+0(FP), BX
   392  	MOVL	BX, 4(SP)	// fd
   393  	MOVL	$2, 8(SP)	// F_SETFD
   394  	MOVL	$1, 12(SP)	// FD_CLOEXEC
   395  	INT	$0x80
   396  	JAE	2(PC)
   397  	NEGL	AX
   398  	RET
   399  
   400  GLOBL runtime·tlsoffset(SB),NOPTR,$4