1
0
Fork 0
forked from AbleOS/ableos
ableos_time/kernel/src/utils.rs
koniifer 07ee8de9f1 push it to prod 😄
experimental avx stuff (enable it yourself, coward)
update hblang & fiddle with stuff
2024-09-30 21:45:57 +01:00

53 lines
1.9 KiB
Rust

//! A module for small utilities to be used kernel wide
//! Simple functions and constants
/// Used when tab `\t` in hardware is not known and we will default to two spaces
pub const TAB: &str = " ";
// 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 use TAB internally
#[macro_export]
macro_rules! tab {
($num:expr) => {
TAB.repeat($num)
};
}
// 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 device types into the device tree
#[macro_export]
macro_rules! device_tree {
($devtree:expr, $dev_type_vec:expr) => {
for each_device_type in $dev_type_vec {
$devtree.devices.insert(each_device_type, 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));
};
}