diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/features/elf.c | 39 | ||||
-rw-r--r-- | src/features/load.c | 13 | ||||
-rw-r--r-- | src/inc/elf.h | 61 | ||||
-rw-r--r-- | src/inc/load.h | 10 | ||||
-rw-r--r-- | src/main.c | 5 |
5 files changed, 25 insertions, 103 deletions
diff --git a/src/features/elf.c b/src/features/elf.c deleted file mode 100644 index f92f399..0000000 --- a/src/features/elf.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <assert.h> -#include <def.h> -#include <elf.h> -#include <fs.h> -#include <mem.h> -#include <str.h> - -int elf_verify(struct elf_header *h) -{ - return (h->ident[0] == ELF_MAG && !strncmp((char *)&h->ident[1], "ELF", 3) && - h->ident[4] == ELF_32 && h->ident[5] == ELF_LITTLE && h->ident[6] == ELF_CURRENT && - h->machine == ELF_386 && (h->type == ET_REL || h->type == ET_EXEC)); -} - -void elf_load(char *path) -{ - u32 *data = read_file(path); - - struct elf_header *h = (struct elf_header *)data; - assert(elf_verify(h)); - - struct elf_program_header *p = (struct elf_program_header *)((u32)data + h->phoff); - struct elf_program_header *p_end = - (struct elf_program_header *)((u32)p + (h->phentsize * h->phnum)); - - u32 offset = (p->vaddr - p->paddr); - while (p < p_end) { - printf("\nheader: 0x%x\n", p->paddr); - printf("filesz: %d\n", p->filesz); - /* memcpy(p->paddr, (u32)data + p->offset, p->filesz); */ - memcpy((u32 *)p->paddr, (u32 *)((u32)data + p->offset), p->filesz); - p++; - } - - void (*entry)(); - entry = (void (*)())(h->entry - offset); - - entry(); -} diff --git a/src/features/load.c b/src/features/load.c new file mode 100644 index 0000000..37ed6ad --- /dev/null +++ b/src/features/load.c @@ -0,0 +1,13 @@ +#include <def.h> +#include <fs.h> +#include <print.h> + +void bin_load(char *path) +{ + char *data = read_file(path); + + void (*entry)(); + *(void **)(&entry) = data + 0xfe; + + entry(); +} diff --git a/src/inc/elf.h b/src/inc/elf.h deleted file mode 100644 index c10ba4e..0000000 --- a/src/inc/elf.h +++ /dev/null @@ -1,61 +0,0 @@ -// MIT License, Copyright (c) 2020 Marvin Borner - -#ifndef ELF_H -#define ELF_H - -#include <def.h> - -#define ELF_MAG 0x7F // 0 -#define ELF_32 1 // 4: 32-bit Architecture -#define ELF_LITTLE 1 // 5: Little Endian -#define ELF_CURRENT 1 // 6: ELF Current Version -#define ELF_386 3 // header->machine x86 machine type - -#define ET_NONE 0 // Unkown type -#define ET_REL 1 // Relocatable file -#define ET_EXEC 2 // Executable file - -struct elf_header { - u8 ident[16]; - u16 type; - u16 machine; - u32 version; - u32 entry; - u32 phoff; - u32 shoff; - u32 flags; - u16 ehsize; - u16 phentsize; - u16 phnum; - u16 shentsize; - u16 shnum; - u16 shstrndx; -}; - -struct elf_section_header { - u32 name; - u32 type; - u32 flags; - u32 addr; - u32 offset; - u32 size; - u32 link; - u32 info; - u32 addralign; - u32 entsize; -}; - -struct elf_program_header { - u32 type; - u32 offset; - u32 vaddr; - u32 paddr; - u32 filesz; - u32 memsz; - u32 flags; - u32 align; -}; - -void elf_load(char *path); - -#endif diff --git a/src/inc/load.h b/src/inc/load.h new file mode 100644 index 0000000..afca249 --- /dev/null +++ b/src/inc/load.h @@ -0,0 +1,10 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#ifndef LOAD_H +#define LOAD_H + +#include <def.h> + +void bin_load(char *path); + +#endif @@ -3,11 +3,11 @@ #include "config.h" #include <boot.h> #include <def.h> -#include <elf.h> #include <fs.h> #include <gui.h> #include <interrupts.h> #include <keyboard.h> +#include <load.h> #include <print.h> #include <serial.h> #include <timer.h> @@ -42,8 +42,7 @@ void main(struct mem_info *mem_info, struct vid_info *vid_info) gui_init(FONT_PATH); gui_term_write("Wake up, " USERNAME "...\n"); - elf_load("/test"); - printf("loaded"); + bin_load("/test"); while (1) { }; |