...
Run Format

Text file src/runtime/sys_freebsd_386.s

Documentation: runtime

     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	m_id(AX), 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·raiseproc(SB),NOSPLIT,$16
   116		// getpid
   117		MOVL	$20, AX
   118		INT	$0x80
   119		// kill(self, sig)
   120		MOVL	AX, 4(SP)
   121		MOVL	sig+0(FP), AX
   122		MOVL	AX, 8(SP)
   123		MOVL	$37, AX
   124		INT	$0x80
   125		RET
   126	
   127	TEXT runtime·mmap(SB),NOSPLIT,$32
   128		LEAL addr+0(FP), SI
   129		LEAL	4(SP), DI
   130		CLD
   131		MOVSL
   132		MOVSL
   133		MOVSL
   134		MOVSL
   135		MOVSL
   136		MOVSL
   137		MOVL	$0, AX	// top 32 bits of file offset
   138		STOSL
   139		MOVL	$477, AX
   140		INT	$0x80
   141		MOVL	AX, ret+24(FP)
   142		RET
   143	
   144	TEXT runtime·munmap(SB),NOSPLIT,$-4
   145		MOVL	$73, AX
   146		INT	$0x80
   147		JAE	2(PC)
   148		MOVL	$0xf1, 0xf1  // crash
   149		RET
   150	
   151	TEXT runtime·madvise(SB),NOSPLIT,$-4
   152		MOVL	$75, AX	// madvise
   153		INT	$0x80
   154		// ignore failure - maybe pages are locked
   155		RET
   156	
   157	TEXT runtime·setitimer(SB), NOSPLIT, $-4
   158		MOVL	$83, AX
   159		INT	$0x80
   160		RET
   161	
   162	// func walltime() (sec int64, nsec int32)
   163	TEXT runtime·walltime(SB), NOSPLIT, $32
   164		MOVL	$232, AX // clock_gettime
   165		LEAL	12(SP), BX
   166		MOVL	$0, 4(SP)	// CLOCK_REALTIME
   167		MOVL	BX, 8(SP)
   168		INT	$0x80
   169		MOVL	12(SP), AX	// sec
   170		MOVL	16(SP), BX	// nsec
   171	
   172		// sec is in AX, nsec in BX
   173		MOVL	AX, sec_lo+0(FP)
   174		MOVL	$0, sec_hi+4(FP)
   175		MOVL	BX, nsec+8(FP)
   176		RET
   177	
   178	// int64 nanotime(void) so really
   179	// void nanotime(int64 *nsec)
   180	TEXT runtime·nanotime(SB), NOSPLIT, $32
   181		MOVL	$232, AX
   182		LEAL	12(SP), BX
   183		// We can use CLOCK_MONOTONIC_FAST here when we drop
   184		// support for FreeBSD 8-STABLE.
   185		MOVL	$4, 4(SP)	// CLOCK_MONOTONIC
   186		MOVL	BX, 8(SP)
   187		INT	$0x80
   188		MOVL	12(SP), AX	// sec
   189		MOVL	16(SP), BX	// nsec
   190	
   191		// sec is in AX, nsec in BX
   192		// convert to DX:AX nsec
   193		MOVL	$1000000000, CX
   194		MULL	CX
   195		ADDL	BX, AX
   196		ADCL	$0, DX
   197	
   198		MOVL	AX, ret_lo+0(FP)
   199		MOVL	DX, ret_hi+4(FP)
   200		RET
   201	
   202	
   203	TEXT runtime·sigaction(SB),NOSPLIT,$-4
   204		MOVL	$416, AX
   205		INT	$0x80
   206		JAE	2(PC)
   207		MOVL	$0xf1, 0xf1  // crash
   208		RET
   209	
   210	TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   211		MOVL	fn+0(FP), AX
   212		MOVL	sig+4(FP), BX
   213		MOVL	info+8(FP), CX
   214		MOVL	ctx+12(FP), DX
   215		MOVL	SP, SI
   216		SUBL	$32, SP
   217		ANDL	$~15, SP	// align stack: handler might be a C function
   218		MOVL	BX, 0(SP)
   219		MOVL	CX, 4(SP)
   220		MOVL	DX, 8(SP)
   221		MOVL	SI, 12(SP)	// save SI: handler might be a Go function
   222		CALL	AX
   223		MOVL	12(SP), AX
   224		MOVL	AX, SP
   225		RET
   226	
   227	TEXT runtime·sigtramp(SB),NOSPLIT,$12
   228		MOVL	signo+0(FP), BX
   229		MOVL	BX, 0(SP)
   230		MOVL	info+4(FP), BX
   231		MOVL	BX, 4(SP)
   232		MOVL	context+8(FP), BX
   233		MOVL	BX, 8(SP)
   234		CALL	runtime·sigtrampgo(SB)
   235	
   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	how+0(FP), AX		// arg 1 - how
   359		MOVL	AX, 4(SP)
   360		MOVL	new+4(FP), AX
   361		MOVL	AX, 8(SP)		// arg 2 - set
   362		MOVL	old+8(FP), AX
   363		MOVL	AX, 12(SP)		// arg 3 - oset
   364		MOVL	$340, AX		// sys_sigprocmask
   365		INT	$0x80
   366		JAE	2(PC)
   367		MOVL	$0xf1, 0xf1  // crash
   368		RET
   369	
   370	// int32 runtime·kqueue(void);
   371	TEXT runtime·kqueue(SB),NOSPLIT,$0
   372		MOVL	$362, AX
   373		INT	$0x80
   374		JAE	2(PC)
   375		NEGL	AX
   376		MOVL	AX, ret+0(FP)
   377		RET
   378	
   379	// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   380	TEXT runtime·kevent(SB),NOSPLIT,$0
   381		MOVL	$363, AX
   382		INT	$0x80
   383		JAE	2(PC)
   384		NEGL	AX
   385		MOVL	AX, ret+24(FP)
   386		RET
   387	
   388	// int32 runtime·closeonexec(int32 fd);
   389	TEXT runtime·closeonexec(SB),NOSPLIT,$32
   390		MOVL	$92, AX		// fcntl
   391		// 0(SP) is where the caller PC would be; kernel skips it
   392		MOVL	fd+0(FP), BX
   393		MOVL	BX, 4(SP)	// fd
   394		MOVL	$2, 8(SP)	// F_SETFD
   395		MOVL	$1, 12(SP)	// FD_CLOEXEC
   396		INT	$0x80
   397		JAE	2(PC)
   398		NEGL	AX
   399		RET
   400	
   401	// func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
   402	TEXT runtime·cpuset_getaffinity(SB), NOSPLIT, $0-28
   403		MOVL	$487, AX
   404		INT	$0x80
   405		JAE	2(PC)
   406		NEGL	AX
   407		MOVL	AX, ret+24(FP)
   408		RET
   409	
   410	GLOBL runtime·tlsoffset(SB),NOPTR,$4

View as plain text