lib: uefi: add EfiSystemTablePointer for debug

Add EfiSystemTablePointer structure for remote debugger to locate
the address of EfiSystemTable.

This feature is described in UEFI SPEC version 2.10. Section 18.4.2.
The implementation ensures support for hardware-assisted debugging and
provides a standardized mechanism for debuggers to discover the EFI
system table.

Signed-off-by: Ying-Chun Liu (PaulLiu) <paulliu@debian.org>
This commit is contained in:
Ying-Chun Liu (PaulLiu)
2025-07-26 02:04:40 +01:00
committed by Kelvin Zhang
parent 777297f156
commit ea327d7242
4 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "debug_support.h"
#include <stdio.h>
#include <string.h>
#include <lib/cksum.h>
#include <uefi/boot_service.h>
#include <uefi/types.h>
#include "memory_protocols.h"
namespace {
struct EfiSystemTablePointer *efi_systab_pointer = nullptr;
}
EfiStatus efi_initialize_system_table_pointer(struct EfiSystemTable *system_table) {
uint32_t crc = 0;
constexpr auto EFI_SYSTEM_TABLE_SIGNATURE =
static_cast<u64>(0x5453595320494249ULL);
/* Allocate efi_system_table_pointer structure with 4MB alignment. */
efi_systab_pointer = reinterpret_cast<EfiSystemTablePointer *>(alloc_page(sizeof(struct EfiSystemTablePointer), 22));
if (!efi_systab_pointer) {
printf("Installing EFI system table pointer failed\n");
return OUT_OF_RESOURCES;
}
memset(efi_systab_pointer, 0, sizeof(struct EfiSystemTablePointer));
efi_systab_pointer->signature = EFI_SYSTEM_TABLE_SIGNATURE;
efi_systab_pointer->system_table_base = system_table;
crc = crc32(crc,
(uint8_t *)efi_systab_pointer,
sizeof(struct EfiSystemTablePointer));
efi_systab_pointer->crc32 = crc;
return SUCCESS;
}

32
lib/uefi/debug_support.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef __DEBUG_SUPPORT_
#define __DEBUG_SUPPORT_
#include <uefi/system_table.h>
#include <uefi/types.h>
struct EfiSystemTablePointer {
uint64_t signature;
EfiSystemTable *system_table_base;
uint32_t crc32;
};
EfiStatus efi_initialize_system_table_pointer(struct EfiSystemTable *system_table);
#endif

View File

@@ -20,6 +20,7 @@ MODULE_SRCS += \
$(LOCAL_DIR)/configuration_table.cpp \
$(LOCAL_DIR)/events.cpp \
$(LOCAL_DIR)/io_stack.cpp \
$(LOCAL_DIR)/debug_support.cpp \
include make/module.mk

View File

@@ -42,6 +42,7 @@
#include "switch_stack.h"
#include "text_protocol.h"
#include "uefi_platform.h"
#include "debug_support.h"
namespace {
@@ -137,6 +138,11 @@ int load_sections_and_execute(bdev_t *dev,
printf("platform_setup_system_table failed: %lu\n", status);
return -static_cast<int>(status);
}
status = efi_initialize_system_table_pointer(&table);
if (status != SUCCESS) {
printf("efi_initialize_system_table_pointer failed: %lu\n", status);
return -static_cast<int>(status);
}
constexpr size_t kStackSize = 1 * 1024ul * 1024;
auto stack = reinterpret_cast<char *>(alloc_page(kStackSize, 23));