syscall.c 777 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. serial_puts(SERIAL_COM1, "syscall ");
  13. serial_putdec(SERIAL_COM1, (unsigned int)num);
  14. serial_puts(SERIAL_COM1, "\n");
  15. switch (num) {
  16. case SYS_PUTSTR:
  17. io_putstr((const char *)a1);
  18. return 0;
  19. case SYS_GET_TICKS_MS:
  20. return (int)get_ticks_ms();
  21. case SYS_SLEEP_MS: {
  22. unsigned int start = get_ticks_ms();
  23. unsigned int ms = (unsigned int)a1;
  24. while (get_ticks_ms() - start < ms)
  25. cpu_idle();
  26. return 0;
  27. }
  28. case SYS_EXIT:
  29. process_exit(); /* never returns */
  30. return 0;
  31. default:
  32. return -1;
  33. }
  34. }