1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utbuffer - Buffer dump routines
6 * Copyright (C) 2000 - 2021, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
13 #define _COMPONENT ACPI_UTILITIES
14 ACPI_MODULE_NAME("utbuffer")
16 /*******************************************************************************
18 * FUNCTION: acpi_ut_dump_buffer
20 * PARAMETERS: buffer - Buffer to dump
21 * count - Amount to dump, in bytes
22 * display - BYTE, WORD, DWORD, or QWORD display:
27 * base_offset - Beginning buffer offset (display only)
31 * DESCRIPTION: Generic dump buffer in both hex and ascii.
33 ******************************************************************************/
34 void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 base_offset)
40 u32 display_data_only = display & DB_DISPLAY_DATA_ONLY;
42 display &= ~DB_DISPLAY_DATA_ONLY;
44 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
48 if ((count < 4) || (count & 0x01)) {
49 display = DB_BYTE_DISPLAY;
52 /* Nasty little dump buffer routine! */
56 /* Print current offset */
58 if (!display_data_only) {
59 acpi_os_printf("%8.4X: ", (base_offset + i));
62 /* Print 16 hex chars */
64 for (j = 0; j < 16;) {
67 /* Dump fill spaces */
69 acpi_os_printf("%*s", ((display * 2) + 1), " ");
76 default: /* Default is BYTE display */
78 acpi_os_printf("%02X ",
79 buffer[(acpi_size)i + j]);
84 ACPI_MOVE_16_TO_32(&temp32,
85 &buffer[(acpi_size)i + j]);
86 acpi_os_printf("%04X ", temp32);
89 case DB_DWORD_DISPLAY:
91 ACPI_MOVE_32_TO_32(&temp32,
92 &buffer[(acpi_size)i + j]);
93 acpi_os_printf("%08X ", temp32);
96 case DB_QWORD_DISPLAY:
98 ACPI_MOVE_32_TO_32(&temp32,
99 &buffer[(acpi_size)i + j]);
100 acpi_os_printf("%08X", temp32);
102 ACPI_MOVE_32_TO_32(&temp32,
103 &buffer[(acpi_size)i + j +
105 acpi_os_printf("%08X ", temp32);
113 * Print the ASCII equivalent characters but watch out for the bad
114 * unprintable ones (printable chars are 0x20 through 0x7E)
116 if (!display_data_only) {
118 for (j = 0; j < 16; j++) {
119 if (i + j >= count) {
120 acpi_os_printf("\n");
125 * Add comment characters so rest of line is ignored when
129 acpi_os_printf("// ");
132 buf_char = buffer[(acpi_size)i + j];
133 if (isprint(buf_char)) {
134 acpi_os_printf("%c", buf_char);
140 /* Done with that line. */
142 acpi_os_printf("\n");
150 /*******************************************************************************
152 * FUNCTION: acpi_ut_debug_dump_buffer
154 * PARAMETERS: buffer - Buffer to dump
155 * count - Amount to dump, in bytes
156 * display - BYTE, WORD, DWORD, or QWORD display:
161 * component_ID - Caller's component ID
165 * DESCRIPTION: Generic dump buffer in both hex and ascii.
167 ******************************************************************************/
170 acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
173 /* Only dump the buffer if tracing is enabled */
175 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
176 (component_id & acpi_dbg_layer))) {
180 acpi_ut_dump_buffer(buffer, count, display, 0);
183 #ifdef ACPI_APPLICATION
184 /*******************************************************************************
186 * FUNCTION: acpi_ut_dump_buffer_to_file
188 * PARAMETERS: file - File descriptor
189 * buffer - Buffer to dump
190 * count - Amount to dump, in bytes
191 * display - BYTE, WORD, DWORD, or QWORD display:
196 * base_offset - Beginning buffer offset (display only)
200 * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
202 ******************************************************************************/
205 acpi_ut_dump_buffer_to_file(ACPI_FILE file,
206 u8 *buffer, u32 count, u32 display, u32 base_offset)
214 fprintf(file, "Null Buffer Pointer in DumpBuffer!\n");
218 if ((count < 4) || (count & 0x01)) {
219 display = DB_BYTE_DISPLAY;
222 /* Nasty little dump buffer routine! */
226 /* Print current offset */
228 fprintf(file, "%8.4X: ", (base_offset + i));
230 /* Print 16 hex chars */
232 for (j = 0; j < 16;) {
233 if (i + j >= count) {
235 /* Dump fill spaces */
237 fprintf(file, "%*s", ((display * 2) + 1), " ");
243 case DB_BYTE_DISPLAY:
244 default: /* Default is BYTE display */
246 fprintf(file, "%02X ",
247 buffer[(acpi_size)i + j]);
250 case DB_WORD_DISPLAY:
252 ACPI_MOVE_16_TO_32(&temp32,
253 &buffer[(acpi_size)i + j]);
254 fprintf(file, "%04X ", temp32);
257 case DB_DWORD_DISPLAY:
259 ACPI_MOVE_32_TO_32(&temp32,
260 &buffer[(acpi_size)i + j]);
261 fprintf(file, "%08X ", temp32);
264 case DB_QWORD_DISPLAY:
266 ACPI_MOVE_32_TO_32(&temp32,
267 &buffer[(acpi_size)i + j]);
268 fprintf(file, "%08X", temp32);
270 ACPI_MOVE_32_TO_32(&temp32,
271 &buffer[(acpi_size)i + j +
273 fprintf(file, "%08X ", temp32);
281 * Print the ASCII equivalent characters but watch out for the bad
282 * unprintable ones (printable chars are 0x20 through 0x7E)
285 for (j = 0; j < 16; j++) {
286 if (i + j >= count) {
291 buf_char = buffer[(acpi_size)i + j];
292 if (isprint(buf_char)) {
293 fprintf(file, "%c", buf_char);
299 /* Done with that line. */