Skip to content

Commit ba7ec80

Browse files
authored
Merge pull request #1411 from fwsGonzo/dev
os: Add post_start, common for all platforms
2 parents 2a3fd19 + bcac6ff commit ba7ec80

5 files changed

Lines changed: 49 additions & 90 deletions

File tree

api/kernel/os.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class OS {
180180
static uintptr_t heap_max() noexcept;
181181

182182
/** The end of usable memory **/
183-
static inline uintptr_t memory_end(){
183+
static uintptr_t memory_end() noexcept {
184184
return memory_end_;
185185
}
186186

@@ -199,6 +199,9 @@ class OS {
199199
return memmap;
200200
}
201201

202+
/** Get "kernel modules", provided by multiboot */
203+
static Span_mods modules();
204+
202205
/**
203206
* Register a custom initialization function. The provided delegate is
204207
* guaranteed to be called after global constructors and device initialization
@@ -219,17 +222,15 @@ class OS {
219222
/** The main event loop. Check interrupts, timers etc., and do callbacks. */
220223
static void event_loop();
221224

222-
/** Start the OS. @todo Should be `init()` - and not accessible from ABI */
225+
/** Initialize platform, devices etc. */
223226
static void start(uint32_t boot_magic, uint32_t boot_addr);
224227

225228
static void start(char *cmdline, uintptr_t mem_size);
226229

227-
/** Get "kernel modules", provided by multiboot */
228-
static Span_mods modules();
229-
230+
/** Initialize common subsystems, call Service::start */
231+
static void post_start();
230232

231233
private:
232-
233234
/** Process multiboot info. Called by 'start' if multibooted **/
234235
static void multiboot(uint32_t boot_addr);
235236

src/kernel/kernel_start.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ void kernel_start(uintptr_t magic, uintptr_t addr)
7575
// Call global ctors
7676
__libc_init_array();
7777

78-
// Initialize OS including devices
78+
// Initialize early OS, platform and devices
7979
OS::start(magic, addr);
8080

81+
// Initialize common subsystems and call Service::start
82+
OS::post_start();
83+
8184
// verify certain read-only sections in memory
8285
kernel_sanity_checks();
8386

src/kernel/os.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,44 @@ void OS::shutdown()
9797
power_ = false;
9898
}
9999

100+
void OS::post_start()
101+
{
102+
MYINFO("Initializing RNG");
103+
PROFILE("RNG init");
104+
RNG::init();
105+
106+
// Seed rand with 32 bits from RNG
107+
srand(rng_extract_uint32());
108+
109+
// Custom initialization functions
110+
MYINFO("Initializing plugins");
111+
// the boot sequence is over when we get to plugins/Service::start
112+
OS::boot_sequence_passed_ = true;
113+
114+
PROFILE("Plugins init");
115+
for (auto plugin : plugins_) {
116+
INFO2("* Initializing %s", plugin.name_);
117+
try{
118+
plugin.func_();
119+
} catch(std::exception& e){
120+
MYINFO("Exception thrown when initializing plugin: %s", e.what());
121+
} catch(...){
122+
MYINFO("Unknown exception when initializing plugin");
123+
}
124+
}
125+
126+
PROFILE("Service::start");
127+
// begin service start
128+
FILLINE('=');
129+
printf(" IncludeOS %s (%s / %i-bit)\n",
130+
version().c_str(), arch().c_str(),
131+
static_cast<int>(sizeof(uintptr_t)) * 8);
132+
printf(" +--> Running [ %s ]\n", Service::name().c_str());
133+
FILLINE('~');
134+
135+
Service::start();
136+
}
137+
100138
void OS::add_stdout(OS::print_func func)
101139
{
102140
os_print_handlers.add(func);

src/platform/x86_pc/os.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#endif
4242

4343
extern "C" void* get_cpu_esp();
44-
extern "C" void kernel_sanity_checks();
4544
extern uintptr_t heap_begin;
4645
extern uintptr_t heap_end;
4746
extern uintptr_t _start;
@@ -180,43 +179,6 @@ void OS::start(uint32_t boot_magic, uint32_t boot_addr)
180179
PROFILE("RTC init");
181180
// Realtime/monotonic clock
182181
RTC::init();
183-
184-
MYINFO("Initializing RNG");
185-
PROFILE("RNG init");
186-
RNG::init();
187-
188-
// Seed rand with 32 bits from RNG
189-
srand(rng_extract_uint32());
190-
191-
// Custom initialization functions
192-
MYINFO("Initializing plugins");
193-
// the boot sequence is over when we get to plugins/Service::start
194-
OS::boot_sequence_passed_ = true;
195-
196-
PROFILE("Plugins init");
197-
for (auto plugin : plugins_) {
198-
INFO2("* Initializing %s", plugin.name_);
199-
try{
200-
plugin.func_();
201-
} catch(std::exception& e){
202-
MYINFO("Exception thrown when initializing plugin: %s", e.what());
203-
} catch(...){
204-
MYINFO("Unknown exception when initializing plugin");
205-
}
206-
}
207-
208-
PROFILE("Service::start");
209-
// begin service start
210-
FILLINE('=');
211-
printf(" IncludeOS %s (%s / %i-bit)\n",
212-
version().c_str(), arch().c_str(),
213-
static_cast<int>(sizeof(uintptr_t)) * 8);
214-
printf(" +--> Running [ %s ]\n", Service::name().c_str());
215-
FILLINE('~');
216-
217-
Service::start();
218-
// NOTE: this is a feature for service writers, don't move!
219-
kernel_sanity_checks();
220182
}
221183

222184
void OS::event_loop()

src/platform/x86_solo5/os.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ static uint64_t* os_cycles_hlt = nullptr;
2020
static uint64_t* os_cycles_total = nullptr;
2121

2222
extern "C" void* get_cpu_esp();
23-
extern "C" void kernel_sanity_checks();
2423
extern uintptr_t heap_begin;
2524
extern uintptr_t heap_end;
2625
extern uintptr_t _start;
@@ -144,30 +143,6 @@ void OS::start(char* _cmdline, uintptr_t mem_size)
144143
MYINFO("Booted at monotonic_ns=%lld walltime_ns=%lld",
145144
solo5_clock_monotonic(), solo5_clock_wall());
146145

147-
MYINFO("Initializing RNG");
148-
PROFILE("RNG init");
149-
RNG::init();
150-
151-
// Seed rand with 32 bits from RNG
152-
srand(rng_extract_uint32());
153-
154-
// Custom initialization functions
155-
MYINFO("Initializing plugins");
156-
// the boot sequence is over when we get to plugins/Service::start
157-
OS::boot_sequence_passed_ = true;
158-
159-
PROFILE("Plugins init");
160-
for (auto plugin : plugins_) {
161-
INFO2("* Initializing %s", plugin.name_);
162-
try{
163-
plugin.func_();
164-
} catch(std::exception& e){
165-
MYINFO("Exception thrown when initializing plugin: %s", e.what());
166-
} catch(...){
167-
MYINFO("Unknown exception when initializing plugin");
168-
}
169-
}
170-
171146
Solo5_manager::init();
172147

173148
// We don't need a start or stop function in solo5.
@@ -182,26 +157,10 @@ void OS::start(char* _cmdline, uintptr_t mem_size)
182157
Timers::oneshot(std::chrono::hours(1000000), [] (auto) {});
183158

184159
Timers::ready();
185-
186-
PROFILE("Service::start");
187-
// begin service start
188-
FILLINE('=');
189-
printf(" IncludeOS %s (%s / %i-bit)\n",
190-
version().c_str(), arch().c_str(),
191-
static_cast<int>(sizeof(uintptr_t)) * 8);
192-
printf(" +--> Running [ %s ]\n", Service::name().c_str());
193-
FILLINE('~');
194-
195-
Service::start();
196-
// NOTE: this is a feature for service writers, don't move!
197-
kernel_sanity_checks();
198160
}
199161

200162
void OS::event_loop()
201163
{
202-
//uint8_t *data = (uint8_t *) malloc(1520);
203-
//assert(data);
204-
205164
while (power_) {
206165
int rc;
207166

@@ -217,10 +176,6 @@ void OS::event_loop()
217176
rc = solo5_poll(solo5_clock_monotonic() + 500000ULL); // now + 0.5 ms
218177
Timers::timers_handler();
219178
if (rc) {
220-
221-
//int len = 1520;
222-
//memset(data, 0, 1520);
223-
224179
for(auto& nic : hw::Devices::devices<hw::Nic>()) {
225180
nic->poll();
226181
break;

0 commit comments

Comments
 (0)