Skip to content

Commit

Permalink
[app][uefi] Add configuration table
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxp1998 committed Oct 24, 2024
1 parent 27fe7b4 commit d74411b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
14 changes: 14 additions & 0 deletions lib/uefi/configuration_table.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "configuration_table.h"
#include "boot_service_provider.h"
#include "system_table.h"
#include <string.h>

void setup_configuration_table(EfiSystemTable *table) {
auto &rng = table->configuration_table[0];
rng.vendor_guid = LINUX_EFI_RANDOM_SEED_TABLE_GUID;
rng.vendor_table = alloc_page(PAGE_SIZE);
auto rng_seed = reinterpret_cast<linux_efi_random_seed *>(rng.vendor_table);
rng_seed->size = 512;
memset(&rng_seed->bits, 0, rng_seed->size);
table->number_of_table_entries = 1;
}
20 changes: 20 additions & 0 deletions lib/uefi/configuration_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __CONFIGURATION_TABLE_
#define __CONFIGURATION_TABLE_

#include "system_table.h"
#include "types.h"

struct linux_efi_random_seed {
uint32_t size;
uint8_t bits[];
};

static constexpr auto LINUX_EFI_RANDOM_SEED_TABLE_GUID =
EfiGuid{0x1ce1e5bc,
0x7ceb,
0x42f2,
{0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b}};

void setup_configuration_table(EfiSystemTable *table);

#endif
12 changes: 6 additions & 6 deletions lib/uefi/include/system_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#include "protocols/simple_text_output_protocol.h"
#include "runtime_service.h"

typedef struct {
struct EfiConfigurationTable {
EfiGuid vendor_guid;
const void* vendor_table;
} EfiConfigurationTable;
void *vendor_table;
};

typedef struct EfiSystemTable {
struct EfiSystemTable {
EfiTableHeader header;
char16_t* firmware_vendor;
uint32_t firmware_revision;
Expand All @@ -43,7 +43,7 @@ typedef struct EfiSystemTable {
EfiRuntimeService *runtime_service;
EfiBootService* boot_services;
size_t number_of_table_entries;
const EfiConfigurationTable* configuration_table;
} EfiSystemTable;
EfiConfigurationTable *configuration_table;
};

#endif // __SYSTEM_TABLE_H__
1 change: 1 addition & 0 deletions lib/uefi/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ MODULE_SRCS += \
$(LOCAL_DIR)/boot_service_provider.cpp \
$(LOCAL_DIR)/runtime_service_provider.cpp \
$(LOCAL_DIR)/switch_stack.S \
$(LOCAL_DIR)/configuration_table.cpp \

include make/module.mk
14 changes: 10 additions & 4 deletions lib/uefi/uefi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include <lk/debug.h>
#include <lk/err.h>
#include <lk/trace.h>
#include <math.h>
#include <platform.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>

#include "configuration_table.h"
#include "protocols/simple_text_output_protocol.h"
#include "runtime_service.h"
#include "runtime_service_provider.h"
Expand Down Expand Up @@ -53,7 +55,7 @@ static constexpr size_t BIT10 = 1 << 10;
@return Immediate address encoded in the instruction
**/
uint16_t ThumbMovtImmediateAddress(uint16_t *Instruction) {
uint16_t ThumbMovtImmediateAddress(const uint16_t *Instruction) {
uint32_t Movt;
uint16_t Address;

Expand Down Expand Up @@ -262,7 +264,7 @@ int load_sections_and_execute(bdev_t *dev,
image_base + optional_header->AddressOfEntryPoint);
printf("Entry function located at %p\n", entry);

EfiSystemTable table{};
EfiSystemTable &table = *static_cast<EfiSystemTable *>(alloc_page(PAGE_SIZE));
EfiBootService boot_service{};
EfiRuntimeService runtime_service{};
fill(&runtime_service, 0);
Expand All @@ -274,8 +276,12 @@ int load_sections_and_execute(bdev_t *dev,
table.header.signature = EFI_SYSTEM_TABLE_SIGNATURE;
EfiSimpleTextOutputProtocol console_out = get_text_output_protocol();
table.con_out = &console_out;
constexpr size_t kStackSize = 1024ul * 1024;
auto stack = reinterpret_cast<char *>(alloc_page(kStackSize, PAGE_SIZE));
table.configuration_table =
reinterpret_cast<EfiConfigurationTable *>(alloc_page(PAGE_SIZE));
setup_configuration_table(&table);

constexpr size_t kStackSize = 8 * 1024ul * 1024;
auto stack = reinterpret_cast<char *>(alloc_page(kStackSize, 23));
memset(stack, 0, kStackSize);
return call_with_stack(stack + kStackSize, entry, image_base, &table);
}
Expand Down

0 comments on commit d74411b

Please sign in to comment.