diff --git a/os/Makefile b/os/Makefile index a9ed0b73..db70d610 100644 --- a/os/Makefile +++ b/os/Makefile @@ -77,7 +77,7 @@ ifeq ($(BOARD),qemu) -machine virt \ -nographic \ -bios $(BOOTLOADER) \ - -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) + -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) -m 1G else (which $(K210-BURNER)) || (cd .. && git clone https://github.com/sipeed/kflash.py.git && mv kflash.py tools) @cp $(BOOTLOADER) $(BOOTLOADER).copy diff --git a/os/src/syscall/mod.rs b/os/src/syscall/mod.rs index 81ade837..a46eb0f9 100644 --- a/os/src/syscall/mod.rs +++ b/os/src/syscall/mod.rs @@ -20,11 +20,11 @@ pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize { SYSCALL_WRITE => sys_write(args[0], args[1] as *const u8, args[2]), SYSCALL_EXIT => sys_exit(args[0] as i32), SYSCALL_YIELD => sys_yield(), - SYSCALL_GET_TIME => sys_get_time(), SYSCALL_GETPID => sys_getpid(), SYSCALL_FORK => sys_fork(), SYSCALL_EXEC => sys_exec(args[0] as *const u8), SYSCALL_WAITPID => sys_waitpid(args[0] as isize, args[1] as *mut i32), + SYSCALL_GET_TIME => sys_get_time(args[0] as *mut TimeVal, args[1]), _ => panic!("Unsupported syscall_id: {}", syscall_id), } } diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index b425d87d..04d1b030 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -5,13 +5,20 @@ use crate::task::{ current_user_token, add_task, }; -use crate::timer::get_time_ms; use crate::mm::{ translated_str, translated_refmut, }; use crate::loader::get_app_data_by_name; use alloc::sync::Arc; +use crate::timer::get_time_us; + +#[repr(C)] +#[derive(Debug)] +pub struct TimeVal { + pub sec: usize, + pub usec: usize, +} pub fn sys_exit(exit_code: i32) -> ! { exit_current_and_run_next(exit_code); @@ -23,10 +30,6 @@ pub fn sys_yield() -> isize { 0 } -pub fn sys_get_time() -> isize { - get_time_ms() as isize -} - pub fn sys_getpid() -> isize { current_task().unwrap().pid.0 as isize } @@ -94,4 +97,15 @@ pub fn sys_waitpid(pid: isize, exit_code_ptr: *mut i32) -> isize { -2 } // ---- release current PCB lock automatically +} + +pub fn sys_get_time(ts: *mut TimeVal, _tz: usize) -> isize { + let us = get_time_us(); + unsafe { + *ts = TimeVal { + sec: us / 1_000_000, + usec: us % 1_000_000, + }; + } + 0 } \ No newline at end of file diff --git a/os/src/timer.rs b/os/src/timer.rs index 92d50e3a..7f78d6e4 100644 --- a/os/src/timer.rs +++ b/os/src/timer.rs @@ -1,16 +1,16 @@ -use riscv::register::time; -use crate::sbi::set_timer; use crate::config::CLOCK_FREQ; +use crate::sbi::set_timer; +use riscv::register::time; const TICKS_PER_SEC: usize = 100; -const MSEC_PER_SEC: usize = 1000; +const MICRO_PER_SEC: usize = 1_000_000; pub fn get_time() -> usize { time::read() } -pub fn get_time_ms() -> usize { - time::read() / (CLOCK_FREQ / MSEC_PER_SEC) +pub fn get_time_us() -> usize { + time::read() / (CLOCK_FREQ / MICRO_PER_SEC) } pub fn set_next_trigger() {