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
|
#include "arch/kernel/main.hpp"
#include "arch/boot/multiboot.hpp"
#include "arch/boot/pointers.hpp"
#include "arch/video/vga/text.hpp"
namespace teachos::arch::kernel
{
auto print_meminfo(multiboot_tag * tag) -> void
{
using namespace video::vga;
uint32_t * pointer = &tag->size;
uint32_t mem_lower = *(++pointer);
uint32_t mem_upper = *(++pointer);
text::write("Lower memory bound: ", text::common_attributes::green_on_black);
text::write_number(mem_lower, text::common_attributes::green_on_black);
text::write("Upper memory bound: ", text::common_attributes::green_on_black);
text::write_number(mem_upper, text::common_attributes::green_on_black);
}
auto print_memory_map(multiboot_tag * tag) -> void
{
using namespace video::vga;
uint32_t * pointer = &tag->size;
uint32_t entry_size = *(++pointer);
uint32_t entry_version = *(++pointer);
text::write("Version: ", text::common_attributes::green_on_black);
text::write_number(entry_version, text::common_attributes::green_on_black);
auto begin = (struct memory_map_entry *)++pointer;
auto end = begin + entry_size;
for (auto itr = begin; itr < end; ++itr)
{
text::write("Base Address: ", text::common_attributes::green_on_black);
text::write_number(itr->base_addr, text::common_attributes::green_on_black);
text::write("Length: ", text::common_attributes::green_on_black);
text::write_number(itr->length, text::common_attributes::green_on_black);
text::write("Type: ", text::common_attributes::green_on_black);
text::write_number(itr->type, text::common_attributes::green_on_black);
text::write("Reserved: ", text::common_attributes::green_on_black);
text::write_number(itr->reserved, text::common_attributes::green_on_black);
}
}
auto main() -> void
{
using namespace video::vga;
text::clear();
text::cursor(false);
text::write("TeachOS is starting up...", text::common_attributes::green_on_black);
auto mip = arch::boot::multiboot_information_pointer;
// Address of the first multiboot tag
auto multiboot_tag = (struct multiboot_tag *)((uint8_t *)mip + 8);
/*
* Loop over the multiboot2 tags to access the information needed.
* Tags are defined in the header.
*/
for (auto tag = multiboot_tag; tag->type != MULTIBOOT_TAG_TYPE_END;
tag = (struct multiboot_tag *)((uint8_t *)tag + ((tag->size + 7) & ~7)))
{
switch (tag->type)
{
case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
print_meminfo(tag);
break;
case MULTIBOOT_TAG_TYPE_MMAP:
print_memory_map(tag);
break;
}
}
}
} // namespace teachos::arch::kernel
|