1 /******************************************************************************
3 * Module Name: aslhex - ASCII hex output file generation (C, ASM, and ASL)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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
54 /* Local prototypes */
73 /*******************************************************************************
75 * FUNCTION: HxDoHexOutput
81 * DESCRIPTION: Create the hex output file. Note: data is obtained by reading
82 * the entire AML output file that was previously generated.
84 ******************************************************************************/
91 switch (Gbl_HexOutputFlag)
110 /* No other output types supported */
117 /*******************************************************************************
119 * FUNCTION: HxReadAmlOutputFile
121 * PARAMETERS: Buffer - Where to return data
125 * DESCRIPTION: Read a line of the AML output prior to formatting the data
127 ******************************************************************************/
130 HxReadAmlOutputFile (
136 Actual = fread (Buffer, 1, HEX_TABLE_LINE_SIZE,
137 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
139 if (ferror (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle))
141 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
149 /*******************************************************************************
151 * FUNCTION: HxDoHexOutputC
157 * DESCRIPTION: Create the hex output file. This is the same data as the AML
158 * output file, but formatted into hex/ascii bytes suitable for
159 * inclusion into a C source file.
161 ******************************************************************************/
167 UINT8 FileData[HEX_TABLE_LINE_SIZE];
174 /* Get AML size, seek back to start */
176 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
177 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
179 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
180 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
182 FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
184 while (Offset < AmlFileSize)
186 /* Read enough bytes needed for one output line */
188 LineLength = HxReadAmlOutputFile (FileData);
194 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
196 for (i = 0; i < LineLength; i++)
199 * Print each hex byte.
200 * Add a comma until the very last byte of the AML file
201 * (Some C compilers complain about a trailing comma)
203 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
204 if ((Offset + i + 1) < AmlFileSize)
206 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
210 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
214 /* Add fill spaces if needed for last line */
216 if (LineLength < HEX_TABLE_LINE_SIZE)
218 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
219 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
222 /* Emit the offset and ascii dump for the entire line */
224 FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
225 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);
313 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
314 HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
316 Offset += LineLength;
319 FlPrintFile (ASL_FILE_HEX_OUTPUT, " })\n");
323 /*******************************************************************************
325 * FUNCTION: HxDoHexOutputAsm
331 * DESCRIPTION: Create the hex output file. This is the same data as the AML
332 * output file, but formatted into hex/ascii bytes suitable for
333 * inclusion into a ASM source file.
335 ******************************************************************************/
341 UINT8 FileData[HEX_TABLE_LINE_SIZE];
348 /* Get AML size, seek back to start */
350 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
351 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
353 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n");
354 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n",
357 while (Offset < AmlFileSize)
359 /* Read enough bytes needed for one output line */
361 LineLength = HxReadAmlOutputFile (FileData);
367 FlPrintFile (ASL_FILE_HEX_OUTPUT, " db ");
369 for (i = 0; i < LineLength; i++)
372 * Print each hex byte.
373 * Add a comma until the last byte of the line
375 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]);
376 if ((i + 1) < LineLength)
378 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
382 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
384 /* Add fill spaces if needed for last line */
386 if (LineLength < HEX_TABLE_LINE_SIZE)
388 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
389 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
392 /* Emit the offset and ascii dump for the entire line */
394 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ; %8.8X", Offset);
395 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
396 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
398 Offset += LineLength;
401 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");