syscall.h 1.7 KB

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