syscall.h 1.8 KB

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