diff options
author | Konstantin Aladyshev <aladyshev22@gmail.com> | 2021-07-03 00:47:16 +0300 |
---|---|---|
committer | Konstantin Aladyshev <aladyshev22@gmail.com> | 2021-07-03 16:18:55 +0300 |
commit | 0872ca11d741d039846c8b301eed1d720d640ed0 (patch) | |
tree | 67c57919a56aba4b4ab5bed9b462d847078c587e /Lesson_28/UefiLessonsPkg/AcpiInfo | |
parent | 560f0303beaac1bfa8966de3fe636657825724da (diff) | |
download | UEFI-Lessons-0872ca11d741d039846c8b301eed1d720d640ed0.tar.gz UEFI-Lessons-0872ca11d741d039846c8b301eed1d720d640ed0.tar.bz2 UEFI-Lessons-0872ca11d741d039846c8b301eed1d720d640ed0.zip |
Add lesson 28
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lesson_28/UefiLessonsPkg/AcpiInfo')
-rw-r--r-- | Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.c | 47 | ||||
-rw-r--r-- | Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.inf | 3 |
2 files changed, 45 insertions, 5 deletions
diff --git a/Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.c b/Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.c index 88c78b6..0511f59 100644 --- a/Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.c +++ b/Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.c @@ -2,6 +2,7 @@ #include <Library/UefiLib.h> #include <Library/BaseMemoryLib.h> +#include <Protocol/Shell.h> EFI_STATUS EFIAPI @@ -10,6 +11,18 @@ UefiMain ( IN EFI_SYSTEM_TABLE *SystemTable ) { + EFI_SHELL_PROTOCOL* ShellProtocol; + EFI_STATUS Status = gBS->LocateProtocol( + &gEfiShellProtocolGuid, + NULL, + (VOID **)&ShellProtocol + ); + + if (EFI_ERROR(Status)) { + Print(L"Can't open EFI_SHELL_PROTOCOL: %r\n", Status); + return EFI_SUCCESS; + } + EFI_ACPI_6_3_ROOT_SYSTEM_DESCRIPTION_POINTER* RSDP = NULL; for (UINTN i=0; i<SystemTable->NumberOfTableEntries; i++) { @@ -55,13 +68,37 @@ UefiMain ( while (offset < XSDT->Length) { UINT64* table_address = (UINT64*)((UINT8*)XSDT + offset); EFI_ACPI_6_3_COMMON_HEADER* table = (EFI_ACPI_6_3_COMMON_HEADER*)(*table_address); - Print(L"\t%c%c%c%c table is placed at address %p with length 0x%x\n", - (CHAR8)((table->Signature>> 0)&0xFF), - (CHAR8)((table->Signature>> 8)&0xFF), - (CHAR8)((table->Signature>>16)&0xFF), - (CHAR8)((table->Signature>>24)&0xFF), + CHAR16 TableName[5]; + TableName[0] = (CHAR16)((table->Signature>> 0)&0xFF); + TableName[1] = (CHAR16)((table->Signature>> 8)&0xFF); + TableName[2] = (CHAR16)((table->Signature>>16)&0xFF); + TableName[3] = (CHAR16)((table->Signature>>24)&0xFF); + TableName[4] = 0; + + Print(L"\t%s table is placed at address %p with length 0x%x\n", + TableName, table, table->Length); + CHAR16 FileName[9] = {0}; + StrCpyS(FileName, 9, TableName); + StrCatS(FileName, 9, L".aml"); + SHELL_FILE_HANDLE FileHandle; + Status = ShellProtocol->OpenFileByName(FileName, + &FileHandle, + EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ); + if (!EFI_ERROR(Status)) { + UINTN size = table->Length; + Status = ShellProtocol->WriteFile(FileHandle, &size, (VOID*)table); + if (EFI_ERROR(Status)) { + Print(L"Error in WriteFile: %r\n", Status); + } + Status = ShellProtocol->CloseFile(FileHandle); + if (EFI_ERROR(Status)) { + Print(L"Error in CloseFile: %r\n", Status); + } + } else { + Print(L"Error in OpenFileByName: %r\n", Status); + } offset += sizeof(UINT64); } diff --git a/Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.inf b/Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.inf index 3884e76..53d0356 100644 --- a/Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.inf +++ b/Lesson_28/UefiLessonsPkg/AcpiInfo/AcpiInfo.inf @@ -19,3 +19,6 @@ [Guids] gEfiAcpi20TableGuid +[Protocols] + gEfiShellProtocolGuid + |