...
Run Format

Text file src/runtime/sys_openbsd_amd64.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 AMD64, 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	// int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
    16	TEXT runtime·tfork(SB),NOSPLIT,$32
    17	
    18		// Copy mp, gp and fn off parent stack for use by child.
    19		MOVQ	mm+16(FP), R8
    20		MOVQ	gg+24(FP), R9
    21		MOVQ	fn+32(FP), R12
    22	
    23		MOVQ	param+0(FP), DI
    24		MOVQ	psize+8(FP), SI
    25		MOVL	$8, AX			// sys___tfork
    26		SYSCALL
    27	
    28		// Return if tfork syscall failed.
    29		JCC	4(PC)
    30		NEGQ	AX
    31		MOVL	AX, ret+40(FP)
    32		RET
    33	
    34		// In parent, return.
    35		CMPL	AX, $0
    36		JEQ	3(PC)
    37		MOVL	AX, ret+40(FP)
    38		RET
    39	
    40		// Set FS to point at m->tls.
    41		LEAQ	m_tls(R8), DI
    42		CALL	runtime·settls(SB)
    43	
    44		// In child, set up new stack.
    45		get_tls(CX)
    46		MOVQ	R8, g_m(R9)
    47		MOVQ	R9, g(CX)
    48		CALL	runtime·stackcheck(SB)
    49	
    50		// Call fn
    51		CALL	R12
    52	
    53		// It shouldn't return. If it does, exit
    54		MOVQ	$0, DI			// arg 1 - notdead
    55		MOVL	$302, AX		// sys___threxit
    56		SYSCALL
    57		JMP	-3(PC)			// keep exiting
    58	
    59	TEXT runtime·osyield(SB),NOSPLIT,$0
    60		MOVL	$298, AX		// sys_sched_yield
    61		SYSCALL
    62		RET
    63	
    64	TEXT runtime·thrsleep(SB),NOSPLIT,$0
    65		MOVQ	ident+0(FP), DI		// arg 1 - ident
    66		MOVL	clock_id+8(FP), SI		// arg 2 - clock_id
    67		MOVQ	tsp+16(FP), DX		// arg 3 - tp
    68		MOVQ	lock+24(FP), R10		// arg 4 - lock
    69		MOVQ	abort+32(FP), R8		// arg 5 - abort
    70		MOVL	$94, AX			// sys___thrsleep
    71		SYSCALL
    72		MOVL	AX, ret+40(FP)
    73		RET
    74	
    75	TEXT runtime·thrwakeup(SB),NOSPLIT,$0
    76		MOVQ	ident+0(FP), DI		// arg 1 - ident
    77		MOVL	n+8(FP), SI		// arg 2 - n
    78		MOVL	$301, AX		// sys___thrwakeup
    79		SYSCALL
    80		MOVL	AX, ret+16(FP)
    81		RET
    82	
    83	// Exit the entire program (like C exit)
    84	TEXT runtime·exit(SB),NOSPLIT,$-8
    85		MOVL	code+0(FP), DI		// arg 1 - exit status
    86		MOVL	$1, AX			// sys_exit
    87		SYSCALL
    88		MOVL	$0xf1, 0xf1		// crash
    89		RET
    90	
    91	// func exitThread(wait *uint32)
    92	TEXT runtime·exitThread(SB),NOSPLIT,$0-8
    93		MOVQ	wait+0(FP), AX
    94		// We're done using the stack.
    95		MOVL	$0, (AX)
    96		MOVQ	$0, DI			// arg 1 - notdead
    97		MOVL	$302, AX		// sys___threxit
    98		SYSCALL
    99		MOVL	$0xf1, 0xf1		// crash
   100		JMP	0(PC)
   101	
   102	TEXT runtime·open(SB),NOSPLIT,$-8
   103		MOVQ	name+0(FP), DI		// arg 1 pathname
   104		MOVL	mode+8(FP), SI		// arg 2 flags
   105		MOVL	perm+12(FP), DX		// arg 3 mode
   106		MOVL	$5, AX
   107		SYSCALL
   108		JCC	2(PC)
   109		MOVL	$-1, AX
   110		MOVL	AX, ret+16(FP)
   111		RET
   112	
   113	TEXT runtime·closefd(SB),NOSPLIT,$-8
   114		MOVL	fd+0(FP), DI		// arg 1 fd
   115		MOVL	$6, AX
   116		SYSCALL
   117		JCC	2(PC)
   118		MOVL	$-1, AX
   119		MOVL	AX, ret+8(FP)
   120		RET
   121	
   122	TEXT runtime·read(SB),NOSPLIT,$-8
   123		MOVL	fd+0(FP), DI		// arg 1 fd
   124		MOVQ	p+8(FP), SI		// arg 2 buf
   125		MOVL	n+16(FP), DX		// arg 3 count
   126		MOVL	$3, AX
   127		SYSCALL
   128		JCC	2(PC)
   129		MOVL	$-1, AX
   130		MOVL	AX, ret+24(FP)
   131		RET
   132	
   133	TEXT runtime·write(SB),NOSPLIT,$-8
   134		MOVQ	fd+0(FP), DI		// arg 1 - fd
   135		MOVQ	p+8(FP), SI		// arg 2 - buf
   136		MOVL	n+16(FP), DX		// arg 3 - nbyte
   137		MOVL	$4, AX			// sys_write
   138		SYSCALL
   139		JCC	2(PC)
   140		MOVL	$-1, AX
   141		MOVL	AX, ret+24(FP)
   142		RET
   143	
   144	TEXT runtime·usleep(SB),NOSPLIT,$16
   145		MOVL	$0, DX
   146		MOVL	usec+0(FP), AX
   147		MOVL	$1000000, CX
   148		DIVL	CX
   149		MOVQ	AX, 0(SP)		// tv_sec
   150		MOVL	$1000, AX
   151		MULL	DX
   152		MOVQ	AX, 8(SP)		// tv_nsec
   153	
   154		MOVQ	SP, DI			// arg 1 - rqtp
   155		MOVQ	$0, SI			// arg 2 - rmtp
   156		MOVL	$91, AX			// sys_nanosleep
   157		SYSCALL
   158		RET
   159	
   160	TEXT runtime·raise(SB),NOSPLIT,$16
   161		MOVL	$299, AX		// sys_getthrid
   162		SYSCALL
   163		MOVQ	AX, DI			// arg 1 - tid
   164		MOVL	sig+0(FP), SI		// arg 2 - signum
   165		MOVQ	$0, DX			// arg 3 - tcb
   166		MOVL	$119, AX		// sys_thrkill
   167		SYSCALL
   168		RET
   169	
   170	TEXT runtime·raiseproc(SB),NOSPLIT,$16
   171		MOVL	$20, AX			// sys_getpid
   172		SYSCALL
   173		MOVQ	AX, DI			// arg 1 - pid
   174		MOVL	sig+0(FP), SI		// arg 2 - signum
   175		MOVL	$122, AX		// sys_kill
   176		SYSCALL
   177		RET
   178	
   179	TEXT runtime·setitimer(SB),NOSPLIT,$-8
   180		MOVL	mode+0(FP), DI		// arg 1 - which
   181		MOVQ	new+8(FP), SI		// arg 2 - itv
   182		MOVQ	old+16(FP), DX		// arg 3 - oitv
   183		MOVL	$69, AX			// sys_setitimer
   184		SYSCALL
   185		RET
   186	
   187	// func walltime() (sec int64, nsec int32)
   188	TEXT runtime·walltime(SB), NOSPLIT, $32
   189		MOVQ	$0, DI			// arg 1 - clock_id
   190		LEAQ	8(SP), SI		// arg 2 - tp
   191		MOVL	$87, AX			// sys_clock_gettime
   192		SYSCALL
   193		MOVQ	8(SP), AX		// sec
   194		MOVQ	16(SP), DX		// nsec
   195	
   196		// sec is in AX, nsec in DX
   197		MOVQ	AX, sec+0(FP)
   198		MOVL	DX, nsec+8(FP)
   199		RET
   200	
   201	TEXT runtime·nanotime(SB),NOSPLIT,$24
   202		MOVQ	CLOCK_MONOTONIC, DI	// arg 1 - clock_id
   203		LEAQ	8(SP), SI		// arg 2 - tp
   204		MOVL	$87, AX			// sys_clock_gettime
   205		SYSCALL
   206		MOVQ	8(SP), AX		// sec
   207		MOVQ	16(SP), DX		// nsec
   208	
   209		// sec is in AX, nsec in DX
   210		// return nsec in AX
   211		IMULQ	$1000000000, AX
   212		ADDQ	DX, AX
   213		MOVQ	AX, ret+0(FP)
   214		RET
   215	
   216	TEXT runtime·sigaction(SB),NOSPLIT,$-8
   217		MOVL	sig+0(FP), DI		// arg 1 - signum
   218		MOVQ	new+8(FP), SI		// arg 2 - nsa
   219		MOVQ	old+16(FP), DX		// arg 3 - osa
   220		MOVL	$46, AX
   221		SYSCALL
   222		JCC	2(PC)
   223		MOVL	$0xf1, 0xf1		// crash
   224		RET
   225	
   226	TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$0
   227		MOVL	how+0(FP), DI		// arg 1 - how
   228		MOVL	new+4(FP), SI		// arg 2 - set
   229		MOVL	$48, AX			// sys_sigprocmask
   230		SYSCALL
   231		JCC	2(PC)
   232		MOVL	$0xf1, 0xf1		// crash
   233		MOVL	AX, ret+8(FP)
   234		RET
   235	
   236	TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   237		MOVQ	fn+0(FP),    AX
   238		MOVL	sig+8(FP),   DI
   239		MOVQ	info+16(FP), SI
   240		MOVQ	ctx+24(FP),  DX
   241		PUSHQ	BP
   242		MOVQ	SP, BP
   243		ANDQ	$~15, SP     // alignment for x86_64 ABI
   244		CALL	AX
   245		MOVQ	BP, SP
   246		POPQ	BP
   247		RET
   248	
   249	TEXT runtime·sigtramp(SB),NOSPLIT,$72
   250		// Save callee-saved C registers, since the caller may be a C signal handler.
   251		MOVQ	BX,  bx-8(SP)
   252		MOVQ	BP,  bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
   253		MOVQ	R12, r12-24(SP)
   254		MOVQ	R13, r13-32(SP)
   255		MOVQ	R14, r14-40(SP)
   256		MOVQ	R15, r15-48(SP)
   257		// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   258		// modify them.
   259	
   260		MOVQ	DX, ctx-56(SP)
   261		MOVQ	SI, info-64(SP)
   262		MOVQ	DI, signum-72(SP)
   263		CALL	runtime·sigtrampgo(SB)
   264	
   265		MOVQ	r15-48(SP), R15
   266		MOVQ	r14-40(SP), R14
   267		MOVQ	r13-32(SP), R13
   268		MOVQ	r12-24(SP), R12
   269		MOVQ	bp-16(SP),  BP
   270		MOVQ	bx-8(SP),   BX
   271		RET
   272	
   273	TEXT runtime·mmap(SB),NOSPLIT,$0
   274		MOVQ	addr+0(FP), DI		// arg 1 - addr
   275		MOVQ	n+8(FP), SI		// arg 2 - len
   276		MOVL	prot+16(FP), DX		// arg 3 - prot
   277		MOVL	flags+20(FP), R10		// arg 4 - flags
   278		MOVL	fd+24(FP), R8		// arg 5 - fd
   279		MOVL	off+28(FP), R9
   280		SUBQ	$16, SP
   281		MOVQ	R9, 8(SP)		// arg 7 - offset (passed on stack)
   282		MOVQ	$0, R9			// arg 6 - pad
   283		MOVL	$197, AX
   284		SYSCALL
   285		JCC	ok
   286		ADDQ	$16, SP
   287		MOVQ	$0, p+32(FP)
   288		MOVQ	AX, err+40(FP)
   289		RET
   290	ok:
   291		ADDQ	$16, SP
   292		MOVQ	AX, p+32(FP)
   293		MOVQ	$0, err+40(FP)
   294		RET
   295	
   296	TEXT runtime·munmap(SB),NOSPLIT,$0
   297		MOVQ	addr+0(FP), DI		// arg 1 - addr
   298		MOVQ	n+8(FP), SI		// arg 2 - len
   299		MOVL	$73, AX			// sys_munmap
   300		SYSCALL
   301		JCC	2(PC)
   302		MOVL	$0xf1, 0xf1		// crash
   303		RET
   304	
   305	TEXT runtime·madvise(SB),NOSPLIT,$0
   306		MOVQ	addr+0(FP), DI		// arg 1 - addr
   307		MOVQ	n+8(FP), SI		// arg 2 - len
   308		MOVL	flags+16(FP), DX	// arg 3 - behav
   309		MOVQ	$75, AX			// sys_madvise
   310		SYSCALL
   311		// ignore failure - maybe pages are locked
   312		RET
   313	
   314	TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   315		MOVQ	new+0(FP), DI		// arg 1 - nss
   316		MOVQ	old+8(FP), SI		// arg 2 - oss
   317		MOVQ	$288, AX		// sys_sigaltstack
   318		SYSCALL
   319		JCC	2(PC)
   320		MOVL	$0xf1, 0xf1		// crash
   321		RET
   322	
   323	// set tls base to DI
   324	TEXT runtime·settls(SB),NOSPLIT,$0
   325		// adjust for ELF: wants to use -8(FS) for g
   326		ADDQ	$8, DI
   327		MOVQ	$329, AX		// sys___settcb
   328		SYSCALL
   329		JCC	2(PC)
   330		MOVL	$0xf1, 0xf1		// crash
   331		RET
   332	
   333	TEXT runtime·sysctl(SB),NOSPLIT,$0
   334		MOVQ	mib+0(FP), DI		// arg 1 - name
   335		MOVL	miblen+8(FP), SI		// arg 2 - namelen
   336		MOVQ	out+16(FP), DX		// arg 3 - oldp
   337		MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   338		MOVQ	dst+32(FP), R8		// arg 5 - newp
   339		MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   340		MOVQ	$202, AX		// sys___sysctl
   341		SYSCALL
   342		JCC	4(PC)
   343		NEGQ	AX
   344		MOVL	AX, ret+48(FP)
   345		RET
   346		MOVL	$0, AX
   347		MOVL	AX, ret+48(FP)
   348		RET
   349	
   350	// int32 runtime·kqueue(void);
   351	TEXT runtime·kqueue(SB),NOSPLIT,$0
   352		MOVQ	$0, DI
   353		MOVQ	$0, SI
   354		MOVQ	$0, DX
   355		MOVL	$269, AX
   356		SYSCALL
   357		JCC	2(PC)
   358		NEGQ	AX
   359		MOVL	AX, ret+0(FP)
   360		RET
   361	
   362	// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   363	TEXT runtime·kevent(SB),NOSPLIT,$0
   364		MOVL	kq+0(FP), DI
   365		MOVQ	ch+8(FP), SI
   366		MOVL	nch+16(FP), DX
   367		MOVQ	ev+24(FP), R10
   368		MOVL	nev+32(FP), R8
   369		MOVQ	ts+40(FP), R9
   370		MOVL	$72, AX
   371		SYSCALL
   372		JCC	2(PC)
   373		NEGQ	AX
   374		MOVL	AX, ret+48(FP)
   375		RET
   376	
   377	// void runtime·closeonexec(int32 fd);
   378	TEXT runtime·closeonexec(SB),NOSPLIT,$0
   379		MOVL	fd+0(FP), DI	// fd
   380		MOVQ	$2, SI		// F_SETFD
   381		MOVQ	$1, DX		// FD_CLOEXEC
   382		MOVL	$92, AX		// fcntl
   383		SYSCALL
   384		RET

View as plain text