syscall.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef __GBLIBC_SYSCALL_H_
  2. #define __GBLIBC_SYSCALL_H_
  3. #include <stdint.h>
  4. #define SYS_read (0)
  5. #define SYS_write (1)
  6. #define SYS_open (2)
  7. #define SYS_close (3)
  8. #define SYS_ioctl (16)
  9. #define SYS_pipe (22)
  10. #define SYS_dup (32)
  11. #define SYS_dup2 (33)
  12. #define SYS_sleep (35)
  13. #define SYS_getpid (39)
  14. #define SYS_fork (57)
  15. #define SYS_execve (59)
  16. #define SYS_exit (60)
  17. #define SYS_wait (61)
  18. #define SYS_getdents (78)
  19. #define SYS_getcwd (79)
  20. #define SYS_chdir (80)
  21. #define SYS_setpgid (109)
  22. #define SYS_getppid (110)
  23. #define SYS_setsid (112)
  24. #define SYS_getsid (124)
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. static inline uint32_t syscall0(uint32_t no)
  29. {
  30. asm volatile(
  31. "movl %1, %%eax\n"
  32. "int $0x80\n"
  33. "movl %%eax, %0"
  34. : "=g"(no)
  35. : "g"(no)
  36. : "eax");
  37. return no;
  38. }
  39. static inline uint32_t syscall1(uint32_t no, uint32_t arg)
  40. {
  41. asm volatile(
  42. "movl %1, %%edi\n"
  43. "movl %2, %%eax\n"
  44. "int $0x80\n"
  45. "movl %%eax, %0"
  46. : "=g"(no)
  47. : "g"(arg), "g"(no)
  48. : "eax", "edi");
  49. return no;
  50. }
  51. static inline uint32_t syscall2(uint32_t no, uint32_t arg1, uint32_t arg2)
  52. {
  53. asm volatile(
  54. "movl %1, %%edi\n"
  55. "movl %2, %%esi\n"
  56. "movl %3, %%eax\n"
  57. "int $0x80\n"
  58. "movl %%eax, %0"
  59. : "=g"(no)
  60. : "g"(arg1), "g"(arg2), "g"(no)
  61. : "eax", "edi", "esi");
  62. return no;
  63. }
  64. static inline uint32_t syscall3(uint32_t no, uint32_t arg1, uint32_t arg2, uint32_t arg3)
  65. {
  66. asm volatile(
  67. "movl %1, %%edi\n"
  68. "movl %2, %%esi\n"
  69. "movl %3, %%edx\n"
  70. "movl %4, %%eax\n"
  71. "int $0x80\n"
  72. "movl %%eax, %0"
  73. : "=g"(no)
  74. : "g"(arg1), "g"(arg2), "g"(arg3), "g"(no)
  75. : "eax", "edx", "edi", "esi");
  76. return no;
  77. }
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif