1efcc2a30SJung-uk Kim /****************************************************************************** 2efcc2a30SJung-uk Kim * 3efcc2a30SJung-uk Kim * Module Name: aslhex - ASCII hex output file generation (C, ASM, and ASL) 4efcc2a30SJung-uk Kim * 5efcc2a30SJung-uk Kim *****************************************************************************/ 6efcc2a30SJung-uk Kim 7*0d84335fSJung-uk Kim /****************************************************************************** 8*0d84335fSJung-uk Kim * 9*0d84335fSJung-uk Kim * 1. Copyright Notice 10*0d84335fSJung-uk Kim * 11*0d84335fSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12efcc2a30SJung-uk Kim * All rights reserved. 13efcc2a30SJung-uk Kim * 14*0d84335fSJung-uk Kim * 2. License 15*0d84335fSJung-uk Kim * 16*0d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 17*0d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 18*0d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 19*0d84335fSJung-uk Kim * property rights. 20*0d84335fSJung-uk Kim * 21*0d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22*0d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 23*0d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24*0d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 25*0d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 26*0d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 27*0d84335fSJung-uk Kim * 28*0d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29*0d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 30*0d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 31*0d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 32*0d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 33*0d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 34*0d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 35*0d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 36*0d84335fSJung-uk Kim * 37*0d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 38*0d84335fSJung-uk Kim * conditions are met: 39*0d84335fSJung-uk Kim * 40*0d84335fSJung-uk Kim * 3. Conditions 41*0d84335fSJung-uk Kim * 42*0d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43*0d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 44*0d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 45*0d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 46*0d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 47*0d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 48*0d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 49*0d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 50*0d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 51*0d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 52*0d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 53*0d84335fSJung-uk Kim * 54*0d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55*0d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 56*0d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 57*0d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 58*0d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 59*0d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 60*0d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 61*0d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 62*0d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 63*0d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 64*0d84335fSJung-uk Kim * make. 65*0d84335fSJung-uk Kim * 66*0d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67*0d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 68*0d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 69*0d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 70*0d84335fSJung-uk Kim * distribution. 71*0d84335fSJung-uk Kim * 72*0d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 73*0d84335fSJung-uk Kim * Intel Code. 74*0d84335fSJung-uk Kim * 75*0d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76*0d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 77*0d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 78*0d84335fSJung-uk Kim * without prior written authorization from Intel. 79*0d84335fSJung-uk Kim * 80*0d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 81*0d84335fSJung-uk Kim * 82*0d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83*0d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84*0d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85*0d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86*0d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87*0d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88*0d84335fSJung-uk Kim * PARTICULAR PURPOSE. 89*0d84335fSJung-uk Kim * 90*0d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91*0d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92*0d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93*0d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94*0d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95*0d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96*0d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97*0d84335fSJung-uk Kim * LIMITED REMEDY. 98*0d84335fSJung-uk Kim * 99*0d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100*0d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 101*0d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 102*0d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 103*0d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 104*0d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 105*0d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 106*0d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 107*0d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108*0d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 109*0d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 110*0d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 111*0d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 112*0d84335fSJung-uk Kim * such license, approval or letter. 113*0d84335fSJung-uk Kim * 114*0d84335fSJung-uk Kim ***************************************************************************** 115*0d84335fSJung-uk Kim * 116*0d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 117*0d84335fSJung-uk Kim * following license: 118*0d84335fSJung-uk Kim * 119efcc2a30SJung-uk Kim * Redistribution and use in source and binary forms, with or without 120efcc2a30SJung-uk Kim * modification, are permitted provided that the following conditions 121efcc2a30SJung-uk Kim * are met: 122efcc2a30SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 123efcc2a30SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 124efcc2a30SJung-uk Kim * without modification. 125efcc2a30SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126efcc2a30SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 127efcc2a30SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 128efcc2a30SJung-uk Kim * including a substantially similar Disclaimer requirement for further 129efcc2a30SJung-uk Kim * binary redistribution. 130efcc2a30SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 131efcc2a30SJung-uk Kim * of any contributors may be used to endorse or promote products derived 132efcc2a30SJung-uk Kim * from this software without specific prior written permission. 133efcc2a30SJung-uk Kim * 134*0d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135*0d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136*0d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137*0d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138*0d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139*0d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140*0d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141*0d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142*0d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143*0d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144*0d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145*0d84335fSJung-uk Kim * 146*0d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 147efcc2a30SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 148efcc2a30SJung-uk Kim * Software Foundation. 149efcc2a30SJung-uk Kim * 150*0d84335fSJung-uk Kim *****************************************************************************/ 151efcc2a30SJung-uk Kim 152efcc2a30SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 153efcc2a30SJung-uk Kim 154efcc2a30SJung-uk Kim #define _COMPONENT ACPI_COMPILER 155efcc2a30SJung-uk Kim ACPI_MODULE_NAME ("ashex") 156efcc2a30SJung-uk Kim 157efcc2a30SJung-uk Kim /* 158efcc2a30SJung-uk Kim * This module emits ASCII hex output files in either C, ASM, or ASL format 159efcc2a30SJung-uk Kim */ 160efcc2a30SJung-uk Kim 161efcc2a30SJung-uk Kim /* Local prototypes */ 162efcc2a30SJung-uk Kim 163efcc2a30SJung-uk Kim static void 164efcc2a30SJung-uk Kim HxDoHexOutputC ( 165efcc2a30SJung-uk Kim void); 166efcc2a30SJung-uk Kim 167efcc2a30SJung-uk Kim static void 168efcc2a30SJung-uk Kim HxDoHexOutputAsl ( 169efcc2a30SJung-uk Kim void); 170efcc2a30SJung-uk Kim 171efcc2a30SJung-uk Kim static void 172efcc2a30SJung-uk Kim HxDoHexOutputAsm ( 173efcc2a30SJung-uk Kim void); 174efcc2a30SJung-uk Kim 175efcc2a30SJung-uk Kim static UINT32 176efcc2a30SJung-uk Kim HxReadAmlOutputFile ( 177efcc2a30SJung-uk Kim UINT8 *Buffer); 178efcc2a30SJung-uk Kim 179efcc2a30SJung-uk Kim 180efcc2a30SJung-uk Kim /******************************************************************************* 181efcc2a30SJung-uk Kim * 182efcc2a30SJung-uk Kim * FUNCTION: HxDoHexOutput 183efcc2a30SJung-uk Kim * 184efcc2a30SJung-uk Kim * PARAMETERS: None 185efcc2a30SJung-uk Kim * 186efcc2a30SJung-uk Kim * RETURN: None 187efcc2a30SJung-uk Kim * 188efcc2a30SJung-uk Kim * DESCRIPTION: Create the hex output file. Note: data is obtained by reading 189efcc2a30SJung-uk Kim * the entire AML output file that was previously generated. 190efcc2a30SJung-uk Kim * 191efcc2a30SJung-uk Kim ******************************************************************************/ 192efcc2a30SJung-uk Kim 193efcc2a30SJung-uk Kim void 194efcc2a30SJung-uk Kim HxDoHexOutput ( 195efcc2a30SJung-uk Kim void) 196efcc2a30SJung-uk Kim { 197efcc2a30SJung-uk Kim 198efcc2a30SJung-uk Kim switch (Gbl_HexOutputFlag) 199efcc2a30SJung-uk Kim { 200efcc2a30SJung-uk Kim case HEX_OUTPUT_C: 201efcc2a30SJung-uk Kim 202efcc2a30SJung-uk Kim HxDoHexOutputC (); 203efcc2a30SJung-uk Kim break; 204efcc2a30SJung-uk Kim 205efcc2a30SJung-uk Kim case HEX_OUTPUT_ASM: 206efcc2a30SJung-uk Kim 207efcc2a30SJung-uk Kim HxDoHexOutputAsm (); 208efcc2a30SJung-uk Kim break; 209efcc2a30SJung-uk Kim 210efcc2a30SJung-uk Kim case HEX_OUTPUT_ASL: 211efcc2a30SJung-uk Kim 212efcc2a30SJung-uk Kim HxDoHexOutputAsl (); 213efcc2a30SJung-uk Kim break; 214efcc2a30SJung-uk Kim 215efcc2a30SJung-uk Kim default: 216a9d8d09cSJung-uk Kim 217efcc2a30SJung-uk Kim /* No other output types supported */ 218a9d8d09cSJung-uk Kim 219efcc2a30SJung-uk Kim break; 220efcc2a30SJung-uk Kim } 221efcc2a30SJung-uk Kim } 222efcc2a30SJung-uk Kim 223efcc2a30SJung-uk Kim 224efcc2a30SJung-uk Kim /******************************************************************************* 225efcc2a30SJung-uk Kim * 226efcc2a30SJung-uk Kim * FUNCTION: HxReadAmlOutputFile 227efcc2a30SJung-uk Kim * 228efcc2a30SJung-uk Kim * PARAMETERS: Buffer - Where to return data 229efcc2a30SJung-uk Kim * 230efcc2a30SJung-uk Kim * RETURN: None 231efcc2a30SJung-uk Kim * 232efcc2a30SJung-uk Kim * DESCRIPTION: Read a line of the AML output prior to formatting the data 233efcc2a30SJung-uk Kim * 234efcc2a30SJung-uk Kim ******************************************************************************/ 235efcc2a30SJung-uk Kim 236efcc2a30SJung-uk Kim static UINT32 237efcc2a30SJung-uk Kim HxReadAmlOutputFile ( 238efcc2a30SJung-uk Kim UINT8 *Buffer) 239efcc2a30SJung-uk Kim { 240efcc2a30SJung-uk Kim UINT32 Actual; 241efcc2a30SJung-uk Kim 242efcc2a30SJung-uk Kim 243efcc2a30SJung-uk Kim Actual = fread (Buffer, 1, HEX_TABLE_LINE_SIZE, 244efcc2a30SJung-uk Kim Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); 245efcc2a30SJung-uk Kim 246efcc2a30SJung-uk Kim if (ferror (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle)) 247efcc2a30SJung-uk Kim { 248efcc2a30SJung-uk Kim FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ); 249efcc2a30SJung-uk Kim AslAbort (); 250efcc2a30SJung-uk Kim } 251efcc2a30SJung-uk Kim 252efcc2a30SJung-uk Kim return (Actual); 253efcc2a30SJung-uk Kim } 254efcc2a30SJung-uk Kim 255efcc2a30SJung-uk Kim 256efcc2a30SJung-uk Kim /******************************************************************************* 257efcc2a30SJung-uk Kim * 258efcc2a30SJung-uk Kim * FUNCTION: HxDoHexOutputC 259efcc2a30SJung-uk Kim * 260efcc2a30SJung-uk Kim * PARAMETERS: None 261efcc2a30SJung-uk Kim * 262efcc2a30SJung-uk Kim * RETURN: None 263efcc2a30SJung-uk Kim * 264efcc2a30SJung-uk Kim * DESCRIPTION: Create the hex output file. This is the same data as the AML 265efcc2a30SJung-uk Kim * output file, but formatted into hex/ascii bytes suitable for 266efcc2a30SJung-uk Kim * inclusion into a C source file. 267efcc2a30SJung-uk Kim * 268efcc2a30SJung-uk Kim ******************************************************************************/ 269efcc2a30SJung-uk Kim 270efcc2a30SJung-uk Kim static void 271efcc2a30SJung-uk Kim HxDoHexOutputC ( 272efcc2a30SJung-uk Kim void) 273efcc2a30SJung-uk Kim { 274efcc2a30SJung-uk Kim UINT8 FileData[HEX_TABLE_LINE_SIZE]; 275efcc2a30SJung-uk Kim UINT32 LineLength; 276efcc2a30SJung-uk Kim UINT32 Offset = 0; 277efcc2a30SJung-uk Kim UINT32 AmlFileSize; 278efcc2a30SJung-uk Kim UINT32 i; 279efcc2a30SJung-uk Kim 280efcc2a30SJung-uk Kim 281efcc2a30SJung-uk Kim /* Get AML size, seek back to start */ 282efcc2a30SJung-uk Kim 283efcc2a30SJung-uk Kim AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT); 284efcc2a30SJung-uk Kim FlSeekFile (ASL_FILE_AML_OUTPUT, 0); 285efcc2a30SJung-uk Kim 286efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n"); 287efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n", 288efcc2a30SJung-uk Kim AmlFileSize); 289efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n"); 290efcc2a30SJung-uk Kim 291efcc2a30SJung-uk Kim while (Offset < AmlFileSize) 292efcc2a30SJung-uk Kim { 293efcc2a30SJung-uk Kim /* Read enough bytes needed for one output line */ 294efcc2a30SJung-uk Kim 295efcc2a30SJung-uk Kim LineLength = HxReadAmlOutputFile (FileData); 296efcc2a30SJung-uk Kim if (!LineLength) 297efcc2a30SJung-uk Kim { 298efcc2a30SJung-uk Kim break; 299efcc2a30SJung-uk Kim } 300efcc2a30SJung-uk Kim 301efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); 302efcc2a30SJung-uk Kim 303efcc2a30SJung-uk Kim for (i = 0; i < LineLength; i++) 304efcc2a30SJung-uk Kim { 305efcc2a30SJung-uk Kim /* 306efcc2a30SJung-uk Kim * Print each hex byte. 307efcc2a30SJung-uk Kim * Add a comma until the very last byte of the AML file 308efcc2a30SJung-uk Kim * (Some C compilers complain about a trailing comma) 309efcc2a30SJung-uk Kim */ 310efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]); 311efcc2a30SJung-uk Kim if ((Offset + i + 1) < AmlFileSize) 312efcc2a30SJung-uk Kim { 313efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); 314efcc2a30SJung-uk Kim } 315efcc2a30SJung-uk Kim else 316efcc2a30SJung-uk Kim { 317efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); 318efcc2a30SJung-uk Kim } 319efcc2a30SJung-uk Kim } 320efcc2a30SJung-uk Kim 321efcc2a30SJung-uk Kim /* Add fill spaces if needed for last line */ 322efcc2a30SJung-uk Kim 323efcc2a30SJung-uk Kim if (LineLength < HEX_TABLE_LINE_SIZE) 324efcc2a30SJung-uk Kim { 325efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s", 326efcc2a30SJung-uk Kim 5 * (HEX_TABLE_LINE_SIZE - LineLength), " "); 327efcc2a30SJung-uk Kim } 328efcc2a30SJung-uk Kim 329efcc2a30SJung-uk Kim /* Emit the offset and ascii dump for the entire line */ 330efcc2a30SJung-uk Kim 331efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset); 332efcc2a30SJung-uk Kim LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData); 333f8146b88SJung-uk Kim 334efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n", 335efcc2a30SJung-uk Kim HEX_TABLE_LINE_SIZE - LineLength + 1, " "); 336efcc2a30SJung-uk Kim 337efcc2a30SJung-uk Kim Offset += LineLength; 338efcc2a30SJung-uk Kim } 339efcc2a30SJung-uk Kim 340efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n"); 341efcc2a30SJung-uk Kim } 342efcc2a30SJung-uk Kim 343efcc2a30SJung-uk Kim 344efcc2a30SJung-uk Kim /******************************************************************************* 345efcc2a30SJung-uk Kim * 346efcc2a30SJung-uk Kim * FUNCTION: HxDoHexOutputAsl 347efcc2a30SJung-uk Kim * 348efcc2a30SJung-uk Kim * PARAMETERS: None 349efcc2a30SJung-uk Kim * 350efcc2a30SJung-uk Kim * RETURN: None 351efcc2a30SJung-uk Kim * 352efcc2a30SJung-uk Kim * DESCRIPTION: Create the hex output file. This is the same data as the AML 353efcc2a30SJung-uk Kim * output file, but formatted into hex/ascii bytes suitable for 354efcc2a30SJung-uk Kim * inclusion into a C source file. 355efcc2a30SJung-uk Kim * 356efcc2a30SJung-uk Kim ******************************************************************************/ 357efcc2a30SJung-uk Kim 358efcc2a30SJung-uk Kim static void 359efcc2a30SJung-uk Kim HxDoHexOutputAsl ( 360efcc2a30SJung-uk Kim void) 361efcc2a30SJung-uk Kim { 362efcc2a30SJung-uk Kim UINT8 FileData[HEX_TABLE_LINE_SIZE]; 363efcc2a30SJung-uk Kim UINT32 LineLength; 364efcc2a30SJung-uk Kim UINT32 Offset = 0; 365efcc2a30SJung-uk Kim UINT32 AmlFileSize; 366efcc2a30SJung-uk Kim UINT32 i; 367efcc2a30SJung-uk Kim 368efcc2a30SJung-uk Kim 369efcc2a30SJung-uk Kim /* Get AML size, seek back to start */ 370efcc2a30SJung-uk Kim 371efcc2a30SJung-uk Kim AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT); 372efcc2a30SJung-uk Kim FlSeekFile (ASL_FILE_AML_OUTPUT, 0); 373efcc2a30SJung-uk Kim 374efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n"); 375efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n", 376efcc2a30SJung-uk Kim AmlFileSize); 377efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " Name (BUF1, Buffer()\n {\n"); 378efcc2a30SJung-uk Kim 379efcc2a30SJung-uk Kim while (Offset < AmlFileSize) 380efcc2a30SJung-uk Kim { 381efcc2a30SJung-uk Kim /* Read enough bytes needed for one output line */ 382efcc2a30SJung-uk Kim 383efcc2a30SJung-uk Kim LineLength = HxReadAmlOutputFile (FileData); 384efcc2a30SJung-uk Kim if (!LineLength) 385efcc2a30SJung-uk Kim { 386efcc2a30SJung-uk Kim break; 387efcc2a30SJung-uk Kim } 388efcc2a30SJung-uk Kim 389efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); 390efcc2a30SJung-uk Kim 391efcc2a30SJung-uk Kim for (i = 0; i < LineLength; i++) 392efcc2a30SJung-uk Kim { 393efcc2a30SJung-uk Kim /* 394efcc2a30SJung-uk Kim * Print each hex byte. 395efcc2a30SJung-uk Kim * Add a comma until the very last byte of the AML file 396efcc2a30SJung-uk Kim * (Some C compilers complain about a trailing comma) 397efcc2a30SJung-uk Kim */ 398efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]); 399efcc2a30SJung-uk Kim if ((Offset + i + 1) < AmlFileSize) 400efcc2a30SJung-uk Kim { 401efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); 402efcc2a30SJung-uk Kim } 403efcc2a30SJung-uk Kim else 404efcc2a30SJung-uk Kim { 405efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); 406efcc2a30SJung-uk Kim } 407efcc2a30SJung-uk Kim } 408efcc2a30SJung-uk Kim 409efcc2a30SJung-uk Kim /* Add fill spaces if needed for last line */ 410efcc2a30SJung-uk Kim 411efcc2a30SJung-uk Kim if (LineLength < HEX_TABLE_LINE_SIZE) 412efcc2a30SJung-uk Kim { 413efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s", 414efcc2a30SJung-uk Kim 5 * (HEX_TABLE_LINE_SIZE - LineLength), " "); 415efcc2a30SJung-uk Kim } 416efcc2a30SJung-uk Kim 417efcc2a30SJung-uk Kim /* Emit the offset and ascii dump for the entire line */ 418efcc2a30SJung-uk Kim 419efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset); 420efcc2a30SJung-uk Kim LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData); 421f8146b88SJung-uk Kim 422efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n", 423efcc2a30SJung-uk Kim HEX_TABLE_LINE_SIZE - LineLength + 1, " "); 424efcc2a30SJung-uk Kim 425efcc2a30SJung-uk Kim Offset += LineLength; 426efcc2a30SJung-uk Kim } 427efcc2a30SJung-uk Kim 428efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " })\n"); 429efcc2a30SJung-uk Kim } 430efcc2a30SJung-uk Kim 431efcc2a30SJung-uk Kim 432efcc2a30SJung-uk Kim /******************************************************************************* 433efcc2a30SJung-uk Kim * 434efcc2a30SJung-uk Kim * FUNCTION: HxDoHexOutputAsm 435efcc2a30SJung-uk Kim * 436efcc2a30SJung-uk Kim * PARAMETERS: None 437efcc2a30SJung-uk Kim * 438efcc2a30SJung-uk Kim * RETURN: None 439efcc2a30SJung-uk Kim * 440efcc2a30SJung-uk Kim * DESCRIPTION: Create the hex output file. This is the same data as the AML 441efcc2a30SJung-uk Kim * output file, but formatted into hex/ascii bytes suitable for 442efcc2a30SJung-uk Kim * inclusion into a ASM source file. 443efcc2a30SJung-uk Kim * 444efcc2a30SJung-uk Kim ******************************************************************************/ 445efcc2a30SJung-uk Kim 446efcc2a30SJung-uk Kim static void 447efcc2a30SJung-uk Kim HxDoHexOutputAsm ( 448efcc2a30SJung-uk Kim void) 449efcc2a30SJung-uk Kim { 450efcc2a30SJung-uk Kim UINT8 FileData[HEX_TABLE_LINE_SIZE]; 451efcc2a30SJung-uk Kim UINT32 LineLength; 452efcc2a30SJung-uk Kim UINT32 Offset = 0; 453efcc2a30SJung-uk Kim UINT32 AmlFileSize; 454efcc2a30SJung-uk Kim UINT32 i; 455efcc2a30SJung-uk Kim 456efcc2a30SJung-uk Kim 457efcc2a30SJung-uk Kim /* Get AML size, seek back to start */ 458efcc2a30SJung-uk Kim 459efcc2a30SJung-uk Kim AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT); 460efcc2a30SJung-uk Kim FlSeekFile (ASL_FILE_AML_OUTPUT, 0); 461efcc2a30SJung-uk Kim 462efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n"); 463efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n", 464efcc2a30SJung-uk Kim AmlFileSize); 465efcc2a30SJung-uk Kim 466efcc2a30SJung-uk Kim while (Offset < AmlFileSize) 467efcc2a30SJung-uk Kim { 468efcc2a30SJung-uk Kim /* Read enough bytes needed for one output line */ 469efcc2a30SJung-uk Kim 470efcc2a30SJung-uk Kim LineLength = HxReadAmlOutputFile (FileData); 471efcc2a30SJung-uk Kim if (!LineLength) 472efcc2a30SJung-uk Kim { 473efcc2a30SJung-uk Kim break; 474efcc2a30SJung-uk Kim } 475efcc2a30SJung-uk Kim 476efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " db "); 477efcc2a30SJung-uk Kim 478efcc2a30SJung-uk Kim for (i = 0; i < LineLength; i++) 479efcc2a30SJung-uk Kim { 480efcc2a30SJung-uk Kim /* 481efcc2a30SJung-uk Kim * Print each hex byte. 482efcc2a30SJung-uk Kim * Add a comma until the last byte of the line 483efcc2a30SJung-uk Kim */ 484efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]); 485efcc2a30SJung-uk Kim if ((i + 1) < LineLength) 486efcc2a30SJung-uk Kim { 487efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); 488efcc2a30SJung-uk Kim } 489efcc2a30SJung-uk Kim } 490efcc2a30SJung-uk Kim 491efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); 492efcc2a30SJung-uk Kim 493efcc2a30SJung-uk Kim /* Add fill spaces if needed for last line */ 494efcc2a30SJung-uk Kim 495efcc2a30SJung-uk Kim if (LineLength < HEX_TABLE_LINE_SIZE) 496efcc2a30SJung-uk Kim { 497efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s", 498efcc2a30SJung-uk Kim 5 * (HEX_TABLE_LINE_SIZE - LineLength), " "); 499efcc2a30SJung-uk Kim } 500efcc2a30SJung-uk Kim 501efcc2a30SJung-uk Kim /* Emit the offset and ascii dump for the entire line */ 502efcc2a30SJung-uk Kim 503efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " ; %8.8X", Offset); 504efcc2a30SJung-uk Kim LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData); 505f8146b88SJung-uk Kim 506efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n"); 507efcc2a30SJung-uk Kim 508efcc2a30SJung-uk Kim Offset += LineLength; 509efcc2a30SJung-uk Kim } 510efcc2a30SJung-uk Kim 511efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n"); 512efcc2a30SJung-uk Kim } 513