mirror of
https://github.com/limine-bootloader/limine
synced 2024-11-23 00:51:54 +03:00
config: Add and document ARCH built-in macro
This commit is contained in:
parent
bc8188e275
commit
670b635ae8
@ -193,3 +193,9 @@ CMDLINE=something before ${MY_MACRO} something after
|
||||
```
|
||||
|
||||
Macros must always be placed inside `${...}` where `...` is the arbitrary macro name.
|
||||
|
||||
### Built-in macros
|
||||
|
||||
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`. 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`.
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <lib/print.h>
|
||||
#include <pxe/tftp.h>
|
||||
#include <crypt/blake2b.h>
|
||||
#include <sys/cpu.h>
|
||||
|
||||
#define CONFIG_B2SUM_SIGNATURE "++CONFIG_B2SUM_SIGNATURE++"
|
||||
#define CONFIG_B2SUM_EMPTY "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
@ -178,6 +179,29 @@ int init_config(size_t config_size) {
|
||||
}
|
||||
|
||||
// Load macros
|
||||
struct macro *arch_macro = ext_mem_alloc(sizeof(struct macro));
|
||||
strcpy(arch_macro->name, "ARCH");
|
||||
#if defined (__x86_64__)
|
||||
strcpy(arch_macro->value, "x86-64");
|
||||
#elif defined (__i386__)
|
||||
{
|
||||
uint32_t eax, ebx, ecx, edx;
|
||||
if (!cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx) || !(edx & (1 << 29))) {
|
||||
strcpy(arch_macro->value, "ia-32");
|
||||
} else {
|
||||
strcpy(arch_macro->value, "x86-64");
|
||||
}
|
||||
}
|
||||
#elif defined (__aarch64__)
|
||||
strcpy(arch_macro->value, "aarch64");
|
||||
#elif defined (__riscv64)
|
||||
strcpy(arch_macro->value, "riscv64");
|
||||
#else
|
||||
#error "Unspecified architecture"
|
||||
#endif
|
||||
arch_macro->next = macros;
|
||||
macros = arch_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)) {
|
||||
|
@ -11,7 +11,7 @@ TERM_WALLPAPER=${WALLPAPER_PATH}
|
||||
TERM_BACKDROP=008080
|
||||
|
||||
:Limine Test
|
||||
COMMENT=Test of the Limine boot protocol.
|
||||
COMMENT=Test of the Limine boot protocol. ${ARCH}
|
||||
|
||||
PROTOCOL=limine
|
||||
KERNEL_PATH=${TEST_KERNEL}
|
||||
|
Loading…
Reference in New Issue
Block a user