Syscall.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <AK/Types.h>
  3. #define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function))
  4. #define DO_SYSCALL_A1(function, arg1) Syscall::invoke((dword)(function), (dword)(arg1))
  5. #define DO_SYSCALL_A2(function, arg1, arg2) Syscall::invoke((dword)(function), (dword)(arg1), (dword)(arg2))
  6. #define DO_SYSCALL_A3(function, arg1, arg2, arg3) Syscall::invoke((dword)(function), (dword)(arg1), (dword)(arg2), (dword)arg3)
  7. namespace Syscall {
  8. enum Function {
  9. Spawn = 0x1981,
  10. Sleep = 0x1982,
  11. Yield = 0x1983,
  12. PutCharacter = 1984,
  13. PosixOpen = 0x1985,
  14. PosixClose = 0x1986,
  15. PosixRead = 0x1987,
  16. PosixSeek = 0x1988,
  17. PosixKill = 0x1989,
  18. PosixGetuid = 0x1990,
  19. PosixExit = 0x1991,
  20. PosixGetgid = 0x1992,
  21. PosixGetpid = 0x1993,
  22. PosixWaitpid = 0x1994,
  23. PosixMmap = 0x1995,
  24. PosixMunmap = 0x1996,
  25. GetDirEntries = 0x1997,
  26. PosixLstat = 0x1998,
  27. PosixGetcwd = 0x1999,
  28. PosixGettimeofday = 0x2000,
  29. PosixGethostname = 0x2001,
  30. };
  31. void initialize();
  32. inline dword invoke(dword function)
  33. {
  34. dword result;
  35. asm volatile("int $0x80":"=a"(result):"a"(function));
  36. return result;
  37. }
  38. inline dword invoke(dword function, dword arg1)
  39. {
  40. dword result;
  41. asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1));
  42. return result;
  43. }
  44. inline dword invoke(dword function, dword arg1, dword arg2)
  45. {
  46. dword result;
  47. asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1),"c"(arg2));
  48. return result;
  49. }
  50. inline dword invoke(dword function, dword arg1, dword arg2, dword arg3)
  51. {
  52. dword result;
  53. asm volatile("int $0x80":"=a"(result):"a"(function),"d"(arg1),"c"(arg2),"b"(arg3));
  54. return result;
  55. }
  56. }