1
0
Fork 0
forked from AbleOS/ableos

another shrimple macro!

(NOTE: I was unable to test on my Nix system for some reason, QEMU just refuses to work even though I ran it within the Nix Shell environment)
This commit is contained in:
IntoTheNight 2023-07-13 19:50:44 +05:30
parent 473598d5df
commit 6a404b8227
2 changed files with 29 additions and 17 deletions

View file

@ -1,3 +1,5 @@
use crate::cpu_features;
use {
alloc::vec::Vec,
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
pub fn features(&self) -> Vec<(&str, bool)> {
let mut fv = Vec::new();
let apic = self.apic();
let avx = self.avx();
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
cpu_features!(self, fv);
return fv;
}
master_attr_reader!(version_information, VersionInformation);

View file

@ -25,4 +25,29 @@ macro_rules! device_tree {
$devtree.devices.insert(each_device_type.to_string(), Vec::new());
}
};
}
// 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));
};
}