1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
% 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 <iostream>
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 <class Driver>
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 <class Type>
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<UnVettable>) {
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}
|