作者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://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1675408894.A.CBA.html
1F:推 peterbrucele: 为什麽要用CHAR16? 02/03 16:04
2F:→ tacoq: error message? 02/03 16:44
3F:→ ssdoz2sk: 帮回一楼,因为 EFI SHELL 输出是宽字元,这样就不用经 02/04 17:37
4F:→ ssdoz2sk: 过转换。 02/04 17:37
5F:→ ssdoz2sk: 然後你 if (Argc>1||Argc<5) 的判断式怪怪的 02/04 17:38
6F:→ ssdoz2sk: 错误讯息请给出来,如果可以,请连 inf 一起 PO 出来 02/04 17:40
7F:推 alan23273850: 楼上那个判断式恒真吧 02/04 22:16
8F:→ ssdoz2sk: 楼上,对的,所以才说有问题 02/05 21:16
9F:→ ssdoz2sk: 刚才build了一下你的 code ,除了把 line32 的 Print => 02/05 21:18
10F:→ ssdoz2sk: 修改一下外,没动过其他 code 是 Build 成功的,如果是 02/05 21:20
11F:→ ssdoz2sk: link error 的话,请检查你的 inf 用到的 Protocols 02/05 21:20
12F:→ ssdoz2sk: 有没有加上去,或是缺少相关的 Packages/LibraryClasses 02/05 21:21
13F:推 fatalfeel2: 宣告成char 使用时再转成unicode 一定可以 03/19 01:56
14F:→ ssdoz2sk: Edk2 的 Codebase 有 AsciiStrToUnicodeStrS 可以使用阿 03/26 01:25
15F:→ ssdoz2sk: ,但空间足够时,为啥不用简便的方式,一开始就宣告成可 03/26 01:26
16F:→ ssdoz2sk: 以直接输出的 type 就好? 03/26 01:26