...
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)
    14TEXT 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)
    21TEXT 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
    30TEXT 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
    38TEXT 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
    46TEXT 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
    54TEXT 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
    62TEXT 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
    81TEXT 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
    92TEXT 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
   103TEXT 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
   123ok:
   124	MOVL	AX, p+24(FP)
   125	MOVL	$0, err+28(FP)
   126	RET
   127
   128TEXT 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
   135TEXT runtime·madvise(SB),NOSPLIT,$-4
   136	MOVL	$75, AX			// sys_madvise
   137	INT	$0x80
   138	JAE	2(PC)
   139	MOVL	$-1, AX
   140	MOVL	AX, ret+12(FP)
   141	RET
   142
   143TEXT runtime·setitimer(SB),NOSPLIT,$-4
   144	MOVL	$425, AX		// sys_setitimer
   145	INT	$0x80
   146	RET
   147
   148// func walltime() (sec int64, nsec int32)
   149TEXT runtime·walltime(SB), NOSPLIT, $32
   150	LEAL	12(SP), BX
   151	MOVL	$0, 4(SP)		// arg 1 - clock_id
   152	MOVL	BX, 8(SP)		// arg 2 - tp
   153	MOVL	$427, AX		// sys_clock_gettime
   154	INT	$0x80
   155
   156	MOVL	12(SP), AX		// sec - l32
   157	MOVL	AX, sec_lo+0(FP)
   158	MOVL	16(SP), AX		// sec - h32
   159	MOVL	AX, sec_hi+4(FP)
   160
   161	MOVL	20(SP), BX		// nsec
   162	MOVL	BX, nsec+8(FP)
   163	RET
   164
   165// int64 nanotime(void) so really
   166// void nanotime(int64 *nsec)
   167TEXT runtime·nanotime(SB),NOSPLIT,$32
   168	LEAL	12(SP), BX
   169	MOVL	$3, 4(SP)		// arg 1 - clock_id CLOCK_MONOTONIC
   170	MOVL	BX, 8(SP)		// arg 2 - tp
   171	MOVL	$427, AX		// sys_clock_gettime
   172	INT	$0x80
   173
   174	MOVL	16(SP), CX		// sec - h32
   175	IMULL	$1000000000, CX
   176
   177	MOVL	12(SP), AX		// sec - l32
   178	MOVL	$1000000000, BX
   179	MULL	BX			// result in dx:ax
   180
   181	MOVL	20(SP), BX		// nsec
   182	ADDL	BX, AX
   183	ADCL	CX, DX			// add high bits with carry
   184
   185	MOVL	AX, ret_lo+0(FP)
   186	MOVL	DX, ret_hi+4(FP)
   187	RET
   188
   189TEXT runtime·getcontext(SB),NOSPLIT,$-4
   190	MOVL	$307, AX		// sys_getcontext
   191	INT	$0x80
   192	JAE	2(PC)
   193	MOVL	$0xf1, 0xf1		// crash
   194	RET
   195
   196TEXT runtime·sigprocmask(SB),NOSPLIT,$-4
   197	MOVL	$293, AX		// sys_sigprocmask
   198	INT	$0x80
   199	JAE	2(PC)
   200	MOVL	$0xf1, 0xf1		// crash
   201	RET
   202
   203TEXT runtime·sigreturn_tramp(SB),NOSPLIT,$0
   204	LEAL	140(SP), AX		// Load address of ucontext
   205	MOVL	AX, 4(SP)
   206	MOVL	$308, AX		// sys_setcontext
   207	INT	$0x80
   208	MOVL	$-1, 4(SP)		// Something failed...
   209	MOVL	$1, AX			// sys_exit
   210	INT	$0x80
   211
   212TEXT runtime·sigaction(SB),NOSPLIT,$24
   213	LEAL	sig+0(FP), SI
   214	LEAL	4(SP), DI
   215	CLD
   216	MOVSL				// arg 1 - sig
   217	MOVSL				// arg 2 - act
   218	MOVSL				// arg 3 - oact
   219	LEAL	runtime·sigreturn_tramp(SB), AX
   220	STOSL				// arg 4 - tramp
   221	MOVL	$2, AX
   222	STOSL				// arg 5 - vers
   223	MOVL	$340, AX		// sys___sigaction_sigtramp
   224	INT	$0x80
   225	JAE	2(PC)
   226	MOVL	$0xf1, 0xf1		// crash
   227	RET
   228
   229TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   230	MOVL	fn+0(FP), AX
   231	MOVL	sig+4(FP), BX
   232	MOVL	info+8(FP), CX
   233	MOVL	ctx+12(FP), DX
   234	MOVL	SP, SI
   235	SUBL	$32, SP
   236	ANDL	$-15, SP	// align stack: handler might be a C function
   237	MOVL	BX, 0(SP)
   238	MOVL	CX, 4(SP)
   239	MOVL	DX, 8(SP)
   240	MOVL	SI, 12(SP)	// save SI: handler might be a Go function
   241	CALL	AX
   242	MOVL	12(SP), AX
   243	MOVL	AX, SP
   244	RET
   245
   246TEXT runtime·sigtramp(SB),NOSPLIT,$28
   247	// Save callee-saved C registers, since the caller may be a C signal handler.
   248	MOVL	BX, bx-4(SP)
   249	MOVL	BP, bp-8(SP)
   250	MOVL	SI, si-12(SP)
   251	MOVL	DI, di-16(SP)
   252	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   253	// modify them.
   254
   255	MOVL	signo+0(FP), BX
   256	MOVL	BX, 0(SP)
   257	MOVL	info+4(FP), BX
   258	MOVL	BX, 4(SP)
   259	MOVL	context+8(FP), BX
   260	MOVL	BX, 8(SP)
   261	CALL	runtime·sigtrampgo(SB)
   262
   263	MOVL	di-16(SP), DI
   264	MOVL	si-12(SP), SI
   265	MOVL	bp-8(SP),  BP
   266	MOVL	bx-4(SP),  BX
   267	RET
   268
   269// int32 lwp_create(void *context, uintptr flags, void *lwpid);
   270TEXT runtime·lwp_create(SB),NOSPLIT,$16
   271	MOVL	$0, 0(SP)
   272	MOVL	ctxt+0(FP), AX
   273	MOVL	AX, 4(SP)		// arg 1 - context
   274	MOVL	flags+4(FP), AX
   275	MOVL	AX, 8(SP)		// arg 2 - flags
   276	MOVL	lwpid+8(FP), AX
   277	MOVL	AX, 12(SP)		// arg 3 - lwpid
   278	MOVL	$309, AX		// sys__lwp_create
   279	INT	$0x80
   280	JCC	2(PC)
   281	NEGL	AX
   282	MOVL	AX, ret+12(FP)
   283	RET
   284
   285TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
   286
   287	// Set FS to point at m->tls
   288	LEAL	m_tls(BX), BP
   289	PUSHAL				// save registers
   290	PUSHL	BP
   291	CALL	runtime·settls(SB)
   292	POPL	AX
   293	POPAL
   294
   295	// Now segment is established. Initialize m, g.
   296	get_tls(AX)
   297	MOVL	DX, g(AX)
   298	MOVL	BX, g_m(DX)
   299
   300	CALL	runtime·stackcheck(SB)	// smashes AX, CX
   301	MOVL	0(DX), DX		// paranoia; check they are not nil
   302	MOVL	0(BX), BX
   303
   304	// more paranoia; check that stack splitting code works
   305	PUSHAL
   306	CALL	runtime·emptyfunc(SB)
   307	POPAL
   308
   309	// Call fn
   310	CALL	SI
   311
   312	// fn should never return
   313	MOVL	$0x1234, 0x1005
   314	RET
   315
   316TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   317	MOVL	$281, AX		// sys___sigaltstack14
   318	MOVL	new+0(FP), BX
   319	MOVL	old+4(FP), CX
   320	INT	$0x80
   321	CMPL	AX, $0xfffff001
   322	JLS	2(PC)
   323	INT	$3
   324	RET
   325
   326TEXT runtime·setldt(SB),NOSPLIT,$8
   327	// Under NetBSD we set the GS base instead of messing with the LDT.
   328	MOVL	16(SP), AX		// tls0
   329	MOVL	AX, 0(SP)
   330	CALL	runtime·settls(SB)
   331	RET
   332
   333TEXT runtime·settls(SB),NOSPLIT,$16
   334	// adjust for ELF: wants to use -4(GS) for g
   335	MOVL	base+0(FP), CX
   336	ADDL	$4, CX
   337	MOVL	$0, 0(SP)		// syscall gap
   338	MOVL	CX, 4(SP)		// arg 1 - ptr
   339	MOVL	$317, AX		// sys__lwp_setprivate
   340	INT	$0x80
   341	JCC	2(PC)
   342	MOVL	$0xf1, 0xf1		// crash
   343	RET
   344
   345TEXT runtime·osyield(SB),NOSPLIT,$-4
   346	MOVL	$350, AX		// sys_sched_yield
   347	INT	$0x80
   348	RET
   349
   350TEXT runtime·lwp_park(SB),NOSPLIT,$-4
   351	MOVL	$478, AX		// sys__lwp_park
   352	INT	$0x80
   353	MOVL	AX, ret+24(FP)
   354	RET
   355
   356TEXT runtime·lwp_unpark(SB),NOSPLIT,$-4
   357	MOVL	$321, AX		// sys__lwp_unpark
   358	INT	$0x80
   359	MOVL	AX, ret+8(FP)
   360	RET
   361
   362TEXT runtime·lwp_self(SB),NOSPLIT,$-4
   363	MOVL	$311, AX		// sys__lwp_self
   364	INT	$0x80
   365	MOVL	AX, ret+0(FP)
   366	RET
   367
   368TEXT runtime·sysctl(SB),NOSPLIT,$28
   369	LEAL	mib+0(FP), SI
   370	LEAL	4(SP), DI
   371	CLD
   372	MOVSL				// arg 1 - name
   373	MOVSL				// arg 2 - namelen
   374	MOVSL				// arg 3 - oldp
   375	MOVSL				// arg 4 - oldlenp
   376	MOVSL				// arg 5 - newp
   377	MOVSL				// arg 6 - newlen
   378	MOVL	$202, AX		// sys___sysctl
   379	INT	$0x80
   380	JAE	4(PC)
   381	NEGL	AX
   382	MOVL	AX, ret+24(FP)
   383	RET
   384	MOVL	$0, AX
   385	MOVL	AX, ret+24(FP)
   386	RET
   387
   388GLOBL runtime·tlsoffset(SB),NOPTR,$4
   389
   390// int32 runtime·kqueue(void)
   391TEXT runtime·kqueue(SB),NOSPLIT,$0
   392	MOVL	$344, AX
   393	INT	$0x80
   394	JAE	2(PC)
   395	NEGL	AX
   396	MOVL	AX, ret+0(FP)
   397	RET
   398
   399// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   400TEXT runtime·kevent(SB),NOSPLIT,$0
   401	MOVL	$435, AX
   402	INT	$0x80
   403	JAE	2(PC)
   404	NEGL	AX
   405	MOVL	AX, ret+24(FP)
   406	RET
   407
   408// int32 runtime·closeonexec(int32 fd)
   409TEXT runtime·closeonexec(SB),NOSPLIT,$32
   410	MOVL	$92, AX		// fcntl
   411	// 0(SP) is where the caller PC would be; kernel skips it
   412	MOVL	fd+0(FP), BX
   413	MOVL	BX, 4(SP)	// fd
   414	MOVL	$2, 8(SP)	// F_SETFD
   415	MOVL	$1, 12(SP)	// FD_CLOEXEC
   416	INT	$0x80
   417	JAE	2(PC)
   418	NEGL	AX
   419	RET

View as plain text