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;
|
Elf32_Word sh_entsize;
|
||||||
} section_t;
|
} 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);
|
section_t *elf_find_section(elf_t *elf, const char *name);
|
||||||
|
|
||||||
#endif
|
#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;
|
||||||
uint32_t mmap_size;
|
uint32_t mmap_size;
|
||||||
log_method_t log_method;
|
log_method_t log_method;
|
||||||
uint64_t ticks;
|
volatile uint64_t ticks;
|
||||||
task_t *current_task;
|
volatile task_t *current_task;
|
||||||
rsdt_t *rsdt;
|
rsdt_t *rsdt;
|
||||||
} kernel_ctx_t;
|
} 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, uint32_t *img) {
|
||||||
int task_init(task_t *task, elf_t *elf) {
|
int task_init(task_t *task, elf_t *elf) {
|
||||||
|
|
||||||
if (!elf) return 0;
|
if (!elf) return 0;
|
||||||
uint8_t *s = (uint8_t *)mmap_find_first_free_block();
|
if (!elf->e_phoff) return 0;
|
||||||
memcpy(s, elf, 0x1000);
|
|
||||||
|
|
||||||
task->eip = elf->e_entry;
|
task->eip = elf->e_entry;
|
||||||
// Allocate a page for a stack
|
// 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
|
// Map remaining entries as non-present u/s
|
||||||
else page_dir[i] = 6;
|
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
|
// Map the ELF image to its specified entry
|
||||||
page_dir[PAGE_DIR_INDEX(elf->e_entry)] = ((uint32_t)page_tab - KERNEL_VMA) | 7;
|
page_dir[PAGE_DIR_INDEX(phdr[i].p_vaddr)] = ((uint32_t)page_tab - KERNEL_VMA) | 7;
|
||||||
page_tab[PAGE_TAB_INDEX(elf->e_entry)] = ((uint32_t)s - KERNEL_VMA) | 7;
|
page_tab[PAGE_TAB_INDEX(phdr[i].p_vaddr)] = ((uint32_t)s - KERNEL_VMA) | 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "../lib/strcmp.h"
|
#include "../lib/strcmp.h"
|
||||||
|
|
||||||
|
static const char test[] = "Hello\n";
|
||||||
|
|
||||||
int strlen(const char *str) {
|
int strlen(const char *str) {
|
||||||
const char *s;
|
const char *s;
|
||||||
for (s = str; *s; s++)
|
for (s = str; *s; s++)
|
||||||
|
@ -86,7 +88,8 @@ void print_int(int num){
|
||||||
|
|
||||||
void _start() {
|
void _start() {
|
||||||
char buf1[256] = {0};
|
char buf1[256] = {0};
|
||||||
puts("Welcome to the Hazel user shell!\n");
|
//puts("Welcome to the Hazel user shell!\n");
|
||||||
|
puts(test);
|
||||||
while (1) {
|
while (1) {
|
||||||
puts("$ ");
|
puts("$ ");
|
||||||
read(0, buf1, 256);
|
read(0, buf1, 256);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user