syscall.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef __GBLIBC_SYSCALL_H_
  2. #define __GBLIBC_SYSCALL_H_
  3. #include <stdint.h>
  4. #define SYS_fork (0x00)
  5. #define SYS_write (0x01)
  6. #define SYS_sleep (0x02)
  7. #define SYS_chdir (0x03)
  8. #define SYS_exec (0x04)
  9. #define SYS_exit (0x05)
  10. #define SYS_wait (0x06)
  11. #define SYS_read (0x07)
  12. #define SYS_getdents (0x08)
  13. #define SYS_open (0x09)
  14. #define SYS_getcwd (0x0a)
  15. #define SYS_setsid (0x0b)
  16. #define SYS_getsid (0x0c)
  17. #define SYS_close (0x0d)
  18. #define SYS_dup (0x0e)
  19. #define SYS_dup2 (0x0f)
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. static inline uint32_t syscall0(uint32_t no)
  24. {
  25. asm volatile(
  26. "movl %1, %%eax\n"
  27. "int $0x80\n"
  28. "movl %%eax, %0"
  29. : "=g"(no)
  30. : "g"(no)
  31. : "eax");
  32. return no;
  33. }
  34. static inline uint32_t syscall1(uint32_t no, uint32_t arg)
  35. {
  36. asm volatile(
  37. "movl %1, %%edi\n"
  38. "movl %2, %%eax\n"
  39. "int $0x80\n"
  40. "movl %%eax, %0"
  41. : "=g"(no)
  42. : "g"(arg), "g"(no)
  43. : "eax", "edi");
  44. return no;
  45. }
  46. static inline uint32_t syscall2(uint32_t no, uint32_t arg1, uint32_t arg2)
  47. {
  48. asm volatile(
  49. "movl %1, %%edi\n"
  50. "movl %2, %%esi\n"
  51. "movl %3, %%eax\n"
  52. "int $0x80\n"
  53. "movl %%eax, %0"
  54. : "=g"(no)
  55. : "g"(arg1), "g"(arg2), "g"(no)
  56. : "eax", "edi", "esi");
  57. return no;
  58. }
  59. static inline uint32_t syscall3(uint32_t no, uint32_t arg1, uint32_t arg2, uint32_t arg3)
  60. {
  61. asm volatile(
  62. "movl %1, %%edi\n"
  63. "movl %2, %%esi\n"
  64. "movl %3, %%edx\n"
  65. "movl %4, %%eax\n"
  66. "int $0x80\n"
  67. "movl %%eax, %0"
  68. : "=g"(no)
  69. : "g"(arg1), "g"(arg2), "g"(arg3), "g"(no)
  70. : "eax", "edx", "edi", "esi");
  71. return no;
  72. }
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif