《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.2 KiB

10 years ago
  1. #include <defs.h>
  2. #include <unistd.h>
  3. #include <stdarg.h>
  4. #include <syscall.h>
  5. #define MAX_ARGS 5
  6. static inline int
  7. syscall(int num, ...) {
  8. va_list ap;
  9. va_start(ap, num);
  10. uint32_t a[MAX_ARGS];
  11. int i, ret;
  12. for (i = 0; i < MAX_ARGS; i ++) {
  13. a[i] = va_arg(ap, uint32_t);
  14. }
  15. va_end(ap);
  16. asm volatile (
  17. "int %1;"
  18. : "=a" (ret)
  19. : "i" (T_SYSCALL),
  20. "a" (num),
  21. "d" (a[0]),
  22. "c" (a[1]),
  23. "b" (a[2]),
  24. "D" (a[3]),
  25. "S" (a[4])
  26. : "cc", "memory");
  27. return ret;
  28. }
  29. int
  30. sys_exit(int error_code) {
  31. return syscall(SYS_exit, error_code);
  32. }
  33. int
  34. sys_fork(void) {
  35. return syscall(SYS_fork);
  36. }
  37. int
  38. sys_wait(int pid, int *store) {
  39. return syscall(SYS_wait, pid, store);
  40. }
  41. int
  42. sys_yield(void) {
  43. return syscall(SYS_yield);
  44. }
  45. int
  46. sys_kill(int pid) {
  47. return syscall(SYS_kill, pid);
  48. }
  49. int
  50. sys_getpid(void) {
  51. return syscall(SYS_getpid);
  52. }
  53. int
  54. sys_putc(int c) {
  55. return syscall(SYS_putc, c);
  56. }
  57. int
  58. sys_pgdir(void) {
  59. return syscall(SYS_pgdir);
  60. }
  61. size_t
  62. sys_gettime(void) {
  63. return syscall(SYS_gettime);
  64. }
  65. void
  66. sys_lab6_set_priority(uint32_t priority)
  67. {
  68. syscall(SYS_lab6_set_priority, priority);
  69. }