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

View as plain text