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 AMD64, Linux
     10 //
     11 
     12 // func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
     13 // Trap # in AX, args in DI SI DX R10 R8 R9, return in AX DX
     14 // Note that this differs from "standard" ABI convention, which
     15 // would pass 4th arg in CX, not R10.
     16 
     17 TEXT	Syscall(SB),NOSPLIT,$0-56
     18 	CALL	runtimeentersyscall(SB)
     19 	MOVQ	a1+8(FP), DI
     20 	MOVQ	a2+16(FP), SI
     21 	MOVQ	a3+24(FP), DX
     22 	MOVQ	$0, R10
     23 	MOVQ	$0, R8
     24 	MOVQ	$0, R9
     25 	MOVQ	trap+0(FP), AX	// syscall entry
     26 	SYSCALL
     27 	CMPQ	AX, $0xfffffffffffff001
     28 	JLS	ok
     29 	MOVQ	$-1, r1+32(FP)
     30 	MOVQ	$0, r2+40(FP)
     31 	NEGQ	AX
     32 	MOVQ	AX, err+48(FP)
     33 	CALL	runtimeexitsyscall(SB)
     34 	RET
     35 ok:
     36 	MOVQ	AX, r1+32(FP)
     37 	MOVQ	DX, r2+40(FP)
     38 	MOVQ	$0, err+48(FP)
     39 	CALL	runtimeexitsyscall(SB)
     40 	RET
     41 
     42 // func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
     43 TEXT Syscall6(SB),NOSPLIT,$0-80
     44 	CALL	runtimeentersyscall(SB)
     45 	MOVQ	a1+8(FP), DI
     46 	MOVQ	a2+16(FP), SI
     47 	MOVQ	a3+24(FP), DX
     48 	MOVQ	a4+32(FP), R10
     49 	MOVQ	a5+40(FP), R8
     50 	MOVQ	a6+48(FP), R9
     51 	MOVQ	trap+0(FP), AX	// syscall entry
     52 	SYSCALL
     53 	CMPQ	AX, $0xfffffffffffff001
     54 	JLS	ok6
     55 	MOVQ	$-1, r1+56(FP)
     56 	MOVQ	$0, r2+64(FP)
     57 	NEGQ	AX
     58 	MOVQ	AX, err+72(FP)
     59 	CALL	runtimeexitsyscall(SB)
     60 	RET
     61 ok6:
     62 	MOVQ	AX, r1+56(FP)
     63 	MOVQ	DX, r2+64(FP)
     64 	MOVQ	$0, err+72(FP)
     65 	CALL	runtimeexitsyscall(SB)
     66 	RET
     67 
     68 // func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
     69 TEXT RawSyscall(SB),NOSPLIT,$0-56
     70 	MOVQ	a1+8(FP), DI
     71 	MOVQ	a2+16(FP), SI
     72 	MOVQ	a3+24(FP), DX
     73 	MOVQ	$0, R10
     74 	MOVQ	$0, R8
     75 	MOVQ	$0, R9
     76 	MOVQ	trap+0(FP), AX	// syscall entry
     77 	SYSCALL
     78 	CMPQ	AX, $0xfffffffffffff001
     79 	JLS	ok1
     80 	MOVQ	$-1, r1+32(FP)
     81 	MOVQ	$0, r2+40(FP)
     82 	NEGQ	AX
     83 	MOVQ	AX, err+48(FP)
     84 	RET
     85 ok1:
     86 	MOVQ	AX, r1+32(FP)
     87 	MOVQ	DX, r2+40(FP)
     88 	MOVQ	$0, err+48(FP)
     89 	RET
     90 
     91 // func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
     92 TEXT RawSyscall6(SB),NOSPLIT,$0-80
     93 	MOVQ	a1+8(FP), DI
     94 	MOVQ	a2+16(FP), SI
     95 	MOVQ	a3+24(FP), DX
     96 	MOVQ	a4+32(FP), R10
     97 	MOVQ	a5+40(FP), R8
     98 	MOVQ	a6+48(FP), R9
     99 	MOVQ	trap+0(FP), AX	// syscall entry
    100 	SYSCALL
    101 	CMPQ	AX, $0xfffffffffffff001
    102 	JLS	ok2
    103 	MOVQ	$-1, r1+56(FP)
    104 	MOVQ	$0, r2+64(FP)
    105 	NEGQ	AX
    106 	MOVQ	AX, err+72(FP)
    107 	RET
    108 ok2:
    109 	MOVQ	AX, r1+56(FP)
    110 	MOVQ	DX, r2+64(FP)
    111 	MOVQ	$0, err+72(FP)
    112 	RET
    113 
    114 // func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
    115 TEXT rawVforkSyscall(SB),NOSPLIT,$0-32
    116 	MOVQ	a1+8(FP), DI
    117 	MOVQ	$0, SI
    118 	MOVQ	$0, DX
    119 	MOVQ	$0, R10
    120 	MOVQ	$0, R8
    121 	MOVQ	$0, R9
    122 	MOVQ	trap+0(FP), AX	// syscall entry
    123 	POPQ	R12 // preserve return address
    124 	SYSCALL
    125 	PUSHQ	R12
    126 	CMPQ	AX, $0xfffffffffffff001
    127 	JLS	ok2
    128 	MOVQ	$-1, r1+16(FP)
    129 	NEGQ	AX
    130 	MOVQ	AX, err+24(FP)
    131 	RET
    132 ok2:
    133 	MOVQ	AX, r1+16(FP)
    134 	MOVQ	$0, err+24(FP)
    135 	RET
    136 
    137 // func gettimeofday(tv *Timeval) (err uintptr)
    138 TEXT gettimeofday(SB),NOSPLIT,$0-16
    139 	MOVQ	tv+0(FP), DI
    140 	MOVQ	$0, SI
    141 	MOVQ	runtime__vdso_gettimeofday_sym(SB), AX
    142 	CALL	AX
    143 
    144 	CMPQ	AX, $0xfffffffffffff001
    145 	JLS	ok7
    146 	NEGQ	AX
    147 	MOVQ	AX, err+8(FP)
    148 	RET
    149 ok7:
    150 	MOVQ	$0, err+8(FP)
    151 	RET
    152