Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: utbuffer - Buffer dump routines
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 
0013 #define _COMPONENT          ACPI_UTILITIES
0014 ACPI_MODULE_NAME("utbuffer")
0015 
0016 /*******************************************************************************
0017  *
0018  * FUNCTION:    acpi_ut_dump_buffer
0019  *
0020  * PARAMETERS:  buffer              - Buffer to dump
0021  *              count               - Amount to dump, in bytes
0022  *              display             - BYTE, WORD, DWORD, or QWORD display:
0023  *                                      DB_BYTE_DISPLAY
0024  *                                      DB_WORD_DISPLAY
0025  *                                      DB_DWORD_DISPLAY
0026  *                                      DB_QWORD_DISPLAY
0027  *              base_offset         - Beginning buffer offset (display only)
0028  *
0029  * RETURN:      None
0030  *
0031  * DESCRIPTION: Generic dump buffer in both hex and ascii.
0032  *
0033  ******************************************************************************/
0034 void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 base_offset)
0035 {
0036     u32 i = 0;
0037     u32 j;
0038     u32 temp32;
0039     u8 buf_char;
0040     u32 display_data_only = display & DB_DISPLAY_DATA_ONLY;
0041 
0042     display &= ~DB_DISPLAY_DATA_ONLY;
0043     if (!buffer) {
0044         acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
0045         return;
0046     }
0047 
0048     if ((count < 4) || (count & 0x01)) {
0049         display = DB_BYTE_DISPLAY;
0050     }
0051 
0052     /* Nasty little dump buffer routine! */
0053 
0054     while (i < count) {
0055 
0056         /* Print current offset */
0057 
0058         if (!display_data_only) {
0059             acpi_os_printf("%8.4X: ", (base_offset + i));
0060         }
0061 
0062         /* Print 16 hex chars */
0063 
0064         for (j = 0; j < 16;) {
0065             if (i + j >= count) {
0066 
0067                 /* Dump fill spaces */
0068 
0069                 acpi_os_printf("%*s", ((display * 2) + 1), " ");
0070                 j += display;
0071                 continue;
0072             }
0073 
0074             switch (display) {
0075             case DB_BYTE_DISPLAY:
0076             default:    /* Default is BYTE display */
0077 
0078                 acpi_os_printf("%02X ",
0079                            buffer[(acpi_size)i + j]);
0080                 break;
0081 
0082             case DB_WORD_DISPLAY:
0083 
0084                 ACPI_MOVE_16_TO_32(&temp32,
0085                            &buffer[(acpi_size)i + j]);
0086                 acpi_os_printf("%04X ", temp32);
0087                 break;
0088 
0089             case DB_DWORD_DISPLAY:
0090 
0091                 ACPI_MOVE_32_TO_32(&temp32,
0092                            &buffer[(acpi_size)i + j]);
0093                 acpi_os_printf("%08X ", temp32);
0094                 break;
0095 
0096             case DB_QWORD_DISPLAY:
0097 
0098                 ACPI_MOVE_32_TO_32(&temp32,
0099                            &buffer[(acpi_size)i + j]);
0100                 acpi_os_printf("%08X", temp32);
0101 
0102                 ACPI_MOVE_32_TO_32(&temp32,
0103                            &buffer[(acpi_size)i + j +
0104                                4]);
0105                 acpi_os_printf("%08X ", temp32);
0106                 break;
0107             }
0108 
0109             j += display;
0110         }
0111 
0112         /*
0113          * Print the ASCII equivalent characters but watch out for the bad
0114          * unprintable ones (printable chars are 0x20 through 0x7E)
0115          */
0116         if (!display_data_only) {
0117             acpi_os_printf(" ");
0118             for (j = 0; j < 16; j++) {
0119                 if (i + j >= count) {
0120                     acpi_os_printf("\n");
0121                     return;
0122                 }
0123 
0124                 /*
0125                  * Add comment characters so rest of line is ignored when
0126                  * compiled
0127                  */
0128                 if (j == 0) {
0129                     acpi_os_printf("// ");
0130                 }
0131 
0132                 buf_char = buffer[(acpi_size)i + j];
0133                 if (isprint(buf_char)) {
0134                     acpi_os_printf("%c", buf_char);
0135                 } else {
0136                     acpi_os_printf(".");
0137                 }
0138             }
0139 
0140             /* Done with that line. */
0141 
0142             acpi_os_printf("\n");
0143         }
0144         i += 16;
0145     }
0146 
0147     return;
0148 }
0149 
0150 /*******************************************************************************
0151  *
0152  * FUNCTION:    acpi_ut_debug_dump_buffer
0153  *
0154  * PARAMETERS:  buffer              - Buffer to dump
0155  *              count               - Amount to dump, in bytes
0156  *              display             - BYTE, WORD, DWORD, or QWORD display:
0157  *                                      DB_BYTE_DISPLAY
0158  *                                      DB_WORD_DISPLAY
0159  *                                      DB_DWORD_DISPLAY
0160  *                                      DB_QWORD_DISPLAY
0161  *              component_ID        - Caller's component ID
0162  *
0163  * RETURN:      None
0164  *
0165  * DESCRIPTION: Generic dump buffer in both hex and ascii.
0166  *
0167  ******************************************************************************/
0168 
0169 void
0170 acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
0171 {
0172 
0173     /* Only dump the buffer if tracing is enabled */
0174 
0175     if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
0176           (component_id & acpi_dbg_layer))) {
0177         return;
0178     }
0179 
0180     acpi_ut_dump_buffer(buffer, count, display, 0);
0181 }
0182 
0183 #ifdef ACPI_APPLICATION
0184 /*******************************************************************************
0185  *
0186  * FUNCTION:    acpi_ut_dump_buffer_to_file
0187  *
0188  * PARAMETERS:  file                - File descriptor
0189  *              buffer              - Buffer to dump
0190  *              count               - Amount to dump, in bytes
0191  *              display             - BYTE, WORD, DWORD, or QWORD display:
0192  *                                      DB_BYTE_DISPLAY
0193  *                                      DB_WORD_DISPLAY
0194  *                                      DB_DWORD_DISPLAY
0195  *                                      DB_QWORD_DISPLAY
0196  *              base_offset         - Beginning buffer offset (display only)
0197  *
0198  * RETURN:      None
0199  *
0200  * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
0201  *
0202  ******************************************************************************/
0203 
0204 void
0205 acpi_ut_dump_buffer_to_file(ACPI_FILE file,
0206                 u8 *buffer, u32 count, u32 display, u32 base_offset)
0207 {
0208     u32 i = 0;
0209     u32 j;
0210     u32 temp32;
0211     u8 buf_char;
0212 
0213     if (!buffer) {
0214         fprintf(file, "Null Buffer Pointer in DumpBuffer!\n");
0215         return;
0216     }
0217 
0218     if ((count < 4) || (count & 0x01)) {
0219         display = DB_BYTE_DISPLAY;
0220     }
0221 
0222     /* Nasty little dump buffer routine! */
0223 
0224     while (i < count) {
0225 
0226         /* Print current offset */
0227 
0228         fprintf(file, "%8.4X: ", (base_offset + i));
0229 
0230         /* Print 16 hex chars */
0231 
0232         for (j = 0; j < 16;) {
0233             if (i + j >= count) {
0234 
0235                 /* Dump fill spaces */
0236 
0237                 fprintf(file, "%*s", ((display * 2) + 1), " ");
0238                 j += display;
0239                 continue;
0240             }
0241 
0242             switch (display) {
0243             case DB_BYTE_DISPLAY:
0244             default:    /* Default is BYTE display */
0245 
0246                 fprintf(file, "%02X ",
0247                     buffer[(acpi_size)i + j]);
0248                 break;
0249 
0250             case DB_WORD_DISPLAY:
0251 
0252                 ACPI_MOVE_16_TO_32(&temp32,
0253                            &buffer[(acpi_size)i + j]);
0254                 fprintf(file, "%04X ", temp32);
0255                 break;
0256 
0257             case DB_DWORD_DISPLAY:
0258 
0259                 ACPI_MOVE_32_TO_32(&temp32,
0260                            &buffer[(acpi_size)i + j]);
0261                 fprintf(file, "%08X ", temp32);
0262                 break;
0263 
0264             case DB_QWORD_DISPLAY:
0265 
0266                 ACPI_MOVE_32_TO_32(&temp32,
0267                            &buffer[(acpi_size)i + j]);
0268                 fprintf(file, "%08X", temp32);
0269 
0270                 ACPI_MOVE_32_TO_32(&temp32,
0271                            &buffer[(acpi_size)i + j +
0272                                4]);
0273                 fprintf(file, "%08X ", temp32);
0274                 break;
0275             }
0276 
0277             j += display;
0278         }
0279 
0280         /*
0281          * Print the ASCII equivalent characters but watch out for the bad
0282          * unprintable ones (printable chars are 0x20 through 0x7E)
0283          */
0284         fprintf(file, " ");
0285         for (j = 0; j < 16; j++) {
0286             if (i + j >= count) {
0287                 fprintf(file, "\n");
0288                 return;
0289             }
0290 
0291             buf_char = buffer[(acpi_size)i + j];
0292             if (isprint(buf_char)) {
0293                 fprintf(file, "%c", buf_char);
0294             } else {
0295                 fprintf(file, ".");
0296             }
0297         }
0298 
0299         /* Done with that line. */
0300 
0301         fprintf(file, "\n");
0302         i += 16;
0303     }
0304 
0305     return;
0306 }
0307 #endif