Merge branch 'master' of ssh://git.ablecorp.us:20/AbleOS/ableos

This commit is contained in:
able 2023-07-14 19:38:46 -05:00
commit d8a68aabee
2 changed files with 29 additions and 17 deletions

View file

@ -1,3 +1,5 @@
use crate::cpu_features;
use { use {
alloc::vec::Vec, alloc::vec::Vec,
core::{arch::asm, fmt, ops::Deref, slice, str}, core::{arch::asm, fmt, ops::Deref, slice, str},
@ -772,23 +774,8 @@ impl Master {
// TODO: Macroify this and also include all of the cpu features from self // TODO: Macroify this and also include all of the cpu features from self
pub fn features(&self) -> Vec<(&str, bool)> { pub fn features(&self) -> Vec<(&str, bool)> {
let mut fv = Vec::new(); let mut fv = Vec::new();
let apic = self.apic(); cpu_features!(self, fv);
let avx = self.avx(); return fv;
let avx2 = self.avx2();
let x2 = self.x2apic();
let gb_pages = self.gigabyte_pages();
let rdseed = self.rdseed();
let rdrand = self.rdrand();
fv.push(("apic", apic));
fv.push(("avx", avx));
fv.push(("avx2", avx2));
fv.push(("gigabyte pages", gb_pages));
fv.push(("rdrand", rdrand));
fv.push(("rdseed", rdseed));
fv.push(("x2apic", x2));
fv
} }
master_attr_reader!(version_information, VersionInformation); master_attr_reader!(version_information, VersionInformation);

View file

@ -26,3 +26,28 @@ macro_rules! device_tree {
} }
}; };
} }
// NOTE: this only reduces the code duplication in source code not in generated code!
// Written by Yours Truly: Munir
/// A simple macro to reduce code duplication when we insert cpu features into the array/vector
#[macro_export]
macro_rules! cpu_features {
($cpu_master_object:expr, $result_vec:expr) => {
// checks for cpu features and returns bool for each feature
let apic = $cpu_master_object.apic();
let avx = $cpu_master_object.avx();
let avx2 = $cpu_master_object.avx2();
let x2 = $cpu_master_object.x2apic();
let gb_pages = $cpu_master_object.gigabyte_pages();
let rdseed = $cpu_master_object.rdseed();
let rdrand = $cpu_master_object.rdrand();
$result_vec.push(("apic", apic));
$result_vec.push(("avx", avx));
$result_vec.push(("avx2", avx2));
$result_vec.push(("gigabyte pages", gb_pages));
$result_vec.push(("rdrand", rdrand));
$result_vec.push(("rdseed", rdseed));
$result_vec.push(("x2apic", x2));
};
}