syscall.h 1.7 KB

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