Text file src/runtime/sys_openbsd_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, OpenBSD
     6  // System calls are implemented in libc/libpthread, this file
     7  // contains trampolines that convert from Go to C calling convention.
     8  // Some direct system call implementations currently remain.
     9  //
    10  
    11  #include "go_asm.h"
    12  #include "go_tls.h"
    13  #include "textflag.h"
    14  
    15  #define	CLOCK_MONOTONIC	$3
    16  
    17  TEXT runtime·setldt(SB),NOSPLIT,$0
    18  	// Nothing to do, pthread already set thread-local storage up.
    19  	RET
    20  
    21  // mstart_stub is the first function executed on a new thread started by pthread_create.
    22  // It just does some low-level setup and then calls mstart.
    23  // Note: called with the C calling convention.
    24  TEXT runtime·mstart_stub(SB),NOSPLIT,$28
    25  	NOP	SP	// tell vet SP changed - stop checking offsets
    26  
    27  	// We are already on m's g0 stack.
    28  
    29  	// Save callee-save registers.
    30  	MOVL	BX, bx-4(SP)
    31  	MOVL	BP, bp-8(SP)
    32  	MOVL	SI, si-12(SP)
    33  	MOVL	DI, di-16(SP)
    34  
    35  	MOVL	32(SP), AX	// m
    36  	MOVL	m_g0(AX), DX
    37  	get_tls(CX)
    38  	MOVL	DX, g(CX)
    39  
    40  	CALL	runtime·mstart(SB)
    41  
    42  	// Restore callee-save registers.
    43  	MOVL	di-16(SP), DI
    44  	MOVL	si-12(SP), SI
    45  	MOVL	bp-8(SP),  BP
    46  	MOVL	bx-4(SP),  BX
    47  
    48  	// Go is all done with this OS thread.
    49  	// Tell pthread everything is ok (we never join with this thread, so
    50  	// the value here doesn't really matter).
    51  	MOVL	$0, AX
    52  	RET
    53  
    54  TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
    55  	MOVL	fn+0(FP), AX
    56  	MOVL	sig+4(FP), BX
    57  	MOVL	info+8(FP), CX
    58  	MOVL	ctx+12(FP), DX
    59  	MOVL	SP, SI
    60  	SUBL	$32, SP
    61  	ANDL	$~15, SP	// align stack: handler might be a C function
    62  	MOVL	BX, 0(SP)
    63  	MOVL	CX, 4(SP)
    64  	MOVL	DX, 8(SP)
    65  	MOVL	SI, 12(SP)	// save SI: handler might be a Go function
    66  	CALL	AX
    67  	MOVL	12(SP), AX
    68  	MOVL	AX, SP
    69  	RET
    70  
    71  // Called by OS using C ABI.
    72  TEXT runtime·sigtramp(SB),NOSPLIT,$28
    73  	NOP	SP	// tell vet SP changed - stop checking offsets
    74  	// Save callee-saved C registers, since the caller may be a C signal handler.
    75  	MOVL	BX, bx-4(SP)
    76  	MOVL	BP, bp-8(SP)
    77  	MOVL	SI, si-12(SP)
    78  	MOVL	DI, di-16(SP)
    79  	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
    80  	// modify them.
    81  
    82  	MOVL	32(SP), BX // signo
    83  	MOVL	BX, 0(SP)
    84  	MOVL	36(SP), BX // info
    85  	MOVL	BX, 4(SP)
    86  	MOVL	40(SP), BX // context
    87  	MOVL	BX, 8(SP)
    88  	CALL	runtime·sigtrampgo(SB)
    89  
    90  	MOVL	di-16(SP), DI
    91  	MOVL	si-12(SP), SI
    92  	MOVL	bp-8(SP),  BP
    93  	MOVL	bx-4(SP),  BX
    94  	RET
    95  
    96  // These trampolines help convert from Go calling convention to C calling convention.
    97  // They should be called with asmcgocall - note that while asmcgocall does
    98  // stack alignment, creation of a frame undoes it again.
    99  // A pointer to the arguments is passed on the stack.
   100  // A single int32 result is returned in AX.
   101  // (For more results, make an args/results structure.)
   102  TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0
   103  	PUSHL	BP
   104  	MOVL	SP, BP
   105  	SUBL	$4, SP
   106  	MOVL	12(SP), DX		// pointer to args
   107  	MOVL	0(DX), AX
   108  	MOVL	AX, 0(SP)		// arg 1 - attr
   109  	CALL	libc_pthread_attr_init(SB)
   110  	MOVL	BP, SP
   111  	POPL	BP
   112  	RET
   113  
   114  TEXT runtime·pthread_attr_destroy_trampoline(SB),NOSPLIT,$0
   115  	PUSHL	BP
   116  	MOVL	SP, BP
   117  	SUBL	$4, SP
   118  	MOVL	12(SP), DX		// pointer to args
   119  	MOVL	0(DX), AX
   120  	MOVL	AX, 0(SP)		// arg 1 - attr
   121  	CALL	libc_pthread_attr_destroy(SB)
   122  	MOVL	BP, SP
   123  	POPL	BP
   124  	RET
   125  
   126  TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0
   127  	PUSHL	BP
   128  	MOVL	SP, BP
   129  	SUBL	$8, SP
   130  	MOVL	16(SP), DX		// pointer to args
   131  	MOVL	0(DX), AX
   132  	MOVL	4(DX), BX
   133  	MOVL	AX, 0(SP)		// arg 1 - attr
   134  	MOVL	BX, 4(SP)		// arg 2 - size
   135  	CALL	libc_pthread_attr_getstacksize(SB)
   136  	MOVL	BP, SP
   137  	POPL	BP
   138  	RET
   139  
   140  TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0
   141  	PUSHL	BP
   142  	MOVL	SP, BP
   143  	SUBL	$8, SP
   144  	MOVL	16(SP), DX		// pointer to args
   145  	MOVL	0(DX), AX
   146  	MOVL	4(DX), BX
   147  	MOVL	AX, 0(SP)		// arg 1 - attr
   148  	MOVL	BX, 4(SP)		// arg 2 - state
   149  	CALL	libc_pthread_attr_setdetachstate(SB)
   150  	MOVL	BP, SP
   151  	POPL	BP
   152  	RET
   153  
   154  TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0
   155  	PUSHL	BP
   156  	MOVL	SP, BP
   157  	SUBL	$20, SP
   158  	MOVL	28(SP), DX		// pointer to args
   159  	LEAL	16(SP), AX
   160  	MOVL	AX, 0(SP)		// arg 1 - &threadid (discarded)
   161  	MOVL	0(DX), AX
   162  	MOVL	4(DX), BX
   163  	MOVL	8(DX), CX
   164  	MOVL	AX, 4(SP)		// arg 2 - attr
   165  	MOVL	BX, 8(SP)		// arg 3 - start
   166  	MOVL	CX, 12(SP)		// arg 4 - arg
   167  	CALL	libc_pthread_create(SB)
   168  	MOVL	BP, SP
   169  	POPL	BP
   170  	RET
   171  
   172  TEXT runtime·thrkill_trampoline(SB),NOSPLIT,$0
   173  	PUSHL	BP
   174  	MOVL	SP, BP
   175  	SUBL	$12, SP
   176  	MOVL	20(SP), DX		// pointer to args
   177  	MOVL	0(DX), AX
   178  	MOVL	4(DX), BX
   179  	MOVL	AX, 0(SP)		// arg 1 - tid
   180  	MOVL	BX, 4(SP)		// arg 2 - signal
   181  	MOVL	$0, 8(SP)		// arg 3 - tcb
   182  	CALL	libc_thrkill(SB)
   183  	MOVL	BP, SP
   184  	POPL	BP
   185  	RET
   186  
   187  TEXT runtime·thrsleep_trampoline(SB),NOSPLIT,$0
   188  	PUSHL	BP
   189  	MOVL	SP, BP
   190  	SUBL	$20, SP
   191  	MOVL	28(SP), DX		// pointer to args
   192  	MOVL	0(DX), AX
   193  	MOVL	4(DX), BX
   194  	MOVL	8(DX), CX
   195  	MOVL	AX, 0(SP)		// arg 1 - id
   196  	MOVL	BX, 4(SP)		// arg 2 - clock_id
   197  	MOVL	CX, 8(SP)		// arg 3 - abstime
   198  	MOVL	12(DX), AX
   199  	MOVL	16(DX), BX
   200  	MOVL	AX, 12(SP)		// arg 4 - lock
   201  	MOVL	BX, 16(SP)		// arg 5 - abort
   202  	CALL	libc_thrsleep(SB)
   203  	MOVL	BP, SP
   204  	POPL	BP
   205  	RET
   206  
   207  TEXT runtime·thrwakeup_trampoline(SB),NOSPLIT,$0
   208  	PUSHL	BP
   209  	MOVL	SP, BP
   210  	SUBL	$8, SP
   211  	MOVL	16(SP), DX		// pointer to args
   212  	MOVL	0(DX), AX
   213  	MOVL	4(DX), BX
   214  	MOVL	AX, 0(SP)		// arg 1 - id
   215  	MOVL	BX, 4(SP)		// arg 2 - count
   216  	CALL	libc_thrwakeup(SB)
   217  	MOVL	BP, SP
   218  	POPL	BP
   219  	RET
   220  
   221  TEXT runtime·exit_trampoline(SB),NOSPLIT,$0
   222  	PUSHL	BP
   223  	MOVL	SP, BP
   224  	SUBL	$4, SP
   225  	MOVL	12(SP), DX		// pointer to args
   226  	MOVL	0(DX), AX
   227  	MOVL	AX, 0(SP)		// arg 1 - status
   228  	CALL	libc_exit(SB)
   229  	MOVL	$0xf1, 0xf1		// crash on failure
   230  	MOVL	BP, SP
   231  	POPL	BP
   232  	RET
   233  
   234  TEXT runtime·getthrid_trampoline(SB),NOSPLIT,$0
   235  	PUSHL	BP
   236  	CALL	libc_getthrid(SB)
   237  	NOP	SP			// tell vet SP changed - stop checking offsets
   238  	MOVL	8(SP), DX		// pointer to return value
   239  	MOVL	AX, 0(DX)
   240  	POPL	BP
   241  	RET
   242  
   243  TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$0
   244  	PUSHL	BP
   245  	MOVL	SP, BP
   246  	SUBL	$8, SP
   247  	MOVL	16(SP), DX
   248  	MOVL	0(DX), BX
   249  	CALL	libc_getpid(SB)
   250  	MOVL	AX, 0(SP)		// arg 1 - pid
   251  	MOVL	BX, 4(SP)		// arg 2 - signal
   252  	CALL	libc_kill(SB)
   253  	MOVL	BP, SP
   254  	POPL	BP
   255  	RET
   256  
   257  TEXT runtime·sched_yield_trampoline(SB),NOSPLIT,$0
   258  	PUSHL	BP
   259  	MOVL	SP, BP
   260  	CALL	libc_sched_yield(SB)
   261  	MOVL	BP, SP
   262  	POPL	BP
   263  	RET
   264  
   265  TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0
   266  	PUSHL	BP
   267  	MOVL	SP, BP
   268  	SUBL	$32, SP
   269  	MOVL	40(SP), DX		// pointer to args
   270  	MOVL	0(DX), AX
   271  	MOVL	4(DX), BX
   272  	MOVL	8(DX), CX
   273  	MOVL	AX, 0(SP)		// arg 1 - addr
   274  	MOVL	BX, 4(SP)		// arg 2 - len
   275  	MOVL	CX, 8(SP)		// arg 3 - prot
   276  	MOVL	12(DX), AX
   277  	MOVL	16(DX), BX
   278  	MOVL	20(DX), CX
   279  	MOVL	AX, 12(SP)		// arg 4 - flags
   280  	MOVL	BX, 16(SP)		// arg 5 - fid
   281  	MOVL	$0, 20(SP)		// pad
   282  	MOVL	CX, 24(SP)		// arg 6 - offset (low 32 bits)
   283  	MOVL	$0, 28(SP)		// offset (high 32 bits)
   284  	CALL	libc_mmap(SB)
   285  	MOVL	$0, BX
   286  	CMPL	AX, $-1
   287  	JNE	ok
   288  	CALL	libc_errno(SB)
   289  	MOVL	(AX), BX
   290  	MOVL	$0, AX
   291  ok:
   292  	MOVL	40(SP), DX
   293  	MOVL	AX, 24(DX)
   294  	MOVL	BX, 28(DX)
   295  	MOVL	BP, SP
   296  	POPL	BP
   297  	RET
   298  
   299  TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0
   300  	PUSHL	BP
   301  	MOVL	SP, BP
   302  	SUBL	$8, SP
   303  	MOVL	16(SP), DX		// pointer to args
   304  	MOVL	0(DX), AX
   305  	MOVL	4(DX), BX
   306  	MOVL	AX, 0(SP)		// arg 1 - addr
   307  	MOVL	BX, 4(SP)		// arg 2 - len
   308  	CALL	libc_munmap(SB)
   309  	CMPL	AX, $-1
   310  	JNE	2(PC)
   311  	MOVL	$0xf1, 0xf1		// crash on failure
   312  	MOVL	BP, SP
   313  	POPL	BP
   314  	RET
   315  
   316  TEXT runtime·madvise_trampoline(SB),NOSPLIT,$0
   317  	PUSHL	BP
   318  	MOVL	SP, BP
   319  	SUBL	$12, SP
   320  	MOVL	20(SP), DX		// pointer to args
   321  	MOVL	0(DX), AX
   322  	MOVL	4(DX), BX
   323  	MOVL	8(DX), CX
   324  	MOVL	AX, 0(SP)		// arg 1 - addr
   325  	MOVL	BX, 4(SP)		// arg 2 - len
   326  	MOVL	CX, 8(SP)		// arg 3 - advice
   327  	CALL	libc_madvise(SB)
   328  	// ignore failure - maybe pages are locked
   329  	MOVL	BP, SP
   330  	POPL	BP
   331  	RET
   332  
   333  TEXT runtime·open_trampoline(SB),NOSPLIT,$0
   334  	PUSHL	BP
   335  	MOVL	SP, BP
   336  	SUBL	$16, SP
   337  	MOVL	24(SP), DX		// pointer to args
   338  	MOVL	0(DX), AX
   339  	MOVL	4(DX), BX
   340  	MOVL	8(DX), CX
   341  	MOVL	AX, 0(SP)		// arg 1 - path
   342  	MOVL	BX, 4(SP)		// arg 2 - flags
   343  	MOVL	CX, 8(SP)		// arg 3 - mode
   344  	MOVL	$0, 12(SP)		// vararg
   345  	CALL	libc_open(SB)
   346  	MOVL	BP, SP
   347  	POPL	BP
   348  	RET
   349  
   350  TEXT runtime·close_trampoline(SB),NOSPLIT,$0
   351  	PUSHL	BP
   352  	MOVL	SP, BP
   353  	SUBL	$4, SP
   354  	MOVL	12(SP), DX
   355  	MOVL	0(DX), AX
   356  	MOVL	AX, 0(SP)		// arg 1 - fd
   357  	CALL	libc_close(SB)
   358  	MOVL	BP, SP
   359  	POPL	BP
   360  	RET
   361  
   362  TEXT runtime·read_trampoline(SB),NOSPLIT,$0
   363  	PUSHL	BP
   364  	MOVL	SP, BP
   365  	SUBL	$12, SP
   366  	MOVL	20(SP), DX		// pointer to args
   367  	MOVL	0(DX), AX
   368  	MOVL	4(DX), BX
   369  	MOVL	8(DX), CX
   370  	MOVL	AX, 0(SP)		// arg 1 - fd
   371  	MOVL	BX, 4(SP)		// arg 2 - buf
   372  	MOVL	CX, 8(SP)		// arg 3 - count
   373  	CALL	libc_read(SB)
   374  	CMPL	AX, $-1
   375  	JNE	noerr
   376  	CALL	libc_errno(SB)
   377  	MOVL	(AX), AX
   378  	NEGL	AX			// caller expects negative errno
   379  noerr:
   380  	MOVL	BP, SP
   381  	POPL	BP
   382  	RET
   383  
   384  TEXT runtime·write_trampoline(SB),NOSPLIT,$0
   385  	PUSHL	BP
   386  	MOVL	SP, BP
   387  	SUBL	$12, SP
   388  	MOVL	20(SP), DX		// pointer to args
   389  	MOVL	0(DX), AX
   390  	MOVL	4(DX), BX
   391  	MOVL	8(DX), CX
   392  	MOVL	AX, 0(SP)		// arg 1 - fd
   393  	MOVL	BX, 4(SP)		// arg 2 - buf
   394  	MOVL	CX, 8(SP)		// arg 3 - count
   395  	CALL	libc_write(SB)
   396  	CMPL	AX, $-1
   397  	JNE	noerr
   398  	CALL	libc_errno(SB)
   399  	MOVL	(AX), AX
   400  	NEGL	AX			// caller expects negative errno
   401  noerr:
   402  	MOVL	BP, SP
   403  	POPL	BP
   404  	RET
   405  
   406  TEXT runtime·pipe2_trampoline(SB),NOSPLIT,$0
   407  	PUSHL	BP
   408  	MOVL	SP, BP
   409  	SUBL	$8, SP
   410  	MOVL	16(SP), DX		// pointer to args
   411  	MOVL	0(DX), AX
   412  	MOVL	4(DX), BX
   413  	MOVL	AX, 0(SP)		// arg 1 - fds
   414  	MOVL	BX, 4(SP)		// arg 2 - flags
   415  	CALL	libc_pipe2(SB)
   416  	CMPL	AX, $-1
   417  	JNE	noerr
   418  	CALL	libc_errno(SB)
   419  	MOVL	(AX), AX
   420  	NEGL	AX			// caller expects negative errno
   421  noerr:
   422  	MOVL	BP, SP
   423  	POPL	BP
   424  	RET
   425  
   426  TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0
   427  	PUSHL	BP
   428  	MOVL	SP, BP
   429  	SUBL	$12, SP
   430  	MOVL	20(SP), DX		// pointer to args
   431  	MOVL	0(DX), AX
   432  	MOVL	4(DX), BX
   433  	MOVL	8(DX), CX
   434  	MOVL	AX, 0(SP)		// arg 1 - which
   435  	MOVL	BX, 4(SP)		// arg 2 - new
   436  	MOVL	CX, 8(SP)		// arg 3 - old
   437  	CALL	libc_setitimer(SB)
   438  	MOVL	BP, SP
   439  	POPL	BP
   440  	RET
   441  
   442  TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0
   443  	PUSHL	BP
   444  	MOVL	SP, BP
   445  	SUBL	$4, SP
   446  	MOVL	12(SP), DX		// pointer to args
   447  	MOVL	0(DX), AX
   448  	MOVL	AX, 0(SP)
   449  	CALL	libc_usleep(SB)
   450  	MOVL	BP, SP
   451  	POPL	BP
   452  	RET
   453  
   454  TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0
   455  	PUSHL	BP
   456  	MOVL	SP, BP
   457  	SUBL	$24, SP
   458  	MOVL	32(SP), DX		// pointer to args
   459  	MOVL	0(DX), AX
   460  	MOVL	4(DX), BX
   461  	MOVL	8(DX), CX
   462  	MOVL	AX, 0(SP)		// arg 1 - name
   463  	MOVL	BX, 4(SP)		// arg 2 - namelen
   464  	MOVL	CX, 8(SP)		// arg 3 - old
   465  	MOVL	12(DX), AX
   466  	MOVL	16(DX), BX
   467  	MOVL	20(DX), CX
   468  	MOVL	AX, 12(SP)		// arg 4 - oldlenp
   469  	MOVL	BX, 16(SP)		// arg 5 - newp
   470  	MOVL	CX, 20(SP)		// arg 6 - newlen
   471  	CALL	libc_sysctl(SB)
   472  	MOVL	BP, SP
   473  	POPL	BP
   474  	RET
   475  
   476  TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0
   477  	PUSHL	BP
   478  	MOVL	SP, BP
   479  	CALL	libc_kqueue(SB)
   480  	MOVL	BP, SP
   481  	POPL	BP
   482  	RET
   483  
   484  TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0
   485  	PUSHL	BP
   486  	MOVL	SP, BP
   487  	SUBL	$24, SP
   488  	MOVL	32(SP), DX		// pointer to args
   489  	MOVL	0(DX), AX
   490  	MOVL	4(DX), BX
   491  	MOVL	8(DX), CX
   492  	MOVL	AX, 0(SP)		// arg 1 - kq
   493  	MOVL	BX, 4(SP)		// arg 2 - keventt
   494  	MOVL	CX, 8(SP)		// arg 3 - nch
   495  	MOVL	12(DX), AX
   496  	MOVL	16(DX), BX
   497  	MOVL	20(DX), CX
   498  	MOVL	AX, 12(SP)		// arg 4 - ev
   499  	MOVL	BX, 16(SP)		// arg 5 - nev
   500  	MOVL	CX, 20(SP)		// arg 6 - ts
   501  	CALL	libc_kevent(SB)
   502  	CMPL	AX, $-1
   503  	JNE	noerr
   504  	CALL	libc_errno(SB)
   505  	MOVL	(AX), AX
   506  	NEGL	AX			// caller expects negative errno
   507  noerr:
   508  	MOVL	BP, SP
   509  	POPL	BP
   510  	RET
   511  
   512  TEXT runtime·clock_gettime_trampoline(SB),NOSPLIT,$0
   513  	PUSHL	BP
   514  	MOVL	SP, BP
   515  	SUBL	$8, SP
   516  	MOVL	16(SP), DX		// pointer to args
   517  	MOVL	0(DX), AX
   518  	MOVL	4(DX), BX
   519  	MOVL	AX, 0(SP)		// arg 1 - tp
   520  	MOVL	BX, 4(SP)		// arg 2 - clock_id
   521  	CALL	libc_clock_gettime(SB)
   522  	CMPL	AX, $-1
   523  	JNE	noerr
   524  	CALL	libc_errno(SB)
   525  	MOVL	(AX), AX
   526  	NEGL	AX			// caller expects negative errno
   527  noerr:
   528  	MOVL	BP, SP
   529  	POPL	BP
   530  	RET
   531  
   532  TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
   533  	PUSHL	BP
   534  	MOVL	SP, BP
   535  	SUBL	$16, SP
   536  	MOVL	24(SP), DX		// pointer to args
   537  	MOVL	0(DX), AX
   538  	MOVL	4(DX), BX
   539  	MOVL	8(DX), CX
   540  	MOVL	AX, 0(SP)		// arg 1 - fd
   541  	MOVL	BX, 4(SP)		// arg 2 - cmd
   542  	MOVL	CX, 8(SP)		// arg 3 - arg
   543  	MOVL	$0, 12(SP)		// vararg
   544  	CALL	libc_fcntl(SB)
   545  	MOVL	BP, SP
   546  	POPL	BP
   547  	RET
   548  
   549  TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0
   550  	PUSHL	BP
   551  	MOVL	SP, BP
   552  	SUBL	$12, SP
   553  	MOVL	20(SP), DX		// pointer to args
   554  	MOVL	0(DX), AX
   555  	MOVL	4(DX), BX
   556  	MOVL	8(DX), CX
   557  	MOVL	AX, 0(SP)		// arg 1 - sig
   558  	MOVL	BX, 4(SP)		// arg 2 - new
   559  	MOVL	CX, 8(SP)		// arg 3 - old
   560  	CALL	libc_sigaction(SB)
   561  	CMPL	AX, $-1
   562  	JNE	2(PC)
   563  	MOVL	$0xf1, 0xf1		// crash on failure
   564  	MOVL	BP, SP
   565  	POPL	BP
   566  	RET
   567  
   568  TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0
   569  	PUSHL	BP
   570  	MOVL	SP, BP
   571  	SUBL	$12, SP
   572  	MOVL	20(SP), DX		// pointer to args
   573  	MOVL	0(DX), AX
   574  	MOVL	4(DX), BX
   575  	MOVL	8(DX), CX
   576  	MOVL	AX, 0(SP)		// arg 1 - how
   577  	MOVL	BX, 4(SP)		// arg 2 - new
   578  	MOVL	CX, 8(SP)		// arg 3 - old
   579  	CALL	libc_pthread_sigmask(SB)
   580  	CMPL	AX, $-1
   581  	JNE	2(PC)
   582  	MOVL	$0xf1, 0xf1		// crash on failure
   583  	MOVL	BP, SP
   584  	POPL	BP
   585  	RET
   586  
   587  TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
   588  	PUSHL	BP
   589  	MOVL	SP, BP
   590  	SUBL	$8, SP
   591  	MOVL	16(SP), DX		// pointer to args
   592  	MOVL	0(DX), AX
   593  	MOVL	4(DX), BX
   594  	MOVL	AX, 0(SP)		// arg 1 - new
   595  	MOVL	BX, 4(SP)		// arg 2 - old
   596  	CALL	libc_sigaltstack(SB)
   597  	CMPL	AX, $-1
   598  	JNE	2(PC)
   599  	MOVL	$0xf1, 0xf1		// crash on failure
   600  	MOVL	BP, SP
   601  	POPL	BP
   602  	RET
   603  
   604  // syscall calls a function in libc on behalf of the syscall package.
   605  // syscall takes a pointer to a struct like:
   606  // struct {
   607  //	fn    uintptr
   608  //	a1    uintptr
   609  //	a2    uintptr
   610  //	a3    uintptr
   611  //	r1    uintptr
   612  //	r2    uintptr
   613  //	err   uintptr
   614  // }
   615  // syscall must be called on the g0 stack with the
   616  // C calling convention (use libcCall).
   617  //
   618  // syscall expects a 32-bit result and tests for 32-bit -1
   619  // to decide there was an error.
   620  TEXT runtime·syscall(SB),NOSPLIT,$0
   621  	PUSHL	BP
   622  	MOVL	SP, BP
   623  
   624  	SUBL	$12, SP
   625  	MOVL	20(SP), BX		// pointer to args
   626  
   627  	MOVL	(1*4)(BX), AX
   628  	MOVL	(2*4)(BX), CX
   629  	MOVL	(3*4)(BX), DX
   630  	MOVL	AX, (0*4)(SP)		// a1
   631  	MOVL	CX, (1*4)(SP)		// a2
   632  	MOVL	DX, (2*4)(SP)		// a3
   633  
   634  	MOVL	(0*4)(BX), AX		// fn
   635  	CALL	AX
   636  
   637  	MOVL	AX, (4*4)(BX)		// r1
   638  	MOVL	DX, (5*4)(BX)		// r2
   639  
   640  	// Standard libc functions return -1 on error and set errno.
   641  	CMPL	AX, $-1
   642  	JNE	ok
   643  
   644  	// Get error code from libc.
   645  	CALL	libc_errno(SB)
   646  	MOVL	(AX), AX
   647  	MOVW	AX, (6*4)(BX)		// err
   648  
   649  ok:
   650  	MOVL	$0, AX			// no error (it's ignored anyway)
   651  	MOVL	BP, SP
   652  	POPL	BP
   653  	RET
   654  
   655  // syscallX calls a function in libc on behalf of the syscall package.
   656  // syscallX takes a pointer to a struct like:
   657  // struct {
   658  //	fn    uintptr
   659  //	a1    uintptr
   660  //	a2    uintptr
   661  //	a3    uintptr
   662  //	r1    uintptr
   663  //	r2    uintptr
   664  //	err   uintptr
   665  // }
   666  // syscallX must be called on the g0 stack with the
   667  // C calling convention (use libcCall).
   668  //
   669  // syscallX is like syscall but expects a 64-bit result
   670  // and tests for 64-bit -1 to decide there was an error.
   671  TEXT runtime·syscallX(SB),NOSPLIT,$0
   672  	PUSHL	BP
   673  	MOVL	SP, BP
   674  
   675  	SUBL	$12, SP
   676  	MOVL	20(SP), BX		// pointer to args
   677  
   678  	MOVL	(1*4)(BX), AX
   679  	MOVL	(2*4)(BX), CX
   680  	MOVL	(3*4)(BX), DX
   681  	MOVL	AX, (0*4)(SP)		// a1
   682  	MOVL	CX, (1*4)(SP)		// a2
   683  	MOVL	DX, (2*4)(SP)		// a3
   684  
   685  	MOVL	(0*4)(BX), AX		// fn
   686  	CALL	AX
   687  
   688  	MOVL	AX, (4*4)(BX)		// r1
   689  	MOVL	DX, (5*4)(BX)		// r2
   690  
   691  	// Standard libc functions return -1 on error and set errno.
   692  	CMPL	AX, $-1
   693  	JNE	ok
   694  	CMPL	DX, $-1
   695  	JNE	ok
   696  
   697  	// Get error code from libc.
   698  	CALL	libc_errno(SB)
   699  	MOVL	(AX), AX
   700  	MOVW	AX, (6*4)(BX)		// err
   701  
   702  ok:
   703  	MOVL	$0, AX			// no error (it's ignored anyway)
   704  	MOVL	BP, SP
   705  	POPL	BP
   706  	RET
   707  
   708  // syscall6 calls a function in libc on behalf of the syscall package.
   709  // syscall6 takes a pointer to a struct like:
   710  // struct {
   711  //	fn    uintptr
   712  //	a1    uintptr
   713  //	a2    uintptr
   714  //	a3    uintptr
   715  //	a4    uintptr
   716  //	a5    uintptr
   717  //	a6    uintptr
   718  //	r1    uintptr
   719  //	r2    uintptr
   720  //	err   uintptr
   721  // }
   722  // syscall6 must be called on the g0 stack with the
   723  // C calling convention (use libcCall).
   724  //
   725  // syscall6 expects a 32-bit result and tests for 32-bit -1
   726  // to decide there was an error.
   727  TEXT runtime·syscall6(SB),NOSPLIT,$0
   728  	PUSHL	BP
   729  	MOVL	SP, BP
   730  
   731  	SUBL	$24, SP
   732  	MOVL	32(SP), BX		// pointer to args
   733  
   734  	MOVL	(1*4)(BX), AX
   735  	MOVL	(2*4)(BX), CX
   736  	MOVL	(3*4)(BX), DX
   737  	MOVL	AX, (0*4)(SP)		// a1
   738  	MOVL	CX, (1*4)(SP)		// a2
   739  	MOVL	DX, (2*4)(SP)		// a3
   740  	MOVL	(4*4)(BX), AX
   741  	MOVL	(5*4)(BX), CX
   742  	MOVL	(6*4)(BX), DX
   743  	MOVL	AX, (3*4)(SP)		// a4
   744  	MOVL	CX, (4*4)(SP)		// a5
   745  	MOVL	DX, (5*4)(SP)		// a6
   746  
   747  	MOVL	(0*4)(BX), AX		// fn
   748  	CALL	AX
   749  
   750  	MOVL	AX, (7*4)(BX)		// r1
   751  	MOVL	DX, (8*4)(BX)		// r2
   752  
   753  	// Standard libc functions return -1 on error and set errno.
   754  	CMPL	AX, $-1
   755  	JNE	ok
   756  
   757  	// Get error code from libc.
   758  	CALL	libc_errno(SB)
   759  	MOVL	(AX), AX
   760  	MOVW	AX, (9*4)(BX)		// err
   761  
   762  ok:
   763  	MOVL	$0, AX			// no error (it's ignored anyway)
   764  	MOVL	BP, SP
   765  	POPL	BP
   766  	RET
   767  
   768  // syscall6X calls a function in libc on behalf of the syscall package.
   769  // syscall6X takes a pointer to a struct like:
   770  // struct {
   771  //	fn    uintptr
   772  //	a1    uintptr
   773  //	a2    uintptr
   774  //	a3    uintptr
   775  //	a4    uintptr
   776  //	a5    uintptr
   777  //	a6    uintptr
   778  //	r1    uintptr
   779  //	r2    uintptr
   780  //	err   uintptr
   781  // }
   782  // syscall6X must be called on the g0 stack with the
   783  // C calling convention (use libcCall).
   784  //
   785  // syscall6X is like syscall6 but expects a 64-bit result
   786  // and tests for 64-bit -1 to decide there was an error.
   787  TEXT runtime·syscall6X(SB),NOSPLIT,$0
   788  	PUSHL	BP
   789  	MOVL	SP, BP
   790  
   791  	SUBL	$24, SP
   792  	MOVL	32(SP), BX		// pointer to args
   793  
   794  	MOVL	(1*4)(BX), AX
   795  	MOVL	(2*4)(BX), CX
   796  	MOVL	(3*4)(BX), DX
   797  	MOVL	AX, (0*4)(SP)		// a1
   798  	MOVL	CX, (1*4)(SP)		// a2
   799  	MOVL	DX, (2*4)(SP)		// a3
   800  	MOVL	(4*4)(BX), AX
   801  	MOVL	(5*4)(BX), CX
   802  	MOVL	(6*4)(BX), DX
   803  	MOVL	AX, (3*4)(SP)		// a4
   804  	MOVL	CX, (4*4)(SP)		// a5
   805  	MOVL	DX, (5*4)(SP)		// a6
   806  
   807  	MOVL	(0*4)(BX), AX		// fn
   808  	CALL	AX
   809  
   810  	MOVL	AX, (7*4)(BX)		// r1
   811  	MOVL	DX, (8*4)(BX)		// r2
   812  
   813  	// Standard libc functions return -1 on error and set errno.
   814  	CMPL	AX, $-1
   815  	JNE	ok
   816  	CMPL	DX, $-1
   817  	JNE	ok
   818  
   819  	// Get error code from libc.
   820  	CALL	libc_errno(SB)
   821  	MOVL	(AX), AX
   822  	MOVW	AX, (9*4)(BX)		// err
   823  
   824  ok:
   825  	MOVL	$0, AX			// no error (it's ignored anyway)
   826  	MOVL	BP, SP
   827  	POPL	BP
   828  	RET
   829  
   830  // syscall10 calls a function in libc on behalf of the syscall package.
   831  // syscall10 takes a pointer to a struct like:
   832  // struct {
   833  //	fn    uintptr
   834  //	a1    uintptr
   835  //	a2    uintptr
   836  //	a3    uintptr
   837  //	a4    uintptr
   838  //	a5    uintptr
   839  //	a6    uintptr
   840  //	a7    uintptr
   841  //	a8    uintptr
   842  //	a9    uintptr
   843  //	a10   uintptr
   844  //	r1    uintptr
   845  //	r2    uintptr
   846  //	err   uintptr
   847  // }
   848  // syscall10 must be called on the g0 stack with the
   849  // C calling convention (use libcCall).
   850  TEXT runtime·syscall10(SB),NOSPLIT,$0
   851  	PUSHL	BP
   852  	MOVL	SP, BP
   853  
   854  	SUBL	$40, SP
   855  	MOVL	48(SP), BX		// pointer to args
   856  
   857  	MOVL	(1*4)(BX), AX
   858  	MOVL	(2*4)(BX), CX
   859  	MOVL	(3*4)(BX), DX
   860  	MOVL	AX, (0*4)(SP)		// a1
   861  	MOVL	CX, (1*4)(SP)		// a2
   862  	MOVL	DX, (2*4)(SP)		// a3
   863  	MOVL	(4*4)(BX), AX
   864  	MOVL	(5*4)(BX), CX
   865  	MOVL	(6*4)(BX), DX
   866  	MOVL	AX, (3*4)(SP)		// a4
   867  	MOVL	CX, (4*4)(SP)		// a5
   868  	MOVL	DX, (5*4)(SP)		// a6
   869  	MOVL	(7*4)(BX), AX
   870  	MOVL	(8*4)(BX), CX
   871  	MOVL	(9*4)(BX), DX
   872  	MOVL	AX, (6*4)(SP)		// a7
   873  	MOVL	CX, (7*4)(SP)		// a8
   874  	MOVL	DX, (8*4)(SP)		// a9
   875  	MOVL	(10*4)(BX), AX
   876  	MOVL	AX, (9*4)(SP)		// a10
   877  
   878  	MOVL	(0*4)(BX), AX		// fn
   879  	CALL	AX
   880  
   881  	MOVL	AX, (11*4)(BX)		// r1
   882  	MOVL	DX, (12*4)(BX)		// r2
   883  
   884  	// Standard libc functions return -1 on error and set errno.
   885  	CMPL	AX, $-1
   886  	JNE	ok
   887  
   888  	// Get error code from libc.
   889  	CALL	libc_errno(SB)
   890  	MOVL	(AX), AX
   891  	MOVW	AX, (13*4)(BX)		// err
   892  
   893  ok:
   894  	MOVL	$0, AX			// no error (it's ignored anyway)
   895  	MOVL	BP, SP
   896  	POPL	BP
   897  	RET
   898  
   899  // syscall10X calls a function in libc on behalf of the syscall package.
   900  // syscall10X takes a pointer to a struct like:
   901  // struct {
   902  //	fn    uintptr
   903  //	a1    uintptr
   904  //	a2    uintptr
   905  //	a3    uintptr
   906  //	a4    uintptr
   907  //	a5    uintptr
   908  //	a6    uintptr
   909  //	a7    uintptr
   910  //	a8    uintptr
   911  //	a9    uintptr
   912  //	a10   uintptr
   913  //	r1    uintptr
   914  //	r2    uintptr
   915  //	err   uintptr
   916  // }
   917  // syscall10X must be called on the g0 stack with the
   918  // C calling convention (use libcCall).
   919  //
   920  // syscall10X is like syscall9 but expects a 64-bit result
   921  // and tests for 64-bit -1 to decide there was an error.
   922  TEXT runtime·syscall10X(SB),NOSPLIT,$0
   923  	PUSHL	BP
   924  	MOVL	SP, BP
   925  
   926  	SUBL	$40, SP
   927  	MOVL	48(SP), BX		// pointer to args
   928  
   929  	MOVL	(1*4)(BX), AX
   930  	MOVL	(2*4)(BX), CX
   931  	MOVL	(3*4)(BX), DX
   932  	MOVL	AX, (0*4)(SP)		// a1
   933  	MOVL	CX, (1*4)(SP)		// a2
   934  	MOVL	DX, (2*4)(SP)		// a3
   935  	MOVL	(4*4)(BX), AX
   936  	MOVL	(5*4)(BX), CX
   937  	MOVL	(6*4)(BX), DX
   938  	MOVL	AX, (3*4)(SP)		// a4
   939  	MOVL	CX, (4*4)(SP)		// a5
   940  	MOVL	DX, (5*4)(SP)		// a6
   941  	MOVL	(7*4)(BX), AX
   942  	MOVL	(8*4)(BX), CX
   943  	MOVL	(9*4)(BX), DX
   944  	MOVL	AX, (6*4)(SP)		// a7
   945  	MOVL	CX, (7*4)(SP)		// a8
   946  	MOVL	DX, (8*4)(SP)		// a9
   947  	MOVL	(10*4)(BX), AX
   948  	MOVL	AX, (9*4)(SP)		// a10
   949  
   950  	MOVL	(0*4)(BX), AX		// fn
   951  	CALL	AX
   952  
   953  	MOVL	AX, (11*4)(BX)		// r1
   954  	MOVL	DX, (12*4)(BX)		// r2
   955  
   956  	// Standard libc functions return -1 on error and set errno.
   957  	CMPL	AX, $-1
   958  	JNE	ok
   959  	CMPL	DX, $-1
   960  	JNE	ok
   961  
   962  	// Get error code from libc.
   963  	CALL	libc_errno(SB)
   964  	MOVL	(AX), AX
   965  	MOVW	AX, (13*4)(BX)		// err
   966  
   967  ok:
   968  	MOVL	$0, AX			// no error (it's ignored anyway)
   969  	MOVL	BP, SP
   970  	POPL	BP
   971  	RET
   972  

View as plain text