mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 04:56:30 +00:00
添加rust重构版本的HPET驱动和tsc驱动,并使用HPET校准tsc频率和cpu总线频率 (#412)
* 添加rust重构版本的HPET驱动和tsc驱动,并使用HPET校准tsc频率和cpu总线频率 * 把hpet.c移动到arch文件夹下
This commit is contained in:
@ -100,32 +100,3 @@ void cpu_cpuid(uint32_t mop, uint32_t sop, uint32_t *eax, uint32_t *ebx, uint32_
|
||||
: "0"(mop), "2"(sop)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取当前cpu核心晶振频率(是一个Write-on-box的值)
|
||||
*
|
||||
* hint: 某些cpu无法提供该数据,返回值为0
|
||||
* @return uint32_t 当前cpu核心晶振频率
|
||||
*/
|
||||
uint32_t cpu_get_core_crysral_freq()
|
||||
{
|
||||
uint32_t a = 0, b = 0, c = 0, d = 0;
|
||||
|
||||
// cpu_cpuid(0x15, 0, &a, &b, &c, &d);
|
||||
__asm__ __volatile__("cpuid \n\t"
|
||||
: "=a"(a), "=b"(b), "=c"(c), "=d"(d)
|
||||
: "0"(0x15), "2"(0)
|
||||
: "memory");
|
||||
// kdebug("Cpu_cpuid_max_Basic_mop = %#03x, a=%ld, b=%ld, c=%ld, d=%ld", Cpu_cpuid_max_Basic_mop, a, b, c, d);
|
||||
|
||||
return c;
|
||||
}
|
||||
/**
|
||||
* @brief 获取处理器的tsc频率(单位:hz)
|
||||
*
|
||||
* @return uint64_t
|
||||
*/
|
||||
uint64_t cpu_get_tsc_freq()
|
||||
{
|
||||
return Cpu_tsc_freq;
|
||||
}
|
||||
|
@ -1002,6 +1002,43 @@ pub fn textui_putchar(
|
||||
}
|
||||
}
|
||||
|
||||
/// 向默认窗口输出一个字符串
|
||||
pub fn textui_putstr(
|
||||
string: &str,
|
||||
fr_color: FontColor,
|
||||
bk_color: FontColor,
|
||||
) -> Result<(), SystemError> {
|
||||
let window = if unsafe { TEXTUI_IS_INIT } {
|
||||
let fw = textui_framework();
|
||||
let w = fw.current_window.clone();
|
||||
Some(w)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut guard = window.as_ref().map(|w| w.lock());
|
||||
|
||||
for character in string.chars() {
|
||||
if unsafe { TEXTUI_IS_INIT } {
|
||||
guard.as_mut().unwrap().textui_putchar_window(
|
||||
character,
|
||||
fr_color,
|
||||
bk_color,
|
||||
ENABLE_PUT_TO_WINDOW.load(Ordering::SeqCst),
|
||||
)?;
|
||||
} else {
|
||||
no_init_textui_putchar_window(
|
||||
character,
|
||||
fr_color,
|
||||
bk_color,
|
||||
ENABLE_PUT_TO_WINDOW.load(Ordering::SeqCst),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
/// 初始化text ui框架
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use core::fmt::{self, Write};
|
||||
|
||||
use super::lib_ui::textui::{textui_putchar, FontColor};
|
||||
use super::lib_ui::textui::{textui_putstr, FontColor};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! print {
|
||||
@ -77,15 +77,11 @@ impl PrintkWriter {
|
||||
/// 并输出白底黑字
|
||||
/// @param str: 要写入的字符
|
||||
pub fn __write_string(&mut self, s: &str) {
|
||||
for c in s.chars() {
|
||||
textui_putchar(c, FontColor::WHITE, FontColor::BLACK).ok();
|
||||
}
|
||||
textui_putstr(s, FontColor::WHITE, FontColor::BLACK).ok();
|
||||
}
|
||||
|
||||
pub fn __write_string_color(&self, fr_color: FontColor, bk_color: FontColor, s: &str) {
|
||||
for c in s.chars() {
|
||||
textui_putchar(c, fr_color, bk_color).ok();
|
||||
}
|
||||
textui_putstr(s, fr_color, bk_color).ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,9 @@ impl<T: Copy> VolatileWritable<T> for *mut Volatile<T> {
|
||||
/// ```
|
||||
macro_rules! volread {
|
||||
($nonnull:expr, $field:ident) => {
|
||||
VolatileReadable::vread(core::ptr::addr_of!((*$nonnull.as_ptr()).$field))
|
||||
crate::libs::volatile::VolatileReadable::vread(core::ptr::addr_of!(
|
||||
(*$nonnull.as_ptr()).$field
|
||||
))
|
||||
};
|
||||
}
|
||||
|
||||
@ -166,7 +168,10 @@ macro_rules! volread {
|
||||
/// ```
|
||||
macro_rules! volwrite {
|
||||
($nonnull:expr, $field:ident, $value:expr) => {
|
||||
VolatileWritable::vwrite(core::ptr::addr_of_mut!((*$nonnull.as_ptr()).$field), $value)
|
||||
crate::libs::volatile::VolatileWritable::vwrite(
|
||||
core::ptr::addr_of_mut!((*$nonnull.as_ptr()).$field),
|
||||
$value,
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user