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
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim *
90d84335fSJung-uk Kim * 1. Copyright Notice
100d84335fSJung-uk Kim *
11*58308fadSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12efcc2a30SJung-uk Kim * All rights reserved.
13efcc2a30SJung-uk Kim *
140d84335fSJung-uk Kim * 2. License
150d84335fSJung-uk Kim *
160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim * property rights.
200d84335fSJung-uk Kim *
210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim *
280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim *
370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim * conditions are met:
390d84335fSJung-uk Kim *
400d84335fSJung-uk Kim * 3. Conditions
410d84335fSJung-uk Kim *
420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim *
540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim * make.
650d84335fSJung-uk Kim *
660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim * distribution.
710d84335fSJung-uk Kim *
720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim * Intel Code.
740d84335fSJung-uk Kim *
750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim * without prior written authorization from Intel.
790d84335fSJung-uk Kim *
800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim *
820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim *
900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim * LIMITED REMEDY.
980d84335fSJung-uk Kim *
990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim * such license, approval or letter.
1130d84335fSJung-uk Kim *
1140d84335fSJung-uk Kim *****************************************************************************
1150d84335fSJung-uk Kim *
1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim * following license:
1180d84335fSJung-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 *
1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim *
1460d84335fSJung-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 *
1500d84335fSJung-uk Kim *****************************************************************************/
151efcc2a30SJung-uk Kim
152efcc2a30SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
153835b56bfSJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
154efcc2a30SJung-uk Kim
155efcc2a30SJung-uk Kim #define _COMPONENT ACPI_COMPILER
156efcc2a30SJung-uk Kim ACPI_MODULE_NAME ("ashex")
157efcc2a30SJung-uk Kim
158efcc2a30SJung-uk Kim /*
159efcc2a30SJung-uk Kim * This module emits ASCII hex output files in either C, ASM, or ASL format
160efcc2a30SJung-uk Kim */
161efcc2a30SJung-uk Kim
162efcc2a30SJung-uk Kim /* Local prototypes */
163efcc2a30SJung-uk Kim
164efcc2a30SJung-uk Kim static void
165efcc2a30SJung-uk Kim HxDoHexOutputC (
166efcc2a30SJung-uk Kim void);
167efcc2a30SJung-uk Kim
168efcc2a30SJung-uk Kim static void
169efcc2a30SJung-uk Kim HxDoHexOutputAsl (
170efcc2a30SJung-uk Kim void);
171efcc2a30SJung-uk Kim
172efcc2a30SJung-uk Kim static void
173efcc2a30SJung-uk Kim HxDoHexOutputAsm (
174efcc2a30SJung-uk Kim void);
175efcc2a30SJung-uk Kim
176efcc2a30SJung-uk Kim static UINT32
177efcc2a30SJung-uk Kim HxReadAmlOutputFile (
178efcc2a30SJung-uk Kim UINT8 *Buffer);
179efcc2a30SJung-uk Kim
180efcc2a30SJung-uk Kim
181efcc2a30SJung-uk Kim /*******************************************************************************
182efcc2a30SJung-uk Kim *
183efcc2a30SJung-uk Kim * FUNCTION: HxDoHexOutput
184efcc2a30SJung-uk Kim *
185efcc2a30SJung-uk Kim * PARAMETERS: None
186efcc2a30SJung-uk Kim *
187efcc2a30SJung-uk Kim * RETURN: None
188efcc2a30SJung-uk Kim *
189efcc2a30SJung-uk Kim * DESCRIPTION: Create the hex output file. Note: data is obtained by reading
190efcc2a30SJung-uk Kim * the entire AML output file that was previously generated.
191efcc2a30SJung-uk Kim *
192efcc2a30SJung-uk Kim ******************************************************************************/
193efcc2a30SJung-uk Kim
194efcc2a30SJung-uk Kim void
HxDoHexOutput(void)195efcc2a30SJung-uk Kim HxDoHexOutput (
196efcc2a30SJung-uk Kim void)
197efcc2a30SJung-uk Kim {
198efcc2a30SJung-uk Kim
1996f1f1a63SJung-uk Kim switch (AslGbl_HexOutputFlag)
200efcc2a30SJung-uk Kim {
201efcc2a30SJung-uk Kim case HEX_OUTPUT_C:
202efcc2a30SJung-uk Kim
203efcc2a30SJung-uk Kim HxDoHexOutputC ();
204efcc2a30SJung-uk Kim break;
205efcc2a30SJung-uk Kim
206efcc2a30SJung-uk Kim case HEX_OUTPUT_ASM:
207efcc2a30SJung-uk Kim
208efcc2a30SJung-uk Kim HxDoHexOutputAsm ();
209efcc2a30SJung-uk Kim break;
210efcc2a30SJung-uk Kim
211efcc2a30SJung-uk Kim case HEX_OUTPUT_ASL:
212efcc2a30SJung-uk Kim
213efcc2a30SJung-uk Kim HxDoHexOutputAsl ();
214efcc2a30SJung-uk Kim break;
215efcc2a30SJung-uk Kim
216efcc2a30SJung-uk Kim default:
217a9d8d09cSJung-uk Kim
218efcc2a30SJung-uk Kim /* No other output types supported */
219a9d8d09cSJung-uk Kim
220efcc2a30SJung-uk Kim break;
221efcc2a30SJung-uk Kim }
222efcc2a30SJung-uk Kim }
223efcc2a30SJung-uk Kim
224efcc2a30SJung-uk Kim
225efcc2a30SJung-uk Kim /*******************************************************************************
226efcc2a30SJung-uk Kim *
227efcc2a30SJung-uk Kim * FUNCTION: HxReadAmlOutputFile
228efcc2a30SJung-uk Kim *
229efcc2a30SJung-uk Kim * PARAMETERS: Buffer - Where to return data
230efcc2a30SJung-uk Kim *
231efcc2a30SJung-uk Kim * RETURN: None
232efcc2a30SJung-uk Kim *
233efcc2a30SJung-uk Kim * DESCRIPTION: Read a line of the AML output prior to formatting the data
234efcc2a30SJung-uk Kim *
235efcc2a30SJung-uk Kim ******************************************************************************/
236efcc2a30SJung-uk Kim
237efcc2a30SJung-uk Kim static UINT32
HxReadAmlOutputFile(UINT8 * Buffer)238efcc2a30SJung-uk Kim HxReadAmlOutputFile (
239efcc2a30SJung-uk Kim UINT8 *Buffer)
240efcc2a30SJung-uk Kim {
241efcc2a30SJung-uk Kim UINT32 Actual;
242efcc2a30SJung-uk Kim
243efcc2a30SJung-uk Kim
244efcc2a30SJung-uk Kim Actual = fread (Buffer, 1, HEX_TABLE_LINE_SIZE,
2456f1f1a63SJung-uk Kim AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle);
246efcc2a30SJung-uk Kim
2476f1f1a63SJung-uk Kim if (ferror (AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle))
248efcc2a30SJung-uk Kim {
249efcc2a30SJung-uk Kim FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
250efcc2a30SJung-uk Kim AslAbort ();
251efcc2a30SJung-uk Kim }
252efcc2a30SJung-uk Kim
253efcc2a30SJung-uk Kim return (Actual);
254efcc2a30SJung-uk Kim }
255efcc2a30SJung-uk Kim
256efcc2a30SJung-uk Kim
257efcc2a30SJung-uk Kim /*******************************************************************************
258efcc2a30SJung-uk Kim *
259efcc2a30SJung-uk Kim * FUNCTION: HxDoHexOutputC
260efcc2a30SJung-uk Kim *
261efcc2a30SJung-uk Kim * PARAMETERS: None
262efcc2a30SJung-uk Kim *
263efcc2a30SJung-uk Kim * RETURN: None
264efcc2a30SJung-uk Kim *
265efcc2a30SJung-uk Kim * DESCRIPTION: Create the hex output file. This is the same data as the AML
266efcc2a30SJung-uk Kim * output file, but formatted into hex/ascii bytes suitable for
267efcc2a30SJung-uk Kim * inclusion into a C source file.
268efcc2a30SJung-uk Kim *
269835b56bfSJung-uk Kim * Note: the base name of the hex output file is prepended to
270835b56bfSJung-uk Kim * all symbols as they are output to the file.
271835b56bfSJung-uk Kim *
272efcc2a30SJung-uk Kim ******************************************************************************/
273efcc2a30SJung-uk Kim
274efcc2a30SJung-uk Kim static void
HxDoHexOutputC(void)275efcc2a30SJung-uk Kim HxDoHexOutputC (
276efcc2a30SJung-uk Kim void)
277efcc2a30SJung-uk Kim {
278efcc2a30SJung-uk Kim UINT8 FileData[HEX_TABLE_LINE_SIZE];
279efcc2a30SJung-uk Kim UINT32 LineLength;
280efcc2a30SJung-uk Kim UINT32 Offset = 0;
281efcc2a30SJung-uk Kim UINT32 AmlFileSize;
282efcc2a30SJung-uk Kim UINT32 i;
283835b56bfSJung-uk Kim char *FileBasename;
284efcc2a30SJung-uk Kim
285efcc2a30SJung-uk Kim
286835b56bfSJung-uk Kim /* Obtain the file basename (filename with no extension) */
287835b56bfSJung-uk Kim
2886f1f1a63SJung-uk Kim FileBasename = FlGetFileBasename (AslGbl_Files [ASL_FILE_HEX_OUTPUT].Filename);
289835b56bfSJung-uk Kim
290efcc2a30SJung-uk Kim /* Get AML size, seek back to start */
291efcc2a30SJung-uk Kim
292efcc2a30SJung-uk Kim AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
293efcc2a30SJung-uk Kim FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
294efcc2a30SJung-uk Kim
295835b56bfSJung-uk Kim /* Finish the file header and emit the non-data symbols */
296835b56bfSJung-uk Kim
297efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
298efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
299efcc2a30SJung-uk Kim AmlFileSize);
300835b56bfSJung-uk Kim
301835b56bfSJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "#ifndef __%s_HEX__\n", FileBasename);
302835b56bfSJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "#define __%s_HEX__\n\n", FileBasename);
303835b56bfSJung-uk Kim
304835b56bfSJung-uk Kim AcpiUtStrlwr (FileBasename);
305835b56bfSJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char %s_aml_code[] =\n{\n", FileBasename);
306efcc2a30SJung-uk Kim
307efcc2a30SJung-uk Kim while (Offset < AmlFileSize)
308efcc2a30SJung-uk Kim {
309efcc2a30SJung-uk Kim /* Read enough bytes needed for one output line */
310efcc2a30SJung-uk Kim
311efcc2a30SJung-uk Kim LineLength = HxReadAmlOutputFile (FileData);
312efcc2a30SJung-uk Kim if (!LineLength)
313efcc2a30SJung-uk Kim {
314efcc2a30SJung-uk Kim break;
315efcc2a30SJung-uk Kim }
316efcc2a30SJung-uk Kim
317efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
318efcc2a30SJung-uk Kim
319efcc2a30SJung-uk Kim for (i = 0; i < LineLength; i++)
320efcc2a30SJung-uk Kim {
321efcc2a30SJung-uk Kim /*
322835b56bfSJung-uk Kim * Output each hex byte in the form: "0xnn,"
323efcc2a30SJung-uk Kim * Add a comma until the very last byte of the AML file
324efcc2a30SJung-uk Kim * (Some C compilers complain about a trailing comma)
325efcc2a30SJung-uk Kim */
326efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
327efcc2a30SJung-uk Kim if ((Offset + i + 1) < AmlFileSize)
328efcc2a30SJung-uk Kim {
329efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
330efcc2a30SJung-uk Kim }
331efcc2a30SJung-uk Kim else
332efcc2a30SJung-uk Kim {
333efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
334efcc2a30SJung-uk Kim }
335efcc2a30SJung-uk Kim }
336efcc2a30SJung-uk Kim
337efcc2a30SJung-uk Kim /* Add fill spaces if needed for last line */
338efcc2a30SJung-uk Kim
339efcc2a30SJung-uk Kim if (LineLength < HEX_TABLE_LINE_SIZE)
340efcc2a30SJung-uk Kim {
341efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
342efcc2a30SJung-uk Kim 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
343efcc2a30SJung-uk Kim }
344efcc2a30SJung-uk Kim
345efcc2a30SJung-uk Kim /* Emit the offset and ascii dump for the entire line */
346efcc2a30SJung-uk Kim
347efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
348efcc2a30SJung-uk Kim LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
349f8146b88SJung-uk Kim
350efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
351efcc2a30SJung-uk Kim HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
352efcc2a30SJung-uk Kim
353efcc2a30SJung-uk Kim Offset += LineLength;
354efcc2a30SJung-uk Kim }
355efcc2a30SJung-uk Kim
356835b56bfSJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n\n");
357835b56bfSJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "#endif\n");
358efcc2a30SJung-uk Kim }
359efcc2a30SJung-uk Kim
360efcc2a30SJung-uk Kim
361efcc2a30SJung-uk Kim /*******************************************************************************
362efcc2a30SJung-uk Kim *
363efcc2a30SJung-uk Kim * FUNCTION: HxDoHexOutputAsl
364efcc2a30SJung-uk Kim *
365efcc2a30SJung-uk Kim * PARAMETERS: None
366efcc2a30SJung-uk Kim *
367efcc2a30SJung-uk Kim * RETURN: None
368efcc2a30SJung-uk Kim *
369efcc2a30SJung-uk Kim * DESCRIPTION: Create the hex output file. This is the same data as the AML
370efcc2a30SJung-uk Kim * output file, but formatted into hex/ascii bytes suitable for
371efcc2a30SJung-uk Kim * inclusion into a C source file.
372efcc2a30SJung-uk Kim *
373efcc2a30SJung-uk Kim ******************************************************************************/
374efcc2a30SJung-uk Kim
375efcc2a30SJung-uk Kim static void
HxDoHexOutputAsl(void)376efcc2a30SJung-uk Kim HxDoHexOutputAsl (
377efcc2a30SJung-uk Kim void)
378efcc2a30SJung-uk Kim {
379efcc2a30SJung-uk Kim UINT8 FileData[HEX_TABLE_LINE_SIZE];
380efcc2a30SJung-uk Kim UINT32 LineLength;
381efcc2a30SJung-uk Kim UINT32 Offset = 0;
382efcc2a30SJung-uk Kim UINT32 AmlFileSize;
383efcc2a30SJung-uk Kim UINT32 i;
384efcc2a30SJung-uk Kim
385efcc2a30SJung-uk Kim
386efcc2a30SJung-uk Kim /* Get AML size, seek back to start */
387efcc2a30SJung-uk Kim
388efcc2a30SJung-uk Kim AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
389efcc2a30SJung-uk Kim FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
390efcc2a30SJung-uk Kim
391efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n");
392efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
393efcc2a30SJung-uk Kim AmlFileSize);
394efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " Name (BUF1, Buffer()\n {\n");
395efcc2a30SJung-uk Kim
396efcc2a30SJung-uk Kim while (Offset < AmlFileSize)
397efcc2a30SJung-uk Kim {
398efcc2a30SJung-uk Kim /* Read enough bytes needed for one output line */
399efcc2a30SJung-uk Kim
400efcc2a30SJung-uk Kim LineLength = HxReadAmlOutputFile (FileData);
401efcc2a30SJung-uk Kim if (!LineLength)
402efcc2a30SJung-uk Kim {
403efcc2a30SJung-uk Kim break;
404efcc2a30SJung-uk Kim }
405efcc2a30SJung-uk Kim
406efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
407efcc2a30SJung-uk Kim
408efcc2a30SJung-uk Kim for (i = 0; i < LineLength; i++)
409efcc2a30SJung-uk Kim {
410efcc2a30SJung-uk Kim /*
411efcc2a30SJung-uk Kim * Print each hex byte.
412efcc2a30SJung-uk Kim * Add a comma until the very last byte of the AML file
413efcc2a30SJung-uk Kim * (Some C compilers complain about a trailing comma)
414efcc2a30SJung-uk Kim */
415efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
416efcc2a30SJung-uk Kim if ((Offset + i + 1) < AmlFileSize)
417efcc2a30SJung-uk Kim {
418efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
419efcc2a30SJung-uk Kim }
420efcc2a30SJung-uk Kim else
421efcc2a30SJung-uk Kim {
422efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
423efcc2a30SJung-uk Kim }
424efcc2a30SJung-uk Kim }
425efcc2a30SJung-uk Kim
426efcc2a30SJung-uk Kim /* Add fill spaces if needed for last line */
427efcc2a30SJung-uk Kim
428efcc2a30SJung-uk Kim if (LineLength < HEX_TABLE_LINE_SIZE)
429efcc2a30SJung-uk Kim {
430efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
431efcc2a30SJung-uk Kim 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
432efcc2a30SJung-uk Kim }
433efcc2a30SJung-uk Kim
434efcc2a30SJung-uk Kim /* Emit the offset and ascii dump for the entire line */
435efcc2a30SJung-uk Kim
436efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
437efcc2a30SJung-uk Kim LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
438f8146b88SJung-uk Kim
439efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
440efcc2a30SJung-uk Kim HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
441efcc2a30SJung-uk Kim
442efcc2a30SJung-uk Kim Offset += LineLength;
443efcc2a30SJung-uk Kim }
444efcc2a30SJung-uk Kim
445efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " })\n");
446efcc2a30SJung-uk Kim }
447efcc2a30SJung-uk Kim
448efcc2a30SJung-uk Kim
449efcc2a30SJung-uk Kim /*******************************************************************************
450efcc2a30SJung-uk Kim *
451efcc2a30SJung-uk Kim * FUNCTION: HxDoHexOutputAsm
452efcc2a30SJung-uk Kim *
453efcc2a30SJung-uk Kim * PARAMETERS: None
454efcc2a30SJung-uk Kim *
455efcc2a30SJung-uk Kim * RETURN: None
456efcc2a30SJung-uk Kim *
457efcc2a30SJung-uk Kim * DESCRIPTION: Create the hex output file. This is the same data as the AML
458efcc2a30SJung-uk Kim * output file, but formatted into hex/ascii bytes suitable for
459efcc2a30SJung-uk Kim * inclusion into a ASM source file.
460efcc2a30SJung-uk Kim *
461efcc2a30SJung-uk Kim ******************************************************************************/
462efcc2a30SJung-uk Kim
463efcc2a30SJung-uk Kim static void
HxDoHexOutputAsm(void)464efcc2a30SJung-uk Kim HxDoHexOutputAsm (
465efcc2a30SJung-uk Kim void)
466efcc2a30SJung-uk Kim {
467efcc2a30SJung-uk Kim UINT8 FileData[HEX_TABLE_LINE_SIZE];
468efcc2a30SJung-uk Kim UINT32 LineLength;
469efcc2a30SJung-uk Kim UINT32 Offset = 0;
470efcc2a30SJung-uk Kim UINT32 AmlFileSize;
471efcc2a30SJung-uk Kim UINT32 i;
472efcc2a30SJung-uk Kim
473efcc2a30SJung-uk Kim
474efcc2a30SJung-uk Kim /* Get AML size, seek back to start */
475efcc2a30SJung-uk Kim
476efcc2a30SJung-uk Kim AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
477efcc2a30SJung-uk Kim FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
478efcc2a30SJung-uk Kim
479efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n");
480efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n",
481efcc2a30SJung-uk Kim AmlFileSize);
482efcc2a30SJung-uk Kim
483efcc2a30SJung-uk Kim while (Offset < AmlFileSize)
484efcc2a30SJung-uk Kim {
485efcc2a30SJung-uk Kim /* Read enough bytes needed for one output line */
486efcc2a30SJung-uk Kim
487efcc2a30SJung-uk Kim LineLength = HxReadAmlOutputFile (FileData);
488efcc2a30SJung-uk Kim if (!LineLength)
489efcc2a30SJung-uk Kim {
490efcc2a30SJung-uk Kim break;
491efcc2a30SJung-uk Kim }
492efcc2a30SJung-uk Kim
493efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " db ");
494efcc2a30SJung-uk Kim
495efcc2a30SJung-uk Kim for (i = 0; i < LineLength; i++)
496efcc2a30SJung-uk Kim {
497efcc2a30SJung-uk Kim /*
498efcc2a30SJung-uk Kim * Print each hex byte.
499efcc2a30SJung-uk Kim * Add a comma until the last byte of the line
500efcc2a30SJung-uk Kim */
501efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]);
502efcc2a30SJung-uk Kim if ((i + 1) < LineLength)
503efcc2a30SJung-uk Kim {
504efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
505efcc2a30SJung-uk Kim }
506efcc2a30SJung-uk Kim }
507efcc2a30SJung-uk Kim
508efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
509efcc2a30SJung-uk Kim
510efcc2a30SJung-uk Kim /* Add fill spaces if needed for last line */
511efcc2a30SJung-uk Kim
512efcc2a30SJung-uk Kim if (LineLength < HEX_TABLE_LINE_SIZE)
513efcc2a30SJung-uk Kim {
514efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
515efcc2a30SJung-uk Kim 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
516efcc2a30SJung-uk Kim }
517efcc2a30SJung-uk Kim
518efcc2a30SJung-uk Kim /* Emit the offset and ascii dump for the entire line */
519efcc2a30SJung-uk Kim
520efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, " ; %8.8X", Offset);
521efcc2a30SJung-uk Kim LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
522f8146b88SJung-uk Kim
523efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
524efcc2a30SJung-uk Kim
525efcc2a30SJung-uk Kim Offset += LineLength;
526efcc2a30SJung-uk Kim }
527efcc2a30SJung-uk Kim
528efcc2a30SJung-uk Kim FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
529efcc2a30SJung-uk Kim }
530