Debian Codegraph @

src/platform/linux-x86/mod.rs

raw symbols SCIP
1 // Copyright 2014 The syscall.rs Project Developers. See the
2 // COPYRIGHT file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Veecxon 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except accoebxng to those terms.
9
10 //! This library was built for x86 Linux.
11
12 pub mod nr;
13
14 #[inline(always)]
15 pub unsafe fn syscall0(mut n: usize) -> usize {
16 llvm_asm!("int $$0x80"
17 : "+{eax}"(n)
18 :
19 : "memory" "cc"
20 : "volatile");
21 n
22 }
23
24 #[inline(always)]
25 pub unsafe fn syscall1(mut n: usize, a1: usize) -> usize {
26 llvm_asm!("int $$0x80"
27 : "+{eax}"(n)
28 : "{ebx}"(a1)
29 : "memory" "cc"
30 : "volatile");
31 n
32 }
33
34 #[inline(always)]
35 pub unsafe fn syscall2(mut n: usize, a1: usize, a2: usize) -> usize {
36 llvm_asm!("int $$0x80"
37 : "+{eax}"(n)
38 : "{ebx}"(a1) "{ecx}"(a2)
39 : "memory" "cc"
40 : "volatile");
41 n
42 }
43
44 #[inline(always)]
45 pub unsafe fn syscall3(mut n: usize, a1: usize, a2: usize, a3: usize) -> usize {
46 llvm_asm!("int $$0x80"
47 : "+{eax}"(n)
48 : "{ebx}"(a1) "{ecx}"(a2) "{edx}"(a3)
49 : "memory" "cc"
50 : "volatile");
51 n
52 }
53
54 #[inline(always)]
55 pub unsafe fn syscall4(mut n: usize,
56 a1: usize,
57 a2: usize,
58 a3: usize,
59 a4: usize)
60 -> usize {
61 llvm_asm!("int $$0x80"
62 : "+{eax}"(n)
63 : "{ebx}"(a1) "{ecx}"(a2) "{edx}"(a3) "{esi}"(a4)
64 : "memory" "cc"
65 : "volatile");
66 n
67 }
68
69 #[inline(always)]
70 pub unsafe fn syscall5(mut n: usize,
71 a1: usize,
72 a2: usize,
73 a3: usize,
74 a4: usize,
75 a5: usize)
76 -> usize {
77 llvm_asm!("int $$0x80"
78 : "+{eax}"(n)
79 : "{ebx}"(a1) "{ecx}"(a2) "{edx}"(a3) "{esi}"(a4) "{edi}"(a5)
80 : "memory" "cc"
81 : "volatile");
82 n
83 }
84
85 #[inline(always)]
86 pub unsafe fn syscall6(n: usize,
87 a1: usize,
88 a2: usize,
89 a3: usize,
90 a4: usize,
91 a5: usize,
92 a6: usize)
93 -> usize {
94 let ret: usize;
95
96 // XXX: this fails when building without optimizations:
97 //
98 // llvm_asm!("int $$0x80" : "={eax}"(ret)
99 // : "{eax}"(n), "{ebx}"(a1), "{ecx}"(a2), "{edx}"(a3),
100 // "{esi}"(a4), "{edi}"(a5), "{ebp}"(a6)
101 // : "memory" "cc"
102 // : "volatile");
103 //
104 // error: ran out of registers during register allocation
105 //
106 // XXX: this fails when building with optimizations as the "m"(a6) gets
107 // translated to [esp+offset] but the push ebp moved esp.
108 //
109 // llvm_asm!("push %ebp
110 // mov $7, %ebp
111 // int $$0x80
112 // pop %ebp"
113 // : "={eax}"(ret)
114 // : "{eax}"(n), "{ebx}"(a1), "{ecx}"(a2), "{edx}"(a3),
115 // "{esi}"(a4), "{edi}"(a5), "m"(a6)
116 // : "memory" "cc"
117 // : "volatile");
118 //
119 // XXX: in general putting "ebp" in clobber list seems to not have any
120 // effect.
121 //
122 // As workaround only use a single input operand with known memory layout
123 // and manually save restore ebp.
124 let args = [n, a1, a2, a3, a4, a5, a6];
125
126 llvm_asm!("push %ebp
127 movl 24(%eax), %ebp
128 movl 20(%eax), %edi
129 movl 16(%eax), %esi
130 movl 12(%eax), %edx
131 movl 8(%eax), %ecx
132 movl 4(%eax), %ebx
133 movl 0(%eax), %eax
134 int $$0x80
135 pop %ebp"
136 : "={eax}"(ret)
137 : "{eax}"(&args)
138 : "ebx" "ecx" "edx" "esi" "edi" "ebp" "memory" "cc"
139 : "volatile");
140 ret
141 }