syscall.h 1.6 KB

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