os_kernel_lab/code/lab5/user/libs/syscall.c
2012-08-22 12:32:13 +08:00

73 lines
1.1 KiB
C

#include <defs.h>
#include <unistd.h>
#include <stdarg.h>
#include <syscall.h>
#define MAX_ARGS 5
static inline int
syscall(int num, ...) {
va_list ap;
va_start(ap, num);
uint32_t a[MAX_ARGS];
int i, ret;
for (i = 0; i < MAX_ARGS; i ++) {
a[i] = va_arg(ap, uint32_t);
}
va_end(ap);
asm volatile (
"int %1;"
: "=a" (ret)
: "i" (T_SYSCALL),
"a" (num),
"d" (a[0]),
"c" (a[1]),
"b" (a[2]),
"D" (a[3]),
"S" (a[4])
: "cc", "memory");
return ret;
}
int
sys_exit(int error_code) {
return syscall(SYS_exit, error_code);
}
int
sys_fork(void) {
return syscall(SYS_fork);
}
int
sys_wait(int pid, int *store) {
return syscall(SYS_wait, pid, store);
}
int
sys_yield(void) {
return syscall(SYS_yield);
}
int
sys_kill(int pid) {
return syscall(SYS_kill, pid);
}
int
sys_getpid(void) {
return syscall(SYS_getpid);
}
int
sys_putc(int c) {
return syscall(SYS_putc, c);
}
int
sys_pgdir(void) {
return syscall(SYS_pgdir);
}