mirror of
https://github.com/limine-bootloader/limine
synced 2025-01-23 04:52:04 +03:00
multiboot2: implement ELF sections tag
Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
This commit is contained in:
parent
b9e7d51c6b
commit
6d034adc5a
@ -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
|
/// SAFETY: The caller must ensure that the provided `elf` is a valid 64-bit
|
||||||
/// ELF file.
|
/// ELF file.
|
||||||
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) {
|
||||||
struct elf64_hdr hdr;
|
struct elf_section_hdr_info* info = ext_mem_alloc(sizeof(struct elf_section_hdr_info));
|
||||||
memcpy(&hdr, elf + (0), sizeof(struct elf32_hdr));
|
|
||||||
|
|
||||||
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_entry_size = hdr.shdr_size;
|
||||||
|
info->section_hdr_size = info->num * info->section_entry_size;
|
||||||
info->str_section_idx = hdr.shstrndx;
|
info->str_section_idx = hdr.shstrndx;
|
||||||
info->section_hdrs = ext_mem_alloc(info->section_hdr_size);
|
info->section_hdrs = ext_mem_alloc(info->section_hdr_size);
|
||||||
|
|
||||||
memcpy(info->section_hdrs, elf + (hdr.shoff), 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
|
/// SAFETY: The caller must ensure that the provided `elf` is a valid 64-bit
|
||||||
/// ELF file.
|
/// 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;
|
struct elf32_hdr hdr;
|
||||||
memcpy(&hdr, elf + (0), sizeof(struct elf32_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_entry_size = hdr.shdr_size;
|
||||||
|
info->section_hdr_size = info->num * info->section_entry_size;
|
||||||
info->str_section_idx = hdr.shstrndx;
|
info->str_section_idx = hdr.shstrndx;
|
||||||
info->section_hdrs = ext_mem_alloc(info->section_hdr_size);
|
info->section_hdrs = ext_mem_alloc(info->section_hdr_size);
|
||||||
|
|
||||||
memcpy(info->section_hdrs, elf + (hdr.shoff), 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) {
|
int elf32_load_section(uint8_t *elf, void *buffer, const char *name, size_t limit) {
|
||||||
|
@ -21,6 +21,7 @@ struct elf_section_hdr_info {
|
|||||||
uint32_t section_hdr_size;
|
uint32_t section_hdr_size;
|
||||||
uint32_t section_entry_size;
|
uint32_t section_entry_size;
|
||||||
uint32_t str_section_idx;
|
uint32_t str_section_idx;
|
||||||
|
uint32_t num;
|
||||||
void* section_hdrs;
|
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(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);
|
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(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);
|
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
|
#endif
|
||||||
|
@ -98,7 +98,7 @@ void multiboot2_load(char *config, char* cmdline) {
|
|||||||
uint32_t kernel_top;
|
uint32_t kernel_top;
|
||||||
|
|
||||||
int bits = elf_bits(kernel);
|
int bits = elf_bits(kernel);
|
||||||
struct elf_section_hdr_info section_hdr_info;
|
struct elf_section_hdr_info* section_hdr_info;
|
||||||
|
|
||||||
switch (bits) {
|
switch (bits) {
|
||||||
case 32:
|
case 32:
|
||||||
@ -122,7 +122,7 @@ void multiboot2_load(char *config, char* cmdline) {
|
|||||||
panic("multiboot1: invalid ELF file bitness");
|
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...
|
// Iterate through the entries...
|
||||||
for (struct multiboot_header_tag* tag = (struct multiboot_header_tag*)(header + 1);
|
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
|
// 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
|
#if uefi == 1
|
||||||
|
Loading…
Reference in New Issue
Block a user