syscall.h 1.7 KB

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