syscall.h 1.8 KB

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