Path: blob/main/sys/contrib/dev/acpica/components/utilities/utbuffer.c
48406 views
/******************************************************************************1*2* Module Name: utbuffer - Buffer dump routines3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153154#define _COMPONENT ACPI_UTILITIES155ACPI_MODULE_NAME ("utbuffer")156157158/*******************************************************************************159*160* FUNCTION: AcpiUtDumpBuffer161*162* PARAMETERS: Buffer - Buffer to dump163* Count - Amount to dump, in bytes164* Display - BYTE, WORD, DWORD, or QWORD display:165* DB_BYTE_DISPLAY166* DB_WORD_DISPLAY167* DB_DWORD_DISPLAY168* DB_QWORD_DISPLAY169* BaseOffset - Beginning buffer offset (display only)170*171* RETURN: None172*173* DESCRIPTION: Generic dump buffer in both hex and ascii.174*175******************************************************************************/176177void178AcpiUtDumpBuffer (179UINT8 *Buffer,180UINT32 Count,181UINT32 Display,182UINT32 BaseOffset)183{184UINT32 i = 0;185UINT32 j;186UINT32 Temp32;187UINT8 BufChar;188UINT32 DisplayDataOnly = Display & DB_DISPLAY_DATA_ONLY;189190191Display &= ~DB_DISPLAY_DATA_ONLY;192if (!Buffer)193{194AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");195return;196}197198if ((Count < 4) || (Count & 0x01))199{200Display = DB_BYTE_DISPLAY;201}202203/* Nasty little dump buffer routine! */204205while (i < Count)206{207/* Print current offset */208209if (!DisplayDataOnly)210{211AcpiOsPrintf ("%8.4X: ", (BaseOffset + i));212}213214/* Print 16 hex chars */215216for (j = 0; j < 16;)217{218if (i + j >= Count)219{220/* Dump fill spaces */221222AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");223j += Display;224continue;225}226227switch (Display)228{229case DB_BYTE_DISPLAY:230default: /* Default is BYTE display */231232AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);233break;234235case DB_WORD_DISPLAY:236237ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);238AcpiOsPrintf ("%04X ", Temp32);239break;240241case DB_DWORD_DISPLAY:242243ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);244AcpiOsPrintf ("%08X ", Temp32);245break;246247case DB_QWORD_DISPLAY:248249ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);250AcpiOsPrintf ("%08X", Temp32);251252ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);253AcpiOsPrintf ("%08X ", Temp32);254break;255}256257j += Display;258}259260/*261* Print the ASCII equivalent characters but watch out for the bad262* unprintable ones (printable chars are 0x20 through 0x7E)263*/264if (!DisplayDataOnly)265{266AcpiOsPrintf (" ");267for (j = 0; j < 16; j++)268{269if (i + j >= Count)270{271AcpiOsPrintf ("\n");272return;273}274275/*276* Add comment characters so rest of line is ignored when277* compiled278*/279if (j == 0)280{281AcpiOsPrintf ("// ");282}283284BufChar = Buffer[(ACPI_SIZE) i + j];285if (isprint (BufChar))286{287AcpiOsPrintf ("%c", BufChar);288}289else290{291AcpiOsPrintf (".");292}293}294295/* Done with that line. */296297AcpiOsPrintf ("\n");298}299i += 16;300}301302return;303}304305306/*******************************************************************************307*308* FUNCTION: AcpiUtDebugDumpBuffer309*310* PARAMETERS: Buffer - Buffer to dump311* Count - Amount to dump, in bytes312* Display - BYTE, WORD, DWORD, or QWORD display:313* DB_BYTE_DISPLAY314* DB_WORD_DISPLAY315* DB_DWORD_DISPLAY316* DB_QWORD_DISPLAY317* ComponentID - Caller's component ID318*319* RETURN: None320*321* DESCRIPTION: Generic dump buffer in both hex and ascii.322*323******************************************************************************/324325void326AcpiUtDebugDumpBuffer (327UINT8 *Buffer,328UINT32 Count,329UINT32 Display,330UINT32 ComponentId)331{332333/* Only dump the buffer if tracing is enabled */334335if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&336(ComponentId & AcpiDbgLayer)))337{338return;339}340341AcpiUtDumpBuffer (Buffer, Count, Display, 0);342}343344345#ifdef ACPI_APPLICATION346/*******************************************************************************347*348* FUNCTION: AcpiUtDumpBufferToFile349*350* PARAMETERS: File - File descriptor351* Buffer - Buffer to dump352* Count - Amount to dump, in bytes353* Display - BYTE, WORD, DWORD, or QWORD display:354* DB_BYTE_DISPLAY355* DB_WORD_DISPLAY356* DB_DWORD_DISPLAY357* DB_QWORD_DISPLAY358* BaseOffset - Beginning buffer offset (display only)359*360* RETURN: None361*362* DESCRIPTION: Generic dump buffer in both hex and ascii to a file.363*364******************************************************************************/365366void367AcpiUtDumpBufferToFile (368ACPI_FILE File,369UINT8 *Buffer,370UINT32 Count,371UINT32 Display,372UINT32 BaseOffset)373{374UINT32 i = 0;375UINT32 j;376UINT32 Temp32;377UINT8 BufChar;378379380if (!Buffer)381{382fprintf (File, "Null Buffer Pointer in DumpBuffer!\n");383return;384}385386if ((Count < 4) || (Count & 0x01))387{388Display = DB_BYTE_DISPLAY;389}390391/* Nasty little dump buffer routine! */392393while (i < Count)394{395/* Print current offset */396397fprintf (File, "%8.4X: ", (BaseOffset + i));398399/* Print 16 hex chars */400401for (j = 0; j < 16;)402{403if (i + j >= Count)404{405/* Dump fill spaces */406407fprintf (File, "%*s", ((Display * 2) + 1), " ");408j += Display;409continue;410}411412switch (Display)413{414case DB_BYTE_DISPLAY:415default: /* Default is BYTE display */416417fprintf (File, "%02X ", Buffer[(ACPI_SIZE) i + j]);418break;419420case DB_WORD_DISPLAY:421422ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);423fprintf (File, "%04X ", Temp32);424break;425426case DB_DWORD_DISPLAY:427428ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);429fprintf (File, "%08X ", Temp32);430break;431432case DB_QWORD_DISPLAY:433434ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);435fprintf (File, "%08X", Temp32);436437ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);438fprintf (File, "%08X ", Temp32);439break;440}441442j += Display;443}444445/*446* Print the ASCII equivalent characters but watch out for the bad447* unprintable ones (printable chars are 0x20 through 0x7E)448*/449fprintf (File, " ");450for (j = 0; j < 16; j++)451{452if (i + j >= Count)453{454fprintf (File, "\n");455return;456}457458BufChar = Buffer[(ACPI_SIZE) i + j];459if (isprint (BufChar))460{461fprintf (File, "%c", BufChar);462}463else464{465fprintf (File, ".");466}467}468469/* Done with that line. */470471fprintf (File, "\n");472i += 16;473}474475return;476}477#endif478479480