summaryrefslogtreecommitdiff
path: root/kc/boot/kc_main.c
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2021-12-26 01:12:31 +0000
committerAda Christine <adachristine18@gmail.com>2021-12-26 01:12:31 +0000
commit2b0734bdc362d5f453e5bfe833b534298072a56a (patch)
tree6007e56e35ef448b43c1de3e7e5998fd2ca360de /kc/boot/kc_main.c
parent257bdba7ddcc8d9893927c458e3c6e377c4e8d9c (diff)
everything builds, probably doesn't work. commit in preparation for a merge
Diffstat (limited to 'kc/boot/kc_main.c')
-rw-r--r--kc/boot/kc_main.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/kc/boot/kc_main.c b/kc/boot/kc_main.c
index 1829616..744ced7 100644
--- a/kc/boot/kc_main.c
+++ b/kc/boot/kc_main.c
@@ -37,9 +37,55 @@ struct efi_loader_image kernel_image =
.path = L"\\adasoft\\sophia\\kernel.os"
};
+static struct efi_loader_interface *loader_interface;
static struct efi_boot_data boot_data;
-// TODO: split relocation code out into library
+static void collect_boot_data(void)
+{
+ EFI_BOOT_SERVICES *ebs = loader_interface->system_table->BootServices;
+ EFI_STATUS status;
+
+ boot_data.memory_map.size = 0;
+
+ status = ebs->GetMemoryMap(&boot_data.memory_map.size,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+
+ if (EFI_BUFFER_TOO_SMALL == status)
+ {
+ boot_data.memory_map.size += EFI_PAGE_SIZE;
+ status = loader_interface->page_alloc(SystemMemoryType,
+ boot_data.memory_map.size,
+ (EFI_PHYSICAL_ADDRESS *)&boot_data.memory_map.buffer.base);
+ }
+
+ if (!EFI_ERROR(status))
+ {
+ boot_data.memory_map.size = boot_data.memory_map.buffer.size;
+
+ status = ebs->GetMemoryMap(&boot_data.memory_map.size,
+ (EFI_MEMORY_DESCRIPTOR *)&boot_data.memory_map.buffer.base,
+ &boot_data.memory_map.key,
+ &boot_data.memory_map.descsize,
+ &boot_data.memory_map.descver);
+ }
+
+ if (EFI_ERROR(status))
+ {
+ __asm__ volatile
+ (
+ "cli\n\t"
+ "int3\n\t"
+ );
+
+ while (1)
+ {
+ __asm__ volatile ("hlt\n\t");
+ }
+ }
+}
EFI_STATUS kc_main(struct efi_loader_interface *interface)
{
@@ -56,11 +102,13 @@ EFI_STATUS kc_main(struct efi_loader_interface *interface)
return EFI_INVALID_PARAMETER;
}
+ loader_interface = interface;
+
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;
+ collect_boot_data();
}
__asm__ volatile (