|
|
@ -17,7 +17,7 @@ fn sys_call(syscall_id: SyscallId, arg0: usize, arg1: usize, arg2: usize, arg3:
|
|
|
|
: "memory"
|
|
|
|
: "memory"
|
|
|
|
: "intel" "volatile");
|
|
|
|
: "intel" "volatile");
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
asm!("int 0x40"
|
|
|
|
asm!("syscall"
|
|
|
|
: "={rax}" (ret)
|
|
|
|
: "={rax}" (ret)
|
|
|
|
: "{rax}" (id), "{rdi}" (arg0), "{rsi}" (arg1), "{rdx}" (arg2), "{rcx}" (arg3), "{r8}" (arg4), "{r9}" (arg5)
|
|
|
|
: "{rax}" (id), "{rdi}" (arg0), "{rsi}" (arg1), "{rdx}" (arg2), "{rcx}" (arg3), "{r8}" (arg4), "{r9}" (arg5)
|
|
|
|
: "memory"
|
|
|
|
: "memory"
|
|
|
@ -64,8 +64,8 @@ pub fn sys_close(fd: usize) -> i32 {
|
|
|
|
sys_call(SyscallId::Close, fd, 0, 0, 0, 0, 0)
|
|
|
|
sys_call(SyscallId::Close, fd, 0, 0, 0, 0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sys_dup(fd1: usize, fd2: usize) -> i32 {
|
|
|
|
pub fn sys_dup2(fd1: usize, fd2: usize) -> i32 {
|
|
|
|
sys_call(SyscallId::Dup, fd1, fd2, 0, 0, 0, 0)
|
|
|
|
sys_call(SyscallId::Dup2, fd1, fd2, 0, 0, 0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Fork the current process. Return the child's PID.
|
|
|
|
/// Fork the current process. Return the child's PID.
|
|
|
@ -101,40 +101,33 @@ pub fn sys_get_time() -> i32 {
|
|
|
|
sys_call(SyscallId::GetTime, 0, 0, 0, 0, 0, 0)
|
|
|
|
sys_call(SyscallId::GetTime, 0, 0, 0, 0, 0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sys_lab6_set_priority(priority: usize) -> i32 {
|
|
|
|
pub fn sys_set_priority(priority: usize) -> i32 {
|
|
|
|
sys_call(SyscallId::Lab6SetPriority, priority, 0, 0, 0, 0, 0)
|
|
|
|
sys_call(SyscallId::SetPriority, priority, 0, 0, 0, 0, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sys_putc(c: u8) -> i32 {
|
|
|
|
|
|
|
|
sys_call(SyscallId::Putc, c as usize, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[allow(dead_code)]
|
|
|
|
enum SyscallId{
|
|
|
|
enum SyscallId {
|
|
|
|
Exit = 1,
|
|
|
|
Exit = 60,
|
|
|
|
Fork = 2,
|
|
|
|
Fork = 57,
|
|
|
|
Wait = 3,
|
|
|
|
Wait = 61,
|
|
|
|
Exec = 4,
|
|
|
|
Exec = 59,
|
|
|
|
Clone = 5,
|
|
|
|
Clone = 56,
|
|
|
|
Yield = 10,
|
|
|
|
Yield = 24,
|
|
|
|
Sleep = 11,
|
|
|
|
Sleep = 35,
|
|
|
|
Kill = 12,
|
|
|
|
Kill = 62,
|
|
|
|
GetTime = 17,
|
|
|
|
GetTime = 96,
|
|
|
|
GetPid = 18,
|
|
|
|
GetPid = 39,
|
|
|
|
Mmap = 20,
|
|
|
|
Mmap = 9,
|
|
|
|
Munmap = 21,
|
|
|
|
Munmap = 11,
|
|
|
|
Shmem = 22,
|
|
|
|
Open = 2,
|
|
|
|
Putc = 30,
|
|
|
|
Close = 3,
|
|
|
|
Pgdir = 31,
|
|
|
|
Read = 0,
|
|
|
|
Open = 100,
|
|
|
|
Write = 1,
|
|
|
|
Close = 101,
|
|
|
|
Seek = 8,
|
|
|
|
Read = 102,
|
|
|
|
Fstat = 4,
|
|
|
|
Write = 103,
|
|
|
|
Fsync = 74,
|
|
|
|
Seek = 104,
|
|
|
|
GetCwd = 79,
|
|
|
|
Fstat = 110,
|
|
|
|
GetDirEntry = 78,
|
|
|
|
Fsync = 111,
|
|
|
|
Dup2 = 33,
|
|
|
|
GetCwd = 121,
|
|
|
|
SetPriority = 141,
|
|
|
|
GetDirEntry = 128,
|
|
|
|
|
|
|
|
Dup = 130,
|
|
|
|
|
|
|
|
Lab6SetPriority = 255,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|