rework langinfo code for ABI compat and for use by time code
[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:      mov %ebx,%edx
20         pop %ebx
21         pop %ebx
22         pop %edi
23         ret
24
25 1:      mov (%esp),%eax
26         add $[__sysinfo-2b],%eax
27         mov (%eax),%eax
28         test %eax,%eax
29         jz 1f
30         push %eax
31         mov 8(%esp),%eax
32         ret                     # tail call to kernel vsyscall entry
33 1:      mov 4(%esp),%eax
34         int $128
35         ret
36
37 # The __vsyscall6 entry point is used only for 6-argument syscalls.
38 # Instead of passing the 5th argument on the stack, a pointer to the
39 # 5th and 6th arguments is passed. This is ugly, but there are no
40 # register constraints the inline asm could use that would make it
41 # possible to pass two arguments on the stack.
42
43 .global __vsyscall6
44 .type __vsyscall6,@function
45 __vsyscall6:
46         push %ebp
47         push %eax
48         mov 12(%esp), %ebp
49         mov (%ebp), %eax
50         mov 4(%ebp), %ebp
51         push %eax
52         mov 4(%esp),%eax
53         call __vsyscall
54         pop %ebp
55         pop %ebp
56         pop %ebp
57         ret
58
59 .global __syscall
60 .type __syscall,@function
61 __syscall:
62         lea 24(%esp),%eax
63         push %esi
64         push %edi
65         push %eax
66         mov 16(%esp),%eax
67         mov 20(%esp),%edx
68         mov 24(%esp),%ecx
69         mov 28(%esp),%edi
70         mov 32(%esp),%esi
71         call __vsyscall6
72         pop %edi
73         pop %edi
74         pop %esi
75         ret