1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utbuffer - Buffer dump routines
6 * Copyright (C) 2000 - 2018, 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
)
42 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
46 if ((count
< 4) || (count
& 0x01)) {
47 display
= DB_BYTE_DISPLAY
;
50 /* Nasty little dump buffer routine! */
54 /* Print current offset */
56 acpi_os_printf("%8.4X: ", (base_offset
+ i
));
58 /* Print 16 hex chars */
60 for (j
= 0; j
< 16;) {
63 /* Dump fill spaces */
65 acpi_os_printf("%*s", ((display
* 2) + 1), " ");
72 default: /* Default is BYTE display */
74 acpi_os_printf("%02X ",
75 buffer
[(acpi_size
)i
+ j
]);
80 ACPI_MOVE_16_TO_32(&temp32
,
81 &buffer
[(acpi_size
)i
+ j
]);
82 acpi_os_printf("%04X ", temp32
);
85 case DB_DWORD_DISPLAY
:
87 ACPI_MOVE_32_TO_32(&temp32
,
88 &buffer
[(acpi_size
)i
+ j
]);
89 acpi_os_printf("%08X ", temp32
);
92 case DB_QWORD_DISPLAY
:
94 ACPI_MOVE_32_TO_32(&temp32
,
95 &buffer
[(acpi_size
)i
+ j
]);
96 acpi_os_printf("%08X", temp32
);
98 ACPI_MOVE_32_TO_32(&temp32
,
99 &buffer
[(acpi_size
)i
+ j
+
101 acpi_os_printf("%08X ", temp32
);
109 * Print the ASCII equivalent characters but watch out for the bad
110 * unprintable ones (printable chars are 0x20 through 0x7E)
113 for (j
= 0; j
< 16; j
++) {
114 if (i
+ j
>= count
) {
115 acpi_os_printf("\n");
120 * Add comment characters so rest of line is ignored when
124 acpi_os_printf("// ");
127 buf_char
= buffer
[(acpi_size
)i
+ j
];
128 if (isprint(buf_char
)) {
129 acpi_os_printf("%c", buf_char
);
135 /* Done with that line. */
137 acpi_os_printf("\n");
144 /*******************************************************************************
146 * FUNCTION: acpi_ut_debug_dump_buffer
148 * PARAMETERS: buffer - Buffer to dump
149 * count - Amount to dump, in bytes
150 * display - BYTE, WORD, DWORD, or QWORD display:
155 * component_ID - Caller's component ID
159 * DESCRIPTION: Generic dump buffer in both hex and ascii.
161 ******************************************************************************/
164 acpi_ut_debug_dump_buffer(u8
*buffer
, u32 count
, u32 display
, u32 component_id
)
167 /* Only dump the buffer if tracing is enabled */
169 if (!((ACPI_LV_TABLES
& acpi_dbg_level
) &&
170 (component_id
& acpi_dbg_layer
))) {
174 acpi_ut_dump_buffer(buffer
, count
, display
, 0);
177 #ifdef ACPI_APPLICATION
178 /*******************************************************************************
180 * FUNCTION: acpi_ut_dump_buffer_to_file
182 * PARAMETERS: file - File descriptor
183 * buffer - Buffer to dump
184 * count - Amount to dump, in bytes
185 * display - BYTE, WORD, DWORD, or QWORD display:
190 * base_offset - Beginning buffer offset (display only)
194 * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
196 ******************************************************************************/
199 acpi_ut_dump_buffer_to_file(ACPI_FILE file
,
200 u8
*buffer
, u32 count
, u32 display
, u32 base_offset
)
208 fprintf(file
, "Null Buffer Pointer in DumpBuffer!\n");
212 if ((count
< 4) || (count
& 0x01)) {
213 display
= DB_BYTE_DISPLAY
;
216 /* Nasty little dump buffer routine! */
220 /* Print current offset */
222 fprintf(file
, "%8.4X: ", (base_offset
+ i
));
224 /* Print 16 hex chars */
226 for (j
= 0; j
< 16;) {
227 if (i
+ j
>= count
) {
229 /* Dump fill spaces */
231 fprintf(file
, "%*s", ((display
* 2) + 1), " ");
237 case DB_BYTE_DISPLAY
:
238 default: /* Default is BYTE display */
240 fprintf(file
, "%02X ",
241 buffer
[(acpi_size
)i
+ j
]);
244 case DB_WORD_DISPLAY
:
246 ACPI_MOVE_16_TO_32(&temp32
,
247 &buffer
[(acpi_size
)i
+ j
]);
248 fprintf(file
, "%04X ", temp32
);
251 case DB_DWORD_DISPLAY
:
253 ACPI_MOVE_32_TO_32(&temp32
,
254 &buffer
[(acpi_size
)i
+ j
]);
255 fprintf(file
, "%08X ", temp32
);
258 case DB_QWORD_DISPLAY
:
260 ACPI_MOVE_32_TO_32(&temp32
,
261 &buffer
[(acpi_size
)i
+ j
]);
262 fprintf(file
, "%08X", temp32
);
264 ACPI_MOVE_32_TO_32(&temp32
,
265 &buffer
[(acpi_size
)i
+ j
+
267 fprintf(file
, "%08X ", temp32
);
275 * Print the ASCII equivalent characters but watch out for the bad
276 * unprintable ones (printable chars are 0x20 through 0x7E)
279 for (j
= 0; j
< 16; j
++) {
280 if (i
+ j
>= count
) {
285 buf_char
= buffer
[(acpi_size
)i
+ j
];
286 if (isprint(buf_char
)) {
287 fprintf(file
, "%c", buf_char
);
293 /* Done with that line. */