syscall.c 730 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* Syscall dispatcher: services int 0x80 requests from ring-3. */
  2. #include "syscall.h"
  3. #include "idle.h"
  4. #include "io.h"
  5. #include "process.h"
  6. #include "serial.h"
  7. #include "timer.h"
  8. int syscall_dispatch(int num, int a1, int a2, int a3)
  9. {
  10. (void)a2;
  11. (void)a3;
  12. switch (num) {
  13. case SYS_PUTSTR:
  14. io_putstr((const char *)a1);
  15. return 0;
  16. case SYS_GET_TICKS_MS:
  17. return (int)get_ticks_ms();
  18. case SYS_SLEEP_MS: {
  19. unsigned int start = get_ticks_ms();
  20. unsigned int ms = (unsigned int)a1;
  21. __asm__ volatile ("sti"); /* re-enable IRQs so hlt wakes on the PIT */
  22. while (get_ticks_ms() - start < ms)
  23. cpu_idle();
  24. return 0;
  25. }
  26. case SYS_EXIT:
  27. process_exit(); /* never returns */
  28. return 0;
  29. default:
  30. return -1;
  31. }
  32. }