《操作系统》的实验代码。
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.

145 lines
2.3 KiB

12 years ago
12 years ago
  1. #include <defs.h>
  2. #include <unistd.h>
  3. #include <stdarg.h>
  4. #include <syscall.h>
  5. #include <stat.h>
  6. #include <dirent.h>
  7. #define MAX_ARGS 5
  8. static inline int
  9. syscall(int num, ...) {
  10. va_list ap;
  11. va_start(ap, num);
  12. uint32_t a[MAX_ARGS];
  13. int i, ret;
  14. for (i = 0; i < MAX_ARGS; i ++) {
  15. a[i] = va_arg(ap, uint32_t);
  16. }
  17. va_end(ap);
  18. asm volatile (
  19. "int %1;"
  20. : "=a" (ret)
  21. : "i" (T_SYSCALL),
  22. "a" (num),
  23. "d" (a[0]),
  24. "c" (a[1]),
  25. "b" (a[2]),
  26. "D" (a[3]),
  27. "S" (a[4])
  28. : "cc", "memory");
  29. return ret;
  30. }
  31. int
  32. sys_exit(int error_code) {
  33. return syscall(SYS_exit, error_code);
  34. }
  35. int
  36. sys_fork(void) {
  37. return syscall(SYS_fork);
  38. }
  39. int
  40. sys_wait(int pid, int *store) {
  41. return syscall(SYS_wait, pid, store);
  42. }
  43. int
  44. sys_yield(void) {
  45. return syscall(SYS_yield);
  46. }
  47. int
  48. sys_kill(int pid) {
  49. return syscall(SYS_kill, pid);
  50. }
  51. int
  52. sys_getpid(void) {
  53. return syscall(SYS_getpid);
  54. }
  55. int
  56. sys_putc(int c) {
  57. return syscall(SYS_putc, c);
  58. }
  59. int
  60. sys_pgdir(void) {
  61. return syscall(SYS_pgdir);
  62. }
  63. void
  64. sys_lab6_set_priority(uint32_t priority)
  65. {
  66. syscall(SYS_lab6_set_priority, priority);
  67. }
  68. int
  69. sys_sleep(unsigned int time) {
  70. return syscall(SYS_sleep, time);
  71. }
  72. int
  73. sys_gettime(void) {
  74. return syscall(SYS_gettime);
  75. }
  76. int
  77. sys_exec(const char *name, int argc, const char **argv) {
  78. return syscall(SYS_exec, name, argc, argv);
  79. }
  80. int
  81. sys_open(const char *path, uint32_t open_flags) {
  82. return syscall(SYS_open, path, open_flags);
  83. }
  84. int
  85. sys_close(int fd) {
  86. return syscall(SYS_close, fd);
  87. }
  88. int
  89. sys_read(int fd, void *base, size_t len) {
  90. return syscall(SYS_read, fd, base, len);
  91. }
  92. int
  93. sys_write(int fd, void *base, size_t len) {
  94. return syscall(SYS_write, fd, base, len);
  95. }
  96. int
  97. sys_seek(int fd, off_t pos, int whence) {
  98. return syscall(SYS_seek, fd, pos, whence);
  99. }
  100. int
  101. sys_fstat(int fd, struct stat *stat) {
  102. return syscall(SYS_fstat, fd, stat);
  103. }
  104. int
  105. sys_fsync(int fd) {
  106. return syscall(SYS_fsync, fd);
  107. }
  108. int
  109. sys_getcwd(char *buffer, size_t len) {
  110. return syscall(SYS_getcwd, buffer, len);
  111. }
  112. int
  113. sys_getdirentry(int fd, struct dirent *dirent) {
  114. return syscall(SYS_getdirentry, fd, dirent);
  115. }
  116. int
  117. sys_dup(int fd1, int fd2) {
  118. return syscall(SYS_dup, fd1, fd2);
  119. }