parse program header of elf file and use load sections
This commit is contained in:
parent
6243b46072
commit
114468a6ad
BIN
boot/initrd
BIN
boot/initrd
Binary file not shown.
|
@ -41,6 +41,30 @@ typedef struct {
|
|||
Elf32_Word sh_entsize;
|
||||
} section_t;
|
||||
|
||||
typedef struct {
|
||||
Elf32_Word p_type;
|
||||
Elf32_Off p_offset;
|
||||
Elf32_Addr p_vaddr;
|
||||
Elf32_Addr p_paddr;
|
||||
Elf32_Word p_filesz;
|
||||
Elf32_Word p_memsz;
|
||||
Elf32_Word p_flags;
|
||||
Elf32_Word p_align;
|
||||
} phdr_t;
|
||||
|
||||
#define PT_NULL 0
|
||||
#define PT_LOAD 1
|
||||
#define PT_DYNAMIC 2
|
||||
#define PT_INTERP 3
|
||||
#define PT_NOTE 4
|
||||
#define PT_SHLIB 5
|
||||
#define PT_PHDR 6
|
||||
#define PT_TLS 7
|
||||
#define PT_LOOS 0x60000000
|
||||
#define PT_HIOS 0x6fffffff
|
||||
#define PT_LOPROC 0x70000000
|
||||
#define PT_HIPROC 0x7fffffff
|
||||
|
||||
section_t *elf_find_section(elf_t *elf, const char *name);
|
||||
|
||||
#endif
|
||||
|
|
6
include/kernel/ide.h
Normal file
6
include/kernel/ide.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef HAZEL_IDE_H_
|
||||
#define HAZEL_IDE_H_
|
||||
|
||||
void ide_init();
|
||||
|
||||
#endif
|
|
@ -22,8 +22,8 @@ typedef struct {
|
|||
uint32_t *mmap;
|
||||
uint32_t mmap_size;
|
||||
log_method_t log_method;
|
||||
uint64_t ticks;
|
||||
task_t *current_task;
|
||||
volatile uint64_t ticks;
|
||||
volatile task_t *current_task;
|
||||
rsdt_t *rsdt;
|
||||
} kernel_ctx_t;
|
||||
|
||||
|
|
5
kernel/ide.c
Normal file
5
kernel/ide.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include <kernel/ide.h>
|
||||
|
||||
void ide_init() {
|
||||
|
||||
}
|
|
@ -7,10 +7,8 @@ extern kernel_ctx_t ctx;
|
|||
|
||||
//int task_init(task_t *task, uint32_t *img) {
|
||||
int task_init(task_t *task, elf_t *elf) {
|
||||
|
||||
if (!elf) return 0;
|
||||
uint8_t *s = (uint8_t *)mmap_find_first_free_block();
|
||||
memcpy(s, elf, 0x1000);
|
||||
if (!elf->e_phoff) return 0;
|
||||
|
||||
task->eip = elf->e_entry;
|
||||
// Allocate a page for a stack
|
||||
|
@ -31,9 +29,17 @@ int task_init(task_t *task, elf_t *elf) {
|
|||
// Map remaining entries as non-present u/s
|
||||
else page_dir[i] = 6;
|
||||
}
|
||||
|
||||
phdr_t *phdr = (phdr_t *)((uint32_t)elf + elf->e_phoff);
|
||||
for (int i = 0; i < elf->e_phnum; i++) {
|
||||
if (phdr[i].p_type == PT_LOAD) {
|
||||
uint8_t *s = (uint8_t *)mmap_find_first_free_block();
|
||||
memcpy(s, (uint8_t *)elf + phdr[i].p_offset, phdr[i].p_filesz);
|
||||
// Map the ELF image to its specified entry
|
||||
page_dir[PAGE_DIR_INDEX(elf->e_entry)] = ((uint32_t)page_tab - KERNEL_VMA) | 7;
|
||||
page_tab[PAGE_TAB_INDEX(elf->e_entry)] = ((uint32_t)s - KERNEL_VMA) | 7;
|
||||
page_dir[PAGE_DIR_INDEX(phdr[i].p_vaddr)] = ((uint32_t)page_tab - KERNEL_VMA) | 7;
|
||||
page_tab[PAGE_TAB_INDEX(phdr[i].p_vaddr)] = ((uint32_t)s - KERNEL_VMA) | 7;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "../lib/strcmp.h"
|
||||
|
||||
static const char test[] = "Hello\n";
|
||||
|
||||
int strlen(const char *str) {
|
||||
const char *s;
|
||||
for (s = str; *s; s++)
|
||||
|
@ -86,7 +88,8 @@ void print_int(int num){
|
|||
|
||||
void _start() {
|
||||
char buf1[256] = {0};
|
||||
puts("Welcome to the Hazel user shell!\n");
|
||||
//puts("Welcome to the Hazel user shell!\n");
|
||||
puts(test);
|
||||
while (1) {
|
||||
puts("$ ");
|
||||
read(0, buf1, 256);
|
||||
|
|
Loading…
Reference in New Issue
Block a user