Skip to content

Commit

Permalink
[Kernel] PMM specially reserves the AP bootstrap page, even though it…
Browse files Browse the repository at this point in the history
…’s in a usable region
  • Loading branch information
codyd51 committed Jan 8, 2023
1 parent 5f7150e commit dc3a921
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
4 changes: 4 additions & 0 deletions kernel/kernel/kernel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef KERNEL_H
#define KERNEL_H

#include <stdint.h>

// https://stackoverflow.com/questions/195975/how-to-make-a-char-string-from-a-c-macros-value
#define _STR_VALUE(arg) #arg
#define _FUNCTION_NAME(name) _STR_VALUE(name)
Expand All @@ -16,4 +18,6 @@
// TODO(PT): Move this to a different file? Where?
void FS_SERVER_EXEC_TRAMPOLINE_NAME(uint32_t arg1, uint32_t arg2, uint32_t arg3);

#define AP_BOOTSTRAP_PAGE 0x8000

#endif
50 changes: 20 additions & 30 deletions kernel/kernel/pmm/pmm.c.x86_64.arch_specific
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdbool.h>
#include <kernel/kernel.h>
#include <kernel/assert.h>
#include <kernel/vmm/vmm.h>
#include <kernel/boot_info.h>
Expand Down Expand Up @@ -72,6 +73,11 @@ void pmm_init(void) {
printf("PMM stack: 0x%p - 0x%p\n", pmm->stack_bottom, pmm->stack_top);
printf("PHYS PMM stack: 0x%p - 0x%p\n", &_pmm_stack, &_pmm_stack + sizeof(_pmm_stack));

uintptr_t extra_frames_to_reserve[] = {
// Used for AP bootstrap code
AP_BOOTSTRAP_PAGE,
};

// TODO(PT): Will there be any bug with PMM allocating the frame used for the init kernel stack?
boot_info_t* info = boot_info_get();
// Mark usable sections of the address space
Expand All @@ -87,40 +93,24 @@ void pmm_init(void) {
uintptr_t len = addr_space_frame_floor(region.len);
uint64_t page_count = (len + (PAGE_SIZE - 1)) / PAGE_SIZE;
for (uint64_t j = page_count; j > 0; j--) {
pmm_push_allocatable_frame(addr + ((j-1) * PAGE_SIZE));
uintptr_t frame_addr = addr + ((j-1) * PAGE_SIZE);
bool will_skip_marking_frame_as_allocatable = false;
for (int k = 0; k < sizeof(extra_frames_to_reserve) / sizeof(extra_frames_to_reserve[0]); k++) {
if (frame_addr == extra_frames_to_reserve[k]) {
will_skip_marking_frame_as_allocatable = true;
break;
}
}
if (will_skip_marking_frame_as_allocatable) {
printf("PMM: Skip marking 0x%p as allocatable\n", frame_addr);
}
else {
pmm_push_allocatable_frame(frame_addr);
}
}
}

pmm_test();

/*
//for identity mapping purposes
//reserve any allocatable memory from 0x0 to start of kernel image
printf("reserve kernel region\n");
pmm_reserve_mem_region(pmm, 0x00000000, info->kernel_image_start);
//map out kernel image region
printf("reserve kernel image\n");
pmm_reserve_mem_region(pmm, info->kernel_image_start, info->kernel_image_size);
//map out framebuffer
printf("reserve framebuffer\n");
pmm_reserve_mem_region(pmm, info->framebuffer.address, info->framebuffer.size);
printf("reserve initrd\n");
pmm_reserve_mem_region(pmm, info->initrd_start, info->initrd_size);
printf("done\n");

/*
multiboot_elf_section_header_table_t symbol_table_info = info->symbol_table_info;
elf_section_header_t* sh = (elf_section_header_t*)symbol_table_info.addr;
uintptr_t shstrtab = sh[symbol_table_info.shndx].addr;
for (uintptr_t i = 0; i < symbol_table_info.num; i++) {
const char* name = (const char*)(shstrtab + sh[i].name);
printf_info("PMM reserving kernel ELF section %s", name);
pmm_reserve_mem_region(pmm, sh[i].addr, sh[i].size);
}
// map out kernel symbol table and string table from ELF image
pmm_reserve_mem_region(pmm, info->kernel_elf_symbol_table.strtab, info->kernel_elf_symbol_table.strtabsz);
pmm_reserve_mem_region(pmm, info->kernel_elf_symbol_table.symtab, info->kernel_elf_symbol_table.symtabsz);
*/
}

uintptr_t find_free_region(pmm_state_t* pmm, uintptr_t region_size) {
Expand Down

0 comments on commit dc3a921

Please sign in to comment.