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 // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP)
      6 // so that go vet can check that they are correct.
      7 
      8 #include "textflag.h"
      9 #include "funcdata.h"
     10 
     11 //
     12 // System call support for AMD64, OpenBSD
     13 //
     14 
     15 // func Syscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
     16 // func Syscall6(trap int64, a1, a2, a3, a4, a5, a6 int64) (r1, r2, err int64);
     17 // func Syscall9(trap int64, a1, a2, a3, a4, a5, a6, a7, a8, a9 int64) (r1, r2, err int64);
     18 // Trap # in AX, args in DI SI DX, return in AX DX
     19 
     20 TEXT	Syscall(SB),NOSPLIT,$0-56
     21 	CALL	runtimeentersyscall(SB)
     22 	MOVQ	8(SP), AX	// syscall entry
     23 	MOVQ	16(SP), DI
     24 	MOVQ	24(SP), SI
     25 	MOVQ	32(SP), DX
     26 	MOVQ	$0, R10
     27 	MOVQ	$0, R8
     28 	MOVQ	$0, R9
     29 	SYSCALL
     30 	JCC	ok
     31 	MOVQ	$-1, 40(SP)	// r1
     32 	MOVQ	$0, 48(SP)	// r2
     33 	MOVQ	AX, 56(SP)	// errno
     34 	CALL	runtimeexitsyscall(SB)
     35 	RET
     36 ok:
     37 	MOVQ	AX, 40(SP)	// r1
     38 	MOVQ	DX, 48(SP)	// r2
     39 	MOVQ	$0, 56(SP)	// errno
     40 	CALL	runtimeexitsyscall(SB)
     41 	RET
     42 
     43 TEXT	Syscall6(SB),NOSPLIT,$0-80
     44 	CALL	runtimeentersyscall(SB)
     45 	MOVQ	8(SP), AX	// syscall entry
     46 	MOVQ	16(SP), DI
     47 	MOVQ	24(SP), SI
     48 	MOVQ	32(SP), DX
     49 	MOVQ	40(SP), R10
     50 	MOVQ	48(SP), R8
     51 	MOVQ	56(SP), R9
     52 	SYSCALL
     53 	JCC	ok6
     54 	MOVQ	$-1, 64(SP)	// r1
     55 	MOVQ	$0, 72(SP)	// r2
     56 	MOVQ	AX, 80(SP)  	// errno
     57 	CALL	runtimeexitsyscall(SB)
     58 	RET
     59 ok6:
     60 	MOVQ	AX, 64(SP)	// r1
     61 	MOVQ	DX, 72(SP)	// r2
     62 	MOVQ	$0, 80(SP)	// errno
     63 	CALL	runtimeexitsyscall(SB)
     64 	RET
     65 
     66 TEXT	Syscall9(SB),NOSPLIT,$0-104
     67 	CALL	runtimeentersyscall(SB)
     68 	MOVQ	8(SP), AX	// syscall entry
     69 	MOVQ	16(SP), DI
     70 	MOVQ	24(SP), SI
     71 	MOVQ	32(SP), DX
     72 	MOVQ	40(SP), R10
     73 	MOVQ	48(SP), R8
     74 	MOVQ	56(SP), R9
     75 	MOVQ	64(SP), R11
     76 	MOVQ	72(SP), R12
     77 	MOVQ	80(SP), R13
     78 	SUBQ    $32, SP
     79 	MOVQ	R11, 8(SP)	// arg 7
     80 	MOVQ	R12, 16(SP)	// arg 8
     81 	MOVQ	R13, 24(SP)	// arg 9
     82 	SYSCALL
     83 	JCC	ok9
     84 	ADDQ    $32, SP
     85 	MOVQ	$-1, 88(SP)	// r1
     86 	MOVQ	$0, 96(SP)	// r2
     87 	MOVQ	AX, 104(SP)	// errno
     88 	CALL	runtimeexitsyscall(SB)
     89 	RET
     90 ok9:
     91 	ADDQ    $32, SP
     92 	MOVQ	AX, 88(SP)	// r1
     93 	MOVQ	DX, 96(SP)	// r2
     94 	MOVQ	$0, 104(SP)	// errno
     95 	CALL	runtimeexitsyscall(SB)
     96 	RET
     97 
     98 TEXT	RawSyscall(SB),NOSPLIT,$0-56
     99 	MOVQ	16(SP), DI
    100 	MOVQ	24(SP), SI
    101 	MOVQ	32(SP), DX
    102 	MOVQ	$0, R10
    103 	MOVQ	$0, R8
    104 	MOVQ	$0, R9
    105 	MOVQ	8(SP), AX	// syscall entry
    106 	SYSCALL
    107 	JCC	ok1
    108 	MOVQ	$-1, 40(SP)	// r1
    109 	MOVQ	$0, 48(SP)	// r2
    110 	MOVQ	AX, 56(SP)	// errno
    111 	RET
    112 ok1:
    113 	MOVQ	AX, 40(SP)	// r1
    114 	MOVQ	DX, 48(SP)	// r2
    115 	MOVQ	$0, 56(SP)	// errno
    116 	RET
    117 
    118 TEXT	RawSyscall6(SB),NOSPLIT,$0-80
    119 	MOVQ	16(SP), DI
    120 	MOVQ	24(SP), SI
    121 	MOVQ	32(SP), DX
    122 	MOVQ	40(SP), R10
    123 	MOVQ	48(SP), R8
    124 	MOVQ	56(SP), R9
    125 	MOVQ	8(SP), AX	// syscall entry
    126 	SYSCALL
    127 	JCC	ok2
    128 	MOVQ	$-1, 64(SP)	// r1
    129 	MOVQ	$0, 72(SP)	// r2
    130 	MOVQ	AX, 80(SP)	// errno
    131 	RET
    132 ok2:
    133 	MOVQ	AX, 64(SP)	// r1
    134 	MOVQ	DX, 72(SP)	// r2
    135 	MOVQ	$0, 80(SP)	// errno
    136 	RET
    137