-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.pp
168 lines (146 loc) · 4.22 KB
/
init.pp
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
// vim: ts=3:filetype=pascal
(* Copyright (C) 2004-2009 Oleksandr Natalenko aka post-factum
This program is free software; you can redistribute it and/or modify
it under the terms of the Universal Program License as published by
Oleksandr Natalenko aka post-factum; see file COPYING for details.
This program 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.
You should have received a copy of the Universal Program
License along with this program; if not, write to
pfactum@gmail.com *)
unit
init;
interface
uses
stypes;
var
initName: String;
initParams: TDynamicStringList;
procedure InitKernelVariables;
implementation
uses
kernel,
syscalls,
modules,
sysutils,
tools,
fs,
debug,
managers,
lock,
keyboard;
{$i config.inc}
var
lineParam1, lineParam2: TDynamicStringList;
procedure InitKernelVariables;
var
i, k: Longint;
begin
(*
here all kernel variables are initialized. If you add some
global variable, you *MUST* initialize it here. For more
difficult cases (like some managers) you should create another
initializing procedure, but in init.pp and make a call of it
from streamos.pp file *AFTER* calling this procedure
*)
Randomize;
SetLength(kernel.process, 1);
InitKeyboard;
(*here we must init KERNEL virtual process*)
with kernel.process[0] do
begin
processName := 'kernel';
processUser := 0;
processStartTime := now;
processState := tps_running;
processAccessKey := tools.ToolsGenerateAccessKey;
processDisplay := 0;
processSignal := 0;
processSignalSender := 0;
processParentDisplay := 0;
processParentPid := 0;
processMainThreadId := 0;
processCurrentDirectory := '/';
processTimerIdProcessing := 0;
SetLength(processChildren, 1);
SetLength(processExports.te_pointers, 1);
SetLength(processExports.te_names, 1);
SetLength(processTimers, 1);
processKey := #0;
InitLock(processMessageLock);
InitLock(processChildrenLock);
InitLock(processTimerIdProcessingLock);
pointer(processOnMessageHandlerProcedure) := @kernel.KernelOnMessageHandler;
end;
(*sets system calls*)
syscalls.SyscallsSetSystemCalls;
(*sets default values for kernel variables*)
kernel.kernelInternalTimerInterval := 5;
kernel.kernelRoot := 'C';
kernel.kernelHostname := '[not set]';
initName := '/bin/init';
setLength(initParams, 2);
initParams[1] := '/etc/inittab';
debug.debugToFile := true;
(*processes kernel command line*)
if ParamCount > 0 then
for i:=1 to ParamCount do
begin
(*
splitting into variables and values
lineParam1[1] - the name of parameter
lineParam2[] - options
*)
SetLength(lineParam1, 1);
lineParam1[0] := '';
SetLength(lineParam2, 1);
lineParam2[0] := '';
lineParam1 := tools.ToolsSplitLine(ParamStr(i), '=');
if Length(lineParam1) > 1 then
lineParam2 := tools.ToolsSplitLine(lineParam1[2], ',');
(*processing each command*)
if lineParam1[1] = 'init' then
begin
(*assigning init name*)
initName := lineParam2[1];
(*transferring init parameters*)
for k := 1 to Length(lineParam2) - 1 do
initParams[k] := lineParam2[k + 1];
end
else
if lineParam1[1] = 'timer' then
begin
(*assigning internal timer interval*)
kernel.kernelInternalTimerInterval := round(1000 / StrToInt(lineParam2[1]));
end
else
if lineParam1[1] = 'debug' then
begin
(*direct debug output to file or screen*)
{$ifdef config_debug}
if lineParam2[1] = 'file' then
debug.debugToFile := true
else
debug.debugToFile := false;
{$endif}
end;
end;
(*sets root directory*)
fs.FsAddToFsTab(kernel.kernelRoot + ':\', '/', 'fat', 'defaults');
(*inits kernel locks*)
InitLock(managers.managersLockMessages);
InitLock(managers.managersLockTimers);
InitLock(managers.managersLockKeys);
InitLock(managers.managersLockExternal);
InitLock(managers.managersLockSingleExternal);
InitLock(kernel.kernelProcessQueueLock);
InitLock(kernel.kernelForkLock);
{$ifdef config_debug}
InitLock(debug.debugLock);
{$endif}
(*loads kernel modules*)
modules.LoadKernelModules;
end;
begin
end.