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