...

Text file src/runtime/sys_netbsd_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, 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#include "cgo/abi_amd64.h"
    13
    14#define CLOCK_REALTIME		0
    15#define CLOCK_MONOTONIC		3
    16
    17#define SYS_exit			1
    18#define SYS_read			3
    19#define SYS_write			4
    20#define SYS_open			5
    21#define SYS_close			6
    22#define SYS_getpid			20
    23#define SYS_kill			37
    24#define SYS_munmap			73
    25#define SYS_madvise			75
    26#define SYS_fcntl			92
    27#define SYS_mmap			197
    28#define SYS___sysctl			202
    29#define SYS___sigaltstack14		281
    30#define SYS___sigprocmask14		293
    31#define SYS_issetugid			305
    32#define SYS_getcontext			307
    33#define SYS_setcontext			308
    34#define SYS__lwp_create			309
    35#define SYS__lwp_exit			310
    36#define SYS__lwp_self			311
    37#define SYS__lwp_setprivate		317
    38#define SYS__lwp_kill			318
    39#define SYS__lwp_unpark			321
    40#define SYS___sigaction_sigtramp	340
    41#define SYS_kqueue			344
    42#define SYS_sched_yield			350
    43#define SYS___setitimer50		425
    44#define SYS___clock_gettime50		427
    45#define SYS___nanosleep50		430
    46#define SYS___kevent50			435
    47#define SYS____lwp_park60		478
    48
    49// int32 lwp_create(void *context, uintptr flags, void *lwpid)
    50TEXT runtime·lwp_create(SB),NOSPLIT,$0
    51	MOVQ	ctxt+0(FP), DI
    52	MOVQ	flags+8(FP), SI
    53	MOVQ	lwpid+16(FP), DX
    54	MOVL	$SYS__lwp_create, AX
    55	SYSCALL
    56	JCC	2(PC)
    57	NEGQ	AX
    58	MOVL	AX, ret+24(FP)
    59	RET
    60
    61TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
    62
    63	// Set FS to point at m->tls.
    64	LEAQ	m_tls(R8), DI
    65	CALL	runtime·settls(SB)
    66
    67	// Set up new stack.
    68	get_tls(CX)
    69	MOVQ	R8, g_m(R9)
    70	MOVQ	R9, g(CX)
    71	CALL	runtime·stackcheck(SB)
    72
    73	// Call fn. This is an ABI0 PC.
    74	CALL	R12
    75
    76	// It shouldn't return. If it does, exit.
    77	MOVL	$SYS__lwp_exit, AX
    78	SYSCALL
    79	JMP	-3(PC)			// keep exiting
    80
    81TEXT ·netbsdMstart(SB),NOSPLIT|TOPFRAME,$0
    82	CALL	·netbsdMstart0(SB)
    83	RET // not reached
    84
    85TEXT runtime·osyield(SB),NOSPLIT,$0
    86	MOVL	$SYS_sched_yield, AX
    87	SYSCALL
    88	RET
    89
    90TEXT runtime·lwp_park(SB),NOSPLIT,$0
    91	MOVL	clockid+0(FP), DI		// arg 1 - clockid
    92	MOVL	flags+4(FP), SI			// arg 2 - flags
    93	MOVQ	ts+8(FP), DX			// arg 3 - ts
    94	MOVL	unpark+16(FP), R10		// arg 4 - unpark
    95	MOVQ	hint+24(FP), R8			// arg 5 - hint
    96	MOVQ	unparkhint+32(FP), R9		// arg 6 - unparkhint
    97	MOVL	$SYS____lwp_park60, AX
    98	SYSCALL
    99	MOVL	AX, ret+40(FP)
   100	RET
   101
   102TEXT runtime·lwp_unpark(SB),NOSPLIT,$0
   103	MOVL	lwp+0(FP), DI		// arg 1 - lwp
   104	MOVQ	hint+8(FP), SI		// arg 2 - hint
   105	MOVL	$SYS__lwp_unpark, AX
   106	SYSCALL
   107	MOVL	AX, ret+16(FP)
   108	RET
   109
   110TEXT runtime·lwp_self(SB),NOSPLIT,$0
   111	MOVL	$SYS__lwp_self, AX
   112	SYSCALL
   113	MOVL	AX, ret+0(FP)
   114	RET
   115
   116// Exit the entire program (like C exit)
   117TEXT runtime·exit(SB),NOSPLIT,$-8
   118	MOVL	code+0(FP), DI		// arg 1 - exit status
   119	MOVL	$SYS_exit, AX
   120	SYSCALL
   121	MOVL	$0xf1, 0xf1		// crash
   122	RET
   123
   124// func exitThread(wait *atomic.Uint32)
   125TEXT runtime·exitThread(SB),NOSPLIT,$0-8
   126	MOVQ	wait+0(FP), AX
   127	// We're done using the stack.
   128	MOVL	$0, (AX)
   129	MOVL	$SYS__lwp_exit, AX
   130	SYSCALL
   131	MOVL	$0xf1, 0xf1		// crash
   132	JMP	0(PC)
   133
   134TEXT runtime·open(SB),NOSPLIT,$-8
   135	MOVQ	name+0(FP), DI		// arg 1 pathname
   136	MOVL	mode+8(FP), SI		// arg 2 flags
   137	MOVL	perm+12(FP), DX		// arg 3 mode
   138	MOVL	$SYS_open, AX
   139	SYSCALL
   140	JCC	2(PC)
   141	MOVL	$-1, AX
   142	MOVL	AX, ret+16(FP)
   143	RET
   144
   145TEXT runtime·closefd(SB),NOSPLIT,$-8
   146	MOVL	fd+0(FP), DI		// arg 1 fd
   147	MOVL	$SYS_close, AX
   148	SYSCALL
   149	JCC	2(PC)
   150	MOVL	$-1, AX
   151	MOVL	AX, ret+8(FP)
   152	RET
   153
   154TEXT runtime·read(SB),NOSPLIT,$-8
   155	MOVL	fd+0(FP), DI		// arg 1 fd
   156	MOVQ	p+8(FP), SI		// arg 2 buf
   157	MOVL	n+16(FP), DX		// arg 3 count
   158	MOVL	$SYS_read, AX
   159	SYSCALL
   160	JCC	2(PC)
   161	NEGQ	AX			// caller expects negative errno
   162	MOVL	AX, ret+24(FP)
   163	RET
   164
   165// func pipe2(flags int32) (r, w int32, errno int32)
   166TEXT runtime·pipe2(SB),NOSPLIT,$0-20
   167	LEAQ	r+8(FP), DI
   168	MOVL	flags+0(FP), SI
   169	MOVL	$453, AX
   170	SYSCALL
   171	MOVL	AX, errno+16(FP)
   172	RET
   173
   174TEXT runtime·write1(SB),NOSPLIT,$-8
   175	MOVQ	fd+0(FP), DI		// arg 1 - fd
   176	MOVQ	p+8(FP), SI		// arg 2 - buf
   177	MOVL	n+16(FP), DX		// arg 3 - nbyte
   178	MOVL	$SYS_write, AX
   179	SYSCALL
   180	JCC	2(PC)
   181	NEGQ	AX			// caller expects negative errno
   182	MOVL	AX, ret+24(FP)
   183	RET
   184
   185TEXT runtime·usleep(SB),NOSPLIT,$16
   186	MOVL	$0, DX
   187	MOVL	usec+0(FP), AX
   188	MOVL	$1000000, CX
   189	DIVL	CX
   190	MOVQ	AX, 0(SP)		// tv_sec
   191	MOVL	$1000, AX
   192	MULL	DX
   193	MOVQ	AX, 8(SP)		// tv_nsec
   194
   195	MOVQ	SP, DI			// arg 1 - rqtp
   196	MOVQ	$0, SI			// arg 2 - rmtp
   197	MOVL	$SYS___nanosleep50, AX
   198	SYSCALL
   199	RET
   200
   201TEXT runtime·lwp_kill(SB),NOSPLIT,$0-16
   202	MOVL	tid+0(FP), DI		// arg 1 - target
   203	MOVQ	sig+8(FP), SI		// arg 2 - signo
   204	MOVL	$SYS__lwp_kill, AX
   205	SYSCALL
   206	RET
   207
   208TEXT runtime·raiseproc(SB),NOSPLIT,$16
   209	MOVL	$SYS_getpid, AX
   210	SYSCALL
   211	MOVQ	AX, DI			// arg 1 - pid
   212	MOVL	sig+0(FP), SI		// arg 2 - signo
   213	MOVL	$SYS_kill, AX
   214	SYSCALL
   215	RET
   216
   217TEXT runtime·setitimer(SB),NOSPLIT,$-8
   218	MOVL	mode+0(FP), DI		// arg 1 - which
   219	MOVQ	new+8(FP), SI		// arg 2 - itv
   220	MOVQ	old+16(FP), DX		// arg 3 - oitv
   221	MOVL	$SYS___setitimer50, AX
   222	SYSCALL
   223	RET
   224
   225// func walltime() (sec int64, nsec int32)
   226TEXT runtime·walltime(SB), NOSPLIT, $32
   227	MOVQ	$CLOCK_REALTIME, DI	// arg 1 - clock_id
   228	LEAQ	8(SP), SI		// arg 2 - tp
   229	MOVL	$SYS___clock_gettime50, AX
   230	SYSCALL
   231	MOVQ	8(SP), AX		// sec
   232	MOVQ	16(SP), DX		// nsec
   233
   234	// sec is in AX, nsec in DX
   235	MOVQ	AX, sec+0(FP)
   236	MOVL	DX, nsec+8(FP)
   237	RET
   238
   239TEXT runtime·nanotime1(SB),NOSPLIT,$32
   240	MOVQ	$CLOCK_MONOTONIC, DI	// arg 1 - clock_id
   241	LEAQ	8(SP), SI		// arg 2 - tp
   242	MOVL	$SYS___clock_gettime50, AX
   243	SYSCALL
   244	MOVQ	8(SP), AX		// sec
   245	MOVQ	16(SP), DX		// nsec
   246
   247	// sec is in AX, nsec in DX
   248	// return nsec in AX
   249	IMULQ	$1000000000, AX
   250	ADDQ	DX, AX
   251	MOVQ	AX, ret+0(FP)
   252	RET
   253
   254TEXT runtime·getcontext(SB),NOSPLIT,$-8
   255	MOVQ	ctxt+0(FP), DI		// arg 1 - context
   256	MOVL	$SYS_getcontext, AX
   257	SYSCALL
   258	JCC	2(PC)
   259	MOVL	$0xf1, 0xf1		// crash
   260	RET
   261
   262TEXT runtime·sigprocmask(SB),NOSPLIT,$0
   263	MOVL	how+0(FP), DI		// arg 1 - how
   264	MOVQ	new+8(FP), SI		// arg 2 - set
   265	MOVQ	old+16(FP), DX		// arg 3 - oset
   266	MOVL	$SYS___sigprocmask14, AX
   267	SYSCALL
   268	JCC	2(PC)
   269	MOVL	$0xf1, 0xf1		// crash
   270	RET
   271
   272TEXT sigreturn_tramp<>(SB),NOSPLIT,$-8
   273	MOVQ	R15, DI			// Load address of ucontext
   274	MOVQ	$SYS_setcontext, AX
   275	SYSCALL
   276	MOVQ	$-1, DI			// Something failed...
   277	MOVL	$SYS_exit, AX
   278	SYSCALL
   279
   280TEXT runtime·sigaction(SB),NOSPLIT,$-8
   281	MOVL	sig+0(FP), DI		// arg 1 - signum
   282	MOVQ	new+8(FP), SI		// arg 2 - nsa
   283	MOVQ	old+16(FP), DX		// arg 3 - osa
   284					// arg 4 - tramp
   285	LEAQ	sigreturn_tramp<>(SB), R10
   286	MOVQ	$2, R8			// arg 5 - vers
   287	MOVL	$SYS___sigaction_sigtramp, AX
   288	SYSCALL
   289	JCC	2(PC)
   290	MOVL	$0xf1, 0xf1		// crash
   291	RET
   292
   293TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   294	MOVQ	fn+0(FP),    AX
   295	MOVL	sig+8(FP),   DI
   296	MOVQ	info+16(FP), SI
   297	MOVQ	ctx+24(FP),  DX
   298	MOVQ	SP, BX		// callee-saved
   299	ANDQ	$~15, SP	// alignment for x86_64 ABI
   300	CALL	AX
   301	MOVQ	BX, SP
   302	RET
   303
   304// Called using C ABI.
   305TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
   306	// Transition from C ABI to Go ABI.
   307	PUSH_REGS_HOST_TO_ABI0()
   308
   309	// Set up ABIInternal environment: g in R14, cleared X15.
   310	get_tls(R12)
   311	MOVQ	g(R12), R14
   312	PXOR	X15, X15
   313
   314	// Reserve space for spill slots.
   315	NOP	SP		// disable vet stack checking
   316	ADJSP   $24
   317
   318	// Call into the Go signal handler
   319	MOVQ	DI, AX	// sig
   320	MOVQ	SI, BX	// info
   321	MOVQ	DX, CX	// ctx
   322	CALL	·sigtrampgo<ABIInternal>(SB)
   323
   324	ADJSP	$-24
   325
   326	POP_REGS_HOST_TO_ABI0()
   327	RET
   328
   329TEXT runtime·mmap(SB),NOSPLIT,$0
   330	MOVQ	addr+0(FP), DI		// arg 1 - addr
   331	MOVQ	n+8(FP), SI		// arg 2 - len
   332	MOVL	prot+16(FP), DX		// arg 3 - prot
   333	MOVL	flags+20(FP), R10		// arg 4 - flags
   334	MOVL	fd+24(FP), R8		// arg 5 - fd
   335	MOVL	off+28(FP), R9
   336	SUBQ	$16, SP
   337	MOVQ	R9, 8(SP)		// arg 7 - offset (passed on stack)
   338	MOVQ	$0, R9			// arg 6 - pad
   339	MOVL	$SYS_mmap, AX
   340	SYSCALL
   341	JCC	ok
   342	ADDQ	$16, SP
   343	MOVQ	$0, p+32(FP)
   344	MOVQ	AX, err+40(FP)
   345	RET
   346ok:
   347	ADDQ	$16, SP
   348	MOVQ	AX, p+32(FP)
   349	MOVQ	$0, err+40(FP)
   350	RET
   351
   352TEXT runtime·munmap(SB),NOSPLIT,$0
   353	MOVQ	addr+0(FP), DI		// arg 1 - addr
   354	MOVQ	n+8(FP), SI		// arg 2 - len
   355	MOVL	$SYS_munmap, AX
   356	SYSCALL
   357	JCC	2(PC)
   358	MOVL	$0xf1, 0xf1		// crash
   359	RET
   360
   361
   362TEXT runtime·madvise(SB),NOSPLIT,$0
   363	MOVQ	addr+0(FP), DI		// arg 1 - addr
   364	MOVQ	n+8(FP), SI		// arg 2 - len
   365	MOVL	flags+16(FP), DX	// arg 3 - behav
   366	MOVQ	$SYS_madvise, AX
   367	SYSCALL
   368	JCC	2(PC)
   369	MOVL	$-1, AX
   370	MOVL	AX, ret+24(FP)
   371	RET
   372
   373TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   374	MOVQ	new+0(FP), DI		// arg 1 - nss
   375	MOVQ	old+8(FP), SI		// arg 2 - oss
   376	MOVQ	$SYS___sigaltstack14, AX
   377	SYSCALL
   378	JCC	2(PC)
   379	MOVL	$0xf1, 0xf1		// crash
   380	RET
   381
   382// set tls base to DI
   383TEXT runtime·settls(SB),NOSPLIT,$8
   384	// adjust for ELF: wants to use -8(FS) for g
   385	ADDQ	$8, DI			// arg 1 - ptr
   386	MOVQ	$SYS__lwp_setprivate, AX
   387	SYSCALL
   388	JCC	2(PC)
   389	MOVL	$0xf1, 0xf1		// crash
   390	RET
   391
   392TEXT runtime·sysctl(SB),NOSPLIT,$0
   393	MOVQ	mib+0(FP), DI		// arg 1 - name
   394	MOVL	miblen+8(FP), SI		// arg 2 - namelen
   395	MOVQ	out+16(FP), DX		// arg 3 - oldp
   396	MOVQ	size+24(FP), R10		// arg 4 - oldlenp
   397	MOVQ	dst+32(FP), R8		// arg 5 - newp
   398	MOVQ	ndst+40(FP), R9		// arg 6 - newlen
   399	MOVQ	$SYS___sysctl, AX
   400	SYSCALL
   401	JCC 4(PC)
   402	NEGQ	AX
   403	MOVL	AX, ret+48(FP)
   404	RET
   405	MOVL	$0, AX
   406	MOVL	AX, ret+48(FP)
   407	RET
   408
   409// int32 runtime·kqueue(void)
   410TEXT runtime·kqueue(SB),NOSPLIT,$0
   411	MOVQ	$0, DI
   412	MOVL	$SYS_kqueue, AX
   413	SYSCALL
   414	JCC	2(PC)
   415	NEGQ	AX
   416	MOVL	AX, ret+0(FP)
   417	RET
   418
   419// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   420TEXT runtime·kevent(SB),NOSPLIT,$0
   421	MOVL	kq+0(FP), DI
   422	MOVQ	ch+8(FP), SI
   423	MOVL	nch+16(FP), DX
   424	MOVQ	ev+24(FP), R10
   425	MOVL	nev+32(FP), R8
   426	MOVQ	ts+40(FP), R9
   427	MOVL	$SYS___kevent50, AX
   428	SYSCALL
   429	JCC	2(PC)
   430	NEGQ	AX
   431	MOVL	AX, ret+48(FP)
   432	RET
   433
   434// func fcntl(fd, cmd, arg int32) (int32, int32)
   435TEXT runtime·fcntl(SB),NOSPLIT,$0
   436	MOVL	fd+0(FP), DI	// fd
   437	MOVL	cmd+4(FP), SI	// cmd
   438	MOVL	arg+8(FP), DX	// arg
   439	MOVL	$SYS_fcntl, AX
   440	SYSCALL
   441	JCC	noerr
   442	MOVL	$-1, ret+16(FP)
   443	MOVL	AX, errno+20(FP)
   444	RET
   445noerr:
   446	MOVL	AX, ret+16(FP)
   447	MOVL	$0, errno+20(FP)
   448	RET
   449
   450// func issetugid() int32
   451TEXT runtime·issetugid(SB),NOSPLIT,$0
   452	MOVQ	$0, DI
   453	MOVQ	$0, SI
   454	MOVQ	$0, DX
   455	MOVL	$SYS_issetugid, AX
   456	SYSCALL
   457	MOVL	AX, ret+0(FP)
   458	RET

View as plain text