Home | History | Annotate | Line # | Download | only in utilities
utbuffer.c revision 1.1.1.11
      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.10  christos  * Copyright (C) 2000 - 2019, 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 #include "acpi.h"
     45       1.1  christos #include "accommon.h"
     46       1.1  christos 
     47       1.1  christos #define _COMPONENT          ACPI_UTILITIES
     48       1.1  christos         ACPI_MODULE_NAME    ("utbuffer")
     49       1.1  christos 
     50       1.1  christos 
     51       1.1  christos /*******************************************************************************
     52       1.1  christos  *
     53       1.1  christos  * FUNCTION:    AcpiUtDumpBuffer
     54       1.1  christos  *
     55       1.1  christos  * PARAMETERS:  Buffer              - Buffer to dump
     56       1.1  christos  *              Count               - Amount to dump, in bytes
     57       1.1  christos  *              Display             - BYTE, WORD, DWORD, or QWORD display:
     58       1.1  christos  *                                      DB_BYTE_DISPLAY
     59       1.1  christos  *                                      DB_WORD_DISPLAY
     60       1.1  christos  *                                      DB_DWORD_DISPLAY
     61       1.1  christos  *                                      DB_QWORD_DISPLAY
     62       1.1  christos  *              BaseOffset          - Beginning buffer offset (display only)
     63       1.1  christos  *
     64       1.1  christos  * RETURN:      None
     65       1.1  christos  *
     66       1.1  christos  * DESCRIPTION: Generic dump buffer in both hex and ascii.
     67       1.1  christos  *
     68       1.1  christos  ******************************************************************************/
     69       1.1  christos 
     70       1.1  christos void
     71       1.1  christos AcpiUtDumpBuffer (
     72       1.1  christos     UINT8                   *Buffer,
     73       1.1  christos     UINT32                  Count,
     74       1.1  christos     UINT32                  Display,
     75       1.1  christos     UINT32                  BaseOffset)
     76       1.1  christos {
     77       1.1  christos     UINT32                  i = 0;
     78       1.1  christos     UINT32                  j;
     79       1.1  christos     UINT32                  Temp32;
     80       1.1  christos     UINT8                   BufChar;
     81  1.1.1.11  christos     UINT32                  DisplayDataOnly = Display & DB_DISPLAY_DATA_ONLY;
     82       1.1  christos 
     83       1.1  christos 
     84  1.1.1.11  christos     Display &= ~DB_DISPLAY_DATA_ONLY;
     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.1.11  christos         if (!DisplayDataOnly)
    103  1.1.1.11  christos         {
    104  1.1.1.11  christos             AcpiOsPrintf ("%8.4X: ", (BaseOffset + i));
    105  1.1.1.11  christos         }
    106       1.1  christos 
    107       1.1  christos         /* Print 16 hex chars */
    108       1.1  christos 
    109       1.1  christos         for (j = 0; j < 16;)
    110       1.1  christos         {
    111       1.1  christos             if (i + j >= Count)
    112       1.1  christos             {
    113       1.1  christos                 /* Dump fill spaces */
    114       1.1  christos 
    115       1.1  christos                 AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");
    116       1.1  christos                 j += Display;
    117       1.1  christos                 continue;
    118       1.1  christos             }
    119       1.1  christos 
    120       1.1  christos             switch (Display)
    121       1.1  christos             {
    122       1.1  christos             case DB_BYTE_DISPLAY:
    123       1.1  christos             default:    /* Default is BYTE display */
    124       1.1  christos 
    125       1.1  christos                 AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);
    126       1.1  christos                 break;
    127       1.1  christos 
    128       1.1  christos             case DB_WORD_DISPLAY:
    129       1.1  christos 
    130       1.1  christos                 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    131       1.1  christos                 AcpiOsPrintf ("%04X ", Temp32);
    132       1.1  christos                 break;
    133       1.1  christos 
    134       1.1  christos             case DB_DWORD_DISPLAY:
    135       1.1  christos 
    136       1.1  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    137       1.1  christos                 AcpiOsPrintf ("%08X ", Temp32);
    138       1.1  christos                 break;
    139       1.1  christos 
    140       1.1  christos             case DB_QWORD_DISPLAY:
    141       1.1  christos 
    142       1.1  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    143       1.1  christos                 AcpiOsPrintf ("%08X", Temp32);
    144       1.1  christos 
    145       1.1  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
    146       1.1  christos                 AcpiOsPrintf ("%08X ", Temp32);
    147       1.1  christos                 break;
    148       1.1  christos             }
    149       1.1  christos 
    150       1.1  christos             j += Display;
    151       1.1  christos         }
    152       1.1  christos 
    153       1.1  christos         /*
    154       1.1  christos          * Print the ASCII equivalent characters but watch out for the bad
    155       1.1  christos          * unprintable ones (printable chars are 0x20 through 0x7E)
    156       1.1  christos          */
    157  1.1.1.11  christos         if (!DisplayDataOnly)
    158       1.1  christos         {
    159  1.1.1.11  christos             AcpiOsPrintf (" ");
    160  1.1.1.11  christos             for (j = 0; j < 16; j++)
    161       1.1  christos             {
    162  1.1.1.11  christos                 if (i + j >= Count)
    163  1.1.1.11  christos                 {
    164  1.1.1.11  christos                     AcpiOsPrintf ("\n");
    165  1.1.1.11  christos                     return;
    166  1.1.1.11  christos                 }
    167  1.1.1.11  christos 
    168  1.1.1.11  christos                 /*
    169  1.1.1.11  christos                  * Add comment characters so rest of line is ignored when
    170  1.1.1.11  christos                  * compiled
    171  1.1.1.11  christos                  */
    172  1.1.1.11  christos                 if (j == 0)
    173  1.1.1.11  christos                 {
    174  1.1.1.11  christos                     AcpiOsPrintf ("// ");
    175  1.1.1.11  christos                 }
    176  1.1.1.11  christos 
    177  1.1.1.11  christos                 BufChar = Buffer[(ACPI_SIZE) i + j];
    178  1.1.1.11  christos                 if (isprint (BufChar))
    179  1.1.1.11  christos                 {
    180  1.1.1.11  christos                     AcpiOsPrintf ("%c", BufChar);
    181  1.1.1.11  christos                 }
    182  1.1.1.11  christos                 else
    183  1.1.1.11  christos                 {
    184  1.1.1.11  christos                     AcpiOsPrintf (".");
    185  1.1.1.11  christos                 }
    186       1.1  christos             }
    187       1.1  christos 
    188  1.1.1.11  christos             /* Done with that line. */
    189   1.1.1.3  christos 
    190  1.1.1.11  christos             AcpiOsPrintf ("\n");
    191       1.1  christos         }
    192       1.1  christos         i += 16;
    193       1.1  christos     }
    194       1.1  christos 
    195       1.1  christos     return;
    196       1.1  christos }
    197       1.1  christos 
    198       1.1  christos 
    199       1.1  christos /*******************************************************************************
    200       1.1  christos  *
    201       1.1  christos  * FUNCTION:    AcpiUtDebugDumpBuffer
    202       1.1  christos  *
    203       1.1  christos  * PARAMETERS:  Buffer              - Buffer to dump
    204       1.1  christos  *              Count               - Amount to dump, in bytes
    205       1.1  christos  *              Display             - BYTE, WORD, DWORD, or QWORD display:
    206       1.1  christos  *                                      DB_BYTE_DISPLAY
    207       1.1  christos  *                                      DB_WORD_DISPLAY
    208       1.1  christos  *                                      DB_DWORD_DISPLAY
    209       1.1  christos  *                                      DB_QWORD_DISPLAY
    210       1.1  christos  *              ComponentID         - Caller's component ID
    211       1.1  christos  *
    212       1.1  christos  * RETURN:      None
    213       1.1  christos  *
    214       1.1  christos  * DESCRIPTION: Generic dump buffer in both hex and ascii.
    215       1.1  christos  *
    216       1.1  christos  ******************************************************************************/
    217       1.1  christos 
    218       1.1  christos void
    219       1.1  christos AcpiUtDebugDumpBuffer (
    220       1.1  christos     UINT8                   *Buffer,
    221       1.1  christos     UINT32                  Count,
    222       1.1  christos     UINT32                  Display,
    223       1.1  christos     UINT32                  ComponentId)
    224       1.1  christos {
    225       1.1  christos 
    226       1.1  christos     /* Only dump the buffer if tracing is enabled */
    227       1.1  christos 
    228       1.1  christos     if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&
    229       1.1  christos         (ComponentId & AcpiDbgLayer)))
    230       1.1  christos     {
    231       1.1  christos         return;
    232       1.1  christos     }
    233       1.1  christos 
    234       1.1  christos     AcpiUtDumpBuffer (Buffer, Count, Display, 0);
    235       1.1  christos }
    236   1.1.1.2  christos 
    237   1.1.1.2  christos 
    238   1.1.1.2  christos #ifdef ACPI_APPLICATION
    239   1.1.1.2  christos /*******************************************************************************
    240   1.1.1.2  christos  *
    241   1.1.1.2  christos  * FUNCTION:    AcpiUtDumpBufferToFile
    242   1.1.1.2  christos  *
    243   1.1.1.2  christos  * PARAMETERS:  File                - File descriptor
    244   1.1.1.2  christos  *              Buffer              - Buffer to dump
    245   1.1.1.2  christos  *              Count               - Amount to dump, in bytes
    246   1.1.1.2  christos  *              Display             - BYTE, WORD, DWORD, or QWORD display:
    247   1.1.1.2  christos  *                                      DB_BYTE_DISPLAY
    248   1.1.1.2  christos  *                                      DB_WORD_DISPLAY
    249   1.1.1.2  christos  *                                      DB_DWORD_DISPLAY
    250   1.1.1.2  christos  *                                      DB_QWORD_DISPLAY
    251   1.1.1.2  christos  *              BaseOffset          - Beginning buffer offset (display only)
    252   1.1.1.2  christos  *
    253   1.1.1.2  christos  * RETURN:      None
    254   1.1.1.2  christos  *
    255   1.1.1.2  christos  * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
    256   1.1.1.2  christos  *
    257   1.1.1.2  christos  ******************************************************************************/
    258   1.1.1.2  christos 
    259   1.1.1.2  christos void
    260   1.1.1.2  christos AcpiUtDumpBufferToFile (
    261   1.1.1.2  christos     ACPI_FILE               File,
    262   1.1.1.2  christos     UINT8                   *Buffer,
    263   1.1.1.2  christos     UINT32                  Count,
    264   1.1.1.2  christos     UINT32                  Display,
    265   1.1.1.2  christos     UINT32                  BaseOffset)
    266   1.1.1.2  christos {
    267   1.1.1.2  christos     UINT32                  i = 0;
    268   1.1.1.2  christos     UINT32                  j;
    269   1.1.1.2  christos     UINT32                  Temp32;
    270   1.1.1.2  christos     UINT8                   BufChar;
    271   1.1.1.2  christos 
    272   1.1.1.2  christos 
    273   1.1.1.2  christos     if (!Buffer)
    274   1.1.1.2  christos     {
    275   1.1.1.6  christos         fprintf (File, "Null Buffer Pointer in DumpBuffer!\n");
    276   1.1.1.2  christos         return;
    277   1.1.1.2  christos     }
    278   1.1.1.2  christos 
    279   1.1.1.2  christos     if ((Count < 4) || (Count & 0x01))
    280   1.1.1.2  christos     {
    281   1.1.1.2  christos         Display = DB_BYTE_DISPLAY;
    282   1.1.1.2  christos     }
    283   1.1.1.2  christos 
    284   1.1.1.2  christos     /* Nasty little dump buffer routine! */
    285   1.1.1.2  christos 
    286   1.1.1.2  christos     while (i < Count)
    287   1.1.1.2  christos     {
    288   1.1.1.2  christos         /* Print current offset */
    289   1.1.1.2  christos 
    290   1.1.1.9  christos         fprintf (File, "%8.4X: ", (BaseOffset + i));
    291   1.1.1.2  christos 
    292   1.1.1.2  christos         /* Print 16 hex chars */
    293   1.1.1.2  christos 
    294   1.1.1.2  christos         for (j = 0; j < 16;)
    295   1.1.1.2  christos         {
    296   1.1.1.2  christos             if (i + j >= Count)
    297   1.1.1.2  christos             {
    298   1.1.1.2  christos                 /* Dump fill spaces */
    299   1.1.1.2  christos 
    300   1.1.1.6  christos                 fprintf (File, "%*s", ((Display * 2) + 1), " ");
    301   1.1.1.2  christos                 j += Display;
    302   1.1.1.2  christos                 continue;
    303   1.1.1.2  christos             }
    304   1.1.1.2  christos 
    305   1.1.1.2  christos             switch (Display)
    306   1.1.1.2  christos             {
    307   1.1.1.2  christos             case DB_BYTE_DISPLAY:
    308   1.1.1.2  christos             default:    /* Default is BYTE display */
    309   1.1.1.2  christos 
    310   1.1.1.6  christos                 fprintf (File, "%02X ", Buffer[(ACPI_SIZE) i + j]);
    311   1.1.1.2  christos                 break;
    312   1.1.1.2  christos 
    313   1.1.1.2  christos             case DB_WORD_DISPLAY:
    314   1.1.1.2  christos 
    315   1.1.1.2  christos                 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    316   1.1.1.6  christos                 fprintf (File, "%04X ", Temp32);
    317   1.1.1.2  christos                 break;
    318   1.1.1.2  christos 
    319   1.1.1.2  christos             case DB_DWORD_DISPLAY:
    320   1.1.1.2  christos 
    321   1.1.1.2  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    322   1.1.1.6  christos                 fprintf (File, "%08X ", Temp32);
    323   1.1.1.2  christos                 break;
    324   1.1.1.2  christos 
    325   1.1.1.2  christos             case DB_QWORD_DISPLAY:
    326   1.1.1.2  christos 
    327   1.1.1.2  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
    328   1.1.1.6  christos                 fprintf (File, "%08X", Temp32);
    329   1.1.1.2  christos 
    330   1.1.1.2  christos                 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
    331   1.1.1.6  christos                 fprintf (File, "%08X ", Temp32);
    332   1.1.1.2  christos                 break;
    333   1.1.1.2  christos             }
    334   1.1.1.2  christos 
    335   1.1.1.2  christos             j += Display;
    336   1.1.1.2  christos         }
    337   1.1.1.2  christos 
    338   1.1.1.2  christos         /*
    339   1.1.1.2  christos          * Print the ASCII equivalent characters but watch out for the bad
    340   1.1.1.2  christos          * unprintable ones (printable chars are 0x20 through 0x7E)
    341   1.1.1.2  christos          */
    342   1.1.1.6  christos         fprintf (File, " ");
    343   1.1.1.2  christos         for (j = 0; j < 16; j++)
    344   1.1.1.2  christos         {
    345   1.1.1.2  christos             if (i + j >= Count)
    346   1.1.1.2  christos             {
    347   1.1.1.6  christos                 fprintf (File, "\n");
    348   1.1.1.2  christos                 return;
    349   1.1.1.2  christos             }
    350   1.1.1.2  christos 
    351   1.1.1.2  christos             BufChar = Buffer[(ACPI_SIZE) i + j];
    352   1.1.1.4  christos             if (isprint (BufChar))
    353   1.1.1.2  christos             {
    354   1.1.1.6  christos                 fprintf (File, "%c", BufChar);
    355   1.1.1.2  christos             }
    356   1.1.1.2  christos             else
    357   1.1.1.2  christos             {
    358   1.1.1.6  christos                 fprintf (File, ".");
    359   1.1.1.2  christos             }
    360   1.1.1.2  christos         }
    361   1.1.1.2  christos 
    362   1.1.1.2  christos         /* Done with that line. */
    363   1.1.1.2  christos 
    364   1.1.1.6  christos         fprintf (File, "\n");
    365   1.1.1.2  christos         i += 16;
    366   1.1.1.2  christos     }
    367   1.1.1.2  christos 
    368   1.1.1.2  christos     return;
    369   1.1.1.2  christos }
    370   1.1.1.2  christos #endif
    371