Home | History | Annotate | Line # | Download | only in utilities
utbuffer.c revision 1.1
      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  christos  * Copyright (C) 2000 - 2013, 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