Text file src/runtime/sys_freebsd_386.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 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  	JAE	2(PC)
    17  	NEGL	AX
    18  	MOVL	AX, ret+20(FP)
    19  	RET
    20  
    21  TEXT runtime·thr_new(SB),NOSPLIT,$-4
    22  	MOVL	$455, AX
    23  	INT	$0x80
    24  	JAE	2(PC)
    25  	NEGL	AX
    26  	MOVL	AX, ret+8(FP)
    27  	RET
    28  
    29  // Called by OS using C ABI.
    30  TEXT runtime·thr_start(SB),NOSPLIT,$0
    31  	NOP	SP	// tell vet SP changed - stop checking offsets
    32  	MOVL	4(SP), AX // m
    33  	MOVL	m_g0(AX), BX
    34  	LEAL	m_tls(AX), BP
    35  	MOVL	m_id(AX), DI
    36  	ADDL	$7, DI
    37  	PUSHAL
    38  	PUSHL	$32
    39  	PUSHL	BP
    40  	PUSHL	DI
    41  	CALL	runtime·setldt(SB)
    42  	POPL	AX
    43  	POPL	AX
    44  	POPL	AX
    45  	POPAL
    46  	get_tls(CX)
    47  	MOVL	BX, g(CX)
    48  
    49  	MOVL	AX, g_m(BX)
    50  	CALL	runtime·stackcheck(SB)		// smashes AX
    51  	CALL	runtime·mstart(SB)
    52  
    53  	MOVL	0, AX			// crash (not reached)
    54  
    55  // Exit the entire program (like C exit)
    56  TEXT runtime·exit(SB),NOSPLIT,$-4
    57  	MOVL	$1, AX
    58  	INT	$0x80
    59  	MOVL	$0xf1, 0xf1  // crash
    60  	RET
    61  
    62  GLOBL exitStack<>(SB),RODATA,$8
    63  DATA exitStack<>+0x00(SB)/4, $0
    64  DATA exitStack<>+0x04(SB)/4, $0
    65  
    66  // func exitThread(wait *uint32)
    67  TEXT runtime·exitThread(SB),NOSPLIT,$0-4
    68  	MOVL	wait+0(FP), AX
    69  	// We're done using the stack.
    70  	MOVL	$0, (AX)
    71  	// thr_exit takes a single pointer argument, which it expects
    72  	// on the stack. We want to pass 0, so switch over to a fake
    73  	// stack of 0s. It won't write to the stack.
    74  	MOVL	$exitStack<>(SB), SP
    75  	MOVL	$431, AX	// thr_exit
    76  	INT	$0x80
    77  	MOVL	$0xf1, 0xf1  // crash
    78  	JMP	0(PC)
    79  
    80  TEXT runtime·open(SB),NOSPLIT,$-4
    81  	MOVL	$5, AX
    82  	INT	$0x80
    83  	JAE	2(PC)
    84  	MOVL	$-1, AX
    85  	MOVL	AX, ret+12(FP)
    86  	RET
    87  
    88  TEXT runtime·closefd(SB),NOSPLIT,$-4
    89  	MOVL	$6, AX
    90  	INT	$0x80
    91  	JAE	2(PC)
    92  	MOVL	$-1, AX
    93  	MOVL	AX, ret+4(FP)
    94  	RET
    95  
    96  TEXT runtime·read(SB),NOSPLIT,$-4
    97  	MOVL	$3, AX
    98  	INT	$0x80
    99  	JAE	2(PC)
   100  	NEGL	AX			// caller expects negative errno
   101  	MOVL	AX, ret+12(FP)
   102  	RET
   103  
   104  // func pipe2(flags int32) (r, w int32, errno int32)
   105  TEXT runtime·pipe2(SB),NOSPLIT,$12-16
   106  	MOVL	$542, AX
   107  	LEAL	r+4(FP), BX
   108  	MOVL	BX, 4(SP)
   109  	MOVL	flags+0(FP), BX
   110  	MOVL	BX, 8(SP)
   111  	INT	$0x80
   112  	JAE	2(PC)
   113  	NEGL	AX
   114  	MOVL	AX, errno+12(FP)
   115  	RET
   116  
   117  TEXT runtime·write1(SB),NOSPLIT,$-4
   118  	MOVL	$4, AX
   119  	INT	$0x80
   120  	JAE	2(PC)
   121  	NEGL	AX			// caller expects negative errno
   122  	MOVL	AX, ret+12(FP)
   123  	RET
   124  
   125  TEXT runtime·thr_self(SB),NOSPLIT,$8-4
   126  	// thr_self(&0(FP))
   127  	LEAL	ret+0(FP), AX
   128  	MOVL	AX, 4(SP)
   129  	MOVL	$432, AX
   130  	INT	$0x80
   131  	RET
   132  
   133  TEXT runtime·thr_kill(SB),NOSPLIT,$-4
   134  	// thr_kill(tid, sig)
   135  	MOVL	$433, AX
   136  	INT	$0x80
   137  	RET
   138  
   139  TEXT runtime·raiseproc(SB),NOSPLIT,$16
   140  	// getpid
   141  	MOVL	$20, AX
   142  	INT	$0x80
   143  	// kill(self, sig)
   144  	MOVL	AX, 4(SP)
   145  	MOVL	sig+0(FP), AX
   146  	MOVL	AX, 8(SP)
   147  	MOVL	$37, AX
   148  	INT	$0x80
   149  	RET
   150  
   151  TEXT runtime·mmap(SB),NOSPLIT,$32
   152  	LEAL addr+0(FP), SI
   153  	LEAL	4(SP), DI
   154  	CLD
   155  	MOVSL
   156  	MOVSL
   157  	MOVSL
   158  	MOVSL
   159  	MOVSL
   160  	MOVSL
   161  	MOVL	$0, AX	// top 32 bits of file offset
   162  	STOSL
   163  	MOVL	$477, AX
   164  	INT	$0x80
   165  	JAE	ok
   166  	MOVL	$0, p+24(FP)
   167  	MOVL	AX, err+28(FP)
   168  	RET
   169  ok:
   170  	MOVL	AX, p+24(FP)
   171  	MOVL	$0, err+28(FP)
   172  	RET
   173  
   174  TEXT runtime·munmap(SB),NOSPLIT,$-4
   175  	MOVL	$73, AX
   176  	INT	$0x80
   177  	JAE	2(PC)
   178  	MOVL	$0xf1, 0xf1  // crash
   179  	RET
   180  
   181  TEXT runtime·madvise(SB),NOSPLIT,$-4
   182  	MOVL	$75, AX	// madvise
   183  	INT	$0x80
   184  	JAE	2(PC)
   185  	MOVL	$-1, AX
   186  	MOVL	AX, ret+12(FP)
   187  	RET
   188  
   189  TEXT runtime·setitimer(SB), NOSPLIT, $-4
   190  	MOVL	$83, AX
   191  	INT	$0x80
   192  	RET
   193  
   194  // func fallback_walltime() (sec int64, nsec int32)
   195  TEXT runtime·fallback_walltime(SB), NOSPLIT, $32-12
   196  	MOVL	$232, AX // clock_gettime
   197  	LEAL	12(SP), BX
   198  	MOVL	$0, 4(SP)	// CLOCK_REALTIME
   199  	MOVL	BX, 8(SP)
   200  	INT	$0x80
   201  	MOVL	12(SP), AX	// sec
   202  	MOVL	16(SP), BX	// nsec
   203  
   204  	// sec is in AX, nsec in BX
   205  	MOVL	AX, sec_lo+0(FP)
   206  	MOVL	$0, sec_hi+4(FP)
   207  	MOVL	BX, nsec+8(FP)
   208  	RET
   209  
   210  // func fallback_nanotime() int64
   211  TEXT runtime·fallback_nanotime(SB), NOSPLIT, $32-8
   212  	MOVL	$232, AX
   213  	LEAL	12(SP), BX
   214  	MOVL	$4, 4(SP)	// CLOCK_MONOTONIC
   215  	MOVL	BX, 8(SP)
   216  	INT	$0x80
   217  	MOVL	12(SP), AX	// sec
   218  	MOVL	16(SP), BX	// nsec
   219  
   220  	// sec is in AX, nsec in BX
   221  	// convert to DX:AX nsec
   222  	MOVL	$1000000000, CX
   223  	MULL	CX
   224  	ADDL	BX, AX
   225  	ADCL	$0, DX
   226  
   227  	MOVL	AX, ret_lo+0(FP)
   228  	MOVL	DX, ret_hi+4(FP)
   229  	RET
   230  
   231  
   232  TEXT runtime·asmSigaction(SB),NOSPLIT,$-4
   233  	MOVL	$416, AX
   234  	INT	$0x80
   235  	MOVL	AX, ret+12(FP)
   236  	RET
   237  
   238  TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   239  	MOVL	fn+0(FP), AX
   240  	MOVL	sig+4(FP), BX
   241  	MOVL	info+8(FP), CX
   242  	MOVL	ctx+12(FP), DX
   243  	MOVL	SP, SI
   244  	SUBL	$32, SP
   245  	ANDL	$~15, SP	// align stack: handler might be a C function
   246  	MOVL	BX, 0(SP)
   247  	MOVL	CX, 4(SP)
   248  	MOVL	DX, 8(SP)
   249  	MOVL	SI, 12(SP)	// save SI: handler might be a Go function
   250  	CALL	AX
   251  	MOVL	12(SP), AX
   252  	MOVL	AX, SP
   253  	RET
   254  
   255  // Called by OS using C ABI.
   256  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$12
   257  	NOP	SP	// tell vet SP changed - stop checking offsets
   258  	MOVL	16(SP), BX	// signo
   259  	MOVL	BX, 0(SP)
   260  	MOVL	20(SP), BX // info
   261  	MOVL	BX, 4(SP)
   262  	MOVL	24(SP), BX // context
   263  	MOVL	BX, 8(SP)
   264  	CALL	runtime·sigtrampgo(SB)
   265  
   266  	// call sigreturn
   267  	MOVL	24(SP), AX	// context
   268  	MOVL	$0, 0(SP)	// syscall gap
   269  	MOVL	AX, 4(SP)
   270  	MOVL	$417, AX	// sigreturn(ucontext)
   271  	INT	$0x80
   272  	MOVL	$0xf1, 0xf1  // crash
   273  	RET
   274  
   275  TEXT runtime·sigaltstack(SB),NOSPLIT,$0
   276  	MOVL	$53, AX
   277  	INT	$0x80
   278  	JAE	2(PC)
   279  	MOVL	$0xf1, 0xf1  // crash
   280  	RET
   281  
   282  TEXT runtime·usleep(SB),NOSPLIT,$20
   283  	MOVL	$0, DX
   284  	MOVL	usec+0(FP), AX
   285  	MOVL	$1000000, CX
   286  	DIVL	CX
   287  	MOVL	AX, 12(SP)		// tv_sec
   288  	MOVL	$1000, AX
   289  	MULL	DX
   290  	MOVL	AX, 16(SP)		// tv_nsec
   291  
   292  	MOVL	$0, 0(SP)
   293  	LEAL	12(SP), AX
   294  	MOVL	AX, 4(SP)		// arg 1 - rqtp
   295  	MOVL	$0, 8(SP)		// arg 2 - rmtp
   296  	MOVL	$240, AX		// sys_nanosleep
   297  	INT	$0x80
   298  	RET
   299  
   300  /*
   301  descriptor entry format for system call
   302  is the native machine format, ugly as it is:
   303  
   304  	2-byte limit
   305  	3-byte base
   306  	1-byte: 0x80=present, 0x60=dpl<<5, 0x1F=type
   307  	1-byte: 0x80=limit is *4k, 0x40=32-bit operand size,
   308  		0x0F=4 more bits of limit
   309  	1 byte: 8 more bits of base
   310  
   311  int i386_get_ldt(int, union ldt_entry *, int);
   312  int i386_set_ldt(int, const union ldt_entry *, int);
   313  
   314  */
   315  
   316  // setldt(int entry, int address, int limit)
   317  TEXT runtime·setldt(SB),NOSPLIT,$32
   318  	MOVL	base+4(FP), BX
   319  	// see comment in sys_linux_386.s; freebsd is similar
   320  	ADDL	$0x4, BX
   321  
   322  	// set up data_desc
   323  	LEAL	16(SP), AX	// struct data_desc
   324  	MOVL	$0, 0(AX)
   325  	MOVL	$0, 4(AX)
   326  
   327  	MOVW	BX, 2(AX)
   328  	SHRL	$16, BX
   329  	MOVB	BX, 4(AX)
   330  	SHRL	$8, BX
   331  	MOVB	BX, 7(AX)
   332  
   333  	MOVW	$0xffff, 0(AX)
   334  	MOVB	$0xCF, 6(AX)	// 32-bit operand, 4k limit unit, 4 more bits of limit
   335  
   336  	MOVB	$0xF2, 5(AX)	// r/w data descriptor, dpl=3, present
   337  
   338  	// call i386_set_ldt(entry, desc, 1)
   339  	MOVL	$0xffffffff, 0(SP)	// auto-allocate entry and return in AX
   340  	MOVL	AX, 4(SP)
   341  	MOVL	$1, 8(SP)
   342  	CALL	i386_set_ldt<>(SB)
   343  
   344  	// compute segment selector - (entry*8+7)
   345  	SHLL	$3, AX
   346  	ADDL	$7, AX
   347  	MOVW	AX, GS
   348  	RET
   349  
   350  TEXT i386_set_ldt<>(SB),NOSPLIT,$16
   351  	LEAL	args+0(FP), AX	// 0(FP) == 4(SP) before SP got moved
   352  	MOVL	$0, 0(SP)	// syscall gap
   353  	MOVL	$1, 4(SP)
   354  	MOVL	AX, 8(SP)
   355  	MOVL	$165, AX
   356  	INT	$0x80
   357  	JAE	2(PC)
   358  	INT	$3
   359  	RET
   360  
   361  TEXT runtime·sysctl(SB),NOSPLIT,$28
   362  	LEAL	mib+0(FP), SI
   363  	LEAL	4(SP), DI
   364  	CLD
   365  	MOVSL				// arg 1 - name
   366  	MOVSL				// arg 2 - namelen
   367  	MOVSL				// arg 3 - oldp
   368  	MOVSL				// arg 4 - oldlenp
   369  	MOVSL				// arg 5 - newp
   370  	MOVSL				// arg 6 - newlen
   371  	MOVL	$202, AX		// sys___sysctl
   372  	INT	$0x80
   373  	JAE	4(PC)
   374  	NEGL	AX
   375  	MOVL	AX, ret+24(FP)
   376  	RET
   377  	MOVL	$0, AX
   378  	MOVL	AX, ret+24(FP)
   379  	RET
   380  
   381  TEXT runtime·osyield(SB),NOSPLIT,$-4
   382  	MOVL	$331, AX		// sys_sched_yield
   383  	INT	$0x80
   384  	RET
   385  
   386  TEXT runtime·sigprocmask(SB),NOSPLIT,$16
   387  	MOVL	$0, 0(SP)		// syscall gap
   388  	MOVL	how+0(FP), AX		// arg 1 - how
   389  	MOVL	AX, 4(SP)
   390  	MOVL	new+4(FP), AX
   391  	MOVL	AX, 8(SP)		// arg 2 - set
   392  	MOVL	old+8(FP), AX
   393  	MOVL	AX, 12(SP)		// arg 3 - oset
   394  	MOVL	$340, AX		// sys_sigprocmask
   395  	INT	$0x80
   396  	JAE	2(PC)
   397  	MOVL	$0xf1, 0xf1  // crash
   398  	RET
   399  
   400  // int32 runtime·kqueue(void);
   401  TEXT runtime·kqueue(SB),NOSPLIT,$0
   402  	MOVL	$362, AX
   403  	INT	$0x80
   404  	JAE	2(PC)
   405  	NEGL	AX
   406  	MOVL	AX, ret+0(FP)
   407  	RET
   408  
   409  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   410  TEXT runtime·kevent(SB),NOSPLIT,$0
   411  	MOVL	$363, AX
   412  	INT	$0x80
   413  	JAE	2(PC)
   414  	NEGL	AX
   415  	MOVL	AX, ret+24(FP)
   416  	RET
   417  
   418  // int32 runtime·closeonexec(int32 fd);
   419  TEXT runtime·closeonexec(SB),NOSPLIT,$32
   420  	MOVL	$92, AX		// fcntl
   421  	// 0(SP) is where the caller PC would be; kernel skips it
   422  	MOVL	fd+0(FP), BX
   423  	MOVL	BX, 4(SP)	// fd
   424  	MOVL	$2, 8(SP)	// F_SETFD
   425  	MOVL	$1, 12(SP)	// FD_CLOEXEC
   426  	INT	$0x80
   427  	JAE	2(PC)
   428  	NEGL	AX
   429  	RET
   430  
   431  // func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
   432  TEXT runtime·cpuset_getaffinity(SB), NOSPLIT, $0-28
   433  	MOVL	$487, AX
   434  	INT	$0x80
   435  	JAE	2(PC)
   436  	NEGL	AX
   437  	MOVL	AX, ret+24(FP)
   438  	RET
   439  
   440  GLOBL runtime·tlsoffset(SB),NOPTR,$4
   441  

View as plain text