syscall.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Syscall dispatcher: services int 0x80 requests from ring-3. */
  2. #include "syscall.h"
  3. #include "io.h"
  4. #include "process.h"
  5. #include "serial.h"
  6. #include "sys_fs.h"
  7. #include "sys_info.h"
  8. #include "timer.h"
  9. int syscall_dispatch(int num, int a1, int a2, int a3)
  10. {
  11. switch (num) {
  12. case SYS_PUTSTR:
  13. io_putstr((const char *)a1);
  14. return 0;
  15. case SYS_GET_TICKS_MS:
  16. return (int)get_ticks_ms();
  17. case SYS_SLEEP_MS:
  18. process_sleep_ms((unsigned int)a1);
  19. return 0;
  20. case SYS_EXIT:
  21. process_exit(); /* never returns */
  22. return 0;
  23. case SYS_READ_FILE:
  24. return sys_read_file((const char *)a1, (void *)a2, (unsigned int)a3);
  25. case SYS_WRITE_FILE:
  26. return sys_write_file((const char *)a1, (const void *)a2,
  27. (unsigned int)a3);
  28. case SYS_LIST_DIR:
  29. return sys_list_dir((const char *)a1, (unsigned int)a2,
  30. (struct sys_dirent *)a3);
  31. case SYS_UNLINK:
  32. return sys_unlink((const char *)a1);
  33. case SYS_MKDIR:
  34. return sys_mkdir((const char *)a1);
  35. case SYS_RMDIR:
  36. return sys_rmdir((const char *)a1);
  37. case SYS_LIST_MOUNTS:
  38. return sys_list_mounts((unsigned int)a1, (struct sys_mount *)a2);
  39. case SYS_MEMINFO:
  40. return sys_meminfo((struct sys_meminfo *)a1);
  41. case SYS_E820:
  42. return sys_e820((unsigned int)a1, (struct sys_e820 *)a2);
  43. case SYS_MOUSEINFO:
  44. return sys_mouseinfo((struct sys_mouseinfo *)a1);
  45. case SYS_STORAGE_INFO:
  46. return sys_storage_info((struct sys_storage_info *)a1);
  47. case SYS_BLKDEV:
  48. return sys_blkdev((unsigned int)a1, (struct sys_blkdev *)a2);
  49. default:
  50. return -1;
  51. }
  52. }