1
0
Fork 0
forked from AbleOS/ableos
ableOS_v1Change/ableos/src/experiments/kinfo.rs
Able 51c841e2de upgrades people upgrades
destroying erins clean code
2022-04-12 13:26:52 -05:00

78 lines
1.8 KiB
Rust

use core::fmt::Display;
use crate::{arch::drivers::sysinfo::master, ALLOCATOR};
use super::systeminfo::SystemMemory;
use versioning::Version;
use x86_64::instructions::interrupts::{disable, enable};
pub enum CpuType {
RiscV(String),
X86_64(String),
}
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,
}
)
}
}
/// simple info you would want to know in a neofetch like program
pub struct KernelInfo {
// os: String,
// host: String,
pub kernel_version: Version,
pub cpu: CpuType,
// gpu: String,
pub memory: SystemMemory,
}
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
)
}
}