comment possibly-confusing i386 vsyscall asm
[musl] / src / internal / i386 / syscall.s
1 .hidden __sysinfo
2
3 # The calling convention for __vsyscall has the syscall number
4 # and 5 args arriving as:  eax, edx, ecx, edi, esi, 4(%esp).
5 # This ensures that the inline asm in the C code never has to touch
6 # ebx or ebp (which are unavailable in PIC and frame-pointer-using
7 # code, respectively), and optimizes for size/simplicity in the caller.
8
9 .global __vsyscall
10 .type __vsyscall,@function
11 __vsyscall:
12         push %edi
13         push %ebx
14         mov %edx,%ebx
15         mov %edi,%edx
16         mov 12(%esp),%edi
17         push %eax
18         call 1f
19 2:      pop %ebx
20         pop %ebx
21         pop %edi
22         ret
23
24 1:      mov (%esp),%eax
25         add $[__sysinfo-2b],%eax
26         mov (%eax),%eax
27         test %eax,%eax
28         jz 1f
29         push %eax
30         mov 8(%esp),%eax
31         ret                     # tail call to kernel vsyscall entry
32 1:      mov 4(%esp),%eax
33         int $128
34         ret
35
36 # The __vsyscall6 entry point is used only for 6-argument syscalls.
37 # Instead of passing the 5th argument on the stack, a pointer to the
38 # 5th and 6th arguments is passed. This is ugly, but there are no
39 # register constraints the inline asm could use that would make it
40 # possible to pass two arguments on the stack.
41
42 .global __vsyscall6
43 .type __vsyscall6,@function
44 __vsyscall6:
45         push %ebp
46         push %eax
47         mov 12(%esp), %ebp
48         mov (%ebp), %eax
49         mov 4(%ebp), %ebp
50         push %eax
51         mov 4(%esp),%eax
52         call __vsyscall
53         pop %ebp
54         pop %ebp
55         pop %ebp
56         ret
57
58 .global __syscall
59 .type __syscall,@function
60 __syscall:
61         lea 24(%esp),%eax
62         push %esi
63         push %edi
64         push %eax
65         mov 16(%esp),%eax
66         mov 20(%esp),%edx
67         mov 24(%esp),%ecx
68         mov 28(%esp),%edi
69         mov 32(%esp),%esi
70         call __vsyscall6
71         pop %edi
72         pop %edi
73         pop %esi
74         ret