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