Text file src/syscall/asm_linux_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  #include "textflag.h"
     6  #include "funcdata.h"
     7  
     8  //
     9  // System calls for 386, Linux
    10  //
    11  
    12  // See ../runtime/sys_linux_386.s for the reason why we always use int 0x80
    13  // instead of the glibc-specific "CALL 0x10(GS)".
    14  #define INVOKE_SYSCALL	INT	$0x80
    15  
    16  // func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
    17  TEXT ·rawVforkSyscall(SB),NOSPLIT|NOFRAME,$0-16
    18  	MOVL	trap+0(FP), AX	// syscall entry
    19  	MOVL	a1+4(FP), BX
    20  	MOVL	$0, CX
    21  	MOVL	$0, DX
    22  	POPL	SI // preserve return address
    23  	INVOKE_SYSCALL
    24  	PUSHL	SI
    25  	CMPL	AX, $0xfffff001
    26  	JLS	ok
    27  	MOVL	$-1, r1+8(FP)
    28  	NEGL	AX
    29  	MOVL	AX, err+12(FP)
    30  	RET
    31  ok:
    32  	MOVL	AX, r1+8(FP)
    33  	MOVL	$0, err+12(FP)
    34  	RET
    35  
    36  // func rawSyscallNoError(trap uintptr, a1, a2, a3 uintptr) (r1, r2 uintptr);
    37  TEXT ·rawSyscallNoError(SB),NOSPLIT,$0-24
    38  	MOVL	trap+0(FP), AX	// syscall entry
    39  	MOVL	a1+4(FP), BX
    40  	MOVL	a2+8(FP), CX
    41  	MOVL	a3+12(FP), DX
    42  	MOVL	$0, SI
    43  	MOVL	$0, DI
    44  	INVOKE_SYSCALL
    45  	MOVL	AX, r1+16(FP)
    46  	MOVL	DX, r2+20(FP)
    47  	RET
    48  
    49  #define SYS_SOCKETCALL 102	/* from zsysnum_linux_386.go */
    50  
    51  // func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err int)
    52  // Kernel interface gets call sub-number and pointer to a0.
    53  TEXT ·socketcall(SB),NOSPLIT,$0-36
    54  	CALL	runtime·entersyscall(SB)
    55  	MOVL	$SYS_SOCKETCALL, AX	// syscall entry
    56  	MOVL	call+0(FP), BX	// socket call number
    57  	LEAL	a0+4(FP), CX	// pointer to call arguments
    58  	MOVL	$0, DX
    59  	MOVL	$0, SI
    60  	MOVL	$0, DI
    61  	INVOKE_SYSCALL
    62  	CMPL	AX, $0xfffff001
    63  	JLS	oksock
    64  	MOVL	$-1, n+28(FP)
    65  	NEGL	AX
    66  	MOVL	AX, err+32(FP)
    67  	CALL	runtime·exitsyscall(SB)
    68  	RET
    69  oksock:
    70  	MOVL	AX, n+28(FP)
    71  	MOVL	$0, err+32(FP)
    72  	CALL	runtime·exitsyscall(SB)
    73  	RET
    74  
    75  // func rawsocketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err int)
    76  // Kernel interface gets call sub-number and pointer to a0.
    77  TEXT ·rawsocketcall(SB),NOSPLIT,$0-36
    78  	MOVL	$SYS_SOCKETCALL, AX	// syscall entry
    79  	MOVL	call+0(FP), BX	// socket call number
    80  	LEAL		a0+4(FP), CX	// pointer to call arguments
    81  	MOVL	$0, DX
    82  	MOVL	$0, SI
    83  	MOVL	$0, DI
    84  	INVOKE_SYSCALL
    85  	CMPL	AX, $0xfffff001
    86  	JLS	oksock1
    87  	MOVL	$-1, n+28(FP)
    88  	NEGL	AX
    89  	MOVL	AX, err+32(FP)
    90  	RET
    91  oksock1:
    92  	MOVL	AX, n+28(FP)
    93  	MOVL	$0, err+32(FP)
    94  	RET
    95  
    96  #define SYS__LLSEEK 140	/* from zsysnum_linux_386.go */
    97  // func Seek(fd int, offset int64, whence int) (newoffset int64, err int)
    98  // Implemented in assembly to avoid allocation when
    99  // taking the address of the return value newoffset.
   100  // Underlying system call is
   101  //	llseek(int fd, int offhi, int offlo, int64 *result, int whence)
   102  TEXT ·seek(SB),NOSPLIT,$0-28
   103  	CALL	runtime·entersyscall(SB)
   104  	MOVL	$SYS__LLSEEK, AX	// syscall entry
   105  	MOVL	fd+0(FP), BX
   106  	MOVL	offset_hi+8(FP), CX
   107  	MOVL	offset_lo+4(FP), DX
   108  	LEAL	newoffset_lo+16(FP), SI	// result pointer
   109  	MOVL	whence+12(FP), DI
   110  	INVOKE_SYSCALL
   111  	CMPL	AX, $0xfffff001
   112  	JLS	okseek
   113  	MOVL	$-1, newoffset_lo+16(FP)
   114  	MOVL	$-1, newoffset_hi+20(FP)
   115  	NEGL	AX
   116  	MOVL	AX, err+24(FP)
   117  	CALL	runtime·exitsyscall(SB)
   118  	RET
   119  okseek:
   120  	// system call filled in newoffset already
   121  	MOVL	$0, err+24(FP)
   122  	CALL	runtime·exitsyscall(SB)
   123  	RET
   124  

View as plain text