Home | History | Annotate | Line # | Download | only in utilities
utbuffer.c revision 1.1.1.2
      1      1.1  christos /******************************************************************************
      2      1.1  christos  *
      3      1.1  christos  * Module Name: utbuffer - Buffer dump routines
      4      1.1  christos  *
      5      1.1  christos  *****************************************************************************/
      6      1.1  christos 
      7      1.1  christos /*
      8  1.1.1.2  christos  * Copyright (C) 2000 - 2014, Intel Corp.
      9      1.1  christos  * All rights reserved.
     10      1.1  christos  *
     11      1.1  christos  * Redistribution and use in source and binary forms, with or without
     12      1.1  christos  * modification, are permitted provided that the following conditions
     13      1.1  christos  * are met:
     14      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15      1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16      1.1  christos  *    without modification.
     17      1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21      1.1  christos  *    binary redistribution.
     22      1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24      1.1  christos  *    from this software without specific prior written permission.
     25      1.1  christos  *
     26      1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27      1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1  christos  * Software Foundation.
     29      1.1  christos  *
     30      1.1  christos  * NO WARRANTY
     31      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1  christos  */
     43      1.1  christos 
     44      1.1  christos #define __UTBUFFER_C__
     45      1.1  christos 
     46      1.1  christos #include "acpi.h"
     47      1.1  christos #include "accommon.h"
     48      1.1  christos 
     49      1.1  christos #define _COMPONENT          ACPI_UTILITIES
     50      1.1  christos         ACPI_MODULE_NAME    ("utbuffer")
     51      1.1  christos 
     52      1.1  christos 
     53      1.1  christos /*******************************************************************************
     54      1.1  christos  *
     55      1.1  christos  * FUNCTION:    AcpiUtDumpBuffer
     56      1.1  christos  *
     57      1.1  christos  * PARAMETERS:  Buffer              - Buffer to dump
     58      1.1  christos  *              Count               - Amount to dump, in bytes
     59      1.1  christos  *              Display             - BYTE, WORD, DWORD, or QWORD display:
     60      1.1  christos  *                                      DB_BYTE_DISPLAY
     61      1.1  christos  *                                      DB_WORD_DISPLAY
     62      1.1  christos  *                                      DB_DWORD_DISPLAY
     63      1.1  christos  *                                      DB_QWORD_DISPLAY
     64      1.1  christos  *              BaseOffset          - Beginning buffer offset (display only)
     65      1.1  christos  *
     66      1.1  christos  * RETURN:      None
     67      1.1  christos  *
     68      1.1  christos  * DESCRIPTION: Generic dump buffer in both hex and ascii.
     69      1.1  christos  *
     70      1.1  christos  ******************************************************************************/
     71      1.1  christos 
     72      1.1  christos void
     73      1.1  christos AcpiUtDumpBuffer (
     74      1.1  christos     UINT8                   *Buffer,
     75      1.1  christos     UINT32                  Count,
     76      1.1  christos     UINT32                  Display,
     77      1.1  christos     UINT32                  BaseOffset)
     78      1.1  christos {
     79      1.1  christos     UINT32                  i = 0;
     80      1.1  christos     UINT32                  j;
     81      1.1  christos     UINT32                  Temp32;
     82      1.1  christos     UINT8                   BufChar;
     83      1.1  christos 
     84      1.1  christos 
     85      1.1  christos     if (!Buffer)
     86      1.1  christos     {
     87      1.1  christos         AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");
     88      1.1  christos         return;
     89      1.1  christos     }
     90      1.1  christos 
     91      1.1  christos     if ((Count < 4) || (Count & 0x01))
     92      1.1  christos     {
     93      1.1  christos         Display = DB_BYTE_DISPLAY;
     94      1.1  christos     }
     95      1.1  christos 
     96      1.1  christos     /* Nasty little dump buffer routine! */
     97      1.1  christos 
     98      1.1  christos     while (i < Count)
     99      1.1  christos     {
    100      1.1  christos         /* Print current offset */
    101      1.1  christos 
    102      1.1  christos         AcpiOsPrintf ("%6.4X: ", (BaseOffset + i));
    103      1.1  christos 
    104      1.1  christos         /* Print 16 hex chars */
    105      1.1  christos 
    106      1.1  christos         for (j = 0; j < 16;)
    107      1.1  christos         {
    108      1.1  christos             if (i + j >= Count)
    109      1.1  christos             {
    110      1.1  christos                 /* Dump fill spaces */
    111      1.1  christos 
    112      1.1  christos                 AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");
    113      1.1  christos                 j += Display;
    114      1.1  christos                 continue;
    115      1.1  christos             }
    116      1.1  christos 
    117      1.1  christos             switch (Display)
    118      1.1  christos             {
    119      1.1  christos             case DB_BYTE_DISPLAY:
    120      1.1  christos             default:    /* Default is BYTE display */
    121      1.1  christos 
    122      1.1  christos                 AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);
    123      1.1  christos                 break;
    124      1.1  christos 
    125      1.1  christos             case DB_WORD_DISPLAY:
    126      1.1  christos 
    127      1.1  christos                 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    128      1.1  christos                 AcpiOsPrintf ("%04X ", Temp32);
    129      1.1  christos                 break;
    130      1.1  christos 
    131      1.1  christos             case DB_DWORD_DISPLAY:
    132      1.1  christos 
    133      1.1  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    134      1.1  christos                 AcpiOsPrintf ("%08X ", Temp32);
    135      1.1  christos                 break;
    136      1.1  christos 
    137      1.1  christos             case DB_QWORD_DISPLAY:
    138      1.1  christos 
    139      1.1  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    140      1.1  christos                 AcpiOsPrintf ("%08X", Temp32);
    141      1.1  christos 
    142      1.1  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
    143      1.1  christos                 AcpiOsPrintf ("%08X ", Temp32);
    144      1.1  christos                 break;
    145      1.1  christos             }
    146      1.1  christos 
    147      1.1  christos             j += Display;
    148      1.1  christos         }
    149      1.1  christos 
    150      1.1  christos         /*
    151      1.1  christos          * Print the ASCII equivalent characters but watch out for the bad
    152      1.1  christos          * unprintable ones (printable chars are 0x20 through 0x7E)
    153      1.1  christos          */
    154      1.1  christos         AcpiOsPrintf (" ");
    155      1.1  christos         for (j = 0; j < 16; j++)
    156      1.1  christos         {
    157      1.1  christos             if (i + j >= Count)
    158      1.1  christos             {
    159      1.1  christos                 AcpiOsPrintf ("\n");
    160      1.1  christos                 return;
    161      1.1  christos             }
    162      1.1  christos 
    163      1.1  christos             BufChar = Buffer[(ACPI_SIZE) i + j];
    164      1.1  christos             if (ACPI_IS_PRINT (BufChar))
    165      1.1  christos             {
    166      1.1  christos                 AcpiOsPrintf ("%c", BufChar);
    167      1.1  christos             }
    168      1.1  christos             else
    169      1.1  christos             {
    170      1.1  christos                 AcpiOsPrintf (".");
    171      1.1  christos             }
    172      1.1  christos         }
    173      1.1  christos 
    174      1.1  christos         /* Done with that line. */
    175      1.1  christos 
    176      1.1  christos         AcpiOsPrintf ("\n");
    177      1.1  christos         i += 16;
    178      1.1  christos     }
    179      1.1  christos 
    180      1.1  christos     return;
    181      1.1  christos }
    182      1.1  christos 
    183      1.1  christos 
    184      1.1  christos /*******************************************************************************
    185      1.1  christos  *
    186      1.1  christos  * FUNCTION:    AcpiUtDebugDumpBuffer
    187      1.1  christos  *
    188      1.1  christos  * PARAMETERS:  Buffer              - Buffer to dump
    189      1.1  christos  *              Count               - Amount to dump, in bytes
    190      1.1  christos  *              Display             - BYTE, WORD, DWORD, or QWORD display:
    191      1.1  christos  *                                      DB_BYTE_DISPLAY
    192      1.1  christos  *                                      DB_WORD_DISPLAY
    193      1.1  christos  *                                      DB_DWORD_DISPLAY
    194      1.1  christos  *                                      DB_QWORD_DISPLAY
    195      1.1  christos  *              ComponentID         - Caller's component ID
    196      1.1  christos  *
    197      1.1  christos  * RETURN:      None
    198      1.1  christos  *
    199      1.1  christos  * DESCRIPTION: Generic dump buffer in both hex and ascii.
    200      1.1  christos  *
    201      1.1  christos  ******************************************************************************/
    202      1.1  christos 
    203      1.1  christos void
    204      1.1  christos AcpiUtDebugDumpBuffer (
    205      1.1  christos     UINT8                   *Buffer,
    206      1.1  christos     UINT32                  Count,
    207      1.1  christos     UINT32                  Display,
    208      1.1  christos     UINT32                  ComponentId)
    209      1.1  christos {
    210      1.1  christos 
    211      1.1  christos     /* Only dump the buffer if tracing is enabled */
    212      1.1  christos 
    213      1.1  christos     if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&
    214      1.1  christos         (ComponentId & AcpiDbgLayer)))
    215      1.1  christos     {
    216      1.1  christos         return;
    217      1.1  christos     }
    218      1.1  christos 
    219      1.1  christos     AcpiUtDumpBuffer (Buffer, Count, Display, 0);
    220      1.1  christos }
    221  1.1.1.2  christos 
    222  1.1.1.2  christos 
    223  1.1.1.2  christos #ifdef ACPI_APPLICATION
    224  1.1.1.2  christos /*******************************************************************************
    225  1.1.1.2  christos  *
    226  1.1.1.2  christos  * FUNCTION:    AcpiUtDumpBufferToFile
    227  1.1.1.2  christos  *
    228  1.1.1.2  christos  * PARAMETERS:  File                - File descriptor
    229  1.1.1.2  christos  *              Buffer              - Buffer to dump
    230  1.1.1.2  christos  *              Count               - Amount to dump, in bytes
    231  1.1.1.2  christos  *              Display             - BYTE, WORD, DWORD, or QWORD display:
    232  1.1.1.2  christos  *                                      DB_BYTE_DISPLAY
    233  1.1.1.2  christos  *                                      DB_WORD_DISPLAY
    234  1.1.1.2  christos  *                                      DB_DWORD_DISPLAY
    235  1.1.1.2  christos  *                                      DB_QWORD_DISPLAY
    236  1.1.1.2  christos  *              BaseOffset          - Beginning buffer offset (display only)
    237  1.1.1.2  christos  *
    238  1.1.1.2  christos  * RETURN:      None
    239  1.1.1.2  christos  *
    240  1.1.1.2  christos  * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
    241  1.1.1.2  christos  *
    242  1.1.1.2  christos  ******************************************************************************/
    243  1.1.1.2  christos 
    244  1.1.1.2  christos void
    245  1.1.1.2  christos AcpiUtDumpBufferToFile (
    246  1.1.1.2  christos     ACPI_FILE               File,
    247  1.1.1.2  christos     UINT8                   *Buffer,
    248  1.1.1.2  christos     UINT32                  Count,
    249  1.1.1.2  christos     UINT32                  Display,
    250  1.1.1.2  christos     UINT32                  BaseOffset)
    251  1.1.1.2  christos {
    252  1.1.1.2  christos     UINT32                  i = 0;
    253  1.1.1.2  christos     UINT32                  j;
    254  1.1.1.2  christos     UINT32                  Temp32;
    255  1.1.1.2  christos     UINT8                   BufChar;
    256  1.1.1.2  christos 
    257  1.1.1.2  christos 
    258  1.1.1.2  christos     if (!Buffer)
    259  1.1.1.2  christos     {
    260  1.1.1.2  christos         AcpiUtFilePrintf (File, "Null Buffer Pointer in DumpBuffer!\n");
    261  1.1.1.2  christos         return;
    262  1.1.1.2  christos     }
    263  1.1.1.2  christos 
    264  1.1.1.2  christos     if ((Count < 4) || (Count & 0x01))
    265  1.1.1.2  christos     {
    266  1.1.1.2  christos         Display = DB_BYTE_DISPLAY;
    267  1.1.1.2  christos     }
    268  1.1.1.2  christos 
    269  1.1.1.2  christos     /* Nasty little dump buffer routine! */
    270  1.1.1.2  christos 
    271  1.1.1.2  christos     while (i < Count)
    272  1.1.1.2  christos     {
    273  1.1.1.2  christos         /* Print current offset */
    274  1.1.1.2  christos 
    275  1.1.1.2  christos         AcpiUtFilePrintf (File, "%6.4X: ", (BaseOffset + i));
    276  1.1.1.2  christos 
    277  1.1.1.2  christos         /* Print 16 hex chars */
    278  1.1.1.2  christos 
    279  1.1.1.2  christos         for (j = 0; j < 16;)
    280  1.1.1.2  christos         {
    281  1.1.1.2  christos             if (i + j >= Count)
    282  1.1.1.2  christos             {
    283  1.1.1.2  christos                 /* Dump fill spaces */
    284  1.1.1.2  christos 
    285  1.1.1.2  christos                 AcpiUtFilePrintf (File, "%*s", ((Display * 2) + 1), " ");
    286  1.1.1.2  christos                 j += Display;
    287  1.1.1.2  christos                 continue;
    288  1.1.1.2  christos             }
    289  1.1.1.2  christos 
    290  1.1.1.2  christos             switch (Display)
    291  1.1.1.2  christos             {
    292  1.1.1.2  christos             case DB_BYTE_DISPLAY:
    293  1.1.1.2  christos             default:    /* Default is BYTE display */
    294  1.1.1.2  christos 
    295  1.1.1.2  christos                 AcpiUtFilePrintf (File, "%02X ", Buffer[(ACPI_SIZE) i + j]);
    296  1.1.1.2  christos                 break;
    297  1.1.1.2  christos 
    298  1.1.1.2  christos             case DB_WORD_DISPLAY:
    299  1.1.1.2  christos 
    300  1.1.1.2  christos                 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    301  1.1.1.2  christos                 AcpiUtFilePrintf (File, "%04X ", Temp32);
    302  1.1.1.2  christos                 break;
    303  1.1.1.2  christos 
    304  1.1.1.2  christos             case DB_DWORD_DISPLAY:
    305  1.1.1.2  christos 
    306  1.1.1.2  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    307  1.1.1.2  christos                 AcpiUtFilePrintf (File, "%08X ", Temp32);
    308  1.1.1.2  christos                 break;
    309  1.1.1.2  christos 
    310  1.1.1.2  christos             case DB_QWORD_DISPLAY:
    311  1.1.1.2  christos 
    312  1.1.1.2  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    313  1.1.1.2  christos                 AcpiUtFilePrintf (File, "%08X", Temp32);
    314  1.1.1.2  christos 
    315  1.1.1.2  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
    316  1.1.1.2  christos                 AcpiUtFilePrintf (File, "%08X ", Temp32);
    317  1.1.1.2  christos                 break;
    318  1.1.1.2  christos             }
    319  1.1.1.2  christos 
    320  1.1.1.2  christos             j += Display;
    321  1.1.1.2  christos         }
    322  1.1.1.2  christos 
    323  1.1.1.2  christos         /*
    324  1.1.1.2  christos          * Print the ASCII equivalent characters but watch out for the bad
    325  1.1.1.2  christos          * unprintable ones (printable chars are 0x20 through 0x7E)
    326  1.1.1.2  christos          */
    327  1.1.1.2  christos         AcpiUtFilePrintf (File, " ");
    328  1.1.1.2  christos         for (j = 0; j < 16; j++)
    329  1.1.1.2  christos         {
    330  1.1.1.2  christos             if (i + j >= Count)
    331  1.1.1.2  christos             {
    332  1.1.1.2  christos                 AcpiUtFilePrintf (File, "\n");
    333  1.1.1.2  christos                 return;
    334  1.1.1.2  christos             }
    335  1.1.1.2  christos 
    336  1.1.1.2  christos             BufChar = Buffer[(ACPI_SIZE) i + j];
    337  1.1.1.2  christos             if (ACPI_IS_PRINT (BufChar))
    338  1.1.1.2  christos             {
    339  1.1.1.2  christos                 AcpiUtFilePrintf (File, "%c", BufChar);
    340  1.1.1.2  christos             }
    341  1.1.1.2  christos             else
    342  1.1.1.2  christos             {
    343  1.1.1.2  christos                 AcpiUtFilePrintf (File, ".");
    344  1.1.1.2  christos             }
    345  1.1.1.2  christos         }
    346  1.1.1.2  christos 
    347  1.1.1.2  christos         /* Done with that line. */
    348  1.1.1.2  christos 
    349  1.1.1.2  christos         AcpiUtFilePrintf (File, "\n");
    350  1.1.1.2  christos         i += 16;
    351  1.1.1.2  christos     }
    352  1.1.1.2  christos 
    353  1.1.1.2  christos     return;
    354  1.1.1.2  christos }
    355  1.1.1.2  christos #endif
    356