Skip to content

Commit

Permalink
feat: Added missing requests for x86_64
Browse files Browse the repository at this point in the history
  • Loading branch information
keyboard-slayer committed Aug 26, 2024
1 parent 1cda20d commit 5638ec1
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/booboot/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,21 @@ EfiFp *_Nonnull efi_rootdir(void)
return _rootdir;
}

char *_Nonnull efi_read_file(uint16_t *_Nonnull path, size_t *_Nullable len)
char *_Nonnull efi_read_file(char const *_Nonnull path, size_t *_Nullable len)
{
EfiFp *file;
uint16_t lpath[256] = {0};
for (size_t i = 0; i < strlen(path); i++)
{
lpath[i] = path[i];
}

EfiStatus status =
efi_rootdir()->open(efi_rootdir(), &file, path, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY);
efi_rootdir()->open(efi_rootdir(), &file, lpath, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY);

if (status != EFI_SUCCESS)
{
error$("failed to open file: ");
efi_console_write(path);
error$("failed to open file: %s", path);
for (;;)
{
__asm__("hlt");
Expand Down
2 changes: 1 addition & 1 deletion src/booboot/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ EfiSfsp *_Nonnull efi_rootfs(void);

EfiFp *_Nonnull efi_rootdir(void);

char *_Nonnull efi_read_file(uint16_t *_Nonnull path, size_t *_Nullable len);
char *_Nonnull efi_read_file(char const *_Nonnull path, size_t *_Nullable len);
71 changes: 70 additions & 1 deletion src/booboot/handover.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include <handover/handover.h>
#include <logging>
#include <tiny-efi/efi.h>

#include "config.h"
#include "file.h"
#include "handover.h"
#include "loader.h"
#include "mem.h"
Expand Down Expand Up @@ -143,12 +145,79 @@ void handover_apply(uintptr_t entry, uintptr_t stack)
(HandoverRecord){
.tag = HANDOVER_CMDLINE,
.flags = 0,
.start = handover_add_string(handover, selected_entry().cmdline),
.start = (uintptr_t)selected_entry().cmdline,
.size = strlen(selected_entry().cmdline) + 1,
});

break;
}
case HANDOVER_FB:
{
EfiGuid guid = EFI_GOP_GUID;
EfiGop *gop;
size_t infoSize;
EfiGopModeInfo *info;

efi_assert_success(efi_st()->boot_services->locate_protocol(&guid, NULL, (void **)&gop));
efi_assert_success(gop->query_mode(gop, gop->mode->max_mode - 1, &infoSize, &info));
efi_assert_success(gop->set_mode(gop, gop->mode->max_mode - 1));

debug$("setting GOP mode to %dx%d", info->horizontal_resolution, info->vertical_resolution);

handover_insert(
handover,
handover->count,
(HandoverRecord){
.tag = HANDOVER_FB,
.flags = 0,
.start = gop->mode->framebuffer_base,
.size = gop->mode->framebuffer_size,
.fb = {
.width = gop->mode->info->horizontal_resolution,
.height = gop->mode->info->vertical_resolution,
.pitch = gop->mode->info->pixels_per_scan_line * sizeof(uint32_t),
.format = HANDOVER_BGRX8888,
}});

break;
}
case HANDOVER_FILE:
{
size_t length;
for (size_t i = 0; i < selected_entry().modules.len; i++)
{
debug$("loading module %s", selected_entry().modules.buf[i].string);
char const *content = efi_read_file(selected_entry().modules.buf[i].string, &length);
handover_append(
handover,
(HandoverRecord){
.tag = HANDOVER_FILE,
.flags = 0,
.start = (uintptr_t)content,
.size = length,
.file = {
.name = handover_add_string(handover, selected_entry().modules.buf[i].string),
},
});
}

break;
}

case HANDOVER_RSDP:
{
handover_append(
handover,
(HandoverRecord){
.tag = HANDOVER_RSDP,
.flags = 0,
.start = uefi_find_rsdp(),
.size = 0x1000,
});

break;
}

default:
{
error$("unsupported request %s", handover_tag_name(reqs[i].tag));
Expand Down
8 changes: 1 addition & 7 deletions src/booboot/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ size_t _ehdr_size = 0;

uintptr_t load_binary(char const *_Nonnull path)
{
uint16_t lpath[256] = {0};
for (size_t i = 0; i < strlen(path); i++)
{
lpath[i] = path[i];
}

char *_Nonnull hdr = efi_read_file(lpath, &_ehdr_size);
char *_Nonnull hdr = efi_read_file(path, &_ehdr_size);
_ehdr = hdr;

char magic[4] = {hdr[EI_MAG0], hdr[EI_MAG1], hdr[EI_MAG2], hdr[EI_MAG3]};
Expand Down
2 changes: 1 addition & 1 deletion src/booboot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ EfiStatus efi_main(EfiHandle handle, EfiSystemTable *st)

info$("booting from Booboot...");

char *_Nonnull cfg = efi_read_file(L"loader.json", NULL);
char *_Nonnull cfg = efi_read_file("loader.json", NULL);
efi_assert_success(config_parse(cfg));

menu();
Expand Down
7 changes: 7 additions & 0 deletions src/booboot/protocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@

#include <stdint.h>

typedef struct
{
uint64_t width;
uint64_t height;
uint64_t bpp;
} Resolution;

uintptr_t apply_protocol(char const *_Nonnull protocol_name, uintptr_t entry, uintptr_t stack);
27 changes: 27 additions & 0 deletions src/booboot/utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <logging>
#include <string.h>
#include <tiny-efi/efi.h>

uintptr_t uefi_find_rsdp(void)
{
EfiGuid acpi = ACPI_TABLE_GUID;
EfiGuid acpi2 = ACPI2_TABLE_GUID;
void *acpi_table = NULL;

for (size_t i = 0; i < efi_st()->num_table_entries; i++)
{
if (memcmp(&efi_st()->config_table[i].vendor_guid, &acpi, sizeof(EfiGuid)) == 0)
{
acpi_table = efi_st()->config_table[i].vendor_table;
break;
}
else if (memcmp(&efi_st()->config_table[i].vendor_guid, &acpi2, sizeof(EfiGuid)) == 0)
{
acpi_table = efi_st()->config_table[i].vendor_table;
break;
}
}

debug$("ACPI table at %p", acpi_table);
return (uintptr_t)acpi_table;
}
2 changes: 2 additions & 0 deletions src/booboot/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
#define align_up$(x, align) (((x) + (align) - 1) & ~((align) - 1))

#define align_down$(x, align) ((x) & ~((align) - 1))

uintptr_t uefi_find_rsdp(void);

0 comments on commit 5638ec1

Please sign in to comment.