aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/fs/elfloader.c
diff options
context:
space:
mode:
authorMarvin Borner2020-03-22 18:30:17 +0100
committerMarvin Borner2020-03-22 18:30:17 +0100
commitcbf21c7f3cced00bd810f102cfa0581cf9b8c402 (patch)
tree260cbb8722caaccbb6c66fefa91a0db776101922 /src/kernel/fs/elfloader.c
parentfa70aaf6f0ded7523662eb0fd4ac53a1b23ef27f (diff)
Just some casual fixes
Diffstat (limited to 'src/kernel/fs/elfloader.c')
-rw-r--r--src/kernel/fs/elfloader.c49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/kernel/fs/elfloader.c b/src/kernel/fs/elfloader.c
index 8b80553..118a882 100644
--- a/src/kernel/fs/elfloader.c
+++ b/src/kernel/fs/elfloader.c
@@ -1,3 +1,4 @@
+#include <kernel/system.h>
#include <kernel/fs/elf.h>
#include <kernel/lib/stdio.h>
#include <kernel/memory/alloc.h>
@@ -5,15 +6,13 @@
#include <kernel/memory/paging.h>
#include "load.h"
-elf_priv_data *elf_probe(uint8_t *buf)
+int elf_probe(uint8_t *buf)
{
elf_header_t *header = (elf_header_t *)buf;
- /* The first four bytes are 0x7f and 'ELF' */
- if (header->e_ident[0] == 0x7f && header->e_ident[1] == 'E' && header->e_ident[2] == 'L' &&
- header->e_ident[3] == 'F') {
- /* Valid ELF! */
+ if (header->ident[0] == 0x7f && header->ident[1] == 'E' && header->ident[2] == 'L' &&
+ header->ident[3] == 'F') {
serial_printf("Buffer is valid ELF file!");
- return (void *)1;
+ return 1;
}
return 0;
}
@@ -21,36 +20,35 @@ elf_priv_data *elf_probe(uint8_t *buf)
uint8_t elf_start(uint8_t *buf)
{
elf_header_t *header = (elf_header_t *)buf;
- serial_printf("Type: %s%s%s", header->e_ident[4] == 1 ? "32bit " : "64 bit",
- header->e_ident[5] == 1 ? "Little Endian " : "Big endian ",
- header->e_ident[6] == 1 ? "True ELF " : "buggy ELF ");
- if (header->e_type != 2) {
+ serial_printf("Type: %s%s%s", header->ident[4] == 1 ? "32bit " : "64 bit",
+ header->ident[5] == 1 ? "Little Endian " : "Big endian ",
+ header->ident[6] == 1 ? "True ELF " : "buggy ELF ");
+ if (header->type != 2) {
serial_printf("File is not executable!");
return 0;
}
- /* Map the virtual space */
+
uint32_t phys_loc = loader_get_unused_load_location();
- uint32_t cr3 = kmalloc(4096);
- /* Find first program header and loop through them */
- elf_program_header_t *ph = (elf_program_header_t *)(buf + header->e_phoff);
- for (int i = 0; i < header->e_phnum; i++, ph++) {
- switch (ph->p_type) {
- case 0: /* NULL */
+ elf_program_header_t *ph = (elf_program_header_t *)(buf + header->phoff);
+ for (int i = 0; i < header->phnum; i++, ph++) {
+ switch (ph->type) {
+ case 0:
break;
- case 1: /* LOAD */
+ case 1:
serial_printf(
"LOAD: offset 0x%x vaddr 0x%x paddr 0x%x filesz 0x%x memsz 0x%x",
- ph->p_offset, ph->p_vaddr, ph->p_paddr, ph->p_filesz, ph->p_memsz);
- paging_map(phys_loc, ph->p_vaddr, PT_PRESENT | PT_RW | PT_USED);
- memcpy(ph->p_vaddr, buf + ph->p_offset, ph->p_filesz);
+ ph->offset, ph->vaddr, ph->paddr, ph->filesz, ph->memsz);
+ paging_map(phys_loc, ph->vaddr, PT_PRESENT | PT_RW | PT_USED);
+ halt_loop();
+ memcpy((void *)ph->vaddr, buf + ph->offset, ph->filesz);
break;
- default: /* @TODO add more */
- serial_printf("Unsupported p_type! Bail out!");
+ default:
+ serial_printf("Unsupported type! Bail out!");
return 0;
}
}
- return 0; //START("elf32", header->e_entry);
+ return 0;
}
void elf_init()
@@ -60,5 +58,4 @@ void elf_init()
elfloader->probe = (void *)elf_probe;
elfloader->start = (void *)elf_start;
register_loader(elfloader);
- // _kill();
-} \ No newline at end of file
+}