utbuffer.c revision 1.1.1.9 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: utbuffer - Buffer dump routines
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.8 christos * Copyright (C) 2000 - 2018, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "acpi.h"
45 1.1 christos #include "accommon.h"
46 1.1 christos
47 1.1 christos #define _COMPONENT ACPI_UTILITIES
48 1.1 christos ACPI_MODULE_NAME ("utbuffer")
49 1.1 christos
50 1.1 christos
51 1.1 christos /*******************************************************************************
52 1.1 christos *
53 1.1 christos * FUNCTION: AcpiUtDumpBuffer
54 1.1 christos *
55 1.1 christos * PARAMETERS: Buffer - Buffer to dump
56 1.1 christos * Count - Amount to dump, in bytes
57 1.1 christos * Display - BYTE, WORD, DWORD, or QWORD display:
58 1.1 christos * DB_BYTE_DISPLAY
59 1.1 christos * DB_WORD_DISPLAY
60 1.1 christos * DB_DWORD_DISPLAY
61 1.1 christos * DB_QWORD_DISPLAY
62 1.1 christos * BaseOffset - Beginning buffer offset (display only)
63 1.1 christos *
64 1.1 christos * RETURN: None
65 1.1 christos *
66 1.1 christos * DESCRIPTION: Generic dump buffer in both hex and ascii.
67 1.1 christos *
68 1.1 christos ******************************************************************************/
69 1.1 christos
70 1.1 christos void
71 1.1 christos AcpiUtDumpBuffer (
72 1.1 christos UINT8 *Buffer,
73 1.1 christos UINT32 Count,
74 1.1 christos UINT32 Display,
75 1.1 christos UINT32 BaseOffset)
76 1.1 christos {
77 1.1 christos UINT32 i = 0;
78 1.1 christos UINT32 j;
79 1.1 christos UINT32 Temp32;
80 1.1 christos UINT8 BufChar;
81 1.1 christos
82 1.1 christos
83 1.1 christos if (!Buffer)
84 1.1 christos {
85 1.1 christos AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");
86 1.1 christos return;
87 1.1 christos }
88 1.1 christos
89 1.1 christos if ((Count < 4) || (Count & 0x01))
90 1.1 christos {
91 1.1 christos Display = DB_BYTE_DISPLAY;
92 1.1 christos }
93 1.1 christos
94 1.1 christos /* Nasty little dump buffer routine! */
95 1.1 christos
96 1.1 christos while (i < Count)
97 1.1 christos {
98 1.1 christos /* Print current offset */
99 1.1 christos
100 1.1.1.9 christos AcpiOsPrintf ("%8.4X: ", (BaseOffset + i));
101 1.1 christos
102 1.1 christos /* Print 16 hex chars */
103 1.1 christos
104 1.1 christos for (j = 0; j < 16;)
105 1.1 christos {
106 1.1 christos if (i + j >= Count)
107 1.1 christos {
108 1.1 christos /* Dump fill spaces */
109 1.1 christos
110 1.1 christos AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");
111 1.1 christos j += Display;
112 1.1 christos continue;
113 1.1 christos }
114 1.1 christos
115 1.1 christos switch (Display)
116 1.1 christos {
117 1.1 christos case DB_BYTE_DISPLAY:
118 1.1 christos default: /* Default is BYTE display */
119 1.1 christos
120 1.1 christos AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);
121 1.1 christos break;
122 1.1 christos
123 1.1 christos case DB_WORD_DISPLAY:
124 1.1 christos
125 1.1 christos ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
126 1.1 christos AcpiOsPrintf ("%04X ", Temp32);
127 1.1 christos break;
128 1.1 christos
129 1.1 christos case DB_DWORD_DISPLAY:
130 1.1 christos
131 1.1 christos ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
132 1.1 christos AcpiOsPrintf ("%08X ", Temp32);
133 1.1 christos break;
134 1.1 christos
135 1.1 christos case DB_QWORD_DISPLAY:
136 1.1 christos
137 1.1 christos ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
138 1.1 christos AcpiOsPrintf ("%08X", Temp32);
139 1.1 christos
140 1.1 christos ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
141 1.1 christos AcpiOsPrintf ("%08X ", Temp32);
142 1.1 christos break;
143 1.1 christos }
144 1.1 christos
145 1.1 christos j += Display;
146 1.1 christos }
147 1.1 christos
148 1.1 christos /*
149 1.1 christos * Print the ASCII equivalent characters but watch out for the bad
150 1.1 christos * unprintable ones (printable chars are 0x20 through 0x7E)
151 1.1 christos */
152 1.1 christos AcpiOsPrintf (" ");
153 1.1 christos for (j = 0; j < 16; j++)
154 1.1 christos {
155 1.1 christos if (i + j >= Count)
156 1.1 christos {
157 1.1 christos AcpiOsPrintf ("\n");
158 1.1 christos return;
159 1.1 christos }
160 1.1 christos
161 1.1.1.3 christos /*
162 1.1.1.3 christos * Add comment characters so rest of line is ignored when
163 1.1.1.3 christos * compiled
164 1.1.1.3 christos */
165 1.1.1.3 christos if (j == 0)
166 1.1.1.3 christos {
167 1.1.1.3 christos AcpiOsPrintf ("// ");
168 1.1.1.3 christos }
169 1.1.1.3 christos
170 1.1 christos BufChar = Buffer[(ACPI_SIZE) i + j];
171 1.1.1.4 christos if (isprint (BufChar))
172 1.1 christos {
173 1.1 christos AcpiOsPrintf ("%c", BufChar);
174 1.1 christos }
175 1.1 christos else
176 1.1 christos {
177 1.1 christos AcpiOsPrintf (".");
178 1.1 christos }
179 1.1 christos }
180 1.1 christos
181 1.1 christos /* Done with that line. */
182 1.1 christos
183 1.1 christos AcpiOsPrintf ("\n");
184 1.1 christos i += 16;
185 1.1 christos }
186 1.1 christos
187 1.1 christos return;
188 1.1 christos }
189 1.1 christos
190 1.1 christos
191 1.1 christos /*******************************************************************************
192 1.1 christos *
193 1.1 christos * FUNCTION: AcpiUtDebugDumpBuffer
194 1.1 christos *
195 1.1 christos * PARAMETERS: Buffer - Buffer to dump
196 1.1 christos * Count - Amount to dump, in bytes
197 1.1 christos * Display - BYTE, WORD, DWORD, or QWORD display:
198 1.1 christos * DB_BYTE_DISPLAY
199 1.1 christos * DB_WORD_DISPLAY
200 1.1 christos * DB_DWORD_DISPLAY
201 1.1 christos * DB_QWORD_DISPLAY
202 1.1 christos * ComponentID - Caller's component ID
203 1.1 christos *
204 1.1 christos * RETURN: None
205 1.1 christos *
206 1.1 christos * DESCRIPTION: Generic dump buffer in both hex and ascii.
207 1.1 christos *
208 1.1 christos ******************************************************************************/
209 1.1 christos
210 1.1 christos void
211 1.1 christos AcpiUtDebugDumpBuffer (
212 1.1 christos UINT8 *Buffer,
213 1.1 christos UINT32 Count,
214 1.1 christos UINT32 Display,
215 1.1 christos UINT32 ComponentId)
216 1.1 christos {
217 1.1 christos
218 1.1 christos /* Only dump the buffer if tracing is enabled */
219 1.1 christos
220 1.1 christos if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&
221 1.1 christos (ComponentId & AcpiDbgLayer)))
222 1.1 christos {
223 1.1 christos return;
224 1.1 christos }
225 1.1 christos
226 1.1 christos AcpiUtDumpBuffer (Buffer, Count, Display, 0);
227 1.1 christos }
228 1.1.1.2 christos
229 1.1.1.2 christos
230 1.1.1.2 christos #ifdef ACPI_APPLICATION
231 1.1.1.2 christos /*******************************************************************************
232 1.1.1.2 christos *
233 1.1.1.2 christos * FUNCTION: AcpiUtDumpBufferToFile
234 1.1.1.2 christos *
235 1.1.1.2 christos * PARAMETERS: File - File descriptor
236 1.1.1.2 christos * Buffer - Buffer to dump
237 1.1.1.2 christos * Count - Amount to dump, in bytes
238 1.1.1.2 christos * Display - BYTE, WORD, DWORD, or QWORD display:
239 1.1.1.2 christos * DB_BYTE_DISPLAY
240 1.1.1.2 christos * DB_WORD_DISPLAY
241 1.1.1.2 christos * DB_DWORD_DISPLAY
242 1.1.1.2 christos * DB_QWORD_DISPLAY
243 1.1.1.2 christos * BaseOffset - Beginning buffer offset (display only)
244 1.1.1.2 christos *
245 1.1.1.2 christos * RETURN: None
246 1.1.1.2 christos *
247 1.1.1.2 christos * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
248 1.1.1.2 christos *
249 1.1.1.2 christos ******************************************************************************/
250 1.1.1.2 christos
251 1.1.1.2 christos void
252 1.1.1.2 christos AcpiUtDumpBufferToFile (
253 1.1.1.2 christos ACPI_FILE File,
254 1.1.1.2 christos UINT8 *Buffer,
255 1.1.1.2 christos UINT32 Count,
256 1.1.1.2 christos UINT32 Display,
257 1.1.1.2 christos UINT32 BaseOffset)
258 1.1.1.2 christos {
259 1.1.1.2 christos UINT32 i = 0;
260 1.1.1.2 christos UINT32 j;
261 1.1.1.2 christos UINT32 Temp32;
262 1.1.1.2 christos UINT8 BufChar;
263 1.1.1.2 christos
264 1.1.1.2 christos
265 1.1.1.2 christos if (!Buffer)
266 1.1.1.2 christos {
267 1.1.1.6 christos fprintf (File, "Null Buffer Pointer in DumpBuffer!\n");
268 1.1.1.2 christos return;
269 1.1.1.2 christos }
270 1.1.1.2 christos
271 1.1.1.2 christos if ((Count < 4) || (Count & 0x01))
272 1.1.1.2 christos {
273 1.1.1.2 christos Display = DB_BYTE_DISPLAY;
274 1.1.1.2 christos }
275 1.1.1.2 christos
276 1.1.1.2 christos /* Nasty little dump buffer routine! */
277 1.1.1.2 christos
278 1.1.1.2 christos while (i < Count)
279 1.1.1.2 christos {
280 1.1.1.2 christos /* Print current offset */
281 1.1.1.2 christos
282 1.1.1.9 christos fprintf (File, "%8.4X: ", (BaseOffset + i));
283 1.1.1.2 christos
284 1.1.1.2 christos /* Print 16 hex chars */
285 1.1.1.2 christos
286 1.1.1.2 christos for (j = 0; j < 16;)
287 1.1.1.2 christos {
288 1.1.1.2 christos if (i + j >= Count)
289 1.1.1.2 christos {
290 1.1.1.2 christos /* Dump fill spaces */
291 1.1.1.2 christos
292 1.1.1.6 christos fprintf (File, "%*s", ((Display * 2) + 1), " ");
293 1.1.1.2 christos j += Display;
294 1.1.1.2 christos continue;
295 1.1.1.2 christos }
296 1.1.1.2 christos
297 1.1.1.2 christos switch (Display)
298 1.1.1.2 christos {
299 1.1.1.2 christos case DB_BYTE_DISPLAY:
300 1.1.1.2 christos default: /* Default is BYTE display */
301 1.1.1.2 christos
302 1.1.1.6 christos fprintf (File, "%02X ", Buffer[(ACPI_SIZE) i + j]);
303 1.1.1.2 christos break;
304 1.1.1.2 christos
305 1.1.1.2 christos case DB_WORD_DISPLAY:
306 1.1.1.2 christos
307 1.1.1.2 christos ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
308 1.1.1.6 christos fprintf (File, "%04X ", Temp32);
309 1.1.1.2 christos break;
310 1.1.1.2 christos
311 1.1.1.2 christos case DB_DWORD_DISPLAY:
312 1.1.1.2 christos
313 1.1.1.2 christos ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
314 1.1.1.6 christos fprintf (File, "%08X ", Temp32);
315 1.1.1.2 christos break;
316 1.1.1.2 christos
317 1.1.1.2 christos case DB_QWORD_DISPLAY:
318 1.1.1.2 christos
319 1.1.1.2 christos ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
320 1.1.1.6 christos fprintf (File, "%08X", Temp32);
321 1.1.1.2 christos
322 1.1.1.2 christos ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
323 1.1.1.6 christos fprintf (File, "%08X ", Temp32);
324 1.1.1.2 christos break;
325 1.1.1.2 christos }
326 1.1.1.2 christos
327 1.1.1.2 christos j += Display;
328 1.1.1.2 christos }
329 1.1.1.2 christos
330 1.1.1.2 christos /*
331 1.1.1.2 christos * Print the ASCII equivalent characters but watch out for the bad
332 1.1.1.2 christos * unprintable ones (printable chars are 0x20 through 0x7E)
333 1.1.1.2 christos */
334 1.1.1.6 christos fprintf (File, " ");
335 1.1.1.2 christos for (j = 0; j < 16; j++)
336 1.1.1.2 christos {
337 1.1.1.2 christos if (i + j >= Count)
338 1.1.1.2 christos {
339 1.1.1.6 christos fprintf (File, "\n");
340 1.1.1.2 christos return;
341 1.1.1.2 christos }
342 1.1.1.2 christos
343 1.1.1.2 christos BufChar = Buffer[(ACPI_SIZE) i + j];
344 1.1.1.4 christos if (isprint (BufChar))
345 1.1.1.2 christos {
346 1.1.1.6 christos fprintf (File, "%c", BufChar);
347 1.1.1.2 christos }
348 1.1.1.2 christos else
349 1.1.1.2 christos {
350 1.1.1.6 christos fprintf (File, ".");
351 1.1.1.2 christos }
352 1.1.1.2 christos }
353 1.1.1.2 christos
354 1.1.1.2 christos /* Done with that line. */
355 1.1.1.2 christos
356 1.1.1.6 christos fprintf (File, "\n");
357 1.1.1.2 christos i += 16;
358 1.1.1.2 christos }
359 1.1.1.2 christos
360 1.1.1.2 christos return;
361 1.1.1.2 christos }
362 1.1.1.2 christos #endif
363