dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / acpi / acpidump / utbuffer.c
blob2f97c647715510adb8728c386db9c11ae7944a34
1 /******************************************************************************
3 * Module Name: utbuffer - Buffer dump routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "acpi.h"
45 #include "accommon.h"
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utbuffer")
51 /*******************************************************************************
53 * FUNCTION: AcpiUtDumpBuffer
55 * PARAMETERS: Buffer - Buffer to dump
56 * Count - Amount to dump, in bytes
57 * Display - BYTE, WORD, DWORD, or QWORD display:
58 * DB_BYTE_DISPLAY
59 * DB_WORD_DISPLAY
60 * DB_DWORD_DISPLAY
61 * DB_QWORD_DISPLAY
62 * BaseOffset - Beginning buffer offset (display only)
64 * RETURN: None
66 * DESCRIPTION: Generic dump buffer in both hex and ascii.
68 ******************************************************************************/
70 void
71 AcpiUtDumpBuffer (
72 UINT8 *Buffer,
73 UINT32 Count,
74 UINT32 Display,
75 UINT32 BaseOffset)
77 UINT32 i = 0;
78 UINT32 j;
79 UINT32 Temp32;
80 UINT8 BufChar;
83 if (!Buffer)
85 AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");
86 return;
89 if ((Count < 4) || (Count & 0x01))
91 Display = DB_BYTE_DISPLAY;
94 /* Nasty little dump buffer routine! */
96 while (i < Count)
98 /* Print current offset */
100 AcpiOsPrintf ("%7.4X: ", (BaseOffset + i));
102 /* Print 16 hex chars */
104 for (j = 0; j < 16;)
106 if (i + j >= Count)
108 /* Dump fill spaces */
110 AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");
111 j += Display;
112 continue;
115 switch (Display)
117 case DB_BYTE_DISPLAY:
118 default: /* Default is BYTE display */
120 AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);
121 break;
123 case DB_WORD_DISPLAY:
125 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
126 AcpiOsPrintf ("%04X ", Temp32);
127 break;
129 case DB_DWORD_DISPLAY:
131 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
132 AcpiOsPrintf ("%08X ", Temp32);
133 break;
135 case DB_QWORD_DISPLAY:
137 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
138 AcpiOsPrintf ("%08X", Temp32);
140 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
141 AcpiOsPrintf ("%08X ", Temp32);
142 break;
145 j += Display;
149 * Print the ASCII equivalent characters but watch out for the bad
150 * unprintable ones (printable chars are 0x20 through 0x7E)
152 AcpiOsPrintf (" ");
153 for (j = 0; j < 16; j++)
155 if (i + j >= Count)
157 AcpiOsPrintf ("\n");
158 return;
162 * Add comment characters so rest of line is ignored when
163 * compiled
165 if (j == 0)
167 AcpiOsPrintf ("// ");
170 BufChar = Buffer[(ACPI_SIZE) i + j];
171 if (isprint (BufChar))
173 AcpiOsPrintf ("%c", BufChar);
175 else
177 AcpiOsPrintf (".");
181 /* Done with that line. */
183 AcpiOsPrintf ("\n");
184 i += 16;
187 return;
191 /*******************************************************************************
193 * FUNCTION: AcpiUtDebugDumpBuffer
195 * PARAMETERS: Buffer - Buffer to dump
196 * Count - Amount to dump, in bytes
197 * Display - BYTE, WORD, DWORD, or QWORD display:
198 * DB_BYTE_DISPLAY
199 * DB_WORD_DISPLAY
200 * DB_DWORD_DISPLAY
201 * DB_QWORD_DISPLAY
202 * ComponentID - Caller's component ID
204 * RETURN: None
206 * DESCRIPTION: Generic dump buffer in both hex and ascii.
208 ******************************************************************************/
210 void
211 AcpiUtDebugDumpBuffer (
212 UINT8 *Buffer,
213 UINT32 Count,
214 UINT32 Display,
215 UINT32 ComponentId)
218 /* Only dump the buffer if tracing is enabled */
220 if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&
221 (ComponentId & AcpiDbgLayer)))
223 return;
226 AcpiUtDumpBuffer (Buffer, Count, Display, 0);
230 #ifdef ACPI_APPLICATION
231 /*******************************************************************************
233 * FUNCTION: AcpiUtDumpBufferToFile
235 * PARAMETERS: File - File descriptor
236 * Buffer - Buffer to dump
237 * Count - Amount to dump, in bytes
238 * Display - BYTE, WORD, DWORD, or QWORD display:
239 * DB_BYTE_DISPLAY
240 * DB_WORD_DISPLAY
241 * DB_DWORD_DISPLAY
242 * DB_QWORD_DISPLAY
243 * BaseOffset - Beginning buffer offset (display only)
245 * RETURN: None
247 * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
249 ******************************************************************************/
251 void
252 AcpiUtDumpBufferToFile (
253 ACPI_FILE File,
254 UINT8 *Buffer,
255 UINT32 Count,
256 UINT32 Display,
257 UINT32 BaseOffset)
259 UINT32 i = 0;
260 UINT32 j;
261 UINT32 Temp32;
262 UINT8 BufChar;
265 if (!Buffer)
267 AcpiUtFilePrintf (File, "Null Buffer Pointer in DumpBuffer!\n");
268 return;
271 if ((Count < 4) || (Count & 0x01))
273 Display = DB_BYTE_DISPLAY;
276 /* Nasty little dump buffer routine! */
278 while (i < Count)
280 /* Print current offset */
282 AcpiUtFilePrintf (File, "%7.4X: ", (BaseOffset + i));
284 /* Print 16 hex chars */
286 for (j = 0; j < 16;)
288 if (i + j >= Count)
290 /* Dump fill spaces */
292 AcpiUtFilePrintf (File, "%*s", ((Display * 2) + 1), " ");
293 j += Display;
294 continue;
297 switch (Display)
299 case DB_BYTE_DISPLAY:
300 default: /* Default is BYTE display */
302 AcpiUtFilePrintf (File, "%02X ", Buffer[(ACPI_SIZE) i + j]);
303 break;
305 case DB_WORD_DISPLAY:
307 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
308 AcpiUtFilePrintf (File, "%04X ", Temp32);
309 break;
311 case DB_DWORD_DISPLAY:
313 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
314 AcpiUtFilePrintf (File, "%08X ", Temp32);
315 break;
317 case DB_QWORD_DISPLAY:
319 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
320 AcpiUtFilePrintf (File, "%08X", Temp32);
322 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
323 AcpiUtFilePrintf (File, "%08X ", Temp32);
324 break;
327 j += Display;
331 * Print the ASCII equivalent characters but watch out for the bad
332 * unprintable ones (printable chars are 0x20 through 0x7E)
334 AcpiUtFilePrintf (File, " ");
335 for (j = 0; j < 16; j++)
337 if (i + j >= Count)
339 AcpiUtFilePrintf (File, "\n");
340 return;
343 BufChar = Buffer[(ACPI_SIZE) i + j];
344 if (isprint (BufChar))
346 AcpiUtFilePrintf (File, "%c", BufChar);
348 else
350 AcpiUtFilePrintf (File, ".");
354 /* Done with that line. */
356 AcpiUtFilePrintf (File, "\n");
357 i += 16;
360 return;
362 #endif