1 /******************************************************************************
3 * Module Name: aslhex - ASCII hex output file generation (C, ASM, and ASL)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
46 #define _COMPONENT ACPI_COMPILER
47 ACPI_MODULE_NAME ("ashex")
50 * This module emits ASCII hex output files in either C, ASM, or ASL format
53 /* Local prototypes */
72 /*******************************************************************************
74 * FUNCTION: HxDoHexOutput
80 * DESCRIPTION: Create the hex output file. Note: data is obtained by reading
81 * the entire AML output file that was previously generated.
83 ******************************************************************************/
90 switch (Gbl_HexOutputFlag)
109 /* No other output types supported */
116 /*******************************************************************************
118 * FUNCTION: HxReadAmlOutputFile
120 * PARAMETERS: Buffer - Where to return data
124 * DESCRIPTION: Read a line of the AML output prior to formatting the data
126 ******************************************************************************/
129 HxReadAmlOutputFile (
135 Actual = fread (Buffer, 1, HEX_TABLE_LINE_SIZE,
136 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
138 if (ferror (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle))
140 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
148 /*******************************************************************************
150 * FUNCTION: HxDoHexOutputC
156 * DESCRIPTION: Create the hex output file. This is the same data as the AML
157 * output file, but formatted into hex/ascii bytes suitable for
158 * inclusion into a C source file.
160 ******************************************************************************/
166 UINT8 FileData[HEX_TABLE_LINE_SIZE];
173 /* Get AML size, seek back to start */
175 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
176 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
178 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
179 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
181 FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
183 while (Offset < AmlFileSize)
185 /* Read enough bytes needed for one output line */
187 LineLength = HxReadAmlOutputFile (FileData);
193 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
195 for (i = 0; i < LineLength; i++)
198 * Print each hex byte.
199 * Add a comma until the very last byte of the AML file
200 * (Some C compilers complain about a trailing comma)
202 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
203 if ((Offset + i + 1) < AmlFileSize)
205 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
209 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
213 /* Add fill spaces if needed for last line */
215 if (LineLength < HEX_TABLE_LINE_SIZE)
217 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
218 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
221 /* Emit the offset and ascii dump for the entire line */
223 FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
224 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
226 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
227 HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
229 Offset += LineLength;
232 FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
236 /*******************************************************************************
238 * FUNCTION: HxDoHexOutputAsl
244 * DESCRIPTION: Create the hex output file. This is the same data as the AML
245 * output file, but formatted into hex/ascii bytes suitable for
246 * inclusion into a C source file.
248 ******************************************************************************/
254 UINT8 FileData[HEX_TABLE_LINE_SIZE];
261 /* Get AML size, seek back to start */
263 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
264 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
266 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n");
267 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
269 FlPrintFile (ASL_FILE_HEX_OUTPUT, " Name (BUF1, Buffer()\n {\n");
271 while (Offset < AmlFileSize)
273 /* Read enough bytes needed for one output line */
275 LineLength = HxReadAmlOutputFile (FileData);
281 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
283 for (i = 0; i < LineLength; i++)
286 * Print each hex byte.
287 * Add a comma until the very last byte of the AML file
288 * (Some C compilers complain about a trailing comma)
290 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
291 if ((Offset + i + 1) < AmlFileSize)
293 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
297 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
301 /* Add fill spaces if needed for last line */
303 if (LineLength < HEX_TABLE_LINE_SIZE)
305 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
306 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
309 /* Emit the offset and ascii dump for the entire line */
311 FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
312 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
314 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
315 HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
317 Offset += LineLength;
320 FlPrintFile (ASL_FILE_HEX_OUTPUT, " })\n");
324 /*******************************************************************************
326 * FUNCTION: HxDoHexOutputAsm
332 * DESCRIPTION: Create the hex output file. This is the same data as the AML
333 * output file, but formatted into hex/ascii bytes suitable for
334 * inclusion into a ASM source file.
336 ******************************************************************************/
342 UINT8 FileData[HEX_TABLE_LINE_SIZE];
349 /* Get AML size, seek back to start */
351 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
352 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
354 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n");
355 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n",
358 while (Offset < AmlFileSize)
360 /* Read enough bytes needed for one output line */
362 LineLength = HxReadAmlOutputFile (FileData);
368 FlPrintFile (ASL_FILE_HEX_OUTPUT, " db ");
370 for (i = 0; i < LineLength; i++)
373 * Print each hex byte.
374 * Add a comma until the last byte of the line
376 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]);
377 if ((i + 1) < LineLength)
379 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
383 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
385 /* Add fill spaces if needed for last line */
387 if (LineLength < HEX_TABLE_LINE_SIZE)
389 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
390 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
393 /* Emit the offset and ascii dump for the entire line */
395 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ; %8.8X", Offset);
396 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
398 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
400 Offset += LineLength;
403 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");