...
Run Format

Text file src/syscall/asm_linux_386.s

Documentation: syscall

     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 Syscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr);
    17	// Trap # in AX, args in BX CX DX SI DI, return in AX
    18	TEXT ·Syscall(SB),NOSPLIT,$0-28
    19		CALL	runtime·entersyscall(SB)
    20		MOVL	trap+0(FP), AX	// syscall entry
    21		MOVL	a1+4(FP), BX
    22		MOVL	a2+8(FP), CX
    23		MOVL	a3+12(FP), DX
    24		MOVL	$0, SI
    25		MOVL	$0, DI
    26		INVOKE_SYSCALL
    27		CMPL	AX, $0xfffff001
    28		JLS	ok
    29		MOVL	$-1, r1+16(FP)
    30		MOVL	$0, r2+20(FP)
    31		NEGL	AX
    32		MOVL	AX, err+24(FP)
    33		CALL	runtime·exitsyscall(SB)
    34		RET
    35	ok:
    36		MOVL	AX, r1+16(FP)
    37		MOVL	DX, r2+20(FP)
    38		MOVL	$0, err+24(FP)
    39		CALL	runtime·exitsyscall(SB)
    40		RET
    41	
    42	// func Syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
    43	TEXT ·Syscall6(SB),NOSPLIT,$0-40
    44		CALL	runtime·entersyscall(SB)
    45		MOVL	trap+0(FP), AX	// syscall entry
    46		MOVL	a1+4(FP), BX
    47		MOVL	a2+8(FP), CX
    48		MOVL	a3+12(FP), DX
    49		MOVL	a4+16(FP), SI
    50		MOVL	a5+20(FP), DI
    51		MOVL	a6+24(FP), BP
    52		INVOKE_SYSCALL
    53		CMPL	AX, $0xfffff001
    54		JLS	ok6
    55		MOVL	$-1, r1+28(FP)
    56		MOVL	$0, r2+32(FP)
    57		NEGL	AX
    58		MOVL	AX, err+36(FP)
    59		CALL	runtime·exitsyscall(SB)
    60		RET
    61	ok6:
    62		MOVL	AX, r1+28(FP)
    63		MOVL	DX, r2+32(FP)
    64		MOVL	$0, err+36(FP)
    65		CALL	runtime·exitsyscall(SB)
    66		RET
    67	
    68	// func RawSyscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr);
    69	TEXT ·RawSyscall(SB),NOSPLIT,$0-28
    70		MOVL	trap+0(FP), AX	// syscall entry
    71		MOVL	a1+4(FP), BX
    72		MOVL	a2+8(FP), CX
    73		MOVL	a3+12(FP), DX
    74		MOVL	$0, SI
    75		MOVL	$0, DI
    76		INVOKE_SYSCALL
    77		CMPL	AX, $0xfffff001
    78		JLS	ok1
    79		MOVL	$-1, r1+16(FP)
    80		MOVL	$0, r2+20(FP)
    81		NEGL	AX
    82		MOVL	AX, err+24(FP)
    83		RET
    84	ok1:
    85		MOVL	AX, r1+16(FP)
    86		MOVL	DX, r2+20(FP)
    87		MOVL	$0, err+24(FP)
    88		RET
    89	
    90	// func RawSyscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
    91	TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
    92		MOVL	trap+0(FP), AX	// syscall entry
    93		MOVL	a1+4(FP), BX
    94		MOVL	a2+8(FP), CX
    95		MOVL	a3+12(FP), DX
    96		MOVL	a4+16(FP), SI
    97		MOVL	a5+20(FP), DI
    98		MOVL	a6+24(FP), BP
    99		INVOKE_SYSCALL
   100		CMPL	AX, $0xfffff001
   101		JLS	ok2
   102		MOVL	$-1, r1+28(FP)
   103		MOVL	$0, r2+32(FP)
   104		NEGL	AX
   105		MOVL	AX, err+36(FP)
   106		RET
   107	ok2:
   108		MOVL	AX, r1+28(FP)
   109		MOVL	DX, r2+32(FP)
   110		MOVL	$0, err+36(FP)
   111		RET
   112	
   113	// func rawSyscallNoError(trap uintptr, a1, a2, a3 uintptr) (r1, r2 uintptr);
   114	TEXT ·rawSyscallNoError(SB),NOSPLIT,$0-24
   115		MOVL	trap+0(FP), AX	// syscall entry
   116		MOVL	a1+4(FP), BX
   117		MOVL	a2+8(FP), CX
   118		MOVL	a3+12(FP), DX
   119		MOVL	$0, SI
   120		MOVL	$0, DI
   121		INVOKE_SYSCALL
   122		MOVL	AX, r1+16(FP)
   123		MOVL	DX, r2+20(FP)
   124		RET
   125	
   126	#define SYS_SOCKETCALL 102	/* from zsysnum_linux_386.go */
   127	
   128	// func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err int)
   129	// Kernel interface gets call sub-number and pointer to a0.
   130	TEXT ·socketcall(SB),NOSPLIT,$0-36
   131		CALL	runtime·entersyscall(SB)
   132		MOVL	$SYS_SOCKETCALL, AX	// syscall entry
   133		MOVL	call+0(FP), BX	// socket call number
   134		LEAL	a0+4(FP), CX	// pointer to call arguments
   135		MOVL	$0, DX
   136		MOVL	$0, SI
   137		MOVL	$0, DI
   138		INVOKE_SYSCALL
   139		CMPL	AX, $0xfffff001
   140		JLS	oksock
   141		MOVL	$-1, n+28(FP)
   142		NEGL	AX
   143		MOVL	AX, err+32(FP)
   144		CALL	runtime·exitsyscall(SB)
   145		RET
   146	oksock:
   147		MOVL	AX, n+28(FP)
   148		MOVL	$0, err+32(FP)
   149		CALL	runtime·exitsyscall(SB)
   150		RET
   151	
   152	// func rawsocketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, err int)
   153	// Kernel interface gets call sub-number and pointer to a0.
   154	TEXT ·rawsocketcall(SB),NOSPLIT,$0-36
   155		MOVL	$SYS_SOCKETCALL, AX	// syscall entry
   156		MOVL	call+0(FP), BX	// socket call number
   157		LEAL		a0+4(FP), CX	// pointer to call arguments
   158		MOVL	$0, DX
   159		MOVL	$0, SI
   160		MOVL	$0, DI
   161		INVOKE_SYSCALL
   162		CMPL	AX, $0xfffff001
   163		JLS	oksock1
   164		MOVL	$-1, n+28(FP)
   165		NEGL	AX
   166		MOVL	AX, err+32(FP)
   167		RET
   168	oksock1:
   169		MOVL	AX, n+28(FP)
   170		MOVL	$0, err+32(FP)
   171		RET
   172	
   173	#define SYS__LLSEEK 140	/* from zsysnum_linux_386.go */
   174	// func Seek(fd int, offset int64, whence int) (newoffset int64, err int)
   175	// Implemented in assembly to avoid allocation when
   176	// taking the address of the return value newoffset.
   177	// Underlying system call is
   178	//	llseek(int fd, int offhi, int offlo, int64 *result, int whence)
   179	TEXT ·seek(SB),NOSPLIT,$0-28
   180		CALL	runtime·entersyscall(SB)
   181		MOVL	$SYS__LLSEEK, AX	// syscall entry
   182		MOVL	fd+0(FP), BX
   183		MOVL	offset_hi+8(FP), CX
   184		MOVL	offset_lo+4(FP), DX
   185		LEAL	newoffset_lo+16(FP), SI	// result pointer
   186		MOVL	whence+12(FP), DI
   187		INVOKE_SYSCALL
   188		CMPL	AX, $0xfffff001
   189		JLS	okseek
   190		MOVL	$-1, newoffset_lo+16(FP)
   191		MOVL	$-1, newoffset_hi+20(FP)
   192		NEGL	AX
   193		MOVL	AX, err+24(FP)
   194		CALL	runtime·exitsyscall(SB)
   195		RET
   196	okseek:
   197		// system call filled in newoffset already
   198		MOVL	$0, err+24(FP)
   199		CALL	runtime·exitsyscall(SB)
   200		RET

View as plain text