a4c82e2cb05abeb734326b90bc0ba14c57b4558c
[reactos.git] / boot / environ / lib / misc / debug.c
1 /*
2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/misc/debug.c
5 * PURPOSE: Boot Library Debug Routines
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "bl.h"
12
13 /* DATA VARIABLES ************************************************************/
14
15 CHAR AnsiBuffer[1024];
16 BOOLEAN BdDebuggerNotPresent;
17 BOOLEAN BdSubsystemInitialized;
18 BOOLEAN BdArchBlockDebuggerOperation;
19
20 /* FUNCTIONS *****************************************************************/
21
22 BOOLEAN
23 BdDebuggerInitialized (
24 VOID
25 )
26 {
27 /* Check if BD was initialized, and is currently usable */
28 return BdSubsystemInitialized && !BdArchBlockDebuggerOperation;
29 }
30
31 NTSTATUS
32 BlBdPullRemoteFile (
33 _In_ PWCHAR FilePath,
34 _Out_ PVOID BaseAddress,
35 _Out_ PULONGLONG FileSize
36 )
37 {
38 /* Is the boot debugger enabled? */
39 if (!BlBdDebuggerEnabled())
40 {
41 /* Nothing to pull */
42 return STATUS_DEBUGGER_INACTIVE;
43 }
44
45 /* TODO */
46 EfiPrintf(L"Todo\r\n");
47 return STATUS_NOT_IMPLEMENTED;
48 }
49
50 BOOLEAN
51 BlBdDebuggerEnabled (
52 VOID
53 )
54 {
55 BOOLEAN Initialized, Enabled;
56
57 /* Check if the debugger is initialized */
58 Initialized = BdDebuggerInitialized();
59
60 /* Check if it's currently active */
61 Enabled = FALSE;
62 if ((Initialized) && !(BdDebuggerNotPresent))
63 {
64 /* Yep! */
65 Enabled = TRUE;
66 }
67
68 /* Return enabled state */
69 return Enabled;
70 }
71
72 VOID
73 BlStatusPrint (
74 _In_ PCWCH Format,
75 ...
76 )
77 {
78 ANSI_STRING AnsiString;
79 UNICODE_STRING UnicodeString;
80 va_list va;
81 NTSTATUS Status;
82
83 va_start(va, Format);
84
85 /* Check if the boot debugger is enabled */
86 if (BlBdDebuggerEnabled()
87 #if (defined(DBG))
88 || TRUE
89 #endif
90 )
91 {
92 /* Print the string out into a buffer */
93 if (vswprintf(BlScratchBuffer, Format, va) > 0)
94 {
95 #if defined(DBG)
96 EfiPrintf(BlScratchBuffer);
97 EfiPrintf(L"\r\n");
98 #endif
99 /* Make it a UNICODE_STRING */
100 RtlInitUnicodeString(&UnicodeString, BlScratchBuffer);
101
102 /* Then convert it into an ANSI_STRING */
103 AnsiString.Length = 0;
104 AnsiString.MaximumLength = sizeof(AnsiBuffer);
105 AnsiString.Buffer = AnsiBuffer;
106 Status = RtlUnicodeStringToAnsiString(&AnsiString, &UnicodeString, FALSE);
107 if (NT_SUCCESS(Status))
108 {
109 /* Print it out to the debugger if that worked */
110 DbgPrint(AnsiString.Buffer);
111 }
112 }
113 }
114
115 va_end(va);
116 }
117
118 VOID
119 BlStatusError (
120 _In_ ULONG ErrorCode,
121 _In_ ULONG Parameter1,
122 _In_ ULONG_PTR Parameter2,
123 _In_ ULONG_PTR Parameter3,
124 _In_ ULONG_PTR Parameter4
125 )
126 {
127 /* Check if the boot debugger is enabled */
128 if (BlBdDebuggerEnabled())
129 {
130 /* Print out the fatal error */
131 BlStatusPrint(L"\n"
132 L"*** Fatal Error 0x%08x :\n"
133 L" (0x%p, 0x%p, 0x%p, 0x%p)\n"
134 L"\n",
135 ErrorCode,
136 Parameter1,
137 Parameter2,
138 Parameter3,
139 Parameter4);
140
141 /* Issue a breakpoint */
142 __debugbreak();
143 }
144 }
145