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