2626#include < string>
2727#include < sstream>
2828#include < vector>
29+ #include < boot/multiboot.h>
2930
3031/* *
3132 * The entrypoint for OS services
@@ -36,15 +37,16 @@ class OS {
3637public:
3738 using print_func = delegate<void (const char *, size_t )>;
3839 using Plugin = delegate<void ()>;
40+ using Span_mods = gsl::span<multiboot_module_t >;
3941
4042 /* *
41- * Returns the version of the OS from when
43+ * Returns the version of the OS from when
4244 * the service was built.
4345 **/
4446 static const std::string& version () noexcept
4547 { return version_field; }
4648
47- /* *
49+ /* *
4850 * Returns the commandline arguments provided,
4951 * if any, to the VM passed on by multiboot or
5052 * other mechanisms. The first argument is always
@@ -113,7 +115,7 @@ class OS {
113115 * The on_panic handler will be called directly after a panic,
114116 * or any condition which will deliberately cause the OS to become
115117 * unresponsive. After the handler is called, the OS goes to sleep.
116- * This handler can thus be used to, for example, automatically
118+ * This handler can thus be used to, for example, automatically
117119 * have the OS restart on any crash.
118120 **/
119121 typedef void (*on_panic_func) ();
@@ -204,6 +206,22 @@ class OS {
204206 /* * Start the OS. @todo Should be `init()` - and not accessible from ABI */
205207 static void start (uint32_t boot_magic, uint32_t boot_addr);
206208
209+ /* * Get "kernel modules", provided by multiboot */
210+ static Span_mods modules () {
211+
212+ if (bootinfo_ and bootinfo_->flags & MULTIBOOT_INFO_MODS) {
213+
214+ Expects (bootinfo_->mods_count < std::numeric_limits<int >::max ());
215+
216+ return Span_mods{
217+ reinterpret_cast <multiboot_module_t *>(bootinfo_->mods_addr ),
218+ static_cast <int >(bootinfo_->mods_count ) };
219+
220+ }
221+
222+ return nullptr ;
223+ }
224+
207225private:
208226
209227 /* * Process multiboot info. Called by 'start' if multibooted **/
@@ -216,15 +234,6 @@ class OS {
216234 static bool is_softreset_magic (uint32_t value);
217235 static void resume_softreset (intptr_t boot_addr);
218236
219- static constexpr int PAGE_SHIFT = 12 ;
220-
221- static bool power_;
222- static bool boot_sequence_passed_;
223-
224- static MHz cpu_mhz_;
225-
226- static std::string version_field;
227-
228237 struct Plugin_struct {
229238 Plugin_struct (Plugin f, const char * n)
230239 : func_{f}, name_{n}
@@ -234,13 +243,19 @@ class OS {
234243 const char * name_;
235244 };
236245
246+ static constexpr int PAGE_SHIFT = 12 ;
247+ static bool power_;
248+ static bool boot_sequence_passed_;
249+ static MHz cpu_mhz_;
250+ static std::string version_field;
237251 static std::vector<Plugin_struct> plugins_;
238-
239252 static uintptr_t low_memory_size_;
240253 static uintptr_t high_memory_size_;
241254 static uintptr_t memory_end_;
242255 static uintptr_t heap_max_;
243256 static const uintptr_t elf_binary_size_;
257+ static multiboot_info_t * bootinfo_;
258+ static std::string cmdline;
244259
245260 // Prohibit copy and move operations
246261 OS (OS&) = delete ;
0 commit comments