1 /****************************************************************************** 2 * 3 * Module Name: utbuffer - Buffer dump routines 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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. 25 * 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. 29 * 30 * NO WARRANTY 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. 42 */ 43 44 #define __UTBUFFER_C__ 45 46 #include "acpi.h" 47 #include "accommon.h" 48 49 #define _COMPONENT ACPI_UTILITIES 50 ACPI_MODULE_NAME ("utbuffer") 51 52 53 /******************************************************************************* 54 * 55 * FUNCTION: AcpiUtDumpBuffer 56 * 57 * PARAMETERS: Buffer - Buffer to dump 58 * Count - Amount to dump, in bytes 59 * Display - BYTE, WORD, DWORD, or QWORD display: 60 * DB_BYTE_DISPLAY 61 * DB_WORD_DISPLAY 62 * DB_DWORD_DISPLAY 63 * DB_QWORD_DISPLAY 64 * BaseOffset - Beginning buffer offset (display only) 65 * 66 * RETURN: None 67 * 68 * DESCRIPTION: Generic dump buffer in both hex and ascii. 69 * 70 ******************************************************************************/ 71 72 void 73 AcpiUtDumpBuffer ( 74 UINT8 *Buffer, 75 UINT32 Count, 76 UINT32 Display, 77 UINT32 BaseOffset) 78 { 79 UINT32 i = 0; 80 UINT32 j; 81 UINT32 Temp32; 82 UINT8 BufChar; 83 84 85 if (!Buffer) 86 { 87 AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n"); 88 return; 89 } 90 91 if ((Count < 4) || (Count & 0x01)) 92 { 93 Display = DB_BYTE_DISPLAY; 94 } 95 96 /* Nasty little dump buffer routine! */ 97 98 while (i < Count) 99 { 100 /* Print current offset */ 101 102 AcpiOsPrintf ("%6.4X: ", (BaseOffset + i)); 103 104 /* Print 16 hex chars */ 105 106 for (j = 0; j < 16;) 107 { 108 if (i + j >= Count) 109 { 110 /* Dump fill spaces */ 111 112 AcpiOsPrintf ("%*s", ((Display * 2) + 1), " "); 113 j += Display; 114 continue; 115 } 116 117 switch (Display) 118 { 119 case DB_BYTE_DISPLAY: 120 default: /* Default is BYTE display */ 121 122 AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]); 123 break; 124 125 case DB_WORD_DISPLAY: 126 127 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); 128 AcpiOsPrintf ("%04X ", Temp32); 129 break; 130 131 case DB_DWORD_DISPLAY: 132 133 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); 134 AcpiOsPrintf ("%08X ", Temp32); 135 break; 136 137 case DB_QWORD_DISPLAY: 138 139 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); 140 AcpiOsPrintf ("%08X", Temp32); 141 142 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]); 143 AcpiOsPrintf ("%08X ", Temp32); 144 break; 145 } 146 147 j += Display; 148 } 149 150 /* 151 * Print the ASCII equivalent characters but watch out for the bad 152 * unprintable ones (printable chars are 0x20 through 0x7E) 153 */ 154 AcpiOsPrintf (" "); 155 for (j = 0; j < 16; j++) 156 { 157 if (i + j >= Count) 158 { 159 AcpiOsPrintf ("\n"); 160 return; 161 } 162 163 BufChar = Buffer[(ACPI_SIZE) i + j]; 164 if (ACPI_IS_PRINT (BufChar)) 165 { 166 AcpiOsPrintf ("%c", BufChar); 167 } 168 else 169 { 170 AcpiOsPrintf ("."); 171 } 172 } 173 174 /* Done with that line. */ 175 176 AcpiOsPrintf ("\n"); 177 i += 16; 178 } 179 180 return; 181 } 182 183 184 /******************************************************************************* 185 * 186 * FUNCTION: AcpiUtDebugDumpBuffer 187 * 188 * PARAMETERS: Buffer - Buffer to dump 189 * Count - Amount to dump, in bytes 190 * Display - BYTE, WORD, DWORD, or QWORD display: 191 * DB_BYTE_DISPLAY 192 * DB_WORD_DISPLAY 193 * DB_DWORD_DISPLAY 194 * DB_QWORD_DISPLAY 195 * ComponentID - Caller's component ID 196 * 197 * RETURN: None 198 * 199 * DESCRIPTION: Generic dump buffer in both hex and ascii. 200 * 201 ******************************************************************************/ 202 203 void 204 AcpiUtDebugDumpBuffer ( 205 UINT8 *Buffer, 206 UINT32 Count, 207 UINT32 Display, 208 UINT32 ComponentId) 209 { 210 211 /* Only dump the buffer if tracing is enabled */ 212 213 if (!((ACPI_LV_TABLES & AcpiDbgLevel) && 214 (ComponentId & AcpiDbgLayer))) 215 { 216 return; 217 } 218 219 AcpiUtDumpBuffer (Buffer, Count, Display, 0); 220 }