...
Run Format

Text file src/runtime/sys_freebsd_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, FreeBSD
     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
    13TEXT runtime·sys_umtx_op(SB),NOSPLIT,$-4
    14	MOVL	$454, AX
    15	INT	$0x80
    16	MOVL	AX, ret+20(FP)
    17	RET
    18
    19TEXT runtime·thr_new(SB),NOSPLIT,$-4
    20	MOVL	$455, AX
    21	INT	$0x80
    22	MOVL	AX, ret+8(FP)
    23	RET
    24
    25TEXT runtime·thr_start(SB),NOSPLIT,$0
    26	MOVL	mm+0(FP), AX
    27	MOVL	m_g0(AX), BX
    28	LEAL	m_tls(AX), BP
    29	MOVL	m_id(AX), DI
    30	ADDL	$7, DI
    31	PUSHAL
    32	PUSHL	$32
    33	PUSHL	BP
    34	PUSHL	DI
    35	CALL	runtime·setldt(SB)
    36	POPL	AX
    37	POPL	AX
    38	POPL	AX
    39	POPAL
    40	get_tls(CX)
    41	MOVL	BX, g(CX)
    42
    43	MOVL	AX, g_m(BX)
    44	CALL	runtime·stackcheck(SB)		// smashes AX
    45	CALL	runtime·mstart(SB)
    46
    47	MOVL	0, AX			// crash (not reached)
    48
    49// Exit the entire program (like C exit)
    50TEXT runtime·exit(SB),NOSPLIT,$-4
    51	MOVL	$1, AX
    52	INT	$0x80
    53	MOVL	$0xf1, 0xf1  // crash
    54	RET
    55
    56GLOBL exitStack<>(SB),RODATA,$8
    57DATA exitStack<>+0x00(SB)/4, $0
    58DATA exitStack<>+0x04(SB)/4, $0
    59
    60// func exitThread(wait *uint32)
    61TEXT runtime·exitThread(SB),NOSPLIT,$0-4
    62	MOVL	wait+0(FP), AX
    63	// We're done using the stack.
    64	MOVL	$0, (AX)
    65	// thr_exit takes a single pointer argument, which it expects
    66	// on the stack. We want to pass 0, so switch over to a fake
    67	// stack of 0s. It won't write to the stack.
    68	MOVL	$exitStack<>(SB), SP
    69	MOVL	$431, AX	// thr_exit
    70	INT	$0x80
    71	MOVL	$0xf1, 0xf1  // crash
    72	JMP	0(PC)
    73
    74TEXT runtime·open(SB),NOSPLIT,$-4
    75	MOVL	$5, AX
    76	INT	$0x80
    77	JAE	2(PC)
    78	MOVL	$-1, AX
    79	MOVL	AX, ret+12(FP)
    80	RET
    81
    82TEXT runtime·closefd(SB),NOSPLIT,$-4
    83	MOVL	$6, AX
    84	INT	$0x80
    85	JAE	2(PC)
    86	MOVL	$-1, AX
    87	MOVL	AX, ret+4(FP)
    88	RET
    89
    90TEXT runtime·read(SB),NOSPLIT,$-4
    91	MOVL	$3, AX
    92	INT	$0x80
    93	JAE	2(PC)
    94	MOVL	$-1, AX
    95	MOVL	AX, ret+12(FP)
    96	RET
    97
    98TEXT runtime·write(SB),NOSPLIT,$-4
    99	MOVL	$4, AX
   100	INT	$0x80
   101	JAE	2(PC)
   102	MOVL	$-1, AX
   103	MOVL	AX, ret+12(FP)
   104	RET
   105
   106TEXT runtime·raise(SB),NOSPLIT,$16
   107	// thr_self(&8(SP))
   108	LEAL	8(SP), AX
   109	MOVL	AX, 4(SP)
   110	MOVL	$432, AX
   111	INT	$0x80
   112	// thr_kill(self, SIGPIPE)
   113	MOVL	8(SP), AX
   114	MOVL	AX, 4(SP)
   115	MOVL	sig+0(FP), AX
   116	MOVL	AX, 8(SP)
   117	MOVL	$433, AX
   118	INT	$0x80
   119	RET
   120
   121TEXT runtime·raiseproc(SB),NOSPLIT,$16
   122	// getpid
   123	MOVL	$20, AX
   124	INT	$0x80
   125	// kill(self, sig)
   126	MOVL	AX, 4(SP)
   127	MOVL	sig+0(FP), AX
   128	MOVL	AX, 8(SP)
   129	MOVL	$37, AX
   130	INT	$0x80
   131	RET
   132
   133TEXT runtime·mmap(SB),NOSPLIT,$32
   134	LEAL addr+0(FP), SI
   135	LEAL	4(SP), DI
   136	CLD
   137	MOVSL
   138	MOVSL
   139	MOVSL
   140	MOVSL
   141	MOVSL
   142	MOVSL
   143	MOVL	$0, AX	// top 32 bits of file offset
   144	STOSL
   145	MOVL	$477, AX
   146	INT	$0x80
   147	JAE	ok
   148	MOVL	$0, p+24(FP)
   149	MOVL	AX, err+28(FP)
   150	RET
   151ok:
   152	MOVL	AX, p+24(FP)
   153	MOVL	$0, err+28(FP)
   154	RET
   155
   156TEXT runtime·munmap(SB),NOSPLIT,$-4
   157	MOVL	$73, AX
   158	INT	$0x80
   159	JAE	2(PC)
   160	MOVL	$0xf1, 0xf1  // crash
   161	RET
   162
   163TEXT runtime·madvise(SB),NOSPLIT,$-4
   164	MOVL	$75, AX	// madvise
   165	INT	$0x80
   166	JAE	2(PC)
   167	MOVL	$-1, AX
   168	MOVL	AX, ret+12(FP)
   169	RET
   170
   171TEXT runtime·setitimer(SB), NOSPLIT, $-4
   172	MOVL	$83, AX
   173	INT	$0x80
   174	RET
   175
   176// func fallback_walltime() (sec int64, nsec int32)
   177TEXT runtime·fallback_walltime(SB), NOSPLIT, $32-12
   178	MOVL	$232, AX // clock_gettime
   179	LEAL	12(SP), BX
   180	MOVL	$0, 4(SP)	// CLOCK_REALTIME
   181	MOVL	BX, 8(SP)
   182	INT	$0x80
   183	MOVL	12(SP), AX	// sec
   184	MOVL	16(SP), BX	// nsec
   185
   186	// sec is in AX, nsec in BX
   187	MOVL	AX, sec_lo+0(FP)
   188	MOVL	$0, sec_hi+4(FP)
   189	MOVL	BX, nsec+8(FP)
   190	RET
   191
   192// func fallback_nanotime() int64
   193TEXT runtime·fallback_nanotime(SB), NOSPLIT, $32-8
   194	MOVL	$232, AX
   195	LEAL	12(SP), BX
   196	MOVL	$4, 4(SP)	// CLOCK_MONOTONIC
   197	MOVL	BX, 8(SP)
   198	INT	$0x80
   199	MOVL	12(SP), AX	// sec
   200	MOVL	16(SP), BX	// nsec
   201
   202	// sec is in AX, nsec in BX
   203	// convert to DX:AX nsec
   204	MOVL	$1000000000, CX
   205	MULL	CX
   206	ADDL	BX, AX
   207	ADCL	$0, DX
   208
   209	MOVL	AX, ret_lo+0(FP)
   210	MOVL	DX, ret_hi+4(FP)
   211	RET
   212
   213
   214TEXT runtime·asmSigaction(SB),NOSPLIT,$-4
   215	MOVL	$416, AX
   216	INT	$0x80
   217	MOVL	AX, ret+12(FP)
   218	RET
   219
   220TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   221	MOVL	fn+0(FP), AX
   222	MOVL	sig+4(FP), BX
   223	MOVL	info+8(FP), CX
   224	MOVL	ctx+12(FP), DX
   225	MOVL	SP, SI
   226	SUBL	$32, SP
   227	ANDL	$~15, SP	// align stack: handler might be a C function
   228	MOVL	BX, 0(SP)
   229	MOVL	CX, 4(SP)
   230	MOVL	DX, 8(SP)
   231	MOVL	SI, 12(SP)	// save SI: handler might be a Go function
   232	CALL	AX
   233	MOVL	12(SP), AX
   234	MOVL	AX, SP
   235	RET
   236
   237TEXT runtime·sigtramp(SB),NOSPLIT,$12
   238	MOVL	signo+0(FP), BX
   239	MOVL	BX, 0(SP)
   240	MOVL	info+4(FP), BX
   241	MOVL	BX, 4(SP)
   242	MOVL	context+8(FP), BX
   243	MOVL	BX, 8(SP)
   244	CALL	runtime·sigtrampgo(SB)
   245
   246	// call sigreturn
   247	MOVL	context+8(FP), AX
   248	MOVL	$0, 0(SP)	// syscall gap
   249	MOVL	AX, 4(SP)
   250	MOVL	$417, AX	// sigreturn(ucontext)
   251	INT	$0x80
   252	MOVL	$0xf1, 0xf1  // crash
   253	RET
   254
   255TEXT runtime·sigaltstack(SB),NOSPLIT,$0
   256	MOVL	$53, AX
   257	INT	$0x80
   258	JAE	2(PC)
   259	MOVL	$0xf1, 0xf1  // crash
   260	RET
   261
   262TEXT runtime·usleep(SB),NOSPLIT,$20
   263	MOVL	$0, DX
   264	MOVL	usec+0(FP), AX
   265	MOVL	$1000000, CX
   266	DIVL	CX
   267	MOVL	AX, 12(SP)		// tv_sec
   268	MOVL	$1000, AX
   269	MULL	DX
   270	MOVL	AX, 16(SP)		// tv_nsec
   271
   272	MOVL	$0, 0(SP)
   273	LEAL	12(SP), AX
   274	MOVL	AX, 4(SP)		// arg 1 - rqtp
   275	MOVL	$0, 8(SP)		// arg 2 - rmtp
   276	MOVL	$240, AX		// sys_nanosleep
   277	INT	$0x80
   278	RET
   279
   280/*
   281descriptor entry format for system call
   282is the native machine format, ugly as it is:
   283
   284	2-byte limit
   285	3-byte base
   286	1-byte: 0x80=present, 0x60=dpl<<5, 0x1F=type
   287	1-byte: 0x80=limit is *4k, 0x40=32-bit operand size,
   288		0x0F=4 more bits of limit
   289	1 byte: 8 more bits of base
   290
   291int i386_get_ldt(int, union ldt_entry *, int);
   292int i386_set_ldt(int, const union ldt_entry *, int);
   293
   294*/
   295
   296// setldt(int entry, int address, int limit)
   297TEXT runtime·setldt(SB),NOSPLIT,$32
   298	MOVL	address+4(FP), BX	// aka base
   299	// see comment in sys_linux_386.s; freebsd is similar
   300	ADDL	$0x4, BX
   301
   302	// set up data_desc
   303	LEAL	16(SP), AX	// struct data_desc
   304	MOVL	$0, 0(AX)
   305	MOVL	$0, 4(AX)
   306
   307	MOVW	BX, 2(AX)
   308	SHRL	$16, BX
   309	MOVB	BX, 4(AX)
   310	SHRL	$8, BX
   311	MOVB	BX, 7(AX)
   312
   313	MOVW	$0xffff, 0(AX)
   314	MOVB	$0xCF, 6(AX)	// 32-bit operand, 4k limit unit, 4 more bits of limit
   315
   316	MOVB	$0xF2, 5(AX)	// r/w data descriptor, dpl=3, present
   317
   318	// call i386_set_ldt(entry, desc, 1)
   319	MOVL	$0xffffffff, 0(SP)	// auto-allocate entry and return in AX
   320	MOVL	AX, 4(SP)
   321	MOVL	$1, 8(SP)
   322	CALL	runtime·i386_set_ldt(SB)
   323
   324	// compute segment selector - (entry*8+7)
   325	SHLL	$3, AX
   326	ADDL	$7, AX
   327	MOVW	AX, GS
   328	RET
   329
   330TEXT runtime·i386_set_ldt(SB),NOSPLIT,$16
   331	LEAL	args+0(FP), AX	// 0(FP) == 4(SP) before SP got moved
   332	MOVL	$0, 0(SP)	// syscall gap
   333	MOVL	$1, 4(SP)
   334	MOVL	AX, 8(SP)
   335	MOVL	$165, AX
   336	INT	$0x80
   337	JAE	2(PC)
   338	INT	$3
   339	RET
   340
   341TEXT runtime·sysctl(SB),NOSPLIT,$28
   342	LEAL	mib+0(FP), SI
   343	LEAL	4(SP), DI
   344	CLD
   345	MOVSL				// arg 1 - name
   346	MOVSL				// arg 2 - namelen
   347	MOVSL				// arg 3 - oldp
   348	MOVSL				// arg 4 - oldlenp
   349	MOVSL				// arg 5 - newp
   350	MOVSL				// arg 6 - newlen
   351	MOVL	$202, AX		// sys___sysctl
   352	INT	$0x80
   353	JAE	4(PC)
   354	NEGL	AX
   355	MOVL	AX, ret+24(FP)
   356	RET
   357	MOVL	$0, AX
   358	MOVL	AX, ret+24(FP)
   359	RET
   360
   361TEXT runtime·osyield(SB),NOSPLIT,$-4
   362	MOVL	$331, AX		// sys_sched_yield
   363	INT	$0x80
   364	RET
   365
   366TEXT runtime·sigprocmask(SB),NOSPLIT,$16
   367	MOVL	$0, 0(SP)		// syscall gap
   368	MOVL	how+0(FP), AX		// arg 1 - how
   369	MOVL	AX, 4(SP)
   370	MOVL	new+4(FP), AX
   371	MOVL	AX, 8(SP)		// arg 2 - set
   372	MOVL	old+8(FP), AX
   373	MOVL	AX, 12(SP)		// arg 3 - oset
   374	MOVL	$340, AX		// sys_sigprocmask
   375	INT	$0x80
   376	JAE	2(PC)
   377	MOVL	$0xf1, 0xf1  // crash
   378	RET
   379
   380// int32 runtime·kqueue(void);
   381TEXT runtime·kqueue(SB),NOSPLIT,$0
   382	MOVL	$362, AX
   383	INT	$0x80
   384	JAE	2(PC)
   385	NEGL	AX
   386	MOVL	AX, ret+0(FP)
   387	RET
   388
   389// int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout);
   390TEXT runtime·kevent(SB),NOSPLIT,$0
   391	MOVL	$363, AX
   392	INT	$0x80
   393	JAE	2(PC)
   394	NEGL	AX
   395	MOVL	AX, ret+24(FP)
   396	RET
   397
   398// int32 runtime·closeonexec(int32 fd);
   399TEXT runtime·closeonexec(SB),NOSPLIT,$32
   400	MOVL	$92, AX		// fcntl
   401	// 0(SP) is where the caller PC would be; kernel skips it
   402	MOVL	fd+0(FP), BX
   403	MOVL	BX, 4(SP)	// fd
   404	MOVL	$2, 8(SP)	// F_SETFD
   405	MOVL	$1, 12(SP)	// FD_CLOEXEC
   406	INT	$0x80
   407	JAE	2(PC)
   408	NEGL	AX
   409	RET
   410
   411// func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
   412TEXT runtime·cpuset_getaffinity(SB), NOSPLIT, $0-28
   413	MOVL	$487, AX
   414	INT	$0x80
   415	JAE	2(PC)
   416	NEGL	AX
   417	MOVL	AX, ret+24(FP)
   418	RET
   419
   420GLOBL runtime·tlsoffset(SB),NOPTR,$4

View as plain text