From 6967fa911723260f3b3753796d09ef6d1a1c6507 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 20 Sep 2022 16:30:34 +0200 Subject: [PATCH] Update config.h to use a .cpp file that will be recompiled when it changes --- kernel/include/config.h | 26 ++++---------------------- kernel/src/config.cpp | 31 +++++++++++++++++++++++++++++++ kernel/src/main.cpp | 2 +- kernel/src/rand/Init.cpp | 2 +- 4 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 kernel/src/config.cpp diff --git a/kernel/include/config.h b/kernel/include/config.h index a0bc9861..72ce5d96 100644 --- a/kernel/include/config.h +++ b/kernel/include/config.h @@ -1,23 +1,5 @@ -#ifndef STRINGIZE -#define STRINGIZE(x) #x -#endif +#pragma once -#ifndef STRINGIZE_VALUE_OF -#define STRINGIZE_VALUE_OF(x) STRINGIZE(x) -#endif - -#ifndef MOON_MAJOR -#define MOON_MAJOR 0 -#endif - -#ifndef MOON_MINOR -#define MOON_MINOR 3 -#endif - -#ifndef MOON_SUFFIX -#ifndef _MOON_SUFFIX -#define MOON_SUFFIX "" -#else -#define MOON_SUFFIX STRINGIZE_VALUE_OF(_MOON_SUFFIX) -#endif -#endif \ No newline at end of file +int __moon_version_major(); +int __moon_version_minor(); +const char* __moon_version_suffix(); \ No newline at end of file diff --git a/kernel/src/config.cpp b/kernel/src/config.cpp new file mode 100644 index 00000000..4b04b372 --- /dev/null +++ b/kernel/src/config.cpp @@ -0,0 +1,31 @@ +#include "config.h" + +#define STRINGIZE(x) #x +#define STRINGIZE_VALUE_OF(x) STRINGIZE(x) + +int __moon_version_major() +{ +#ifndef MOON_MAJOR + return 0; +#else + return MOON_MAJOR; +#endif +} + +int __moon_version_minor() +{ +#ifndef MOON_MINOR + return 3; +#else + return MOON_MINOR; +#endif +} + +const char* __moon_version_suffix() +{ +#ifndef _MOON_SUFFIX + return ""; +#else + return STRINGIZE_VALUE_OF(_MOON_SUFFIX); +#endif +} \ No newline at end of file diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 2ef56dd0..297fce11 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -32,7 +32,7 @@ extern "C" void _start() Init::disable_smp(); // Put all other cores except the bootstrap one in an infinite loop Init::early_init(); - kinfoln("Starting Moon %d.%d%s", MOON_MAJOR, MOON_MINOR, MOON_SUFFIX); + kinfoln("Starting Moon %d.%d%s", __moon_version_major(), __moon_version_minor(), __moon_version_suffix()); CPU::log_cpu_information(); diff --git a/kernel/src/rand/Init.cpp b/kernel/src/rand/Init.cpp index b322db51..c984281c 100644 --- a/kernel/src/rand/Init.cpp +++ b/kernel/src/rand/Init.cpp @@ -43,7 +43,7 @@ void Mersenne::init() has_rdrand = CPU::has_feature(CPU::Features::RDRAND); has_rdseed = asm_test_rdseed(); - state ^= (0x45fe1024UL + MOON_MAJOR) * (MOON_MINOR ^ 200UL); + state ^= (0x45fe1024UL + __moon_version_major()) * (__moon_version_minor() ^ 200UL); state ^= 0xe0e4f5332ea75b;