|
| 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