Fix the bug that debug output fails to print hex value to screen. Remove module internal SPrint() and use UnicodeSPrintAsciiFormat() in print library instead.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8057 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2009-04-10 06:52:02 +00:00
parent c41c3e55d5
commit f05b1c14ec

View File

@ -543,88 +543,6 @@ DumpExceptionDataDebugOut (
} }
#endif #endif
UINTN
SPrint (
IN OUT CHAR16 *Buffer,
IN CONST CHAR16 *Format,
...
)
{
VA_LIST Marker;
UINTN Index;
UINTN Flags;
UINTN Width;
UINT64 Value;
VA_START (Marker, Format);
//
// Process the format string. Stop if Buffer is over run.
//
for (Index = 0; *Format != 0; Format++) {
if (*Format != L'%') {
Buffer[Index++] = *Format;
} else {
//
// Now it's time to parse what follows after %
// Support: % [ 0 width ] [ l ] x
// width - fill 0, to ensure the width of x will be "width"
// l - UINT64 instead of UINT32
//
Width = 0;
Flags = 0;
Format ++;
if (*Format == L'0') {
Flags |= PREFIX_ZERO;
do {
Width += Width * 10 + (*Format - L'0');
Format ++;
} while (*Format >= L'1' && *Format <= L'9');
}
if (*Format == L'l') {
Flags |= LONG_TYPE;
Format ++;
}
switch (*Format) {
case 'X':
Flags |= PREFIX_ZERO;
Width = sizeof (UINT64) * 2;
//
// break skiped on purpose
//
case 'x':
if ((Flags & LONG_TYPE) == LONG_TYPE) {
Value = VA_ARG (Marker, UINT64);
} else {
Value = VA_ARG (Marker, UINTN);
}
UnicodeValueToString (Buffer+Index, Flags, Value, Width);
for ( ; Buffer[Index] != L'\0'; Index ++) {
}
break;
default:
//
// if the type is unknown print it to the screen
//
Buffer[Index++] = *Format;
}
}
}
Buffer[Index++] = '\0';
VA_END (Marker);
return Index;
}
VOID VOID
DumpExceptionDataVgaOut ( DumpExceptionDataVgaOut (
@ -646,31 +564,35 @@ DumpExceptionDataVgaOut (
VideoBuffer = (CHAR16 *) (UINTN) 0xb8000; VideoBuffer = (CHAR16 *) (UINTN) 0xb8000;
#ifdef EFI32 #ifdef EFI32
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"!!!! IA32 Exception Type - %08x !!!!", COLUMN_MAX * sizeof (CHAR16),
"!!!! IA32 Exception Type - %08x !!!!",
InterruptType InterruptType
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"EIP - %08x, CS - %08x, EFLAGS - %08x", COLUMN_MAX * sizeof (CHAR16),
"EIP - %08x, CS - %08x, EFLAGS - %08x",
SystemContext.SystemContextIa32->Eip, SystemContext.SystemContextIa32->Eip,
SystemContext.SystemContextIa32->Cs, SystemContext.SystemContextIa32->Cs,
SystemContext.SystemContextIa32->Eflags SystemContext.SystemContextIa32->Eflags
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
if (ErrorCodeFlag & (1 << InterruptType)) { if (ErrorCodeFlag & (1 << InterruptType)) {
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"ExceptionData - %08x", COLUMN_MAX * sizeof (CHAR16),
"ExceptionData - %08x",
SystemContext.SystemContextIa32->ExceptionData SystemContext.SystemContextIa32->ExceptionData
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
} }
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x", COLUMN_MAX * sizeof (CHAR16),
"EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x",
SystemContext.SystemContextIa32->Eax, SystemContext.SystemContextIa32->Eax,
SystemContext.SystemContextIa32->Ecx, SystemContext.SystemContextIa32->Ecx,
SystemContext.SystemContextIa32->Edx, SystemContext.SystemContextIa32->Edx,
@ -678,9 +600,10 @@ DumpExceptionDataVgaOut (
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x", COLUMN_MAX * sizeof (CHAR16),
"ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x",
SystemContext.SystemContextIa32->Esp, SystemContext.SystemContextIa32->Esp,
SystemContext.SystemContextIa32->Ebp, SystemContext.SystemContextIa32->Ebp,
SystemContext.SystemContextIa32->Esi, SystemContext.SystemContextIa32->Esi,
@ -688,9 +611,10 @@ DumpExceptionDataVgaOut (
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x", COLUMN_MAX * sizeof (CHAR16),
"DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x",
SystemContext.SystemContextIa32->Ds, SystemContext.SystemContextIa32->Ds,
SystemContext.SystemContextIa32->Es, SystemContext.SystemContextIa32->Es,
SystemContext.SystemContextIa32->Fs, SystemContext.SystemContextIa32->Fs,
@ -699,9 +623,10 @@ DumpExceptionDataVgaOut (
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"GDTR - %08x %08x, IDTR - %08x %08x", COLUMN_MAX * sizeof (CHAR16),
"GDTR - %08x %08x, IDTR - %08x %08x",
SystemContext.SystemContextIa32->Gdtr[0], SystemContext.SystemContextIa32->Gdtr[0],
SystemContext.SystemContextIa32->Gdtr[1], SystemContext.SystemContextIa32->Gdtr[1],
SystemContext.SystemContextIa32->Idtr[0], SystemContext.SystemContextIa32->Idtr[0],
@ -709,17 +634,19 @@ DumpExceptionDataVgaOut (
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"LDTR - %08x, TR - %08x", COLUMN_MAX * sizeof (CHAR16),
"LDTR - %08x, TR - %08x",
SystemContext.SystemContextIa32->Ldtr, SystemContext.SystemContextIa32->Ldtr,
SystemContext.SystemContextIa32->Tr SystemContext.SystemContextIa32->Tr
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x", COLUMN_MAX * sizeof (CHAR16),
"CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x",
SystemContext.SystemContextIa32->Cr0, SystemContext.SystemContextIa32->Cr0,
SystemContext.SystemContextIa32->Cr2, SystemContext.SystemContextIa32->Cr2,
SystemContext.SystemContextIa32->Cr3, SystemContext.SystemContextIa32->Cr3,
@ -727,9 +654,10 @@ DumpExceptionDataVgaOut (
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x", COLUMN_MAX * sizeof (CHAR16),
"DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x",
SystemContext.SystemContextIa32->Dr0, SystemContext.SystemContextIa32->Dr0,
SystemContext.SystemContextIa32->Dr1, SystemContext.SystemContextIa32->Dr1,
SystemContext.SystemContextIa32->Dr2, SystemContext.SystemContextIa32->Dr2,
@ -737,24 +665,27 @@ DumpExceptionDataVgaOut (
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"DR6 - %08x, DR7 - %08x", COLUMN_MAX * sizeof (CHAR16),
"DR6 - %08x, DR7 - %08x",
SystemContext.SystemContextIa32->Dr6, SystemContext.SystemContextIa32->Dr6,
SystemContext.SystemContextIa32->Dr7 SystemContext.SystemContextIa32->Dr7
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
#else #else
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"!!!! X64 Exception Type - %016lx !!!!", COLUMN_MAX * sizeof (CHAR16),
"!!!! X64 Exception Type - %016lx !!!!",
(UINT64)InterruptType (UINT64)InterruptType
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"RIP - %016lx, CS - %016lx, RFLAGS - %016lx", COLUMN_MAX * sizeof (CHAR16),
"RIP - %016lx, CS - %016lx, RFLAGS - %016lx",
SystemContext.SystemContextX64->Rip, SystemContext.SystemContextX64->Rip,
SystemContext.SystemContextX64->Cs, SystemContext.SystemContextX64->Cs,
SystemContext.SystemContextX64->Rflags SystemContext.SystemContextX64->Rflags
@ -762,130 +693,145 @@ DumpExceptionDataVgaOut (
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
if (ErrorCodeFlag & (1 << InterruptType)) { if (ErrorCodeFlag & (1 << InterruptType)) {
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"ExceptionData - %016lx", COLUMN_MAX * sizeof (CHAR16),
"ExceptionData - %016lx",
SystemContext.SystemContextX64->ExceptionData SystemContext.SystemContextX64->ExceptionData
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
} }
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"RAX - %016lx, RCX - %016lx, RDX - %016lx", COLUMN_MAX * sizeof (CHAR16),
"RAX - %016lx, RCX - %016lx, RDX - %016lx",
SystemContext.SystemContextX64->Rax, SystemContext.SystemContextX64->Rax,
SystemContext.SystemContextX64->Rcx, SystemContext.SystemContextX64->Rcx,
SystemContext.SystemContextX64->Rdx SystemContext.SystemContextX64->Rdx
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"RBX - %016lx, RSP - %016lx, RBP - %016lx", COLUMN_MAX * sizeof (CHAR16),
"RBX - %016lx, RSP - %016lx, RBP - %016lx",
SystemContext.SystemContextX64->Rbx, SystemContext.SystemContextX64->Rbx,
SystemContext.SystemContextX64->Rsp, SystemContext.SystemContextX64->Rsp,
SystemContext.SystemContextX64->Rbp SystemContext.SystemContextX64->Rbp
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"RSI - %016lx, RDI - %016lx", COLUMN_MAX * sizeof (CHAR16),
"RSI - %016lx, RDI - %016lx",
SystemContext.SystemContextX64->Rsi, SystemContext.SystemContextX64->Rsi,
SystemContext.SystemContextX64->Rdi SystemContext.SystemContextX64->Rdi
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"R8 - %016lx, R9 - %016lx, R10 - %016lx", COLUMN_MAX * sizeof (CHAR16),
"R8 - %016lx, R9 - %016lx, R10 - %016lx",
SystemContext.SystemContextX64->R8, SystemContext.SystemContextX64->R8,
SystemContext.SystemContextX64->R9, SystemContext.SystemContextX64->R9,
SystemContext.SystemContextX64->R10 SystemContext.SystemContextX64->R10
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"R11 - %016lx, R12 - %016lx, R13 - %016lx", COLUMN_MAX * sizeof (CHAR16),
"R11 - %016lx, R12 - %016lx, R13 - %016lx",
SystemContext.SystemContextX64->R11, SystemContext.SystemContextX64->R11,
SystemContext.SystemContextX64->R12, SystemContext.SystemContextX64->R12,
SystemContext.SystemContextX64->R13 SystemContext.SystemContextX64->R13
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"R14 - %016lx, R15 - %016lx", COLUMN_MAX * sizeof (CHAR16),
"R14 - %016lx, R15 - %016lx",
SystemContext.SystemContextX64->R14, SystemContext.SystemContextX64->R14,
SystemContext.SystemContextX64->R15 SystemContext.SystemContextX64->R15
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"DS - %016lx, ES - %016lx, FS - %016lx", COLUMN_MAX * sizeof (CHAR16),
"DS - %016lx, ES - %016lx, FS - %016lx",
SystemContext.SystemContextX64->Ds, SystemContext.SystemContextX64->Ds,
SystemContext.SystemContextX64->Es, SystemContext.SystemContextX64->Es,
SystemContext.SystemContextX64->Fs SystemContext.SystemContextX64->Fs
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"GS - %016lx, SS - %016lx", COLUMN_MAX * sizeof (CHAR16),
"GS - %016lx, SS - %016lx",
SystemContext.SystemContextX64->Gs, SystemContext.SystemContextX64->Gs,
SystemContext.SystemContextX64->Ss SystemContext.SystemContextX64->Ss
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"GDTR - %016lx %016lx, LDTR - %016lx", COLUMN_MAX * sizeof (CHAR16),
"GDTR - %016lx %016lx, LDTR - %016lx",
SystemContext.SystemContextX64->Gdtr[0], SystemContext.SystemContextX64->Gdtr[0],
SystemContext.SystemContextX64->Gdtr[1], SystemContext.SystemContextX64->Gdtr[1],
SystemContext.SystemContextX64->Ldtr SystemContext.SystemContextX64->Ldtr
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"IDTR - %016lx %016lx, TR - %016lx", COLUMN_MAX * sizeof (CHAR16),
"IDTR - %016lx %016lx, TR - %016lx",
SystemContext.SystemContextX64->Idtr[0], SystemContext.SystemContextX64->Idtr[0],
SystemContext.SystemContextX64->Idtr[1], SystemContext.SystemContextX64->Idtr[1],
SystemContext.SystemContextX64->Tr SystemContext.SystemContextX64->Tr
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"CR0 - %016lx, CR2 - %016lx, CR3 - %016lx", COLUMN_MAX * sizeof (CHAR16),
"CR0 - %016lx, CR2 - %016lx, CR3 - %016lx",
SystemContext.SystemContextX64->Cr0, SystemContext.SystemContextX64->Cr0,
SystemContext.SystemContextX64->Cr2, SystemContext.SystemContextX64->Cr2,
SystemContext.SystemContextX64->Cr3 SystemContext.SystemContextX64->Cr3
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"CR4 - %016lx, CR8 - %016lx", COLUMN_MAX * sizeof (CHAR16),
"CR4 - %016lx, CR8 - %016lx",
SystemContext.SystemContextX64->Cr4, SystemContext.SystemContextX64->Cr4,
SystemContext.SystemContextX64->Cr8 SystemContext.SystemContextX64->Cr8
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"DR0 - %016lx, DR1 - %016lx, DR2 - %016lx", COLUMN_MAX * sizeof (CHAR16),
"DR0 - %016lx, DR1 - %016lx, DR2 - %016lx",
SystemContext.SystemContextX64->Dr0, SystemContext.SystemContextX64->Dr0,
SystemContext.SystemContextX64->Dr1, SystemContext.SystemContextX64->Dr1,
SystemContext.SystemContextX64->Dr2 SystemContext.SystemContextX64->Dr2
); );
VideoBuffer += COLUMN_MAX; VideoBuffer += COLUMN_MAX;
SPrint ( UnicodeSPrintAsciiFormat (
VideoBuffer, VideoBuffer,
L"DR3 - %016lx, DR6 - %016lx, DR7 - %016lx", COLUMN_MAX * sizeof (CHAR16),
"DR3 - %016lx, DR6 - %016lx, DR7 - %016lx",
SystemContext.SystemContextX64->Dr3, SystemContext.SystemContextX64->Dr3,
SystemContext.SystemContextX64->Dr6, SystemContext.SystemContextX64->Dr6,
SystemContext.SystemContextX64->Dr7 SystemContext.SystemContextX64->Dr7