1 /******************************************************************************
3 * Module Name: aslhex - ASCII hex output file generation (C, ASM, and ASL)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
45 #include "aslcompiler.h"
47 #define _COMPONENT ACPI_COMPILER
48 ACPI_MODULE_NAME ("ashex")
51 * This module emits ASCII hex output files in either C, ASM, or ASL format
55 /* Local prototypes */
74 /*******************************************************************************
76 * FUNCTION: HxDoHexOutput
82 * DESCRIPTION: Create the hex output file. Note: data is obtained by reading
83 * the entire AML output file that was previously generated.
85 ******************************************************************************/
92 switch (Gbl_HexOutputFlag
)
111 /* No other output types supported */
118 /*******************************************************************************
120 * FUNCTION: HxReadAmlOutputFile
122 * PARAMETERS: Buffer - Where to return data
126 * DESCRIPTION: Read a line of the AML output prior to formatting the data
128 ******************************************************************************/
131 HxReadAmlOutputFile (
137 Actual
= fread (Buffer
, 1, HEX_TABLE_LINE_SIZE
,
138 Gbl_Files
[ASL_FILE_AML_OUTPUT
].Handle
);
140 if (ferror (Gbl_Files
[ASL_FILE_AML_OUTPUT
].Handle
))
142 FlFileError (ASL_FILE_AML_OUTPUT
, ASL_MSG_READ
);
150 /*******************************************************************************
152 * FUNCTION: HxDoHexOutputC
158 * DESCRIPTION: Create the hex output file. This is the same data as the AML
159 * output file, but formatted into hex/ascii bytes suitable for
160 * inclusion into a C source file.
162 ******************************************************************************/
168 UINT8 FileData
[HEX_TABLE_LINE_SIZE
];
175 /* Get AML size, seek back to start */
177 AmlFileSize
= FlGetFileSize (ASL_FILE_AML_OUTPUT
);
178 FlSeekFile (ASL_FILE_AML_OUTPUT
, 0);
180 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " * C source code output\n");
181 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " * AML code block contains 0x%X bytes\n *\n */\n",
183 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "unsigned char AmlCode[] =\n{\n");
185 while (Offset
< AmlFileSize
)
187 /* Read enough bytes needed for one output line */
189 LineLength
= HxReadAmlOutputFile (FileData
);
195 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " ");
197 for (i
= 0; i
< LineLength
; i
++)
200 * Print each hex byte.
201 * Add a comma until the very last byte of the AML file
202 * (Some C compilers complain about a trailing comma)
204 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "0x%2.2X", FileData
[i
]);
205 if ((Offset
+ i
+ 1) < AmlFileSize
)
207 FlPrintFile (ASL_FILE_HEX_OUTPUT
, ",");
211 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " ");
215 /* Add fill spaces if needed for last line */
217 if (LineLength
< HEX_TABLE_LINE_SIZE
)
219 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "%*s",
220 5 * (HEX_TABLE_LINE_SIZE
- LineLength
), " ");
223 /* Emit the offset and ascii dump for the entire line */
225 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " /* %8.8X", Offset
);
226 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT
, LineLength
, FileData
);
227 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "%*s*/\n",
228 HEX_TABLE_LINE_SIZE
- LineLength
+ 1, " ");
230 Offset
+= LineLength
;
233 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "};\n");
237 /*******************************************************************************
239 * FUNCTION: HxDoHexOutputAsl
245 * DESCRIPTION: Create the hex output file. This is the same data as the AML
246 * output file, but formatted into hex/ascii bytes suitable for
247 * inclusion into a C source file.
249 ******************************************************************************/
255 UINT8 FileData
[HEX_TABLE_LINE_SIZE
];
262 /* Get AML size, seek back to start */
264 AmlFileSize
= FlGetFileSize (ASL_FILE_AML_OUTPUT
);
265 FlSeekFile (ASL_FILE_AML_OUTPUT
, 0);
267 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " * ASL source code output\n");
268 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " * AML code block contains 0x%X bytes\n *\n */\n",
270 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " Name (BUF1, Buffer()\n {\n");
272 while (Offset
< AmlFileSize
)
274 /* Read enough bytes needed for one output line */
276 LineLength
= HxReadAmlOutputFile (FileData
);
282 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " ");
284 for (i
= 0; i
< LineLength
; i
++)
287 * Print each hex byte.
288 * Add a comma until the very last byte of the AML file
289 * (Some C compilers complain about a trailing comma)
291 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "0x%2.2X", FileData
[i
]);
292 if ((Offset
+ i
+ 1) < AmlFileSize
)
294 FlPrintFile (ASL_FILE_HEX_OUTPUT
, ",");
298 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " ");
302 /* Add fill spaces if needed for last line */
304 if (LineLength
< HEX_TABLE_LINE_SIZE
)
306 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "%*s",
307 5 * (HEX_TABLE_LINE_SIZE
- LineLength
), " ");
310 /* Emit the offset and ascii dump for the entire line */
312 FlPrintFile (ASL_FILE_HEX_OUTPUT
, " /* %8.8X", Offset
);
313 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
);
397 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "\n");
399 Offset
+= LineLength
;
402 FlPrintFile (ASL_FILE_HEX_OUTPUT
, "\n");