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

View as plain text