diff options
| author | Ada Christine <adachristine18@gmail.com> | 2021-12-16 12:06:04 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2021-12-16 12:06:04 +0000 |
| commit | ec1233b4fcd61a8d1eccbf030cede36e9848e06c (patch) | |
| tree | 13ffdc3b3948275e8c764ccf10368d555ff4d5e1 /shim | |
| parent | a7f79219706c357c6c15978cea5e654042b14acb (diff) | |
reworking loader
Diffstat (limited to 'shim')
| -rw-r--r-- | shim/Makefile | 36 | ||||
| -rw-r--r-- | shim/entry.c | 83 | ||||
| -rw-r--r-- | shim/shim.ld | 49 |
3 files changed, 168 insertions, 0 deletions
diff --git a/shim/Makefile b/shim/Makefile new file mode 100644 index 0000000..51ec96c --- /dev/null +++ b/shim/Makefile @@ -0,0 +1,36 @@ +include ../defaults.mk + +VPATH := ../lib + +TARGET := efi.os +.DEFAULT: $(TARGET) + +# EFI API for temporary things + +EFIAPIDIR := /usr/local/include/efi + +CPPFLAGS += -I../api -I$(EFIAPIDIR) -I$(EFIAPIDIR)/$(ARCH) -I$(EFIAPIDIR)/protocol +CFLAGS += -Wno-unused-const-variable -Wno-unused-function -fvisibility=hidden \ + -g -fshort-wchar -mgeneral-regs-only + +LIBDIRS += -L$(dir $(shell $(CC) -print-libgcc-file-name)) +LDSCRIPT := shim.ld +LDFLAGS += -z max-page-size=4096 --export-dynamic +LOADLIBES := -lgcc + +OBJS := entry.o memcmp.o memcpy.o memmove.o memset.o +$(OBJS): CFLAGS += -fPIC -fPIE + +DEPS := $(patsubst %.o,%.d,$(OBJS)) + +$(TARGET): $(LDSCRIPT) $(MAKEFILE_LIST) +$(TARGET): $(OBJS) + +CLEANLIST := $(wildcard $(OBJS) $(TARGET)) +DCLEANLIST := $(wildcard $(DEPS)) + +include ../rules.mk +-include $(DEPS) + +.DEFAULT: $(TARGET) + diff --git a/shim/entry.c b/shim/entry.c new file mode 100644 index 0000000..303f582 --- /dev/null +++ b/shim/entry.c @@ -0,0 +1,83 @@ +#include <loader/efi/shim.h> +#include <kernel/memory/range.h> + +#include <stdbool.h> + +#include "../lib/elf.h" + +struct efi_memory_map +{ + struct memory_range buffer; + UINTN size; + UINTN key; + UINTN descsize; + UINT32 descver; +}; + +struct efi_video_data +{ + struct memory_range buffer; + UINT32 width; + UINT32 height; + UINT32 pitch; + EFI_GRAPHICS_PIXEL_FORMAT format; + EFI_PIXEL_BITMASK mask; +}; + +struct efi_boot_data +{ + struct efi_memory_map memory_map; + struct efi_video_data video_data; + void *acpi_rsdp; + unsigned long acpi_version; +}; + +struct efi_loader_image kernel_image = +{ + .path = L"\\adasoft\\sophia\\kernel.os" +}; + +static struct efi_loader_image *shim_image; +static struct efi_boot_data boot_data; + +EFI_STATUS efi_shim_entry(struct efi_loader_image *image, + struct efi_loader_interface *interface) +{ + /* 1. load kernel and boot modules into memory + * 2. generate page tables for kernel and boot modules + * 2. gather boot data, store as type SystemMemoryType + * 3. exit boot services + * 5. ??????????? + */ + + EFI_STATUS status; + + if (!image) + { + return EFI_INVALID_PARAMETER; + } + else if (!shim_image) + { + shim_image = image; + kernel_image.image_handle = shim_image->image_handle; + } + else + { + return EFI_ALREADY_STARTED; + } + + if (!EFI_ERROR((status = interface->image_open(&kernel_image))) && + !EFI_ERROR((status = interface->image_alloc(&kernel_image))) && + !EFI_ERROR((status = interface->image_load(&kernel_image)))) + { + (void)boot_data; + } + + __asm__ volatile ( + "cli\n\t" + "hlt\n\t" + ); + + return status; +} + diff --git a/shim/shim.ld b/shim/shim.ld new file mode 100644 index 0000000..f0643ca --- /dev/null +++ b/shim/shim.ld @@ -0,0 +1,49 @@ +ENTRY(efi_shim_entry) + +SECTIONS +{ + . = sizeof_headers; + + .rel : + { + *(.rel.*) + } + + .rela : + { + *(.rela.*) + } + + .text : ALIGN(4K) + { + PROVIDE(_text_begin = .); + *(.text) + . = ALIGN(4K); + PROVIDE(_text_end = .); + } =0xcc + + .data : + { + PROVIDE(_data_begin = .); + *(.rodata) + *(.data) + } + + .data.rel : + { + *(.data.rel) + *(.data.rel.*) + } + + .bss : + { + *(.bss) + PROVIDE(_data_end = .); + } + + /DISCARD/ : + { + *(.eh_frame) + } +} + |
