...
Run Format

Text file src/runtime/sys_netbsd_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, NetBSD
     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	// Exit the entire program (like C exit)
    14	TEXT runtime·exit(SB),NOSPLIT,$-4
    15		MOVL	$1, AX
    16		INT	$0x80
    17		MOVL	$0xf1, 0xf1		// crash
    18		RET
    19	
    20	// func exitThread(wait *uint32)
    21	TEXT runtime·exitThread(SB),NOSPLIT,$0-4
    22		MOVL	wait+0(FP), AX
    23		// We're done using the stack.
    24		MOVL	$0, (AX)
    25		MOVL	$310, AX		// sys__lwp_exit
    26		INT	$0x80
    27		MOVL	$0xf1, 0xf1		// crash
    28		JMP	0(PC)
    29	
    30	TEXT runtime·open(SB),NOSPLIT,$-4
    31		MOVL	$5, AX
    32		INT	$0x80
    33		JAE	2(PC)
    34		MOVL	$-1, AX
    35		MOVL	AX, ret+12(FP)
    36		RET
    37	
    38	TEXT runtime·closefd(SB),NOSPLIT,$-4
    39		MOVL	$6, AX
    40		INT	$0x80
    41		JAE	2(PC)
    42		MOVL	$-1, AX
    43		MOVL	AX, ret+4(FP)
    44		RET
    45	
    46	TEXT runtime·read(SB),NOSPLIT,$-4
    47		MOVL	$3, AX
    48		INT	$0x80
    49		JAE	2(PC)
    50		MOVL	$-1, AX
    51		MOVL	AX, ret+12(FP)
    52		RET
    53	
    54	TEXT runtime·write(SB),NOSPLIT,$-4
    55		MOVL	$4, AX			// sys_write
    56		INT	$0x80
    57		JAE	2(PC)
    58		MOVL	$-1, AX
    59		MOVL	AX, ret+12(FP)
    60		RET
    61	
    62	TEXT runtime·usleep(SB),NOSPLIT,$24
    63		MOVL	$0, DX
    64		MOVL	usec+0(FP), AX
    65		MOVL	$1000000, CX
    66		DIVL	CX
    67		MOVL	AX, 12(SP)		// tv_sec - l32
    68		MOVL	$0, 16(SP)		// tv_sec - h32
    69		MOVL	$1000, AX
    70		MULL	DX
    71		MOVL	AX, 20(SP)		// tv_nsec
    72	
    73		MOVL	$0, 0(SP)
    74		LEAL	12(SP), AX
    75		MOVL	AX, 4(SP)		// arg 1 - rqtp
    76		MOVL	$0, 8(SP)		// arg 2 - rmtp
    77		MOVL	$430, AX		// sys_nanosleep
    78		INT	$0x80
    79		RET
    80	
    81	TEXT runtime·raise(SB),NOSPLIT,$12
    82		MOVL	$311, AX		// sys__lwp_self
    83		INT	$0x80
    84		MOVL	$0, 0(SP)
    85		MOVL	AX, 4(SP)		// arg 1 - target
    86		MOVL	sig+0(FP), AX
    87		MOVL	AX, 8(SP)		// arg 2 - signo
    88		MOVL	$318, AX		// sys__lwp_kill
    89		INT	$0x80
    90		RET
    91	
    92	TEXT runtime·raiseproc(SB),NOSPLIT,$12
    93		MOVL	$20, AX			// sys_getpid
    94		INT	$0x80
    95		MOVL	$0, 0(SP)
    96		MOVL	AX, 4(SP)		// arg 1 - pid
    97		MOVL	sig+0(FP), AX
    98		MOVL	AX, 8(SP)		// arg 2 - signo
    99		MOVL	$37, AX			// sys_kill
   100		INT	$0x80
   101		RET
   102	
   103	TEXT runtime·mmap(SB),NOSPLIT,$36
   104		LEAL	addr+0(FP), SI
   105		LEAL	4(SP), DI
   106		CLD
   107		MOVSL				// arg 1 - addr
   108		MOVSL				// arg 2 - len
   109		MOVSL				// arg 3 - prot
   110		MOVSL				// arg 4 - flags
   111		MOVSL				// arg 5 - fd
   112		MOVL	$0, AX
   113		STOSL				// arg 6 - pad
   114		MOVSL				// arg 7 - offset
   115		MOVL	$0, AX			// top 32 bits of file offset
   116		STOSL
   117		MOVL	$197, AX		// sys_mmap
   118		INT	$0x80
   119		JAE	ok
   120		MOVL	$0, p+24(FP)
   121		MOVL	AX, err+28(FP)
   122		RET
   123	ok:
   124		MOVL	AX, p+24(FP)
   125		MOVL	$0, err+28(FP)
   126		RET
   127	
   128	TEXT runtime·munmap(SB),NOSPLIT,$-4
   129		MOVL	$73, AX			// sys_munmap
   130		INT	$0x80
   131		JAE	2(PC)
   132		MOVL	$0xf1, 0xf1		// crash
   133		RET
   134	
   135	TEXT runtime·madvise(SB),NOSPLIT,$-4
   136		MOVL	$75, AX			// sys_madvise
   137		INT	$0x80
   138		// ignore failure - maybe pages are locked
   139		RET
   140	
   141	TEXT runtime·setitimer(SB),NOSPLIT,$-4
   142		MOVL	$425, AX		// sys_setitimer
   143		INT	$0x80
   144		RET
   145	
   146	// func walltime() (sec int64, nsec int32)
   147	TEXT runtime·walltime(SB), NOSPLIT, $32
   148		LEAL	12(SP), BX
   149		MOVL	$0, 4(SP)		// arg 1 - clock_id
   150		MOVL	BX, 8(SP)		// arg 2 - tp
   151		MOVL	$427, AX		// sys_clock_gettime
   152		INT	$0x80
   153	
   154		MOVL	12(SP), AX		// sec - l32
   155		MOVL	AX, sec_lo+0(FP)
   156		MOVL	16(SP), AX		// sec - h32
   157		MOVL	AX, sec_hi+4(FP)
   158	
   159		MOVL	20(SP), BX		// nsec
   160		MOVL	BX, nsec+8(FP)
   161		RET
   162	
   163	// int64 nanotime(void) so really
   164	// void nanotime(int64 *nsec)
   165	TEXT runtime·nanotime(SB),NOSPLIT,$32
   166		LEAL	12(SP), BX
   167		MOVL	$3, 4(SP)		// arg 1 - clock_id CLOCK_MONOTONIC
   168		MOVL	BX, 8(SP)		// arg 2 - tp
   169		MOVL	$427, AX		// sys_clock_gettime
   170		INT	$0x80
   171	
   172		MOVL	16(SP), CX		// sec - h32
   173		IMULL	$1000000000, CX
   174	
   175		MOVL	12(SP), AX		// sec - l32
   176		MOVL	$1000000000, BX
   177		MULL	BX			// result in dx:ax
   178	
   179		MOVL	20(SP), BX		// nsec
   180		ADDL	BX, AX
   181		ADCL	CX, DX			// add high bits with carry
   182	
   183		MOVL	AX, ret_lo+0(FP)
   184		MOVL	DX, ret_hi+4(FP)
   185		RET
   186	
   187	TEXT runtime·getcontext(SB),NOSPLIT,$-4
   188		MOVL	$307, AX		// sys_getcontext
   189		INT	$0x80
   190		JAE	2(PC)
   191		MOVL	$0xf1, 0xf1		// crash
   192		RET
   193	
   194	TEXT runtime·sigprocmask(SB),NOSPLIT,$-4
   195		MOVL	$293, AX		// sys_sigprocmask
   196		INT	$0x80
   197		JAE	2(PC)
   198		MOVL	$0xf1, 0xf1		// crash
   199		RET
   200	
   201	TEXT runtime·sigreturn_tramp(SB),NOSPLIT,$0
   202		LEAL	140(SP), AX		// Load address of ucontext
   203		MOVL	AX, 4(SP)
   204		MOVL	$308, AX		// sys_setcontext
   205		INT	$0x80
   206		MOVL	$-1, 4(SP)		// Something failed...
   207		MOVL	$1, AX			// sys_exit
   208		INT	$0x80
   209	
   210	TEXT runtime·sigaction(SB),NOSPLIT,$24
   211		LEAL	sig+0(FP), SI
   212		LEAL	4(SP), DI
   213		CLD
   214		MOVSL				// arg 1 - sig
   215		MOVSL				// arg 2 - act
   216		MOVSL				// arg 3 - oact
   217		LEAL	runtime·sigreturn_tramp(SB), AX
   218		STOSL				// arg 4 - tramp
   219		MOVL	$2, AX
   220		STOSL				// arg 5 - vers
   221		MOVL	$340, AX		// sys___sigaction_sigtramp
   222		INT	$0x80
   223		JAE	2(PC)
   224		MOVL	$0xf1, 0xf1		// crash
   225		RET
   226	
   227	TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   228		MOVL	fn+0(FP), AX
   229		MOVL	sig+4(FP), BX
   230		MOVL	info+8(FP), CX
   231		MOVL	ctx+12(FP), DX
   232		MOVL	SP, SI
   233		SUBL	$32, SP
   234		ANDL	$-15, SP	// align stack: handler might be a C function
   235		MOVL	BX, 0(SP)
   236		MOVL	CX, 4(SP)
   237		MOVL	DX, 8(SP)
   238		MOVL	SI, 12(SP)	// save SI: handler might be a Go function
   239		CALL	AX
   240		MOVL	12(SP), AX
   241		MOVL	AX, SP
   242		RET
   243	
   244	TEXT runtime·sigtramp(SB),NOSPLIT,$28
   245		// Save callee-saved C registers, since the caller may be a C signal handler.
   246		MOVL	BX, bx-4(SP)
   247		MOVL	BP, bp-8(SP)
   248		MOVL	SI, si-12(SP)
   249		MOVL	DI, di-16(SP)
   250		// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   251		// modify them.
   252	
   253		MOVL	signo+0(FP), BX
   254		MOVL	BX, 0(SP)
   255		MOVL	info+4(FP), BX
   256		MOVL	BX, 4(SP)
   257		MOVL	context+8(FP), BX
   258		MOVL	BX, 8(SP)
   259		CALL	runtime·sigtrampgo(SB)
   260	
   261		MOVL	di-16(SP), DI
   262		MOVL	si-12(SP), SI
   263		MOVL	bp-8(SP),  BP
   264		MOVL	bx-4(SP),  BX
   265		RET
   266	
   267	// int32 lwp_create(void *context, uintptr flags, void *lwpid);
   268	TEXT runtime·lwp_create(SB),NOSPLIT,$16
   269		MOVL	$0, 0(SP)
   270		MOVL	ctxt+0(FP), AX
   271		MOVL	AX, 4(SP)		// arg 1 - context
   272		MOVL	flags+4(FP), AX
   273		MOVL	AX, 8(SP)		// arg 2 - flags
   274		MOVL	lwpid+8(FP), AX
   275		MOVL	AX, 12(SP)		// arg 3 - lwpid
   276		MOVL	$309, AX		// sys__lwp_create
   277		INT	$0x80
   278		JCC	2(PC)
   279		NEGL	AX
   280		MOVL	AX, ret+12(FP)
   281		RET
   282	
   283	TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
   284	
   285		// Set FS to point at m->tls
   286		LEAL	m_tls(BX), BP
   287		PUSHAL				// save registers
   288		PUSHL	BP
   289		CALL	runtime·settls(SB)
   290		POPL	AX
   291		POPAL
   292	
   293		// Now segment is established. Initialize m, g.
   294		get_tls(AX)
   295		MOVL	DX, g(AX)
   296		MOVL	BX, g_m(DX)
   297	
   298		CALL	runtime·stackcheck(SB)	// smashes AX, CX
   299		MOVL	0(DX), DX		// paranoia; check they are not nil
   300		MOVL	0(BX), BX
   301	
   302		// more paranoia; check that stack splitting code works
   303		PUSHAL
   304		CALL	runtime·emptyfunc(SB)
   305		POPAL
   306	
   307		// Call fn
   308		CALL	SI
   309	
   310		// fn should never return
   311		MOVL	$0x1234, 0x1005
   312		RET
   313	
   314	TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   315		MOVL	$281, AX		// sys___sigaltstack14
   316		MOVL	new+0(FP), BX
   317		MOVL	old+4(FP), CX
   318		INT	$0x80
   319		CMPL	AX, $0xfffff001
   320		JLS	2(PC)
   321		INT	$3
   322		RET
   323	
   324	TEXT runtime·setldt(SB),NOSPLIT,$8
   325		// Under NetBSD we set the GS base instead of messing with the LDT.
   326		MOVL	16(SP), AX		// tls0
   327		MOVL	AX, 0(SP)
   328		CALL	runtime·settls(SB)
   329		RET
   330	
   331	TEXT runtime·settls(SB),NOSPLIT,$16
   332		// adjust for ELF: wants to use -4(GS) for g
   333		MOVL	base+0(FP), CX
   334		ADDL	$4, CX
   335		MOVL	$0, 0(SP)		// syscall gap
   336		MOVL	CX, 4(SP)		// arg 1 - ptr
   337		MOVL	$317, AX		// sys__lwp_setprivate
   338		INT	$0x80
   339		JCC	2(PC)
   340		MOVL	$0xf1, 0xf1		// crash
   341		RET
   342	
   343	TEXT runtime·osyield(SB),NOSPLIT,$-4
   344		MOVL	$350, AX		// sys_sched_yield
   345		INT	$0x80
   346		RET
   347	
   348	TEXT runtime·lwp_park(SB),NOSPLIT,$-4
   349		MOVL	$478, AX		// sys__lwp_park
   350		INT	$0x80
   351		MOVL	AX, ret+24(FP)
   352		RET
   353	
   354	TEXT runtime·lwp_unpark(SB),NOSPLIT,$-4
   355		MOVL	$321, AX		// sys__lwp_unpark
   356		INT	$0x80
   357		MOVL	AX, ret+8(FP)
   358		RET
   359	
   360	TEXT runtime·lwp_self(SB),NOSPLIT,$-4
   361		MOVL	$311, AX		// sys__lwp_self
   362		INT	$0x80
   363		MOVL	AX, ret+0(FP)
   364		RET
   365	
   366	TEXT runtime·sysctl(SB),NOSPLIT,$28
   367		LEAL	mib+0(FP), SI
   368		LEAL	4(SP), DI
   369		CLD
   370		MOVSL				// arg 1 - name
   371		MOVSL				// arg 2 - namelen
   372		MOVSL				// arg 3 - oldp
   373		MOVSL				// arg 4 - oldlenp
   374		MOVSL				// arg 5 - newp
   375		MOVSL				// arg 6 - newlen
   376		MOVL	$202, AX		// sys___sysctl
   377		INT	$0x80
   378		JAE	4(PC)
   379		NEGL	AX
   380		MOVL	AX, ret+24(FP)
   381		RET
   382		MOVL	$0, AX
   383		MOVL	AX, ret+24(FP)
   384		RET
   385	
   386	GLOBL runtime·tlsoffset(SB),NOPTR,$4
   387	
   388	// int32 runtime·kqueue(void)
   389	TEXT runtime·kqueue(SB),NOSPLIT,$0
   390		MOVL	$344, AX
   391		INT	$0x80
   392		JAE	2(PC)
   393		NEGL	AX
   394		MOVL	AX, ret+0(FP)
   395		RET
   396	
   397	// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   398	TEXT runtime·kevent(SB),NOSPLIT,$0
   399		MOVL	$435, AX
   400		INT	$0x80
   401		JAE	2(PC)
   402		NEGL	AX
   403		MOVL	AX, ret+24(FP)
   404		RET
   405	
   406	// int32 runtime·closeonexec(int32 fd)
   407	TEXT runtime·closeonexec(SB),NOSPLIT,$32
   408		MOVL	$92, AX		// fcntl
   409		// 0(SP) is where the caller PC would be; kernel skips it
   410		MOVL	fd+0(FP), BX
   411		MOVL	BX, 4(SP)	// fd
   412		MOVL	$2, 8(SP)	// F_SETFD
   413		MOVL	$1, 12(SP)	// FD_CLOEXEC
   414		INT	$0x80
   415		JAE	2(PC)
   416		NEGL	AX
   417		RET

View as plain text