:: commit 29907c9d12d5cef33697c10475427856e353c254

mintsuki <mintsuki@protonmail.com> — 2024-10-27 00:51

parents: 1e299ae403

config: Add and document FW_TYPE built-in macro. Fixes #422

diff --git a/CONFIG.md b/CONFIG.md
index a8648488..d7531f32 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -198,3 +198,4 @@ Macros must always be placed inside `${...}` where `...` is the arbitrary macro
 Limine automatically defines these macros:
 
 * `ARCH` - This built-in macro expands to the architecture of the machine. Possible values are: `x86-64`, `ia-32`, `aarch64`, `riscv64`, `loongarch64`. In the case of IA-32, BIOS or UEFI, the macro will always expand to `x86-64` if the 64-bit extensions are available, else `ia-32`.
+* `FW_TYPE` - This built-in macro expands to `UEFI` if booted using UEFI firmware, or `BIOS` if booted using legacy x86 BIOS.
diff --git a/common/lib/config.c b/common/lib/config.c
index 633d218f..a0155b93 100644
--- a/common/lib/config.c
+++ b/common/lib/config.c
@@ -235,6 +235,16 @@ skip_loop:
     arch_macro->next = macros;
     macros = arch_macro;
 
+    struct macro *fw_type_macro = ext_mem_alloc(sizeof(struct macro));
+    strcpy(fw_type_macro->name, "FW_TYPE");
+#if defined (UEFI)
+    strcpy(fw_type_macro->value, "UEFI");
+#else
+    strcpy(fw_type_macro->value, "BIOS");
+#endif
+    fw_type_macro->next = macros;
+    macros = fw_type_macro;
+
     for (size_t i = 0; i < config_size;) {
         if ((config_size - i >= 3 && memcmp(config_addr + i, "\n${", 3) == 0)
          || (config_size - i >= 2 && i == 0 && memcmp(config_addr, "${", 2) == 0)) {
diff --git a/test/limine.conf b/test/limine.conf
index 0815a9d0..303aeb95 100644
--- a/test/limine.conf
+++ b/test/limine.conf
@@ -10,7 +10,7 @@ wallpaper: ${WALLPAPER_PATH}
 backdrop: 008080
 
 /Limine Test
-    comment: Test of the Limine boot protocol. ${ARCH}
+    comment: Test of the Limine boot protocol. ${ARCH} ${FW_TYPE}
 
     protocol: limine
     kernel_path: ${TEST_KERNEL}
tab: 248 wrap: offon