aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-06 08:45:04 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2024-10-06 08:45:04 +0000
commitf7df7167f0c54bd8da79dbf2d48bda5d7491fd32 (patch)
tree716dc5e9566cc57c2d534dd47487186a4767cf41
parent1ab9c3c09d32283b39ca1026a9e29ada5ff7fda5 (diff)
downloadteachos-f7df7167f0c54bd8da79dbf2d48bda5d7491fd32.tar.xz
teachos-f7df7167f0c54bd8da79dbf2d48bda5d7491fd32.zip
Remove high memory kernel and needless prints
-rw-r--r--arch/x86_64/scripts/kernel.ld22
-rw-r--r--arch/x86_64/src/boot/boot.s24
-rw-r--r--arch/x86_64/src/kernel/main.cpp120
3 files changed, 48 insertions, 118 deletions
diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld
index 943266c..31d8be3 100644
--- a/arch/x86_64/scripts/kernel.ld
+++ b/arch/x86_64/scripts/kernel.ld
@@ -3,7 +3,6 @@ ENTRY(_start)
/*****************************************************************************
* Virtual and linear start addresses of the TeachOS kernel
*****************************************************************************/
-TEACHOS_HIGH = -2048M;
TEACHOS_LOW = 1M;
PHDRS {
@@ -31,7 +30,7 @@ SECTIONS
* symbols at the beginning.
***************************************************************************/
_start_linear = .;
- _start_virtual = . + TEACHOS_HIGH;
+ _start_virtual = .;
/***************************************************************************
* The bootstrapping infratructure goes first. We first place the read-only
@@ -66,9 +65,8 @@ SECTIONS
* also make sure to align the loaded data onto a page boundary.
***************************************************************************/
. = ALIGN(4K);
- . += TEACHOS_HIGH;
- .init ALIGN(4K) : AT(ADDR (.init) - TEACHOS_HIGH)
+ .init ALIGN(4K) : AT(ADDR (.init))
{
/*
* Make sure that the crt code is wrapped around the compiler generated
@@ -79,7 +77,7 @@ SECTIONS
KEEP(*crtn.s.o*(.init))
} :text
- .fini ALIGN(4K) : AT(ADDR (.fini) - TEACHOS_HIGH)
+ .fini ALIGN(4K) : AT(ADDR (.fini))
{
/*
* Make sure that the crt code is wrapped around the compiler generated
@@ -90,18 +88,18 @@ SECTIONS
KEEP(*crtn.s.o*(.fini))
}
- .text ALIGN(4K) : AT(ADDR (.text) - TEACHOS_HIGH)
+ .text ALIGN(4K) : AT(ADDR (.text))
{
*(.text*)
}
- .rodata ALIGN(4K) : AT (ADDR (.rodata) - TEACHOS_HIGH)
+ .rodata ALIGN(4K) : AT (ADDR (.rodata))
{
*(.rodata)
*(.rodata.*)
} :rodata
- .ctors ALIGN(4K) : AT (ADDR (.ctors) - TEACHOS_HIGH)
+ .ctors ALIGN(4K) : AT (ADDR (.ctors))
{
KEEP(*crtbegin.o(.ctors))
KEEP(*(EXCLUDE_FILE (*crtend.o) .ctors))
@@ -109,7 +107,7 @@ SECTIONS
KEEP(*crtend.o(.ctors))
} :data
- .dtors ALIGN(4K) : AT (ADDR (.dtors) - TEACHOS_HIGH)
+ .dtors ALIGN(4K) : AT (ADDR (.dtors))
{
KEEP(*crtbegin.o(.dtors))
KEEP(*(EXCLUDE_FILE (*crtend.o) .dtors))
@@ -117,12 +115,12 @@ SECTIONS
KEEP(*crtend.o(.dtors))
}
- .data ALIGN(4K) : AT (ADDR (.data) - TEACHOS_HIGH)
+ .data ALIGN(4K) : AT (ADDR (.data))
{
*(.data*)
}
- .bss ALIGN(4K) : AT (ADDR (.bss) - TEACHOS_HIGH)
+ .bss ALIGN(4K) : AT (ADDR (.bss))
{
*(COMMON)
*(.bss*)
@@ -133,7 +131,7 @@ SECTIONS
* symbols to mark the end of our loaded image.
***************************************************************************/
_end_virtual = ADDR(.bss) + SIZEOF(.bss);
- _end_linear = _end_virtual - TEACHOS_HIGH;
+ _end_linear = _end_virtual;
/DISCARD/ : { *(.comment) }
}
diff --git a/arch/x86_64/src/boot/boot.s b/arch/x86_64/src/boot/boot.s
index 7b4e193..0c21c66 100644
--- a/arch/x86_64/src/boot/boot.s
+++ b/arch/x86_64/src/boot/boot.s
@@ -17,8 +17,8 @@
*
* We need:
* - A single PML 4 (since we will only use 4-level paging)
- * - 2 PML 3s (since we need to map high (-2GiB) and low (1+MiB) memory)
- * - 2 PML 2s (since we need to map high (-2GiB) and low (1+MiB) memory)
+ * - 2 PML 3s (since we need to map low (1+MiB) memory)
+ * - 2 PML 2s (since we need to map low (1+MiB) memory)
*/
.global page_map_level_4
@@ -26,13 +26,9 @@ page_map_level_4: .skip 512 * 8
.global page_map_level_3_low
page_map_level_3_low: .skip 512 * 8
-.global page_map_level_3_high
-page_map_level_3_high: .skip 512 * 8
.global page_map_level_2_low
page_map_level_2_low: .skip 512 * 8
-.global page_map_level_2_high
-page_map_level_2_high: .skip 512 * 8
/**
* Reserve some space for the Multiboot 2 information pointer.
@@ -306,10 +302,7 @@ enable_sse:
*
* We map all physical memory we were loaded in plus one additional page. The
* mapping is done in terms of huge pages (2 MiB per page) to save on required
- * page map entries. Note that we also map memory both in the low and high
- * virtual address ranges, giving us two ways of accessing it. We need to do
- * this, because the bootstrapping code lives in low memory, while the rest of
- * the kernel will reside on the high end.
+ * page map entries.
*/
prepare_page_maps:
/* Add an entry to the PML4, pointing to the low PML3 */
@@ -317,21 +310,11 @@ prepare_page_maps:
or $0x3, %eax
mov %eax, (page_map_level_4 + ((0x0000000000100000 >> 39) & 0x1ff) * 8)
- /* Add an entry to the PML4, pointing to the high PML3 */
- mov $page_map_level_3_high, %eax
- or $0x3, %eax
- mov %eax, (page_map_level_4 + ((0xffffffff80100000 >> 39) & 0x1ff) * 8)
-
/* Add an entry to the low PML3, pointing to the low PML2 */
mov $page_map_level_2_low, %eax
or $0x3, %eax
mov %eax, (page_map_level_3_low + ((0x0000000000100000 >> 30) & 0x1ff) * 8)
- /* Add an entry to the high PML3, pointing to the high PML2 */
- mov $page_map_level_2_high, %eax
- or $0x3, %eax
- mov %eax, (page_map_level_3_high + ((0xffffffff80100000 >> 30) & 0x1ff) * 8)
-
xor %ecx, %ecx
mov $_end_linear, %esi
@@ -343,7 +326,6 @@ prepare_page_maps:
mul %ecx
or $((1 << 0) | (1 << 1) | (1 << 7)), %eax
mov %eax, page_map_level_2_low(,%ecx,8)
- mov %eax, page_map_level_2_high(,%ecx,8)
inc %ecx
cmp %esi, %ecx
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index 4d6296a..e867bad 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -9,47 +9,28 @@ namespace teachos::arch::kernel
auto print_mem_info(arch::memory::memory_info * mem_info) -> void
{
using namespace video::vga;
-
auto mem_lower = mem_info->mem_lower;
- text::write("Lower memory (kB): ", text::common_attributes::green_on_black);
- text::write_number(mem_lower, text::common_attributes::green_on_black);
-
auto mem_upper = mem_info->mem_upper;
- text::write("Upper memory (kB): ", text::common_attributes::green_on_black);
- text::write_number(mem_upper, text::common_attributes::green_on_black);
}
auto print_memory_map(arch::memory::memory_map * mminfo) -> void
{
using namespace video::vga;
- uint32_t const entry_size = mminfo->entry_size;
- text::write("Entry Size: ", text::common_attributes::green_on_black);
- text::write_number(entry_size, text::common_attributes::green_on_black);
-
- uint32_t const entry_version = mminfo->entry_version;
- text::write("Version: ", text::common_attributes::green_on_black);
- text::write_number(entry_version, text::common_attributes::green_on_black);
-
- uint32_t const remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t));
- uint32_t const entry_amount = remaining_size / entry_size;
+ auto entry_size = mminfo->entry_size;
+ auto entry_version = mminfo->entry_version;
+ auto remaining_size = mminfo->tag.size - (4 * sizeof(uint32_t));
+ auto entry_amount = remaining_size / entry_size;
auto begin = &mminfo->entries;
auto end = begin + entry_amount;
- for (auto entry = begin; entry != end; ++entry)
+ for (auto entry = begin; entry != end;
+ entry = (teachos::arch::memory::memory_area *)(((uint8_t *)entry) + ((entry_size + 7) & ~7)))
{
- text::write("Base Address: ", text::common_attributes::green_on_black);
- text::write_number(entry->base_addr, text::common_attributes::green_on_black);
-
- text::write("Length: ", text::common_attributes::green_on_black);
- text::write_number(entry->length, text::common_attributes::green_on_black);
-
- text::write("Type: ", text::common_attributes::green_on_black);
- text::write_number(static_cast<std::underlying_type<arch::memory::memory_area_type>::type>(entry->type),
- text::common_attributes::green_on_black);
-
- text::write("Reserved: ", text::common_attributes::green_on_black);
- text::write_number(entry->reserved, text::common_attributes::green_on_black);
+ auto base_addr = entry->base_addr;
+ auto length = entry->length;
+ auto type = entry->type;
+ auto reserved = entry->reserved;
}
}
@@ -57,61 +38,33 @@ namespace teachos::arch::kernel
{
using namespace video::vga;
- uint16_t const num = symbol->num;
- text::write("Number of entries: ", text::common_attributes::green_on_black);
- text::write_number(num, text::common_attributes::green_on_black);
-
- uint16_t const entsize = symbol->entsize;
- text::write("Entry Size: ", text::common_attributes::green_on_black);
- text::write_number(entsize, text::common_attributes::green_on_black);
-
- uint16_t const shndx = symbol->shndx;
- text::write("Section index: ", text::common_attributes::green_on_black);
- text::write_number(shndx, text::common_attributes::green_on_black);
+ auto num = symbol->num;
+ auto entsize = symbol->entsize;
+ auto shndx = symbol->shndx;
auto begin = &symbol->sections;
auto end = begin + num;
- for (auto section = begin; section != end; ++section)
- {
- uint32_t const sh_name = section->sh_name;
- text::write("Section name: ", text::common_attributes::green_on_black);
- text::write_number(sh_name, text::common_attributes::green_on_black);
-
- uint32_t const sh_type = section->sh_type;
- text::write("Section type: ", text::common_attributes::green_on_black);
- text::write_number(sh_type, text::common_attributes::green_on_black);
-
- uint64_t const sh_flags = section->sh_flags;
- text::write("Section flags: ", text::common_attributes::green_on_black);
- text::write_number(sh_flags, text::common_attributes::green_on_black);
- uint64_t const sh_addr = section->sh_addr;
- text::write("Section address: ", text::common_attributes::green_on_black);
- text::write_number(sh_addr, text::common_attributes::green_on_black);
-
- uint64_t const sh_offset = section->sh_offset;
- text::write("Section offset: ", text::common_attributes::green_on_black);
- text::write_number(sh_offset, text::common_attributes::green_on_black);
-
- uint64_t const sh_size = section->sh_size;
- text::write("Section size: ", text::common_attributes::green_on_black);
- text::write_number(sh_size, text::common_attributes::green_on_black);
-
- uint32_t const sh_link = section->sh_link;
- text::write("Section link: ", text::common_attributes::green_on_black);
- text::write_number(sh_link, text::common_attributes::green_on_black);
-
- uint32_t const sh_info = section->sh_info;
- text::write("Section info: ", text::common_attributes::green_on_black);
- text::write_number(sh_info, text::common_attributes::green_on_black);
-
- uint64_t const sh_addralign = section->sh_addralign;
- text::write("Section address align: ", text::common_attributes::green_on_black);
- text::write_number(sh_addralign, text::common_attributes::green_on_black);
-
- uint64_t const sh_entsize = section->sh_entsize;
- text::write("Section entry size: ", text::common_attributes::green_on_black);
- text::write_number(sh_entsize, text::common_attributes::green_on_black);
+ /*
+ * Loop over the elf section to access the information needed.
+ * Sections are defined in the header file and are padded so that each
+ * Section starts at an 8-bytes aligned adress.
+ *
+ * The increment part aligns the size to an 8-byte address.
+ */
+ for (auto section = begin; section != end;
+ section = (teachos::arch::memory::elf_section_header *)(((uint8_t *)section) + ((entsize + 7) & ~7)))
+ {
+ auto sh_name = section->sh_name;
+ auto sh_type = section->sh_type;
+ auto sh_flags = section->sh_flags;
+ auto sh_addr = section->sh_addr;
+ auto sh_offset = section->sh_offset;
+ auto sh_size = section->sh_size;
+ auto sh_link = section->sh_link;
+ auto sh_info = section->sh_info;
+ auto sh_addralign = section->sh_addralign;
+ auto sh_entsize = section->sh_entsize;
}
}
@@ -127,11 +80,8 @@ namespace teachos::arch::kernel
(arch::memory::multi_boot_info *)arch::boot::multiboot_information_pointer;
auto multiboot_tag = &(multiboot_information_pointer->tags);
- text::write("Multiboot Start: ", text::common_attributes::green_on_black);
- text::write_number(arch::boot::multiboot_information_pointer, text::common_attributes::green_on_black);
- text::write("Multiboot End: ", text::common_attributes::green_on_black);
- text::write_number(arch::boot::multiboot_information_pointer + multiboot_information_pointer->total_size,
- text::common_attributes::green_on_black);
+ auto multiboot_start = arch::boot::multiboot_information_pointer;
+ auto multiboot_end = arch::boot::multiboot_information_pointer + multiboot_information_pointer->total_size;
/*
* Loop over the multiboot2 tags to access the information needed.