_Actually_ move the kernel to the last TiB.

More work on process page tables, including only mapping the last 2 pml4
entries (the highest 1TiB of the address space, ie, kernel space) into a
new table.

Includes the work of actually moving the kernel there, which I had
apparently done in name only previously. Oops.
This commit is contained in:
Justin C. Miller
2018-09-01 14:54:12 -07:00
parent d33f1bc6f2
commit 799fbbdd10
9 changed files with 16 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
ENTRY(_start)
SECTIONS
{
OFFSET = 0xFFFF800000000000;
OFFSET = 0xFFFFFF0000000000;
. = OFFSET + 0x100000;
.header : {

View File

@@ -9,11 +9,7 @@
#endif
#ifndef KERNEL_VIRT_ADDRESS
#define KERNEL_VIRT_ADDRESS 0xFFFF800000000000
#endif
#ifndef VIRTUAL_OFFSET
#define VIRTUAL_OFFSET 0xf00000000
#define KERNEL_VIRT_ADDRESS 0xFFFFFF0000000000
#endif
#ifndef KERNEL_MEMTYPE

View File

@@ -82,9 +82,9 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
status = loader_load_kernel(bootsvc, &load);
CHECK_EFI_STATUS_OR_FAIL(status);
con_printf(L" %u image bytes at 0x%x\r\n", load.kernel_length, load.kernel);
con_printf(L" %u font bytes at 0x%x\r\n", load.font_length, load.font);
con_printf(L" %u data bytes at 0x%x\r\n", load.data_length, load.data);
con_printf(L" image bytes at 0x%x : %x\r\n", load.kernel, load.kernel_length);
con_printf(L" font bytes at 0x%x : %x\r\n", load.font, load.font_length);
con_printf(L" data bytes at 0x%x : %x\r\n", load.data, load.data_length);
struct kernel_header *version = (struct kernel_header *)load.kernel;
if (version->magic != KERNEL_HEADER_MAGIC) {

View File

@@ -113,6 +113,7 @@ tss_set_entry(uint8_t i, uint64_t base, uint64_t limit)
tssd.base_16 = (base >> 16) & 0xff;
tssd.base_24 = (base >> 24) & 0xff;
tssd.base_32 = (base >> 32) & 0xffffffff;
tssd.reserved = 0;
tssd.type =
gdt_type::accessed |

View File

@@ -84,7 +84,6 @@ kernel_main(popcorn_data *header)
header->frame_buffer_length);
init_console(header);
// pager->dump_blocks();
device_manager *devices =
new (&device_manager::get()) device_manager(header->acpi_table);

View File

@@ -4,7 +4,7 @@
#include "page_manager.h"
const unsigned efi_page_size = 0x1000;
const unsigned ident_page_flags = 0xf; // TODO: set to 0xb when user/kernel page tables are better sorted
const unsigned ident_page_flags = 0xb;
enum class efi_memory_type : uint32_t
{
@@ -436,7 +436,7 @@ memory_initialize(const void *memory_map, size_t map_length, size_t desc_length)
// Offset-map this region into the higher half.
uint64_t free_region_start_virt =
free_region_start_phys + page_manager::high_offset;
free_region_start_phys + page_manager::page_offset;
uint64_t free_next = free_region_start_virt;

View File

@@ -227,7 +227,10 @@ page_table *
page_manager::create_process_map()
{
page_table *table = get_table_page();
kutil::memcpy(table, m_kernel_pml4, page_size);
kutil::memset(table, 0, page_size);
table->entries[510] = m_kernel_pml4->entries[510];
table->entries[511] = m_kernel_pml4->entries[511];
// Create the initial user stack
map_pages(

View File

@@ -21,7 +21,7 @@ public:
static const size_t page_size = 0x1000;
/// Start of the higher half.
static const addr_t high_offset = 0xffff800000000000;
static const addr_t high_offset = 0xffffff0000000000;
/// Offset from physical where page tables are mapped.
static const addr_t page_offset = 0xffffff8000000000;

View File

@@ -8,7 +8,8 @@
#include "scheduler.h"
scheduler scheduler::s_instance(nullptr);
static const uint32_t quantum = 2000000;
//static const uint32_t quantum = 2000000;
static const uint32_t quantum = 20000000;
const int stack_size = 0x1000;
@@ -42,7 +43,7 @@ create_process(uint16_t pid, void (*rip)())
state->ds = state->ss = ss;
state->cs = cs;
state->rflags = 0x202; // testing. TODO: 0x202
state->rflags = 0x202;
state->rip = reinterpret_cast<uint64_t>(rip);
page_table *pml4 = page_manager::get()->create_process_map();