multiboot2: implement ELF sections tag

Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
This commit is contained in:
Andy-Python-Programmer 2021-09-10 18:02:54 +10:00
parent b9e7d51c6b
commit 6d034adc5a
No known key found for this signature in database
GPG Key ID: 80E0357347554B89
3 changed files with 32 additions and 11 deletions

View File

@ -249,30 +249,40 @@ int elf64_load_section(uint8_t *elf, void *buffer, const char *name, size_t limi
/// SAFETY: The caller must ensure that the provided `elf` is a valid 64-bit
/// ELF file.
void elf64_section_hdr_info(uint8_t *elf, struct elf_section_hdr_info* info) {
struct elf64_hdr hdr;
memcpy(&hdr, elf + (0), sizeof(struct elf32_hdr));
void elf64_section_hdr_info(uint8_t *elf, struct elf_section_hdr_info** _info) {
struct elf_section_hdr_info* info = ext_mem_alloc(sizeof(struct elf_section_hdr_info));
info->section_hdr_size = hdr.sh_num * hdr.shdr_size;
struct elf64_hdr hdr;
memcpy(&hdr, elf + (0), sizeof(struct elf64_hdr));
info->num = hdr.sh_num;
info->section_entry_size = hdr.shdr_size;
info->section_hdr_size = info->num * info->section_entry_size;
info->str_section_idx = hdr.shstrndx;
info->section_hdrs = ext_mem_alloc(info->section_hdr_size);
memcpy(info->section_hdrs, elf + (hdr.shoff), info->section_hdr_size);
*_info = info;
}
/// SAFETY: The caller must ensure that the provided `elf` is a valid 64-bit
/// ELF file.
void elf32_section_hdr_info(uint8_t *elf, struct elf_section_hdr_info* info) {
void elf32_section_hdr_info(uint8_t *elf, struct elf_section_hdr_info** _info) {
struct elf_section_hdr_info* info = ext_mem_alloc(sizeof(struct elf_section_hdr_info));
struct elf32_hdr hdr;
memcpy(&hdr, elf + (0), sizeof(struct elf32_hdr));
info->section_hdr_size = hdr.sh_num * hdr.shdr_size;
info->num = hdr.sh_num;
info->section_entry_size = hdr.shdr_size;
info->section_hdr_size = info->num * info->section_entry_size;
info->str_section_idx = hdr.shstrndx;
info->section_hdrs = ext_mem_alloc(info->section_hdr_size);
memcpy(info->section_hdrs, elf + (hdr.shoff), info->section_hdr_size);
*_info = info;
}
int elf32_load_section(uint8_t *elf, void *buffer, const char *name, size_t limit) {

View File

@ -21,6 +21,7 @@ struct elf_section_hdr_info {
uint32_t section_hdr_size;
uint32_t section_entry_size;
uint32_t str_section_idx;
uint32_t num;
void* section_hdrs;
};
@ -28,10 +29,10 @@ int elf_bits(uint8_t *elf);
int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_slide, uint32_t alloc_type, bool kaslr, bool use_paddr, struct elf_range **ranges, uint64_t *ranges_count);
int elf64_load_section(uint8_t *elf, void *buffer, const char *name, size_t limit, uint64_t slide);
void elf64_section_hdr_info(uint8_t *elf, struct elf_section_hdr_info* info);
void elf64_section_hdr_info(uint8_t *elf, struct elf_section_hdr_info** info);
int elf32_load(uint8_t *elf, uint32_t *entry_point, uint32_t *top, uint32_t alloc_type);
int elf32_load_section(uint8_t *elf, void *buffer, const char *name, size_t limit);
void elf32_section_hdr_info(uint8_t *elf, struct elf_section_hdr_info* info);
void elf32_section_hdr_info(uint8_t *elf, struct elf_section_hdr_info** info);
#endif

View File

@ -98,7 +98,7 @@ void multiboot2_load(char *config, char* cmdline) {
uint32_t kernel_top;
int bits = elf_bits(kernel);
struct elf_section_hdr_info section_hdr_info;
struct elf_section_hdr_info* section_hdr_info;
switch (bits) {
case 32:
@ -122,7 +122,7 @@ void multiboot2_load(char *config, char* cmdline) {
panic("multiboot1: invalid ELF file bitness");
}
print("multiboot2: found kernel entry point at: %X\n", entry_point);
print("multiboot2: found kernel entry point at: %x\n", entry_point);
// Iterate through the entries...
for (struct multiboot_header_tag* tag = (struct multiboot_header_tag*)(header + 1);
@ -174,7 +174,17 @@ void multiboot2_load(char *config, char* cmdline) {
// Create ELF info tag
//////////////////////////////////////////////
{
// ADD ME
uint32_t size = sizeof(struct multiboot_tag_elf_sections) + section_hdr_info->section_hdr_size;
struct multiboot_tag_elf_sections* tag = (struct multiboot_tag_elf_sections*)push_boot_param(NULL, size);
tag->type = MULTIBOOT_TAG_TYPE_ELF_SECTIONS;
tag->size = size;
tag->num = section_hdr_info->num;
tag->entsize = section_hdr_info->section_entry_size;
tag->shndx = section_hdr_info->str_section_idx;
memcpy(tag->sections, section_hdr_info->section_hdrs, section_hdr_info->section_hdr_size);
}
#if uefi == 1