xref: /DragonOS/kernel/crates/kcmdline_macros/src/lib.rs (revision fae6e9ade46a52976ad5d099643d51cc20876448)
1 #![no_std]
2 #![deny(clippy::all)]
3 #![allow(clippy::crate_in_macro_def)]
4 
5 /// 定义一个bool类型的参数
6 ///
7 /// # 参数
8 ///
9 /// - `$varname`: 参数的变量名
10 /// - `$name`: 参数的名称
11 /// - `$default_bool`: 默认值
12 /// - `$inv`: 是否反转
13 #[macro_export]
14 macro_rules! kernel_cmdline_param_arg {
15     ($varname:ident, $name:ident, $default_bool:expr, $inv:expr) => {
16         #[::linkme::distributed_slice(crate::init::cmdline::KCMDLINE_PARAM_ARG)]
17         static $varname: crate::init::cmdline::KernelCmdlineParameter =
18             crate::init::cmdline::KernelCmdlineParamBuilder::new(
19                 stringify!($name),
20                 crate::init::cmdline::KCmdlineParamType::Arg,
21             )
22             .default_bool($default_bool)
23             .inv($inv)
24             .build()
25             .unwrap();
26     };
27 }
28 
29 /// 定义一个key-value类型的参数
30 ///
31 /// # 参数
32 /// - `$varname`: 参数的变量名
33 /// - `$name`: 参数的名称
34 /// - `$default_str`: 默认值
35 #[macro_export]
36 macro_rules! kernel_cmdline_param_kv {
37     ($varname:ident, $name:ident, $default_str:expr) => {
38         #[::linkme::distributed_slice(crate::init::cmdline::KCMDLINE_PARAM_KV)]
39         static $varname: crate::init::cmdline::KernelCmdlineParameter =
40             crate::init::cmdline::KernelCmdlineParamBuilder::new(
41                 stringify!($name),
42                 crate::init::cmdline::KCmdlineParamType::KV,
43             )
44             .default_str($default_str)
45             .build()
46             .unwrap();
47     };
48 }
49 
50 /// 定义一个内存管理初始化之前就要设置的key-value类型的参数
51 ///
52 /// # 参数
53 /// - `$varname`: 参数的变量名
54 /// - `$name`: 参数的名称
55 /// - `$default_str`: 默认值
56 #[macro_export]
57 macro_rules! kernel_cmdline_param_early_kv {
58     ($varname:ident, $name:ident, $default_str:expr) => {
59         #[::linkme::distributed_slice(crate::init::cmdline::KCMDLINE_PARAM_EARLY_KV)]
60         static $varname: crate::init::cmdline::KernelCmdlineParameter = {
61             static ___KV: crate::init::cmdline::KernelCmdlineEarlyKV = {
62                 const { assert!($default_str.len() < KernelCmdlineEarlyKV::VALUE_MAX_LEN) };
63                 crate::init::cmdline::KernelCmdlineParamBuilder::new(
64                     stringify!($name),
65                     crate::init::cmdline::KCmdlineParamType::EarlyKV,
66                 )
67                 .default_str($default_str)
68                 .build_early_kv()
69                 .unwrap()
70             };
71             crate::init::cmdline::KernelCmdlineParameter::EarlyKV(&___KV)
72         };
73     };
74 }
75