syscall.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef __GBLIBC_SYSCALL_H_
  2. #define __GBLIBC_SYSCALL_H_
  3. #include <stdint.h>
  4. #define SYS_exit (0x01)
  5. #define SYS_fork (0x02)
  6. #define SYS_read (0x03)
  7. #define SYS_write (0x04)
  8. #define SYS_open (0x05)
  9. #define SYS_close (0x06)
  10. #define SYS_waitpid (0x07)
  11. #define SYS_execve (0x0b)
  12. #define SYS_chdir (0x0c)
  13. #define SYS_getpid (0x14)
  14. #define SYS_dup (0x29)
  15. #define SYS_pipe (0x2a)
  16. #define SYS_ioctl (0x36)
  17. #define SYS_setpgid (0x39)
  18. #define SYS_dup2 (0x3f)
  19. #define SYS_getppid (0x40)
  20. #define SYS_setsid (0x42)
  21. #define SYS_getdents (0x84)
  22. #define SYS_writev (0x92)
  23. #define SYS_getsid (0x93)
  24. #define SYS_getcwd (0xb7)
  25. #define SYS_set_thread_area (0xf3)
  26. #define SYS_exit_group (0xfc)
  27. #define SYS_set_tid_address (0x102)
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. static inline uint32_t syscall0(uint32_t no)
  32. {
  33. asm volatile(
  34. "movl %1, %%eax\n"
  35. "int $0x80\n"
  36. "movl %%eax, %0"
  37. : "=g"(no)
  38. : "g"(no)
  39. : "eax");
  40. return no;
  41. }
  42. static inline uint32_t syscall1(uint32_t no, uint32_t arg)
  43. {
  44. asm volatile(
  45. "movl %1, %%ebx\n"
  46. "movl %2, %%eax\n"
  47. "int $0x80\n"
  48. "movl %%eax, %0"
  49. : "=g"(no)
  50. : "g"(arg), "g"(no)
  51. : "eax", "ebx");
  52. return no;
  53. }
  54. static inline uint32_t syscall2(uint32_t no, uint32_t arg1, uint32_t arg2)
  55. {
  56. asm volatile(
  57. "movl %1, %%ebx\n"
  58. "movl %2, %%ecx\n"
  59. "movl %3, %%eax\n"
  60. "int $0x80\n"
  61. "movl %%eax, %0"
  62. : "=g"(no)
  63. : "g"(arg1), "g"(arg2), "g"(no)
  64. : "eax", "ebx", "ecx");
  65. return no;
  66. }
  67. static inline uint32_t syscall3(uint32_t no, uint32_t arg1, uint32_t arg2, uint32_t arg3)
  68. {
  69. asm volatile(
  70. "movl %1, %%ebx\n"
  71. "movl %2, %%ecx\n"
  72. "movl %3, %%edx\n"
  73. "movl %4, %%eax\n"
  74. "int $0x80\n"
  75. "movl %%eax, %0"
  76. : "=g"(no)
  77. : "g"(arg1), "g"(arg2), "g"(arg3), "g"(no)
  78. : "eax", "ebx", "ecx", "edx");
  79. return no;
  80. }
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif