syscall.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef __GBLIBC_SYSCALL_H_
  2. #define __GBLIBC_SYSCALL_H_
  3. #include <stdint.h>
  4. #define SYS_exit (0x01)
  5. #define SYS_fork (0x02)
  6. #define SYS_read (0x03)
  7. #define SYS_write (0x04)
  8. #define SYS_open (0x05)
  9. #define SYS_close (0x06)
  10. #define SYS_waitpid (0x07)
  11. #define SYS_execve (0x0b)
  12. #define SYS_chdir (0x0c)
  13. #define SYS_stat (0x12)
  14. #define SYS_getpid (0x14)
  15. #define SYS_fstat (0x1c)
  16. #define SYS_kill (0x25)
  17. #define SYS_dup (0x29)
  18. #define SYS_pipe (0x2a)
  19. #define SYS_brk (0x2d)
  20. #define SYS_ioctl (0x36)
  21. #define SYS_setpgid (0x39)
  22. #define SYS_dup2 (0x3f)
  23. #define SYS_umask (0x3c)
  24. #define SYS_getppid (0x40)
  25. #define SYS_setsid (0x42)
  26. #define SYS_gettimeofday (0x4e)
  27. #define SYS_getdents (0x84)
  28. #define SYS_writev (0x92)
  29. #define SYS_getsid (0x93)
  30. #define SYS_nanosleep (0xa2)
  31. #define SYS_getcwd (0xb7)
  32. #define SYS_set_thread_area (0xf3)
  33. #define SYS_exit_group (0xfc)
  34. #define SYS_set_tid_address (0x102)
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. static inline uint32_t syscall0(uint32_t no)
  39. {
  40. asm volatile(
  41. "movl %1, %%eax\n"
  42. "int $0x80\n"
  43. "movl %%eax, %0"
  44. : "=g"(no)
  45. : "g"(no)
  46. : "eax");
  47. return no;
  48. }
  49. static inline uint32_t syscall1(uint32_t no, uint32_t arg)
  50. {
  51. asm volatile(
  52. "movl %1, %%ebx\n"
  53. "movl %2, %%eax\n"
  54. "int $0x80\n"
  55. "movl %%eax, %0"
  56. : "=g"(no)
  57. : "g"(arg), "g"(no)
  58. : "eax", "ebx");
  59. return no;
  60. }
  61. static inline uint32_t syscall2(uint32_t no, uint32_t arg1, uint32_t arg2)
  62. {
  63. asm volatile(
  64. "movl %1, %%ebx\n"
  65. "movl %2, %%ecx\n"
  66. "movl %3, %%eax\n"
  67. "int $0x80\n"
  68. "movl %%eax, %0"
  69. : "=g"(no)
  70. : "g"(arg1), "g"(arg2), "g"(no)
  71. : "eax", "ebx", "ecx");
  72. return no;
  73. }
  74. static inline uint32_t syscall3(uint32_t no, uint32_t arg1, uint32_t arg2, uint32_t arg3)
  75. {
  76. asm volatile(
  77. "movl %1, %%ebx\n"
  78. "movl %2, %%ecx\n"
  79. "movl %3, %%edx\n"
  80. "movl %4, %%eax\n"
  81. "int $0x80\n"
  82. "movl %%eax, %0"
  83. : "=g"(no)
  84. : "g"(arg1), "g"(arg2), "g"(arg3), "g"(no)
  85. : "eax", "ebx", "ecx", "edx");
  86. return no;
  87. }
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif