...
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)
    16TEXT 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)
    23TEXT 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
    29TEXT 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
    37TEXT 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
    45TEXT 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
    53TEXT 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
    61TEXT 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
    80TEXT 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
    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 - signum
    99	MOVL	$122, 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	$69, AX
   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	$87, 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	CLOCK_MONOTONIC, 4(SP)	// arg 1 - clock_id
   170	MOVL	BX, 8(SP)		// arg 2 - tp
   171	MOVL	$87, 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·sigaction(SB),NOSPLIT,$-4
   190	MOVL	$46, AX			// sys_sigaction
   191	INT	$0x80
   192	JAE	2(PC)
   193	MOVL	$0xf1, 0xf1		// crash
   194	RET
   195
   196TEXT runtime·obsdsigprocmask(SB),NOSPLIT,$-4
   197	MOVL	$48, AX			// sys_sigprocmask
   198	INT	$0x80
   199	JAE	2(PC)
   200	MOVL	$0xf1, 0xf1		// crash
   201	MOVL	AX, ret+8(FP)
   202	RET
   203
   204TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   205	MOVL	fn+0(FP), AX
   206	MOVL	sig+4(FP), BX
   207	MOVL	info+8(FP), CX
   208	MOVL	ctx+12(FP), DX
   209	MOVL	SP, SI
   210	SUBL	$32, SP
   211	ANDL	$~15, SP	// align stack: handler might be a C function
   212	MOVL	BX, 0(SP)
   213	MOVL	CX, 4(SP)
   214	MOVL	DX, 8(SP)
   215	MOVL	SI, 12(SP)	// save SI: handler might be a Go function
   216	CALL	AX
   217	MOVL	12(SP), AX
   218	MOVL	AX, SP
   219	RET
   220
   221TEXT runtime·sigtramp(SB),NOSPLIT,$28
   222	// Save callee-saved C registers, since the caller may be a C signal handler.
   223	MOVL	BX, bx-4(SP)
   224	MOVL	BP, bp-8(SP)
   225	MOVL	SI, si-12(SP)
   226	MOVL	DI, di-16(SP)
   227	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   228	// modify them.
   229
   230	MOVL	signo+0(FP), BX
   231	MOVL	BX, 0(SP)
   232	MOVL	info+4(FP), BX
   233	MOVL	BX, 4(SP)
   234	MOVL	context+8(FP), BX
   235	MOVL	BX, 8(SP)
   236	CALL	runtime·sigtrampgo(SB)
   237
   238	MOVL	di-16(SP), DI
   239	MOVL	si-12(SP), SI
   240	MOVL	bp-8(SP),  BP
   241	MOVL	bx-4(SP),  BX
   242	RET
   243
   244// int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
   245TEXT runtime·tfork(SB),NOSPLIT,$12
   246
   247	// Copy mp, gp and fn from the parent stack onto the child stack.
   248	MOVL	param+0(FP), AX
   249	MOVL	8(AX), CX		// tf_stack
   250	SUBL	$16, CX
   251	MOVL	CX, 8(AX)
   252	MOVL	mm+8(FP), SI
   253	MOVL	SI, 0(CX)
   254	MOVL	gg+12(FP), SI
   255	MOVL	SI, 4(CX)
   256	MOVL	fn+16(FP), SI
   257	MOVL	SI, 8(CX)
   258	MOVL	$1234, 12(CX)
   259
   260	MOVL	$0, 0(SP)		// syscall gap
   261	MOVL	param+0(FP), AX
   262	MOVL	AX, 4(SP)		// arg 1 - param
   263	MOVL	psize+4(FP), AX
   264	MOVL	AX, 8(SP)		// arg 2 - psize
   265	MOVL	$8, AX			// sys___tfork
   266	INT	$0x80
   267
   268	// Return if tfork syscall failed.
   269	JCC	4(PC)
   270	NEGL	AX
   271	MOVL	AX, ret+20(FP)
   272	RET
   273
   274	// In parent, return.
   275	CMPL	AX, $0
   276	JEQ	3(PC)
   277	MOVL	AX, ret+20(FP)
   278	RET
   279
   280	// Paranoia: check that SP is as we expect.
   281	MOVL	12(SP), BP
   282	CMPL	BP, $1234
   283	JEQ	2(PC)
   284	INT	$3
   285
   286	// Reload registers.
   287	MOVL	0(SP), BX		// m
   288	MOVL	4(SP), DX		// g
   289	MOVL	8(SP), SI		// fn
   290
   291	// Set FS to point at m->tls.
   292	LEAL	m_tls(BX), BP
   293	PUSHAL				// save registers
   294	PUSHL	BP
   295	CALL	runtime·settls(SB)
   296	POPL	AX
   297	POPAL
   298
   299	// Now segment is established. Initialize m, g.
   300	get_tls(AX)
   301	MOVL	DX, g(AX)
   302	MOVL	BX, g_m(DX)
   303
   304	CALL	runtime·stackcheck(SB)	// smashes AX, CX
   305	MOVL	0(DX), DX		// paranoia; check they are not nil
   306	MOVL	0(BX), BX
   307
   308	// More paranoia; check that stack splitting code works.
   309	PUSHAL
   310	CALL	runtime·emptyfunc(SB)
   311	POPAL
   312
   313	// Call fn.
   314	CALL	SI
   315
   316	// fn should never return.
   317	MOVL	$0x1234, 0x1005
   318	RET
   319
   320TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   321	MOVL	$288, AX		// sys_sigaltstack
   322	MOVL	new+0(FP), BX
   323	MOVL	old+4(FP), CX
   324	INT	$0x80
   325	CMPL	AX, $0xfffff001
   326	JLS	2(PC)
   327	INT	$3
   328	RET
   329
   330TEXT runtime·setldt(SB),NOSPLIT,$4
   331	// Under OpenBSD we set the GS base instead of messing with the LDT.
   332	MOVL	tls0+4(FP), AX
   333	MOVL	AX, 0(SP)
   334	CALL	runtime·settls(SB)
   335	RET
   336
   337TEXT runtime·settls(SB),NOSPLIT,$8
   338	// adjust for ELF: wants to use -4(GS) for g
   339	MOVL	tlsbase+0(FP), CX
   340	ADDL	$4, CX
   341	MOVL	$0, 0(SP)		// syscall gap
   342	MOVL	CX, 4(SP)		// arg 1 - tcb
   343	MOVL	$329, AX		// sys___set_tcb
   344	INT	$0x80
   345	JCC	2(PC)
   346	MOVL	$0xf1, 0xf1		// crash
   347	RET
   348
   349TEXT runtime·osyield(SB),NOSPLIT,$-4
   350	MOVL	$298, AX		// sys_sched_yield
   351	INT	$0x80
   352	RET
   353
   354TEXT runtime·thrsleep(SB),NOSPLIT,$-4
   355	MOVL	$94, AX			// sys___thrsleep
   356	INT	$0x80
   357	MOVL	AX, ret+20(FP)
   358	RET
   359
   360TEXT runtime·thrwakeup(SB),NOSPLIT,$-4
   361	MOVL	$301, AX		// sys___thrwakeup
   362	INT	$0x80
   363	MOVL	AX, ret+8(FP)
   364	RET
   365
   366TEXT runtime·sysctl(SB),NOSPLIT,$28
   367	LEAL	mib+0(FP), SI
   368	LEAL	4(SP), DI
   369	CLD
   370	MOVSL				// arg 1 - name
   371	MOVSL				// arg 2 - namelen
   372	MOVSL				// arg 3 - oldp
   373	MOVSL				// arg 4 - oldlenp
   374	MOVSL				// arg 5 - newp
   375	MOVSL				// arg 6 - newlen
   376	MOVL	$202, AX		// sys___sysctl
   377	INT	$0x80
   378	JCC	4(PC)
   379	NEGL	AX
   380	MOVL	AX, ret+24(FP)
   381	RET
   382	MOVL	$0, AX
   383	MOVL	AX, ret+24(FP)
   384	RET
   385
   386// int32 runtime·kqueue(void);
   387TEXT runtime·kqueue(SB),NOSPLIT,$0
   388	MOVL	$269, AX
   389	INT	$0x80
   390	JAE	2(PC)
   391	NEGL	AX
   392	MOVL	AX, ret+0(FP)
   393	RET
   394
   395// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   396TEXT runtime·kevent(SB),NOSPLIT,$0
   397	MOVL	$72, AX			// sys_kevent
   398	INT	$0x80
   399	JAE	2(PC)
   400	NEGL	AX
   401	MOVL	AX, ret+24(FP)
   402	RET
   403
   404// int32 runtime·closeonexec(int32 fd);
   405TEXT runtime·closeonexec(SB),NOSPLIT,$32
   406	MOVL	$92, AX			// sys_fcntl
   407	// 0(SP) is where the caller PC would be; kernel skips it
   408	MOVL	fd+0(FP), BX
   409	MOVL	BX, 4(SP)	// fd
   410	MOVL	$2, 8(SP)	// F_SETFD
   411	MOVL	$1, 12(SP)	// FD_CLOEXEC
   412	INT	$0x80
   413	JAE	2(PC)
   414	NEGL	AX
   415	RET
   416
   417GLOBL runtime·tlsoffset(SB),NOPTR,$4

View as plain text