syscall.h 1.8 KB

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