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

View as plain text