diff --git a/Makefile b/Makefile index e17f7a8..396cbb6 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ ISO := Hazel.iso CFLAGS := -ffreestanding -Wall -Wextra -Werror -I $(INCLUDEDIR) -I lib LDFLAGS := -ffreestanding -nostdlib -lgcc -T kernel/kernel.ld -QEMUFLAGS := -cdrom $(BUILDDIR)/$(ISO) -s -m 512M -serial stdio -device virtio-gpu +QEMUFLAGS := -cdrom $(BUILDDIR)/$(ISO) -s -m 512M -serial stdio -device virtio-gpu $(BUILDDIR)/$(KIMG): $(KOBJ) $(LOBJ) $(CC) $^ -o $@ $(LDFLAGS) diff --git a/boot/initrd b/boot/initrd index 0430873..2c9cf00 100755 Binary files a/boot/initrd and b/boot/initrd differ diff --git a/hdd.img b/hdd.img new file mode 100644 index 0000000..e9784eb Binary files /dev/null and b/hdd.img differ diff --git a/include/kernel/elf.h b/include/kernel/elf.h index b8b21a7..23572d5 100644 --- a/include/kernel/elf.h +++ b/include/kernel/elf.h @@ -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 diff --git a/include/kernel/ide.h b/include/kernel/ide.h new file mode 100644 index 0000000..43896ae --- /dev/null +++ b/include/kernel/ide.h @@ -0,0 +1,6 @@ +#ifndef HAZEL_IDE_H_ +#define HAZEL_IDE_H_ + +void ide_init(); + +#endif diff --git a/include/kernel/kernel.h b/include/kernel/kernel.h index 4ee59c4..0ce2001 100644 --- a/include/kernel/kernel.h +++ b/include/kernel/kernel.h @@ -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; diff --git a/kernel/ide.c b/kernel/ide.c new file mode 100644 index 0000000..2522373 --- /dev/null +++ b/kernel/ide.c @@ -0,0 +1,5 @@ +#include + +void ide_init() { + +} diff --git a/kernel/task.c b/kernel/task.c index b364bd3..c4b1954 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -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; } - // 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; + + 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(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; } diff --git a/user/shell.c b/user/shell.c index 9ca0db6..828d9dc 100644 --- a/user/shell.c +++ b/user/shell.c @@ -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);