syscall.h 1.9 KB

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