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