aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/kernel/main.cpp
blob: 8e5aa05126473871093fd188cd8110e73dd0f19f (plain)
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
#include "arch/kernel/main.hpp"

#include "arch/exception_handling/assert.hpp"
#include "arch/memory/allocator/area_frame_allocator.hpp"
#include "arch/memory/multiboot/reader.hpp"
#include "arch/memory/paging/page_mapper.hpp"
#include "arch/video/vga/text.hpp"

#include <algorithm>

namespace teachos::arch::kernel
{
  auto main() -> void
  {
    video::vga::text::clear();
    video::vga::text::cursor(false);
    video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black);

    auto memory_information = memory::multiboot::read_multiboot2();
    memory::allocator::area_frame_allocator allocator(memory_information);

    auto last_allocated = allocator.allocate_frame();
    auto allocated = last_allocated;
    do
    {
      last_allocated = allocated;
      allocated = allocator.allocate_frame();
    } while (allocated);
    video::vga::text::write("Allocated Frames", video::vga::text::common_attributes::green_on_black);
    video::vga::text::write_number(last_allocated.value().frame_number,
                                   video::vga::text::common_attributes::green_on_black);
    memory::paging::map_page_to_frame(allocator, memory::paging::virtual_page{0U}, last_allocated.value(), 0U);
    memory::paging::map_next_free_page_to_frame(allocator, memory::paging::virtual_page{0U}, 0U);
    memory::paging::identity_map(allocator, last_allocated.value(), 0U);
    memory::paging::unmap_page(allocator, memory::paging::virtual_page{0U});
  }
}  // namespace teachos::arch::kernel