From 07f2e73a22ca4def152a7f8f984754e60e44907e Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Sat, 9 Aug 2025 23:58:52 +0200 Subject: [PATCH] Add helper functions used by the boot protocol during system startup --- xtldr/bootutil.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 xtldr/bootutil.c diff --git a/xtldr/bootutil.c b/xtldr/bootutil.c new file mode 100644 index 0000000..9ca1aa9 --- /dev/null +++ b/xtldr/bootutil.c @@ -0,0 +1,87 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/bootutil.c + * DESCRIPTION: Helper functions used by the boot protocol during system startup + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Checks if a specific option exists in the list of provided boot parameters. + * + * @param Parameters + * A pointer to the wide-character string containing the boot parameters, separated by spaces. + * + * @param Needle + * A pointer to the wide-character string representing the kernel option to find. + * + * @return This routine returns TRUE if the option is found, otherwise FALSE. + * + * @since XT 1.0 + */ +XTCDECL +BOOLEAN +BlGetBooleanParameter(IN CONST PWCHAR Parameters, + IN CONST PWCHAR Needle) +{ + PWCHAR CurrentPosition, TokenEnd, TokenStart; + SIZE_T NeedleLength, TokenLength; + + /* Validate input data and ensure the option is not an empty string */ + if(Parameters == NULL || Needle == NULL || *Needle == L'\0') + { + /* One of the parameters was invalid */ + return FALSE; + } + + CurrentPosition = Parameters; + NeedleLength = RtlWideStringLength(Needle, 0); + + /* Iterate through the entire parameters string */ + while(*CurrentPosition != L'\0') + { + /* Skip any leading whitespace to find the start of the token */ + while(*CurrentPosition == L' ') + { + CurrentPosition++; + } + + /* Check if end of the string has been reached */ + if(*CurrentPosition == L'\0') + { + /* End of string reached, no more tokens */ + break; + } + + /* Identify the boundaries of the current token */ + TokenStart = CurrentPosition; + TokenEnd = TokenStart; + while(*TokenEnd != L'\0' && *TokenEnd != L' ') + { + TokenEnd++; + } + + /* Calculate the length of the token found */ + TokenLength = TokenEnd - TokenStart; + + /* Compare the token length */ + if(TokenLength == NeedleLength) + { + /* Length matches, compare the strings */ + if(RtlCompareWideStringInsensitive(TokenStart, Needle, NeedleLength) == 0) + { + /* A match was found */ + return TRUE; + } + } + + /* Move the position past the current token to continue the search */ + CurrentPosition = TokenEnd; + } + + /* No match was found */ + return FALSE; +}