This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkernel_config.cpp
274 lines (248 loc) · 6.86 KB
/
kernel_config.cpp
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <kconfig.hpp>
#include <convert.h>
#include <cargs.h>
#include <printf.h>
#include <targp.h>
#include "kernel.h"
static struct cag_option ConfigOptions[] = {
{.identifier = 'a',
.access_letters = "aA",
.access_name = "alloc",
.value_name = "TYPE",
.description = "Memory allocator to use"},
{.identifier = 'c',
.access_letters = "cC",
.access_name = "cores",
.value_name = "VALUE",
.description = "Number of cores to use (0 = all; 1 is the first code, not 0)"},
{.identifier = 'p',
.access_letters = "pP",
.access_name = "ioapicirq",
.value_name = "VALUE",
.description = "Which core will be used for I/O APIC interrupts"},
{.identifier = 't',
.access_letters = "tT",
.access_name = "tasking",
.value_name = "MODE",
.description = "Tasking mode (multi, single)"},
{.identifier = 'd',
.access_letters = "dD",
.access_name = "drvdir",
.value_name = "PATH",
.description = "Directory to load drivers from"},
{.identifier = 'i',
.access_letters = "iI",
.access_name = "init",
.value_name = "PATH",
.description = "Path to init program"},
{.identifier = 'y',
.access_letters = "yY",
.access_name = "linux",
.value_name = "BOOL",
.description = "Use Linux syscalls by default"},
{.identifier = 'l',
.access_letters = NULL,
.access_name = "udl",
.value_name = "BOOL",
.description = "Unlock the deadlock after 10 retries"},
{.identifier = 'o',
.access_letters = NULL,
.access_name = "ioc",
.value_name = "BOOL",
.description = "Enable Interrupts On Crash. If enabled, the navigation keys will be enabled on crash"},
{.identifier = 's',
.access_letters = NULL,
.access_name = "simd",
.value_name = "BOOL",
.description = "Enable SIMD instructions"},
{.identifier = 'b',
.access_letters = NULL,
.access_name = "quiet",
.value_name = "BOOL",
.description = "Enable quiet boot"},
{.identifier = 'h',
.access_letters = "h",
.access_name = "help",
.value_name = NULL,
.description = "Show help on screen and halt"}};
void ParseConfig(char *ConfigString, KernelConfig *ModConfig)
{
if (ConfigString == NULL ||
strlen(ConfigString) == 0)
{
KPrint("Empty kernel parameters!");
return;
}
if (ModConfig == NULL)
{
KPrint("ModConfig is NULL!");
return;
}
KPrint("Kernel parameters: %s", ConfigString);
debug("Kernel parameters: %s", ConfigString);
char *argv[32];
int argc = 0;
/* Not sure if the quotes are being parsed correctly. */
targp_parse(ConfigString, argv, &argc);
#ifdef DEBUG
for (int i = 0; i < argc; i++)
debug("argv[%d] = %s", i, argv[i]);
debug("argc = %d", argc);
#endif
char identifier;
const char *value;
cag_option_context context;
cag_option_prepare(&context, ConfigOptions,
CAG_ARRAY_SIZE(ConfigOptions), argc, argv);
while (cag_option_fetch(&context))
{
identifier = cag_option_get(&context);
switch (identifier)
{
case 'a':
{
value = cag_option_get_value(&context);
if (strcmp(value, "xallocv1") == 0)
{
KPrint("Using XallocV1 as memory allocator");
ModConfig->AllocatorType = Memory::XallocV1;
}
else if (strcmp(value, "xallocv2") == 0)
{
KPrint("Using XallocV2 as memory allocator");
ModConfig->AllocatorType = Memory::XallocV2;
}
else if (strcmp(value, "liballoc11") == 0)
{
KPrint("Using Liballoc11 as memory allocator");
ModConfig->AllocatorType = Memory::liballoc11;
}
else if (strcmp(value, "pages") == 0)
{
KPrint("Using Pages as memory allocator");
ModConfig->AllocatorType = Memory::Pages;
}
break;
}
case 'c':
{
value = cag_option_get_value(&context);
KPrint("Using %s cores", atoi(value) ? value : "all");
ModConfig->Cores = atoi(value);
break;
}
case 'p':
{
value = cag_option_get_value(&context);
KPrint("Redirecting I/O APIC interrupts to %s%s",
atoi(value) ? "core " : "", atoi(value) ? value : "BSP");
ModConfig->IOAPICInterruptCore = atoi(value);
break;
}
case 't':
{
value = cag_option_get_value(&context);
if (strcmp(value, "multi") == 0)
{
KPrint("Using Multi-Tasking Scheduler");
ModConfig->SchedulerType = Multi;
}
else if (strcmp(value, "single") == 0)
{
KPrint("Using Single-Tasking Scheduler");
ModConfig->SchedulerType = Mono;
}
else
{
KPrint("Unknown scheduler: %s", value);
ModConfig->SchedulerType = Multi;
}
break;
}
case 'd':
{
value = cag_option_get_value(&context);
strncpy(ModConfig->DriverDirectory, value, strlen(value));
KPrint("Using %s as module directory", value);
break;
}
case 'i':
{
value = cag_option_get_value(&context);
strncpy(ModConfig->InitPath, value, strlen(value));
KPrint("Using %s as init program", value);
break;
}
case 'y':
{
value = cag_option_get_value(&context);
strcmp(value, "true") == 0
? ModConfig->UseLinuxSyscalls = true
: ModConfig->UseLinuxSyscalls = false;
KPrint("Use Linux syscalls by default: %s", value);
break;
}
case 'o':
{
value = cag_option_get_value(&context);
strcmp(value, "true") == 0
? ModConfig->InterruptsOnCrash = true
: ModConfig->InterruptsOnCrash = false;
KPrint("Interrupts on crash: %s", value);
break;
}
case 'l':
{
value = cag_option_get_value(&context);
strcmp(value, "true") == 0
? ModConfig->UnlockDeadLock = true
: ModConfig->UnlockDeadLock = false;
KPrint("Unlocking the deadlock after 10 retries");
break;
}
case 's':
{
value = cag_option_get_value(&context);
strcmp(value, "true") == 0 ? ModConfig->SIMD = true
: ModConfig->SIMD = false;
KPrint("Single Instruction, Multiple Data (SIMD): %s", value);
break;
}
case 'b':
{
value = cag_option_get_value(&context);
strcmp(value, "true") == 0 ? ModConfig->Quiet = true
: ModConfig->Quiet = false;
KPrint("Quiet boot: %s", value);
break;
}
case 'h':
{
KPrint("\n---------------------------------------------------------------------------\nUsage: fennix.elf [OPTION]...\nKernel configuration.");
cag_option_print(ConfigOptions, CAG_ARRAY_SIZE(ConfigOptions),
nullptr);
KPrint("\x1b[1;31;41mSystem Halted.");
CPU::Stop();
}
default:
{
KPrint("\x1b[31mUnknown option: %c", identifier);
break;
}
}
}
debug("Config loaded");
}