syscall.S 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * June 27, 2001 Manuel Novoa III
  3. *
  4. * This is a heavily modified version of gcc's output for the _syscall5 macro.
  5. * The idea (originally from dietlibc) is that all syscall functions simply set
  6. * the syscall number as the first argument, then set the syscall arguments as
  7. * the next up-to-five arguments, and then jump here. All the common work is
  8. * done by syscall(), saving a fair amount of generated code when a number of
  9. * syscalls are used. The (potential) cost is some unnecessary pushes, pops,
  10. * and movs but the execution time penalty should be relatively small compared
  11. * to the cost of the syscall itself.
  12. *
  13. * July 24, 2002
  14. *
  15. * Modified by Erik Andersen to take all function parameters from off the stack
  16. * like a proper function and eliminates the old 255 syscall number limit. So
  17. * now we can just call this as a function as syscall() per the function
  18. * prototype in unistd.h, so to call _exit(42) you can just call.
  19. * syscall(__NR_exit, 42);
  20. * and things will just work.
  21. */
  22. .text
  23. .align 4
  24. .globl syscall
  25. .type syscall,@function
  26. syscall:
  27. pushl %edi
  28. pushl %esi
  29. pushl %ebx
  30. movl 36(%esp),%edi; /* Load the 5 syscall argument registers */
  31. movl 32(%esp),%esi;
  32. movl 28(%esp),%edx;
  33. movl 24(%esp),%ecx;
  34. movl 20(%esp),%ebx;
  35. movl 16(%esp),%eax /* Load syscall number into %eax. */
  36. #APP
  37. int $0x80
  38. #NO_APP
  39. cmpl $-4095,%eax
  40. jbe .Ldone
  41. #ifdef PIC
  42. call Lhere
  43. Lhere:
  44. popl %ebx
  45. addl $_GLOBAL_OFFSET_TABLE_+[.-Lhere],%ebx
  46. negl %eax
  47. movl %eax,%ecx
  48. #ifdef __UCLIBC_HAS_THREADS__
  49. call __errno_location@PLT
  50. #else
  51. movl errno@GOT(%ebx),%eax
  52. #endif /* __UCLIBC_HAS_THREADS__ */
  53. movl %ecx,(%eax)
  54. #else
  55. negl %eax
  56. #ifdef __UCLIBC_HAS_THREADS__
  57. movl %eax,%ecx
  58. call __errno_location
  59. movl %ecx,(%eax)
  60. #else
  61. movl %eax,errno
  62. #endif /* __UCLIBC_HAS_THREADS__ */
  63. #endif /* PIC */
  64. movl $-1,%eax
  65. .p2align 4,,7
  66. .Ldone:
  67. popl %ebx
  68. popl %esi
  69. popl %edi
  70. ret
  71. .Lsize:
  72. .size syscall,.Lsize-syscall