Text file src/runtime/sys_netbsd_386.s

     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  #define CLOCK_REALTIME		0
    14  #define CLOCK_MONOTONIC		3
    15  #define FD_CLOEXEC		1
    16  #define F_SETFD			2
    17  
    18  #define SYS_exit			1
    19  #define SYS_read			3
    20  #define SYS_write			4
    21  #define SYS_open			5
    22  #define SYS_close			6
    23  #define SYS_getpid			20
    24  #define SYS_kill			37
    25  #define SYS_munmap			73
    26  #define SYS_madvise			75
    27  #define SYS_fcntl			92
    28  #define SYS_mmap			197
    29  #define SYS___sysctl			202
    30  #define SYS___sigaltstack14		281
    31  #define SYS___sigprocmask14		293
    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  // Exit the entire program (like C exit)
    50  TEXT runtime·exit(SB),NOSPLIT,$-4
    51  	MOVL	$SYS_exit, AX
    52  	INT	$0x80
    53  	MOVL	$0xf1, 0xf1		// crash
    54  	RET
    55  
    56  // func exitThread(wait *uint32)
    57  TEXT runtime·exitThread(SB),NOSPLIT,$0-4
    58  	MOVL	wait+0(FP), AX
    59  	// We're done using the stack.
    60  	MOVL	$0, (AX)
    61  	MOVL	$SYS__lwp_exit, AX
    62  	INT	$0x80
    63  	MOVL	$0xf1, 0xf1		// crash
    64  	JMP	0(PC)
    65  
    66  TEXT runtime·open(SB),NOSPLIT,$-4
    67  	MOVL	$SYS_open, AX
    68  	INT	$0x80
    69  	JAE	2(PC)
    70  	MOVL	$-1, AX
    71  	MOVL	AX, ret+12(FP)
    72  	RET
    73  
    74  TEXT runtime·closefd(SB),NOSPLIT,$-4
    75  	MOVL	$SYS_close, AX
    76  	INT	$0x80
    77  	JAE	2(PC)
    78  	MOVL	$-1, AX
    79  	MOVL	AX, ret+4(FP)
    80  	RET
    81  
    82  TEXT runtime·read(SB),NOSPLIT,$-4
    83  	MOVL	$SYS_read, AX
    84  	INT	$0x80
    85  	JAE	2(PC)
    86  	NEGL	AX			// caller expects negative errno
    87  	MOVL	AX, ret+12(FP)
    88  	RET
    89  
    90  // func pipe2(flags int32) (r, w int32, errno int32)
    91  TEXT runtime·pipe2(SB),NOSPLIT,$12-16
    92  	MOVL	$453, AX
    93  	LEAL	r+4(FP), BX
    94  	MOVL	BX, 4(SP)
    95  	MOVL	flags+0(FP), BX
    96  	MOVL	BX, 8(SP)
    97  	INT	$0x80
    98  	MOVL	AX, errno+12(FP)
    99  	RET
   100  
   101  TEXT runtime·write1(SB),NOSPLIT,$-4
   102  	MOVL	$SYS_write, AX
   103  	INT	$0x80
   104  	JAE	2(PC)
   105  	NEGL	AX			// caller expects negative errno
   106  	MOVL	AX, ret+12(FP)
   107  	RET
   108  
   109  TEXT runtime·usleep(SB),NOSPLIT,$24
   110  	MOVL	$0, DX
   111  	MOVL	usec+0(FP), AX
   112  	MOVL	$1000000, CX
   113  	DIVL	CX
   114  	MOVL	AX, 12(SP)		// tv_sec - l32
   115  	MOVL	$0, 16(SP)		// tv_sec - h32
   116  	MOVL	$1000, AX
   117  	MULL	DX
   118  	MOVL	AX, 20(SP)		// tv_nsec
   119  
   120  	MOVL	$0, 0(SP)
   121  	LEAL	12(SP), AX
   122  	MOVL	AX, 4(SP)		// arg 1 - rqtp
   123  	MOVL	$0, 8(SP)		// arg 2 - rmtp
   124  	MOVL	$SYS___nanosleep50, AX
   125  	INT	$0x80
   126  	RET
   127  
   128  TEXT runtime·lwp_kill(SB),NOSPLIT,$12-8
   129  	MOVL	$0, 0(SP)
   130  	MOVL	tid+0(FP), AX
   131  	MOVL	AX, 4(SP)		// arg 1 - target
   132  	MOVL	sig+4(FP), AX
   133  	MOVL	AX, 8(SP)		// arg 2 - signo
   134  	MOVL	$SYS__lwp_kill, AX
   135  	INT	$0x80
   136  	RET
   137  
   138  TEXT runtime·raiseproc(SB),NOSPLIT,$12
   139  	MOVL	$SYS_getpid, AX
   140  	INT	$0x80
   141  	MOVL	$0, 0(SP)
   142  	MOVL	AX, 4(SP)		// arg 1 - pid
   143  	MOVL	sig+0(FP), AX
   144  	MOVL	AX, 8(SP)		// arg 2 - signo
   145  	MOVL	$SYS_kill, AX
   146  	INT	$0x80
   147  	RET
   148  
   149  TEXT runtime·mmap(SB),NOSPLIT,$36
   150  	LEAL	addr+0(FP), SI
   151  	LEAL	4(SP), DI
   152  	CLD
   153  	MOVSL				// arg 1 - addr
   154  	MOVSL				// arg 2 - len
   155  	MOVSL				// arg 3 - prot
   156  	MOVSL				// arg 4 - flags
   157  	MOVSL				// arg 5 - fd
   158  	MOVL	$0, AX
   159  	STOSL				// arg 6 - pad
   160  	MOVSL				// arg 7 - offset
   161  	MOVL	$0, AX			// top 32 bits of file offset
   162  	STOSL
   163  	MOVL	$SYS_mmap, AX
   164  	INT	$0x80
   165  	JAE	ok
   166  	MOVL	$0, p+24(FP)
   167  	MOVL	AX, err+28(FP)
   168  	RET
   169  ok:
   170  	MOVL	AX, p+24(FP)
   171  	MOVL	$0, err+28(FP)
   172  	RET
   173  
   174  TEXT runtime·munmap(SB),NOSPLIT,$-4
   175  	MOVL	$SYS_munmap, AX
   176  	INT	$0x80
   177  	JAE	2(PC)
   178  	MOVL	$0xf1, 0xf1		// crash
   179  	RET
   180  
   181  TEXT runtime·madvise(SB),NOSPLIT,$-4
   182  	MOVL	$SYS_madvise, AX
   183  	INT	$0x80
   184  	JAE	2(PC)
   185  	MOVL	$-1, AX
   186  	MOVL	AX, ret+12(FP)
   187  	RET
   188  
   189  TEXT runtime·setitimer(SB),NOSPLIT,$-4
   190  	MOVL	$SYS___setitimer50, AX
   191  	INT	$0x80
   192  	RET
   193  
   194  // func walltime() (sec int64, nsec int32)
   195  TEXT runtime·walltime(SB), NOSPLIT, $32
   196  	LEAL	12(SP), BX
   197  	MOVL	$CLOCK_REALTIME, 4(SP)	// arg 1 - clock_id
   198  	MOVL	BX, 8(SP)		// arg 2 - tp
   199  	MOVL	$SYS___clock_gettime50, AX
   200  	INT	$0x80
   201  
   202  	MOVL	12(SP), AX		// sec - l32
   203  	MOVL	AX, sec_lo+0(FP)
   204  	MOVL	16(SP), AX		// sec - h32
   205  	MOVL	AX, sec_hi+4(FP)
   206  
   207  	MOVL	20(SP), BX		// nsec
   208  	MOVL	BX, nsec+8(FP)
   209  	RET
   210  
   211  // int64 nanotime1(void) so really
   212  // void nanotime1(int64 *nsec)
   213  TEXT runtime·nanotime1(SB),NOSPLIT,$32
   214  	LEAL	12(SP), BX
   215  	MOVL	$CLOCK_MONOTONIC, 4(SP)	// arg 1 - clock_id
   216  	MOVL	BX, 8(SP)		// arg 2 - tp
   217  	MOVL	$SYS___clock_gettime50, AX
   218  	INT	$0x80
   219  
   220  	MOVL	16(SP), CX		// sec - h32
   221  	IMULL	$1000000000, CX
   222  
   223  	MOVL	12(SP), AX		// sec - l32
   224  	MOVL	$1000000000, BX
   225  	MULL	BX			// result in dx:ax
   226  
   227  	MOVL	20(SP), BX		// nsec
   228  	ADDL	BX, AX
   229  	ADCL	CX, DX			// add high bits with carry
   230  
   231  	MOVL	AX, ret_lo+0(FP)
   232  	MOVL	DX, ret_hi+4(FP)
   233  	RET
   234  
   235  TEXT runtime·getcontext(SB),NOSPLIT,$-4
   236  	MOVL	$SYS_getcontext, AX
   237  	INT	$0x80
   238  	JAE	2(PC)
   239  	MOVL	$0xf1, 0xf1		// crash
   240  	RET
   241  
   242  TEXT runtime·sigprocmask(SB),NOSPLIT,$-4
   243  	MOVL	$SYS___sigprocmask14, AX
   244  	INT	$0x80
   245  	JAE	2(PC)
   246  	MOVL	$0xf1, 0xf1		// crash
   247  	RET
   248  
   249  TEXT sigreturn_tramp<>(SB),NOSPLIT,$0
   250  	LEAL	140(SP), AX		// Load address of ucontext
   251  	MOVL	AX, 4(SP)
   252  	MOVL	$SYS_setcontext, AX
   253  	INT	$0x80
   254  	MOVL	$-1, 4(SP)		// Something failed...
   255  	MOVL	$SYS_exit, AX
   256  	INT	$0x80
   257  
   258  TEXT runtime·sigaction(SB),NOSPLIT,$24
   259  	LEAL	sig+0(FP), SI
   260  	LEAL	4(SP), DI
   261  	CLD
   262  	MOVSL				// arg 1 - sig
   263  	MOVSL				// arg 2 - act
   264  	MOVSL				// arg 3 - oact
   265  	LEAL	sigreturn_tramp<>(SB), AX
   266  	STOSL				// arg 4 - tramp
   267  	MOVL	$2, AX
   268  	STOSL				// arg 5 - vers
   269  	MOVL	$SYS___sigaction_sigtramp, AX
   270  	INT	$0x80
   271  	JAE	2(PC)
   272  	MOVL	$0xf1, 0xf1		// crash
   273  	RET
   274  
   275  TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
   276  	MOVL	fn+0(FP), AX
   277  	MOVL	sig+4(FP), BX
   278  	MOVL	info+8(FP), CX
   279  	MOVL	ctx+12(FP), DX
   280  	MOVL	SP, SI
   281  	SUBL	$32, SP
   282  	ANDL	$-15, SP	// align stack: handler might be a C function
   283  	MOVL	BX, 0(SP)
   284  	MOVL	CX, 4(SP)
   285  	MOVL	DX, 8(SP)
   286  	MOVL	SI, 12(SP)	// save SI: handler might be a Go function
   287  	CALL	AX
   288  	MOVL	12(SP), AX
   289  	MOVL	AX, SP
   290  	RET
   291  
   292  // Called by OS using C ABI.
   293  TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$28
   294  	NOP	SP	// tell vet SP changed - stop checking offsets
   295  	// Save callee-saved C registers, since the caller may be a C signal handler.
   296  	MOVL	BX, bx-4(SP)
   297  	MOVL	BP, bp-8(SP)
   298  	MOVL	SI, si-12(SP)
   299  	MOVL	DI, di-16(SP)
   300  	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   301  	// modify them.
   302  
   303  	MOVL	32(SP), BX // signo
   304  	MOVL	BX, 0(SP)
   305  	MOVL	36(SP), BX // info
   306  	MOVL	BX, 4(SP)
   307  	MOVL	40(SP), BX // context
   308  	MOVL	BX, 8(SP)
   309  	CALL	runtime·sigtrampgo(SB)
   310  
   311  	MOVL	di-16(SP), DI
   312  	MOVL	si-12(SP), SI
   313  	MOVL	bp-8(SP),  BP
   314  	MOVL	bx-4(SP),  BX
   315  	RET
   316  
   317  // int32 lwp_create(void *context, uintptr flags, void *lwpid);
   318  TEXT runtime·lwp_create(SB),NOSPLIT,$16
   319  	MOVL	$0, 0(SP)
   320  	MOVL	ctxt+0(FP), AX
   321  	MOVL	AX, 4(SP)		// arg 1 - context
   322  	MOVL	flags+4(FP), AX
   323  	MOVL	AX, 8(SP)		// arg 2 - flags
   324  	MOVL	lwpid+8(FP), AX
   325  	MOVL	AX, 12(SP)		// arg 3 - lwpid
   326  	MOVL	$SYS__lwp_create, AX
   327  	INT	$0x80
   328  	JCC	2(PC)
   329  	NEGL	AX
   330  	MOVL	AX, ret+12(FP)
   331  	RET
   332  
   333  TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
   334  
   335  	// Set FS to point at m->tls
   336  	LEAL	m_tls(BX), BP
   337  	PUSHAL				// save registers
   338  	PUSHL	BP
   339  	CALL	lwp_setprivate<>(SB)
   340  	POPL	AX
   341  	POPAL
   342  
   343  	// Now segment is established. Initialize m, g.
   344  	get_tls(AX)
   345  	MOVL	DX, g(AX)
   346  	MOVL	BX, g_m(DX)
   347  
   348  	CALL	runtime·stackcheck(SB)	// smashes AX, CX
   349  	MOVL	0(DX), DX		// paranoia; check they are not nil
   350  	MOVL	0(BX), BX
   351  
   352  	// more paranoia; check that stack splitting code works
   353  	PUSHAL
   354  	CALL	runtime·emptyfunc(SB)
   355  	POPAL
   356  
   357  	// Call fn
   358  	CALL	SI
   359  
   360  	// fn should never return
   361  	MOVL	$0x1234, 0x1005
   362  	RET
   363  
   364  TEXT ·netbsdMstart(SB),NOSPLIT|TOPFRAME,$0
   365  	CALL	·netbsdMstart0(SB)
   366  	RET // not reached
   367  
   368  TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   369  	MOVL	$SYS___sigaltstack14, AX
   370  	MOVL	new+0(FP), BX
   371  	MOVL	old+4(FP), CX
   372  	INT	$0x80
   373  	CMPL	AX, $0xfffff001
   374  	JLS	2(PC)
   375  	INT	$3
   376  	RET
   377  
   378  TEXT runtime·setldt(SB),NOSPLIT,$8
   379  	// Under NetBSD we set the GS base instead of messing with the LDT.
   380  	MOVL	base+4(FP), AX
   381  	MOVL	AX, 0(SP)
   382  	CALL	lwp_setprivate<>(SB)
   383  	RET
   384  
   385  TEXT lwp_setprivate<>(SB),NOSPLIT,$16
   386  	// adjust for ELF: wants to use -4(GS) for g
   387  	MOVL	base+0(FP), CX
   388  	ADDL	$4, CX
   389  	MOVL	$0, 0(SP)		// syscall gap
   390  	MOVL	CX, 4(SP)		// arg 1 - ptr
   391  	MOVL	$SYS__lwp_setprivate, AX
   392  	INT	$0x80
   393  	JCC	2(PC)
   394  	MOVL	$0xf1, 0xf1		// crash
   395  	RET
   396  
   397  TEXT runtime·osyield(SB),NOSPLIT,$-4
   398  	MOVL	$SYS_sched_yield, AX
   399  	INT	$0x80
   400  	RET
   401  
   402  TEXT runtime·lwp_park(SB),NOSPLIT,$-4
   403  	MOVL	$SYS____lwp_park60, AX
   404  	INT	$0x80
   405  	MOVL	AX, ret+24(FP)
   406  	RET
   407  
   408  TEXT runtime·lwp_unpark(SB),NOSPLIT,$-4
   409  	MOVL	$SYS__lwp_unpark, AX
   410  	INT	$0x80
   411  	MOVL	AX, ret+8(FP)
   412  	RET
   413  
   414  TEXT runtime·lwp_self(SB),NOSPLIT,$-4
   415  	MOVL	$SYS__lwp_self, AX
   416  	INT	$0x80
   417  	MOVL	AX, ret+0(FP)
   418  	RET
   419  
   420  TEXT runtime·sysctl(SB),NOSPLIT,$28
   421  	LEAL	mib+0(FP), SI
   422  	LEAL	4(SP), DI
   423  	CLD
   424  	MOVSL				// arg 1 - name
   425  	MOVSL				// arg 2 - namelen
   426  	MOVSL				// arg 3 - oldp
   427  	MOVSL				// arg 4 - oldlenp
   428  	MOVSL				// arg 5 - newp
   429  	MOVSL				// arg 6 - newlen
   430  	MOVL	$SYS___sysctl, AX
   431  	INT	$0x80
   432  	JAE	4(PC)
   433  	NEGL	AX
   434  	MOVL	AX, ret+24(FP)
   435  	RET
   436  	MOVL	$0, AX
   437  	MOVL	AX, ret+24(FP)
   438  	RET
   439  
   440  GLOBL runtime·tlsoffset(SB),NOPTR,$4
   441  
   442  // int32 runtime·kqueue(void)
   443  TEXT runtime·kqueue(SB),NOSPLIT,$0
   444  	MOVL	$SYS_kqueue, AX
   445  	INT	$0x80
   446  	JAE	2(PC)
   447  	NEGL	AX
   448  	MOVL	AX, ret+0(FP)
   449  	RET
   450  
   451  // int32 runtime·kevent(int kq, Kevent *changelist, int nchanges, Kevent *eventlist, int nevents, Timespec *timeout)
   452  TEXT runtime·kevent(SB),NOSPLIT,$0
   453  	MOVL	$SYS___kevent50, AX
   454  	INT	$0x80
   455  	JAE	2(PC)
   456  	NEGL	AX
   457  	MOVL	AX, ret+24(FP)
   458  	RET
   459  
   460  // int32 runtime·closeonexec(int32 fd)
   461  TEXT runtime·closeonexec(SB),NOSPLIT,$32
   462  	MOVL	$SYS_fcntl, AX
   463  	// 0(SP) is where the caller PC would be; kernel skips it
   464  	MOVL	fd+0(FP), BX
   465  	MOVL	BX, 4(SP)	// fd
   466  	MOVL	$F_SETFD, 8(SP)
   467  	MOVL	$FD_CLOEXEC, 12(SP)
   468  	INT	$0x80
   469  	JAE	2(PC)
   470  	NEGL	AX
   471  	RET
   472  

View as plain text