2022-04-12 13:26:52 -05:00
|
|
|
use core::fmt::Display;
|
|
|
|
|
|
|
|
use crate::{arch::drivers::sysinfo::master, ALLOCATOR};
|
|
|
|
|
2022-04-11 17:23:11 -05:00
|
|
|
use super::systeminfo::SystemMemory;
|
2022-04-12 13:26:52 -05:00
|
|
|
use versioning::Version;
|
|
|
|
use x86_64::instructions::interrupts::{disable, enable};
|
2022-04-11 17:23:11 -05:00
|
|
|
|
2022-04-12 13:26:52 -05:00
|
|
|
pub enum CpuType {
|
|
|
|
RiscV(String),
|
|
|
|
X86_64(String),
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2022-04-12 13:26:52 -05:00
|
|
|
impl Display for CpuType {
|
|
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"{}",
|
|
|
|
match self {
|
|
|
|
CpuType::RiscV(s) => s,
|
|
|
|
CpuType::X86_64(s) => s,
|
|
|
|
}
|
|
|
|
)
|
2022-02-18 12:25:54 -06:00
|
|
|
}
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2022-04-11 17:23:11 -05:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
/// simple info you would want to know in a neofetch like program
|
|
|
|
pub struct KernelInfo {
|
2022-02-18 12:25:54 -06:00
|
|
|
// os: String,
|
|
|
|
// host: String,
|
2022-04-12 13:26:52 -05:00
|
|
|
pub kernel_version: Version,
|
|
|
|
pub cpu: CpuType,
|
2022-02-18 12:25:54 -06:00
|
|
|
// gpu: String,
|
|
|
|
pub memory: SystemMemory,
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2022-04-12 13:26:52 -05:00
|
|
|
|
|
|
|
impl KernelInfo {
|
|
|
|
pub fn get() -> KernelInfo {
|
|
|
|
disable();
|
|
|
|
let allocator = ALLOCATOR.lock();
|
|
|
|
let total = allocator.size();
|
|
|
|
let used = allocator.used();
|
|
|
|
enable();
|
|
|
|
|
|
|
|
let cpu = CpuType::X86_64(master().unwrap().brand_string().unwrap().to_string());
|
|
|
|
KernelInfo {
|
|
|
|
kernel_version: Version {
|
|
|
|
major: 0,
|
|
|
|
minor: 0,
|
|
|
|
patch: 0,
|
|
|
|
},
|
|
|
|
cpu,
|
|
|
|
memory: SystemMemory { total, used },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for KernelInfo {
|
|
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"
|
|
|
|
OS: AbleOS
|
|
|
|
Host: {{}}
|
|
|
|
Kernel: {}.{}.{}
|
|
|
|
CPU: {}
|
|
|
|
Memory: {}/{}
|
|
|
|
",
|
|
|
|
self.kernel_version.major,
|
|
|
|
self.kernel_version.minor,
|
|
|
|
self.kernel_version.patch,
|
|
|
|
self.cpu,
|
|
|
|
self.memory.used,
|
|
|
|
self.memory.total
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|