% AUTHOR: Amlal El Mahrouss % PURPOSE: WG01: A Methodology for Freestanding Development \documentclass[11pt, a4paper]{article} \usepackage{graphicx} \usepackage{listings} \usepackage{xcolor} \usepackage{hyperref} \usepackage[margin=0.5in,top=1in,bottom=1in]{geometry} \setlength{\columnsep}{20pt} \definecolor{codegray}{gray}{0.95} \definecolor{codeblue}{rgb}{0.1,0.1,0.8} \definecolor{codegreen}{rgb}{0,0.6,0} \definecolor{codepurple}{rgb}{0.58,0,0.82} \title{Methodology for Freestanding Development.} \author{Amlal El Mahrouss\\amlal@nekernel.org} \date{December 2025\\Last Edited: January 2026} \lstset{ language=C++, backgroundcolor=\color{codegray}, basicstyle=\footnotesize\ttfamily, keywordstyle=\color{codeblue}\bfseries, commentstyle=\color{codegreen}, stringstyle=\color{codepurple}, numbers=left, numberstyle=\tiny\color{gray}, stepnumber=1, numbersep=5pt, breaklines=true, breakatwhitespace=false, frame=single, rulecolor=\color{black}, captionpos=b, keepspaces=true, showspaces=false, showstringspaces=false, showtabs=false, tabsize=2 } \begin{document} \bf \maketitle \begin{center} \rule[0.01cm]{17cm}{0.01cm} \end{center} \abstract{Many low-level software have been shipped using the C programming language. And some of them, such as EKA2 use the C++ programming language. Although notoriously difficult, one may adapt to those constraints in order to deliver one such operating system kernel. This is why most production-grade software (Linux, XNU, and NT) are mostly written in C. With a higher-level subset in C++. However, when correctly applying the following principles to freestanding development, it becomes much easier to ensure correctness of such programs. } \begin{center} \rule[1cm]{17cm}{0.01cm} \end{center} \section{The Three Principles of Freestanding Development.} \subsection{I: The Run-Time Evaluation Domain.} { The problem lies in the programming language runtime—which assumes an existing host. The contrary of a hosted environment is freestanding—a computing mode which doesn't expect a hosted runtime. Such programs may use the compile-time evaluation domain to achieve minimal run-time domain usage. } \subsection{II: The Compile-Time Evaluation Domain.} { One may avoid Virtual Method Tables or a runtime when possible. While focusing instead on meta-programming and compile-time features offered by C++. For example one may use templates to implement a scheduling policy algorithm. One example of such implementation may be: \begin{lstlisting} struct FileTree final { static constexpr bool is_virtual_memory = false; static constexpr bool is_memory = false; static constexpr bool is_file = true; /// ... }; struct MemoryTree final { static constexpr bool is_virtual_memory = false; static constexpr bool is_memory = true; static constexpr bool is_file = false; /// ... }; \end{lstlisting} Source: \href{https://github.com/ne-foss-org/nekernel/blob/develop/src/kernel/KernelKit/CoreProcessScheduler.h#L78-L105}{Link}. \\ Which is why the `constexpr' keyword is very powerful here for the Compile-Time Evaluation Domain, we avoid the many pitfalls of the Run-Time Evaluation Domain. \subsection{III: Memory Layout and the example of C++.} { The Virtual Method Table (now defined as the VMT) is a big part of the problem, one may illustrate the following: \begin{lstlisting} /// /std:c++20 /Wall #include class A { public: explicit A() = default; virtual ~A() = default; virtual void doImpl() { std::cout << "doImpl()\r\n"; } }; class B : public A { public: explicit B() = default; ~B() override = default; }; int main() { B callImpl; callImpl.doImpl(); } \end{lstlisting} Source: \href{https://godbolt.org/z/aK6Y98xnd}{Link}. \\The following can instead be done to achieve similar results using the Compile-Time Evaluation Domain. \begin{lstlisting} inline constexpr auto kInvalidType = 0; template concept IsValidDriver = requires(Driver drv) { { drv.IsActive() && drv.Type() > kInvalidType }; }; \end{lstlisting} Source: \href{https://github.com/ne-foss-org/nekernel/blob/develop/src/libDDK/DriverKit/c%2B%2B/driver_base.h}{Link}.\\ Now, the problem with freestanding development is that such feature may be abused, and it is mitigated by following the TTPI. \subsection{IV: The Three Prongs on Inheritance.} The TTPI is a boolean framework used to evaluate whether one may consider using a Object Oriented programming language inside a freestanding program, consider the following: \begin{itemize} \item[1:] Is this implementable with compile-time protocols/concepts? \item[2:] Is this implementable without three trade-off costs? \subitem Without violating the Runtime cost? \subitem The Verification cost? \subitem The Known-Ahead-Correctness cost? \item[3:] Is this implementable without using a VMT? \end{itemize} } \subsection{V: Compile-Time Vetting in a Freestanding Evaluation Domain.} The following concept makes sure that the `class T' is vetted by the domain. Such properties are called `Vettable' such program in the domain makes sure that a `Container' is truly deemed fit for a Run-Time or Compile-Time Evaluation Domain. The `Vettable' structure makes use of template meta-programming in C++ to evaluate whether a `Container' shall be vetted. Such system may look as such in a Compile-Time Evaluation Domain: \begin{lstlisting} #define NE_VETTABLE static constexpr BOOL kVettable = YES; #define NE_NON_VETTABLE static constexpr BOOL kVettable = NO; template concept IsVettable = requires(Type) { (Type::kVettable); }; /// This structure is vettable. struct Vettable { NE_VETTABLE; }; /// This structure is unvettable. struct UnVettable { NE_NON_VETTABLE; }; /// One example of a usage. if constexpr (IsVettable) { instVet->Vet(); } else { instVet->Abort(); } \end{lstlisting} Source: \href{https://github.com/ne-foss-org/nekernel/blob/develop/src/kernel/NeKit/Vettable.h}{Link}. \section{VI: Conclusion} { Safe and correct development in a freestanding domain is indeed possible granted the above concepts are applied and respected.} \section{References} \begin{enumerate} \item NeKernel.org (2025). NeKernel Operating System. Available at: \url{https://nekernel.org} \item Sales, J., Tasker, M. (2005). Introducing EKA2. Symbian OS Internals. Wiley. Available at: \url{https://media.wiley.com/product_data/excerpt/47/04700252/0470025247.pdf} \item Driesen, K., Hölzle, U. (1996). The direct cost of virtual function calls in C++. \textit{OOPSLA '96}. ACM. DOI: 10.1145/236338.236369 \item El Mahrouss, A. (2026). Methodology for Process and Image Computation. (v1.0.0). Zenodo. https://doi.org/10.5281/zenodo.18362503 \item El Mahrouss, A. (2026). The Execution Semantics: On Axioms, Domains, and Authority. (v1.0.0). Zenodo. https://doi.org/10.5281/zenodo.18362375 \end{enumerate} \end{document}