Skip to content

Commit

Permalink
continue work on create_task_from_elf
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamos82 committed Nov 1, 2024
1 parent 179601d commit 71836a6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/include/kernel/mem/hh_direct_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
void early_map_physical_memory(uint64_t end_of_reserved_area);

void *hhdm_get_variable ( uintptr_t phys_address );
void *hhdm_get_phys_address(uintptr_t hhdm_address);
void hhdm_map_physical_memory();

#endif
2 changes: 1 addition & 1 deletion src/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void _init_basic_system(unsigned long addr){
tag_start = (struct multiboot_tag *) (addr + _HIGHER_HALF_KERNEL_MEM_START + 8);
_mmap_parse(tagmmap);
pmm_setup(addr, mbi_size);
kernel_settings.kernel_uptime = 0;
kernel_settings.kernel_uptime = 0;
kernel_settings.paging.page_root_address = p4_table;
uint64_t p4_table_phys_address = (uint64_t) p4_table - _HIGHER_HALF_KERNEL_MEM_START;
kernel_settings.paging.hhdm_page_root_address = (uint64_t*) hhdm_get_variable( (uintptr_t) p4_table_phys_address);
Expand Down
11 changes: 11 additions & 0 deletions src/kernel/mem/hh_direct_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ void *hhdm_get_variable ( uintptr_t phys_address ) {
return NULL;
}

/**
* This is an helper function return the physical address given a hhdm one
*
*
* @return phys_address the physical address we want to retrieve
* @param hhdm_address of the physical address or NULL in case of error
*/
void *hhdm_get_phys_address(uintptr_t hhdm_address) {
return (void *)(hhdm_address - higherHalfDirectMapBase);
}


void hhdm_map_physical_memory() {
// This function should be called only once, and the hhdm shouldn't change during the kernel uptime
Expand Down
13 changes: 11 additions & 2 deletions src/kernel/scheduling/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ task_t *create_task_from_elf(char *name, void *args, Elf64_Ehdr *elf_header){
Elf64_Phdr phdr = phdr_list[i];
size_t vmm_hdr_flags = elf_flags_to_memory_flags(phdr.p_type);
pretty_logf(Verbose, "\t[%d]: Type: 0x%x, Flags: 0x%x - Vaddr: 0x%x - aligned: 0x%x ", i, phdr.p_type, phdr.p_flags, phdr.p_vaddr, align_value_to_page(phdr.p_vaddr));
pretty_logf(Verbose, "\t\t - FileSz: 0x%x, Memsz: 0x%x, vmm flags: 0x%x", phdr.p_filesz, phdr.p_memsz, vmm_hdr_flags);
pretty_logf(Verbose, "\t\t - FileSz: 0x%x, Memsz: 0x%x, vmm flags: 0x%x - p_align: 0x%x", phdr.p_filesz, phdr.p_memsz, vmm_hdr_flags, phdr.p_align);
Elf64_Half mem_pages = (Elf64_Half) get_number_of_pages_from_size(phdr.p_memsz);
Elf64_Half filesz_pages = (Elf64_Half) get_number_of_pages_from_size(phdr.p_filesz);

uint64_t offset_address = elf_header + phdr.p_offset;
uint64_t vaddr_address = align_value_to_page(phdr.p_vaddr);
for (int i = 0; i < mem_pages; i++) {
pretty_logf(Verbose, "Mapping: offset: 0x%x in vaddr: 0x%x", hhdm_get_phys_address(offset_address), vaddr_address);
map_phys_to_virt_addr_hh(hhdm_get_phys_address(offset_address), vaddr_address, vmm_hdr_flags, new_task->vmm_data.root_table_hhdm);
//I need a mem copy. I need to fopy the content of elf_header + phdr.p_offset into phdr.p_vaddr
offset_address += phdr.p_align;
vaddr_address += phdr.p_align;
//I need to allocate memory and map it into the new memory space,
}
}
}
// Create a new thread
Expand Down

0 comments on commit 71836a6

Please sign in to comment.