...
Run Format

Text file src/runtime/sys_openbsd_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, OpenBSD
     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	#define	CLOCK_MONOTONIC	$3
    14	
    15	// Exit the entire program (like C exit)
    16	TEXT runtime·exit(SB),NOSPLIT,$-4
    17		MOVL	$1, AX
    18		INT	$0x80
    19		MOVL	$0xf1, 0xf1		// crash
    20		RET
    21	
    22	// func exitThread(wait *uint32)
    23	TEXT runtime·exitThread(SB),NOSPLIT,$0-4
    24		MOVL	$302, AX		// sys___threxit
    25		INT	$0x80
    26		MOVL	$0xf1, 0xf1		// crash
    27		JMP	0(PC)
    28	
    29	TEXT runtime·open(SB),NOSPLIT,$-4
    30		MOVL	$5, AX
    31		INT	$0x80
    32		JAE	2(PC)
    33		MOVL	$-1, AX
    34		MOVL	AX, ret+12(FP)
    35		RET
    36	
    37	TEXT runtime·closefd(SB),NOSPLIT,$-4
    38		MOVL	$6, AX
    39		INT	$0x80
    40		JAE	2(PC)
    41		MOVL	$-1, AX
    42		MOVL	AX, ret+4(FP)
    43		RET
    44	
    45	TEXT runtime·read(SB),NOSPLIT,$-4
    46		MOVL	$3, AX
    47		INT	$0x80
    48		JAE	2(PC)
    49		MOVL	$-1, AX
    50		MOVL	AX, ret+12(FP)
    51		RET
    52	
    53	TEXT runtime·write(SB),NOSPLIT,$-4
    54		MOVL	$4, AX			// sys_write
    55		INT	$0x80
    56		JAE	2(PC)
    57		MOVL	$-1, AX
    58		MOVL	AX, ret+12(FP)
    59		RET
    60	
    61	TEXT runtime·usleep(SB),NOSPLIT,$24
    62		MOVL	$0, DX
    63		MOVL	usec+0(FP), AX
    64		MOVL	$1000000, CX
    65		DIVL	CX
    66		MOVL	AX, 12(SP)		// tv_sec - l32
    67		MOVL	$0, 16(SP)		// tv_sec - h32
    68		MOVL	$1000, AX
    69		MULL	DX
    70		MOVL	AX, 20(SP)		// tv_nsec
    71	
    72		MOVL	$0, 0(SP)
    73		LEAL	12(SP), AX
    74		MOVL	AX, 4(SP)		// arg 1 - rqtp
    75		MOVL	$0, 8(SP)		// arg 2 - rmtp
    76		MOVL	$91, AX			// sys_nanosleep
    77		INT	$0x80
    78		RET
    79	
    80	TEXT runtime·raise(SB),NOSPLIT,$16
    81		MOVL	$299, AX		// sys_getthrid
    82		INT	$0x80
    83		MOVL	$0, 0(SP)
    84		MOVL	AX, 4(SP)		// arg 1 - tid
    85		MOVL	sig+0(FP), AX
    86		MOVL	AX, 8(SP)		// arg 2 - signum
    87		MOVL	$0, 12(SP)		// arg 3 - tcb
    88		MOVL	$119, AX		// sys_thrkill
    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 - signum
    99		MOVL	$122, 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		JAE	2(PC)
   139		MOVL	$0xf1, 0xf1		// crash
   140		RET
   141	
   142	TEXT runtime·setitimer(SB),NOSPLIT,$-4
   143		MOVL	$69, AX
   144		INT	$0x80
   145		RET
   146	
   147	// func walltime() (sec int64, nsec int32)
   148	TEXT runtime·walltime(SB), NOSPLIT, $32
   149		LEAL	12(SP), BX
   150		MOVL	$0, 4(SP)		// arg 1 - clock_id
   151		MOVL	BX, 8(SP)		// arg 2 - tp
   152		MOVL	$87, AX			// sys_clock_gettime
   153		INT	$0x80
   154	
   155		MOVL	12(SP), AX		// sec - l32
   156		MOVL	AX, sec_lo+0(FP)
   157		MOVL	16(SP), AX		// sec - h32
   158		MOVL	AX, sec_hi+4(FP)
   159	
   160		MOVL	20(SP), BX		// nsec
   161		MOVL	BX, nsec+8(FP)
   162		RET
   163	
   164	// int64 nanotime(void) so really
   165	// void nanotime(int64 *nsec)
   166	TEXT runtime·nanotime(SB),NOSPLIT,$32
   167		LEAL	12(SP), BX
   168		MOVL	CLOCK_MONOTONIC, 4(SP)	// arg 1 - clock_id
   169		MOVL	BX, 8(SP)		// arg 2 - tp
   170		MOVL	$87, AX			// sys_clock_gettime
   171		INT	$0x80
   172	
   173		MOVL    16(SP), CX		// sec - h32
   174		IMULL   $1000000000, CX
   175	
   176		MOVL    12(SP), AX		// sec - l32
   177		MOVL    $1000000000, BX
   178		MULL    BX			// result in dx:ax
   179	
   180		MOVL	20(SP), BX		// nsec
   181		ADDL	BX, AX
   182		ADCL	CX, DX			// add high bits with carry
   183	
   184		MOVL	AX, ret_lo+0(FP)
   185		MOVL	DX, ret_hi+4(FP)
   186		RET
   187	
   188	TEXT runtime·sigaction(SB),NOSPLIT,$-4
   189		MOVL	$46, AX			// sys_sigaction
   190		INT	$0x80
   191		JAE	2(PC)
   192		MOVL	$0xf1, 0xf1		// crash
   193		RET
   194	
   195	TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$-4
   196		MOVL	$48, AX			// sys_sigprocmask
   197		INT	$0x80
   198		JAE	2(PC)
   199		MOVL	$0xf1, 0xf1		// crash
   200		MOVL	AX, ret+8(FP)
   201		RET
   202	
   203	TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   204		MOVL	fn+0(FP), AX
   205		MOVL	sig+4(FP), BX
   206		MOVL	info+8(FP), CX
   207		MOVL	ctx+12(FP), DX
   208		MOVL	SP, SI
   209		SUBL	$32, SP
   210		ANDL	$~15, SP	// align stack: handler might be a C function
   211		MOVL	BX, 0(SP)
   212		MOVL	CX, 4(SP)
   213		MOVL	DX, 8(SP)
   214		MOVL	SI, 12(SP)	// save SI: handler might be a Go function
   215		CALL	AX
   216		MOVL	12(SP), AX
   217		MOVL	AX, SP
   218		RET
   219	
   220	TEXT runtime·sigtramp(SB),NOSPLIT,$28
   221		// Save callee-saved C registers, since the caller may be a C signal handler.
   222		MOVL	BX, bx-4(SP)
   223		MOVL	BP, bp-8(SP)
   224		MOVL	SI, si-12(SP)
   225		MOVL	DI, di-16(SP)
   226		// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   227		// modify them.
   228	
   229		MOVL	signo+0(FP), BX
   230		MOVL	BX, 0(SP)
   231		MOVL	info+4(FP), BX
   232		MOVL	BX, 4(SP)
   233		MOVL	context+8(FP), BX
   234		MOVL	BX, 8(SP)
   235		CALL	runtime·sigtrampgo(SB)
   236	
   237		MOVL	di-16(SP), DI
   238		MOVL	si-12(SP), SI
   239		MOVL	bp-8(SP),  BP
   240		MOVL	bx-4(SP),  BX
   241		RET
   242	
   243	// int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
   244	TEXT runtime·tfork(SB),NOSPLIT,$12
   245	
   246		// Copy mp, gp and fn from the parent stack onto the child stack.
   247		MOVL	param+0(FP), AX
   248		MOVL	8(AX), CX		// tf_stack
   249		SUBL	$16, CX
   250		MOVL	CX, 8(AX)
   251		MOVL	mm+8(FP), SI
   252		MOVL	SI, 0(CX)
   253		MOVL	gg+12(FP), SI
   254		MOVL	SI, 4(CX)
   255		MOVL	fn+16(FP), SI
   256		MOVL	SI, 8(CX)
   257		MOVL	$1234, 12(CX)
   258	
   259		MOVL	$0, 0(SP)		// syscall gap
   260		MOVL	param+0(FP), AX
   261		MOVL	AX, 4(SP)		// arg 1 - param
   262		MOVL	psize+4(FP), AX
   263		MOVL	AX, 8(SP)		// arg 2 - psize
   264		MOVL	$8, AX			// sys___tfork
   265		INT	$0x80
   266	
   267		// Return if tfork syscall failed.
   268		JCC	4(PC)
   269		NEGL	AX
   270		MOVL	AX, ret+20(FP)
   271		RET
   272	
   273		// In parent, return.
   274		CMPL	AX, $0
   275		JEQ	3(PC)
   276		MOVL	AX, ret+20(FP)
   277		RET
   278	
   279		// Paranoia: check that SP is as we expect.
   280		MOVL	12(SP), BP
   281		CMPL	BP, $1234
   282		JEQ	2(PC)
   283		INT	$3
   284	
   285		// Reload registers.
   286		MOVL	0(SP), BX		// m
   287		MOVL	4(SP), DX		// g
   288		MOVL	8(SP), SI		// fn
   289	
   290		// Set FS to point at m->tls.
   291		LEAL	m_tls(BX), BP
   292		PUSHAL				// save registers
   293		PUSHL	BP
   294		CALL	runtime·settls(SB)
   295		POPL	AX
   296		POPAL
   297		
   298		// Now segment is established. Initialize m, g.
   299		get_tls(AX)
   300		MOVL	DX, g(AX)
   301		MOVL	BX, g_m(DX)
   302	
   303		CALL	runtime·stackcheck(SB)	// smashes AX, CX
   304		MOVL	0(DX), DX		// paranoia; check they are not nil
   305		MOVL	0(BX), BX
   306	
   307		// More paranoia; check that stack splitting code works.
   308		PUSHAL
   309		CALL	runtime·emptyfunc(SB)
   310		POPAL
   311	
   312		// Call fn.
   313		CALL	SI
   314	
   315		// fn should never return.
   316		MOVL	$0x1234, 0x1005
   317		RET
   318	
   319	TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   320		MOVL	$288, AX		// sys_sigaltstack
   321		MOVL	new+0(FP), BX
   322		MOVL	old+4(FP), CX
   323		INT	$0x80
   324		CMPL	AX, $0xfffff001
   325		JLS	2(PC)
   326		INT	$3
   327		RET
   328	
   329	TEXT runtime·setldt(SB),NOSPLIT,$4
   330		// Under OpenBSD we set the GS base instead of messing with the LDT.
   331		MOVL	tls0+4(FP), AX
   332		MOVL	AX, 0(SP)
   333		CALL	runtime·settls(SB)
   334		RET
   335	
   336	TEXT runtime·settls(SB),NOSPLIT,$8
   337		// adjust for ELF: wants to use -4(GS) for g
   338		MOVL	tlsbase+0(FP), CX
   339		ADDL	$4, CX
   340		MOVL	$0, 0(SP)		// syscall gap
   341		MOVL	CX, 4(SP)		// arg 1 - tcb
   342		MOVL	$329, AX		// sys___set_tcb
   343		INT	$0x80
   344		JCC	2(PC)
   345		MOVL	$0xf1, 0xf1		// crash
   346		RET
   347	
   348	TEXT runtime·osyield(SB),NOSPLIT,$-4
   349		MOVL	$298, AX		// sys_sched_yield
   350		INT	$0x80
   351		RET
   352	
   353	TEXT runtime·thrsleep(SB),NOSPLIT,$-4
   354		MOVL	$94, AX			// sys___thrsleep
   355		INT	$0x80
   356		MOVL	AX, ret+20(FP)
   357		RET
   358	
   359	TEXT runtime·thrwakeup(SB),NOSPLIT,$-4
   360		MOVL	$301, AX		// sys___thrwakeup
   361		INT	$0x80
   362		MOVL	AX, ret+8(FP)
   363		RET
   364	
   365	TEXT runtime·sysctl(SB),NOSPLIT,$28
   366		LEAL	mib+0(FP), SI
   367		LEAL	4(SP), DI
   368		CLD
   369		MOVSL				// arg 1 - name
   370		MOVSL				// arg 2 - namelen
   371		MOVSL				// arg 3 - oldp
   372		MOVSL				// arg 4 - oldlenp
   373		MOVSL				// arg 5 - newp
   374		MOVSL				// arg 6 - newlen
   375		MOVL	$202, AX		// sys___sysctl
   376		INT	$0x80
   377		JCC	4(PC)
   378		NEGL	AX
   379		MOVL	AX, ret+24(FP)
   380		RET
   381		MOVL	$0, AX
   382		MOVL	AX, ret+24(FP)
   383		RET
   384	
   385	// int32 runtime·kqueue(void);
   386	TEXT runtime·kqueue(SB),NOSPLIT,$0
   387		MOVL	$269, AX
   388		INT	$0x80
   389		JAE	2(PC)
   390		NEGL	AX
   391		MOVL	AX, ret+0(FP)
   392		RET
   393	
   394	// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   395	TEXT runtime·kevent(SB),NOSPLIT,$0
   396		MOVL	$72, AX			// sys_kevent
   397		INT	$0x80
   398		JAE	2(PC)
   399		NEGL	AX
   400		MOVL	AX, ret+24(FP)
   401		RET
   402	
   403	// int32 runtime·closeonexec(int32 fd);
   404	TEXT runtime·closeonexec(SB),NOSPLIT,$32
   405		MOVL	$92, AX			// sys_fcntl
   406		// 0(SP) is where the caller PC would be; kernel skips it
   407		MOVL	fd+0(FP), BX
   408		MOVL	BX, 4(SP)	// fd
   409		MOVL	$2, 8(SP)	// F_SETFD
   410		MOVL	$1, 12(SP)	// FD_CLOEXEC
   411		INT	$0x80
   412		JAE	2(PC)
   413		NEGL	AX
   414		RET
   415	
   416	GLOBL runtime·tlsoffset(SB),NOPTR,$4

View as plain text