作者devcc (凱西)
看板C_and_CPP
標題[問題] 呼叫字串陣列並輸出
時間Fri Feb 3 15:21:30 2023
最近在學習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;
}
--
有沒有準備好我不知道,
但我已經做了我最好的選擇。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.51.167.201 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1675408894.A.CBA.html
推 peterbrucele: 為什麼要用CHAR16? 02/03 16:04
→ tacoq: error message? 02/03 16:44
→ ssdoz2sk: 幫回一樓,因為 EFI SHELL 輸出是寬字元,這樣就不用經 02/04 17:37
→ ssdoz2sk: 過轉換。 02/04 17:37
→ ssdoz2sk: 然後你 if (Argc>1||Argc<5) 的判斷式怪怪的 02/04 17:38
→ ssdoz2sk: 錯誤訊息請給出來,如果可以,請連 inf 一起 PO 出來 02/04 17:40
推 alan23273850: 樓上那個判斷式恆真吧 02/04 22:16
→ ssdoz2sk: 樓上,對的,所以才說有問題 02/05 21:16
→ ssdoz2sk: 剛才build了一下你的 code ,除了把 line32 的 Print => 02/05 21:18
→ ssdoz2sk: 修改一下外,沒動過其他 code 是 Build 成功的,如果是 02/05 21:20
→ ssdoz2sk: link error 的話,請檢查你的 inf 用到的 Protocols 02/05 21:20
→ ssdoz2sk: 有沒有加上去,或是缺少相關的 Packages/LibraryClasses 02/05 21:21
推 fatalfeel2: 宣告成char 使用時再轉成unicode 一定可以 03/19 01:56
→ ssdoz2sk: Edk2 的 Codebase 有 AsciiStrToUnicodeStrS 可以使用阿 03/26 01:25
→ ssdoz2sk: ,但空間足夠時,為啥不用簡便的方式,一開始就宣告成可 03/26 01:26
→ ssdoz2sk: 以直接輸出的 type 就好? 03/26 01:26