Skip to content

Commit 6dc45c2

Browse files
committed
kernel: separate multiboot code
1 parent d0255d5 commit 6dc45c2

3 files changed

Lines changed: 80 additions & 4 deletions

File tree

api/kernel/os.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ class OS {
3838
using Plugin = delegate<void()>;
3939

4040
/**
41-
* Returns the version of the OS from when
41+
* Returns the version of the OS from when
4242
* the service was built.
4343
**/
4444
static const std::string& version() noexcept
4545
{ return version_field; }
4646

47-
/**
47+
/**
4848
* Returns the commandline arguments provided,
4949
* if any, to the VM passed on by multiboot or
5050
* other mechanisms. The first argument is always
@@ -113,7 +113,7 @@ class OS {
113113
* The on_panic handler will be called directly after a panic,
114114
* or any condition which will deliberately cause the OS to become
115115
* unresponsive. After the handler is called, the OS goes to sleep.
116-
* This handler can thus be used to, for example, automatically
116+
* This handler can thus be used to, for example, automatically
117117
* have the OS restart on any crash.
118118
**/
119119
typedef void (*on_panic_func) ();
@@ -242,6 +242,8 @@ class OS {
242242
static uintptr_t heap_max_;
243243
static const uintptr_t elf_binary_size_;
244244

245+
static std::string cmdline;
246+
245247
// Prohibit copy and move operations
246248
OS(OS&) = delete;
247249
OS(OS&&) = delete;

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ add_custom_command(
2727
# TODO: i wanted to use a glob, but then found out that not everything is included
2828
set(OS_OBJECTS
2929
kernel/kernel_start.cpp kernel/sanity_checks.cpp kernel/syscalls.cpp
30-
kernel/irq_manager.cpp
30+
kernel/irq_manager.cpp kernel/multiboot.cpp
3131
kernel/os.cpp kernel/cpuid.cpp kernel/memmap.cpp kernel/pci_manager.cpp
3232
kernel/heap.cpp kernel/service_stub.cpp kernel/main_call.cpp
3333
kernel/elf.cpp kernel/terminal.cpp kernel/terminal_disk.cpp

src/kernel/multiboot.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2017 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#include <os>
19+
#include <boot/multiboot.h>
20+
21+
#define MYINFO(X,...) INFO("Kernel", X, ##__VA_ARGS__)
22+
23+
void OS::multiboot(uint32_t boot_magic, uint32_t boot_addr){
24+
MYINFO("Booted with multiboot");
25+
INFO2("* magic value: 0x%x Multiboot info at 0x%x", boot_magic, boot_addr);
26+
27+
multiboot_info_t* bootinfo = (multiboot_info_t*) boot_addr;
28+
29+
if (! bootinfo->flags & MULTIBOOT_INFO_MEMORY) {
30+
INFO2("* No memory info provided in multiboot info");
31+
return;
32+
}
33+
34+
uint32_t mem_low_start = 0;
35+
uint32_t mem_low_end = (bootinfo->mem_lower * 1024) - 1;
36+
uint32_t mem_low_kb = bootinfo->mem_lower;
37+
uint32_t mem_high_start = 0x100000;
38+
uint32_t mem_high_end = mem_high_start + (bootinfo->mem_upper * 1024) - 1;
39+
uint32_t mem_high_kb = bootinfo->mem_upper;
40+
41+
OS::low_memory_size_ = mem_low_kb * 1024;
42+
OS::high_memory_size_ = mem_high_kb * 1024;
43+
OS::memory_end_ = high_memory_size_ + mem_high_start;
44+
45+
INFO2("* Valid memory (%i Kib):", mem_low_kb + mem_high_kb);
46+
INFO2("\t 0x%08x - 0x%08x (%i Kib)",
47+
mem_low_start, mem_low_end, mem_low_kb);
48+
INFO2("\t 0x%08x - 0x%08x (%i Kib)",
49+
mem_high_start, mem_high_end, mem_high_kb);
50+
INFO2("");
51+
52+
if (bootinfo->flags & MULTIBOOT_INFO_CMDLINE) {
53+
INFO2("* Booted with parameters @ %p: %s",(void*)bootinfo->cmdline, (char*)bootinfo->cmdline);
54+
cmdline = std::string((char*) bootinfo->cmdline);
55+
}
56+
57+
if (bootinfo->flags & MULTIBOOT_INFO_MEM_MAP) {
58+
INFO2("* Multiboot provided memory map (%i entries @ %p)",
59+
bootinfo->mmap_length / sizeof(multiboot_memory_map_t), (void*)bootinfo->mmap_addr);
60+
gsl::span<multiboot_memory_map_t> mmap { reinterpret_cast<multiboot_memory_map_t*>(bootinfo->mmap_addr),
61+
(int)(bootinfo->mmap_length / sizeof(multiboot_memory_map_t))};
62+
63+
for (auto map : mmap) {
64+
const char* str_type = map.type & MULTIBOOT_MEMORY_AVAILABLE ? "FREE" : "RESERVED";
65+
INFO2("\t 0x%08llx - 0x%08llx %s (%llu Kb.)",
66+
map.addr, map.addr + map.len - 1, str_type, map.len / 1024 );
67+
68+
if (not (map.type & MULTIBOOT_MEMORY_AVAILABLE)) {
69+
memory_map().assign_range({static_cast<uintptr_t>(map.addr), static_cast<uintptr_t>(map.addr + map.len - 1), "Reserved", "Multiboot / BIOS"});
70+
}
71+
}
72+
printf("\n");
73+
}
74+
}

0 commit comments

Comments
 (0)