syscall.h 1.6 KB

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