[問題] 呼叫字串陣列並輸出

作者: devcc (遊俠)   2023-02-03 15:21:30
最近在學習BIOS 在寫memory Map相關的練習 目前剛在構想怎麼完成
我想問 先告一個字串陣列該怎麼把它列印出來?
這部分一直build不過
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/ShellParameters.h>
EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol;
const CHAR16 *memory_types[] = { //有人有用const、STATIC,或沒用,但我都過不了
L"EfiReservedMemoryType",
L"EfiLoaderCode",
L"EfiLoaderData",
L"EfiBootServicesCode",
L"EfiBootServicesData",
L"EfiRuntimeServicesCode",
L"EfiRuntimeServicesData",
L"EfiConventionalMemory",
L"EfiUnusableMemory",
L"EfiACPIReclaimMemory",
L"EfiACPIMemoryNVS",
L"EfiMemoryMappedIO",
L"EfiMemoryMappedIOPortSpace",
L"EfiPalCode",
L"EfiPersistentMemory",
L"EfiMaxMemoryType",
};
VOID PrintNUMType()
{
Print(L" NUM_type\n");
for (int i = 0; i < 3; i++) {
print(L" %d. %c", i+1, memory_types[i]);
}
};
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
CHAR16 **Argv;
UINTN Argc;
UINTN Index;
UINTN Value[4];
Status = gBS->OpenProtocol(ImageHandle,
&gEfiShellParametersProtocolGuid,
(VOID **)&EfiShellParametersProtocol,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
Print(L"Status %r\n", Status);
return Status;
}
Print(L"Ex3 Protocol Status %r\n", Status);
Argc = EfiShellParametersProtocol->Argc;
Argv = EfiShellParametersProtocol->Argv;
// Judgment input value
if(Argc>1||Argc<5) {
for (Index = 1; Index < Argc; Index++) {
Print(L"Arg[%d]= %s \n", Index, *(Argv + Index));
Value[Index] = StrHexToUintn(*(Argv + Index));
Print(L"Data = %2X %2c %d %s\n", Value[Index], Value[Index],
Value[Index] );
}
}
switch (Argc) {
case 1:
Print(L"-map [Get Memory Map]\n");
Print(L"-page NUM_type size [Allocate memory Page & decide size and
type\n");
Print(L"-pool NUM_type size [Allocate memory pool & decide size and
type\n");
Print(L"-dump address [Dump specific memory address region (256
bytes)\n");
Print(L"-write address value[Dump specific memory address region (256
bytes)\n");
PrintNUMType();
break;
case 2:
case 3:
case 4:
Print(L"Tool text\n");
break;
default:
Print(L"ERROR\n");
break;
}
return Status;
}
作者: peterbrucele (DM5)   2023-02-03 16:04:00
為什麼要用CHAR16?
作者: tacoq (章魚Q)   2023-02-03 16:44:00
error message?
作者: ssdoz2sk (眷戀著提拉米蘇的風采~)   2023-02-04 17:37:00
幫回一樓,因為 EFI SHELL 輸出是寬字元,這樣就不用經過轉換。然後你 if (Argc>1||Argc<5) 的判斷式怪怪的錯誤訊息請給出來,如果可以,請連 inf 一起 PO 出來
作者: alan23273850   2023-02-04 22:16:00
樓上那個判斷式恆真吧
作者: ssdoz2sk (眷戀著提拉米蘇的風采~)   2023-02-05 21:16:00
樓上,對的,所以才說有問題剛才build了一下你的 code ,除了把 line32 的 Print =>修改一下外,沒動過其他 code 是 Build 成功的,如果是link error 的話,請檢查你的 inf 用到的 Protocols有沒有加上去,或是缺少相關的 Packages/LibraryClasses
作者: fatalfeel2 (風在動)   2023-03-19 01:56:00
宣告成char 使用時再轉成unicode 一定可以
作者: ssdoz2sk (眷戀著提拉米蘇的風采~)   2023-03-26 01:25:00
Edk2 的 Codebase 有 AsciiStrToUnicodeStrS 可以使用阿,但空間足夠時,為啥不用簡便的方式,一開始就宣告成可以直接輸出的 type 就好?

Links booklink

Contact Us: admin [ a t ] ucptt.com