syscall.h 1.6 KB

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