[问题] 呼叫字串阵列并输出

楼主: 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