cpuid
This commit is contained in:
12
nel_os_kernel/Cargo.lock
generated
12
nel_os_kernel/Cargo.lock
generated
@@ -101,6 +101,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"linked_list_allocator",
|
||||
"nel_os_common",
|
||||
"raw-cpuid 11.5.0",
|
||||
"spin 0.10.0",
|
||||
"uart_16550",
|
||||
"x86_64",
|
||||
@@ -124,6 +125,15 @@ dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raw-cpuid"
|
||||
version = "11.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6df7ab838ed27997ba19a4664507e6f82b41fe6e20be42929332156e5e85146"
|
||||
dependencies = [
|
||||
"bitflags 2.9.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.21"
|
||||
@@ -194,7 +204,7 @@ checksum = "2781db97787217ad2a2845c396a5efe286f87467a5810836db6d74926e94a385"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"bitflags 1.3.2",
|
||||
"raw-cpuid",
|
||||
"raw-cpuid 10.7.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -11,3 +11,4 @@ x86_64 = "0.15.2"
|
||||
nel_os_common = { path = "../nel_os_common" }
|
||||
linked_list_allocator = "0.9.1"
|
||||
ab_glyph = { version = "0.2", features = ["libm"], default-features = false }
|
||||
raw-cpuid = "11.5.0"
|
||||
|
||||
18
nel_os_kernel/src/cpuid.rs
Normal file
18
nel_os_kernel/src/cpuid.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use alloc::string::{String, ToString};
|
||||
use raw_cpuid::CpuId;
|
||||
|
||||
pub fn get_vendor_id() -> String {
|
||||
let cpuid = CpuId::new();
|
||||
if let Some(vf) = cpuid.get_vendor_info() {
|
||||
return vf.as_str().to_string();
|
||||
}
|
||||
"Unknown".to_string()
|
||||
}
|
||||
|
||||
pub fn get_brand() -> String {
|
||||
let cpuid = CpuId::new();
|
||||
if let Some(brand) = cpuid.get_processor_brand_string() {
|
||||
return brand.as_str().to_string();
|
||||
}
|
||||
"Unknown".to_string()
|
||||
}
|
||||
@@ -5,6 +5,7 @@ extern crate alloc;
|
||||
|
||||
pub mod allocator;
|
||||
pub mod constant;
|
||||
pub mod cpuid;
|
||||
pub mod graphics;
|
||||
pub mod logging;
|
||||
pub mod memory;
|
||||
@@ -17,7 +18,7 @@ use core::arch::asm;
|
||||
use core::panic::PanicInfo;
|
||||
use core::ptr::addr_of;
|
||||
|
||||
use x86_64::{structures::paging::OffsetPageTable, VirtAddr};
|
||||
use x86_64::{registers::control::Cr3, structures::paging::OffsetPageTable, VirtAddr};
|
||||
|
||||
use crate::{
|
||||
constant::{BANNER, KERNEL_STACK_SIZE, PKG_VERSION},
|
||||
@@ -120,7 +121,19 @@ pub extern "sysv64" fn main(boot_info: &nel_os_common::BootInfo) {
|
||||
|
||||
FRAME_BUFFER.lock().replace(frame_buffer);
|
||||
|
||||
println!("{} v{}", BANNER, PKG_VERSION);
|
||||
println!("");
|
||||
info!("Kernel initialized successfully");
|
||||
|
||||
info!("Kernel version: {}", PKG_VERSION);
|
||||
info!(
|
||||
"Level 4 page table at {:#x}",
|
||||
Cr3::read().0.start_address().as_u64()
|
||||
);
|
||||
info!(
|
||||
"Memory bitmap: {} -> {}",
|
||||
bitmap_table.start, bitmap_table.end
|
||||
);
|
||||
info!("CPU: {} {}", cpuid::get_vendor_id(), cpuid::get_brand());
|
||||
info!(
|
||||
"Usable memory: {}MiB ({:.1}GiB)",
|
||||
usable_frame * 4 / 1024,
|
||||
|
||||
Reference in New Issue
Block a user