1 /******************************************************************************
3 * Module Name: utbuffer - Buffer dump routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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/acpi.h>
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME("utbuffer")
50 /*******************************************************************************
52 * FUNCTION: acpi_ut_dump_buffer
54 * PARAMETERS: buffer - Buffer to dump
55 * count - Amount to dump, in bytes
56 * display - BYTE, WORD, DWORD, or QWORD display:
61 * base_offset - Beginning buffer offset (display only)
65 * DESCRIPTION: Generic dump buffer in both hex and ascii.
67 ******************************************************************************/
68 void acpi_ut_dump_buffer(u8
*buffer
, u32 count
, u32 display
, u32 base_offset
)
76 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
80 if ((count
< 4) || (count
& 0x01)) {
81 display
= DB_BYTE_DISPLAY
;
84 /* Nasty little dump buffer routine! */
88 /* Print current offset */
90 acpi_os_printf("%6.4X: ", (base_offset
+ i
));
92 /* Print 16 hex chars */
94 for (j
= 0; j
< 16;) {
97 /* Dump fill spaces */
99 acpi_os_printf("%*s", ((display
* 2) + 1), " ");
105 case DB_BYTE_DISPLAY
:
106 default: /* Default is BYTE display */
108 acpi_os_printf("%02X ",
109 buffer
[(acpi_size
) i
+ j
]);
112 case DB_WORD_DISPLAY
:
114 ACPI_MOVE_16_TO_32(&temp32
,
115 &buffer
[(acpi_size
) i
+ j
]);
116 acpi_os_printf("%04X ", temp32
);
119 case DB_DWORD_DISPLAY
:
121 ACPI_MOVE_32_TO_32(&temp32
,
122 &buffer
[(acpi_size
) i
+ j
]);
123 acpi_os_printf("%08X ", temp32
);
126 case DB_QWORD_DISPLAY
:
128 ACPI_MOVE_32_TO_32(&temp32
,
129 &buffer
[(acpi_size
) i
+ j
]);
130 acpi_os_printf("%08X", temp32
);
132 ACPI_MOVE_32_TO_32(&temp32
,
133 &buffer
[(acpi_size
) i
+ j
+
135 acpi_os_printf("%08X ", temp32
);
143 * Print the ASCII equivalent characters but watch out for the bad
144 * unprintable ones (printable chars are 0x20 through 0x7E)
147 for (j
= 0; j
< 16; j
++) {
148 if (i
+ j
>= count
) {
149 acpi_os_printf("\n");
154 * Add comment characters so rest of line is ignored when
158 acpi_os_printf("// ");
161 buf_char
= buffer
[(acpi_size
) i
+ j
];
162 if (isprint(buf_char
)) {
163 acpi_os_printf("%c", buf_char
);
169 /* Done with that line. */
171 acpi_os_printf("\n");
178 /*******************************************************************************
180 * FUNCTION: acpi_ut_debug_dump_buffer
182 * PARAMETERS: buffer - Buffer to dump
183 * count - Amount to dump, in bytes
184 * display - BYTE, WORD, DWORD, or QWORD display:
189 * component_ID - Caller's component ID
193 * DESCRIPTION: Generic dump buffer in both hex and ascii.
195 ******************************************************************************/
198 acpi_ut_debug_dump_buffer(u8
*buffer
, u32 count
, u32 display
, u32 component_id
)
201 /* Only dump the buffer if tracing is enabled */
203 if (!((ACPI_LV_TABLES
& acpi_dbg_level
) &&
204 (component_id
& acpi_dbg_layer
))) {
208 acpi_ut_dump_buffer(buffer
, count
, display
, 0);
211 #ifdef ACPI_APPLICATION
212 /*******************************************************************************
214 * FUNCTION: acpi_ut_dump_buffer_to_file
216 * PARAMETERS: file - File descriptor
217 * buffer - Buffer to dump
218 * count - Amount to dump, in bytes
219 * display - BYTE, WORD, DWORD, or QWORD display:
224 * base_offset - Beginning buffer offset (display only)
228 * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
230 ******************************************************************************/
233 acpi_ut_dump_buffer_to_file(ACPI_FILE file
,
234 u8
*buffer
, u32 count
, u32 display
, u32 base_offset
)
242 acpi_ut_file_printf(file
,
243 "Null Buffer Pointer in DumpBuffer!\n");
247 if ((count
< 4) || (count
& 0x01)) {
248 display
= DB_BYTE_DISPLAY
;
251 /* Nasty little dump buffer routine! */
255 /* Print current offset */
257 acpi_ut_file_printf(file
, "%6.4X: ", (base_offset
+ i
));
259 /* Print 16 hex chars */
261 for (j
= 0; j
< 16;) {
262 if (i
+ j
>= count
) {
264 /* Dump fill spaces */
266 acpi_ut_file_printf(file
, "%*s",
267 ((display
* 2) + 1), " ");
273 case DB_BYTE_DISPLAY
:
274 default: /* Default is BYTE display */
276 acpi_ut_file_printf(file
, "%02X ",
277 buffer
[(acpi_size
) i
+ j
]);
280 case DB_WORD_DISPLAY
:
282 ACPI_MOVE_16_TO_32(&temp32
,
283 &buffer
[(acpi_size
) i
+ j
]);
284 acpi_ut_file_printf(file
, "%04X ", temp32
);
287 case DB_DWORD_DISPLAY
:
289 ACPI_MOVE_32_TO_32(&temp32
,
290 &buffer
[(acpi_size
) i
+ j
]);
291 acpi_ut_file_printf(file
, "%08X ", temp32
);
294 case DB_QWORD_DISPLAY
:
296 ACPI_MOVE_32_TO_32(&temp32
,
297 &buffer
[(acpi_size
) i
+ j
]);
298 acpi_ut_file_printf(file
, "%08X", temp32
);
300 ACPI_MOVE_32_TO_32(&temp32
,
301 &buffer
[(acpi_size
) i
+ j
+
303 acpi_ut_file_printf(file
, "%08X ", temp32
);
311 * Print the ASCII equivalent characters but watch out for the bad
312 * unprintable ones (printable chars are 0x20 through 0x7E)
314 acpi_ut_file_printf(file
, " ");
315 for (j
= 0; j
< 16; j
++) {
316 if (i
+ j
>= count
) {
317 acpi_ut_file_printf(file
, "\n");
321 buf_char
= buffer
[(acpi_size
) i
+ j
];
322 if (isprint(buf_char
)) {
323 acpi_ut_file_printf(file
, "%c", buf_char
);
325 acpi_ut_file_printf(file
, ".");
329 /* Done with that line. */
331 acpi_ut_file_printf(file
, "\n");