blob: 2a1510273a875bcbd66705e0d1098380114ed419 [file] [log] [blame]
Bruce Beare3c543e12010-03-04 10:29:38 -08001/*
2 * Generic syscall call.
Jin Weic164f2a2012-04-12 16:50:42 +08003 * Upon entry:
4 * %eax: system call number - caller save
5 * %ebx: arg0 to system call - callee save
6 * %ecx: arg1 - caller save
7 * %edx: arg2 - caller save
8 * %esi: arg3 - callee save
9 * %edi: arg4 - callee save
10 * %ebp: arg5 - callee save
Bruce Beare3c543e12010-03-04 10:29:38 -080011 */
12
Elliott Hughesa85aaf12014-01-02 16:23:24 -080013#include <private/bionic_asm.h>
Bruce Beare3c543e12010-03-04 10:29:38 -080014
Elliott Hughesbdff26d2013-02-11 17:08:16 -080015ENTRY(syscall)
Jin Weic164f2a2012-04-12 16:50:42 +080016 # Push the callee save registers.
Bruce Beare3c543e12010-03-04 10:29:38 -080017 push %ebx
Christopher Ferris605ee812015-04-13 14:20:11 -070018 .cfi_adjust_cfa_offset 4
19 .cfi_rel_offset ebx, 0
Bruce Beare3c543e12010-03-04 10:29:38 -080020 push %esi
Christopher Ferris605ee812015-04-13 14:20:11 -070021 .cfi_adjust_cfa_offset 4
22 .cfi_rel_offset esi, 0
Bruce Beare3c543e12010-03-04 10:29:38 -080023 push %edi
Christopher Ferris605ee812015-04-13 14:20:11 -070024 .cfi_adjust_cfa_offset 4
25 .cfi_rel_offset edi, 0
Jin Weic164f2a2012-04-12 16:50:42 +080026 push %ebp
Christopher Ferris605ee812015-04-13 14:20:11 -070027 .cfi_adjust_cfa_offset 4
28 .cfi_rel_offset ebp, 0
Bruce Beare3c543e12010-03-04 10:29:38 -080029
Jin Weic164f2a2012-04-12 16:50:42 +080030 # Load all the arguments from the calling frame.
31 # (Not all will be valid, depending on the syscall.)
32 mov 20(%esp),%eax
33 mov 24(%esp),%ebx
34 mov 28(%esp),%ecx
35 mov 32(%esp),%edx
36 mov 36(%esp),%esi
37 mov 40(%esp),%edi
38 mov 44(%esp),%ebp
39
40 # Make the system call.
Bruce Beare3c543e12010-03-04 10:29:38 -080041 int $0x80
42
Jin Weic164f2a2012-04-12 16:50:42 +080043 # Error?
Elliott Hughesa85aaf12014-01-02 16:23:24 -080044 cmpl $-MAX_ERRNO, %eax
Bruce Beare3c543e12010-03-04 10:29:38 -080045 jb 1f
Jin Weic164f2a2012-04-12 16:50:42 +080046 # Yes, so set errno.
Bruce Beare3c543e12010-03-04 10:29:38 -080047 negl %eax
48 pushl %eax
Elliott Hughes011e1112014-09-08 15:25:01 -070049 call __set_errno_internal
Bruce Beare3c543e12010-03-04 10:29:38 -080050 addl $4, %esp
Bruce Beare3c543e12010-03-04 10:29:38 -0800511:
Jin Weic164f2a2012-04-12 16:50:42 +080052 # Restore the callee save registers.
53 pop %ebp
Christopher Ferris605ee812015-04-13 14:20:11 -070054 .cfi_adjust_cfa_offset -4
Christopher Ferris940d3122015-04-14 17:02:31 -070055 .cfi_restore ebp
Bruce Beare3c543e12010-03-04 10:29:38 -080056 pop %edi
Christopher Ferris605ee812015-04-13 14:20:11 -070057 .cfi_adjust_cfa_offset -4
Christopher Ferris940d3122015-04-14 17:02:31 -070058 .cfi_restore edi
Bruce Beare3c543e12010-03-04 10:29:38 -080059 pop %esi
Christopher Ferris605ee812015-04-13 14:20:11 -070060 .cfi_adjust_cfa_offset -4
Christopher Ferris940d3122015-04-14 17:02:31 -070061 .cfi_restore esi
Bruce Beare3c543e12010-03-04 10:29:38 -080062 pop %ebx
Christopher Ferris605ee812015-04-13 14:20:11 -070063 .cfi_adjust_cfa_offset -4
Christopher Ferris940d3122015-04-14 17:02:31 -070064 .cfi_restore ebx
Bruce Beare3c543e12010-03-04 10:29:38 -080065 ret
Elliott Hughesbdff26d2013-02-11 17:08:16 -080066END(syscall)