mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-28 04:43:23 +00:00
实现gettimeofday()系统调用和clocksource+timekeeping子模块 (#278)
- 实现gettimeofday()系统调用 - 实现clocksource+timekeeping子模块部分功能 - 实现了timespec转换成日期时间
This commit is contained in:
@ -1,18 +1,18 @@
|
||||
use core::{arch::asm, ptr::read_volatile};
|
||||
use core::arch::asm;
|
||||
|
||||
#[inline]
|
||||
pub fn local_irq_save(flags: &mut u64) {
|
||||
pub fn local_irq_save() -> usize {
|
||||
let x: usize;
|
||||
unsafe {
|
||||
asm!("pushfq", "pop rax", "mov rax, {0}", "cli", out(reg)(*flags),);
|
||||
asm!("pushfq ; pop {} ; cli", out(reg) x, options(nostack));
|
||||
}
|
||||
x
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn local_irq_restore(flags: &u64) {
|
||||
let x = unsafe { read_volatile(flags) };
|
||||
|
||||
// 恢复先前保存的rflags的值x
|
||||
pub fn local_irq_restore(x: usize) {
|
||||
unsafe {
|
||||
asm!("push r15",
|
||||
"popfq", in("r15")(x));
|
||||
asm!("push {} ; popfq", in(reg) x, options(nostack));
|
||||
}
|
||||
}
|
||||
|
@ -79,8 +79,7 @@ impl FpState {
|
||||
/// @brief 从用户态进入内核时,保存浮点寄存器,并关闭浮点功能
|
||||
pub fn fp_state_save(pcb: &mut process_control_block) {
|
||||
// 该过程中不允许中断
|
||||
let mut rflags: u64 = 0;
|
||||
local_irq_save(&mut rflags);
|
||||
let rflags = local_irq_save();
|
||||
|
||||
let fp: &mut FpState = if pcb.fp_state == null_mut() {
|
||||
let f = Box::leak(Box::new(FpState::default()));
|
||||
@ -112,14 +111,13 @@ pub fn fp_state_save(pcb: &mut process_control_block) {
|
||||
"mov cr4, rax" */
|
||||
)
|
||||
}
|
||||
local_irq_restore(&rflags);
|
||||
local_irq_restore(rflags);
|
||||
}
|
||||
|
||||
/// @brief 从内核态返回用户态时,恢复浮点寄存器,并开启浮点功能
|
||||
pub fn fp_state_restore(pcb: &mut process_control_block) {
|
||||
// 该过程中不允许中断
|
||||
let mut rflags: u64 = 0;
|
||||
local_irq_save(&mut rflags);
|
||||
let rflags = local_irq_save();
|
||||
|
||||
if pcb.fp_state == null_mut() {
|
||||
panic!("fp_state_restore: fp_state is null. pid={}", pcb.pid);
|
||||
@ -143,5 +141,5 @@ pub fn fp_state_restore(pcb: &mut process_control_block) {
|
||||
fp.restore();
|
||||
fp.clear();
|
||||
|
||||
local_irq_restore(&rflags);
|
||||
local_irq_restore(rflags);
|
||||
}
|
||||
|
@ -48,8 +48,7 @@ impl InterruptArch for X86_64InterruptArch {
|
||||
|
||||
unsafe fn save_and_disable_irq() -> IrqFlagsGuard {
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
let mut rflags: u64 = 0;
|
||||
local_irq_save(&mut rflags);
|
||||
let rflags = local_irq_save() as u64;
|
||||
let flags = IrqFlags::new(rflags);
|
||||
let guard = IrqFlagsGuard::new(flags);
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
@ -58,7 +57,7 @@ impl InterruptArch for X86_64InterruptArch {
|
||||
|
||||
unsafe fn restore_irq(flags: IrqFlags) {
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
local_irq_restore(&flags.flags());
|
||||
local_irq_restore(flags.flags() as usize);
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user