Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / compiler / aslhex.c
blobcc2ba6f36311ca9eb5002b4aad50a56336e64525
1 /******************************************************************************
3 * Module Name: aslhex - ASCII hex output file generation (C, ASM, and ASL)
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 */
57 static void
58 HxDoHexOutputC (
59 void);
61 static void
62 HxDoHexOutputAsl (
63 void);
65 static void
66 HxDoHexOutputAsm (
67 void);
69 static UINT32
70 HxReadAmlOutputFile (
71 UINT8 *Buffer);
74 /*******************************************************************************
76 * FUNCTION: HxDoHexOutput
78 * PARAMETERS: None
80 * RETURN: None
82 * DESCRIPTION: Create the hex output file. Note: data is obtained by reading
83 * the entire AML output file that was previously generated.
85 ******************************************************************************/
87 void
88 HxDoHexOutput (
89 void)
92 switch (Gbl_HexOutputFlag)
94 case HEX_OUTPUT_C:
96 HxDoHexOutputC ();
97 break;
99 case HEX_OUTPUT_ASM:
101 HxDoHexOutputAsm ();
102 break;
104 case HEX_OUTPUT_ASL:
106 HxDoHexOutputAsl ();
107 break;
109 default:
111 /* No other output types supported */
113 break;
118 /*******************************************************************************
120 * FUNCTION: HxReadAmlOutputFile
122 * PARAMETERS: Buffer - Where to return data
124 * RETURN: None
126 * DESCRIPTION: Read a line of the AML output prior to formatting the data
128 ******************************************************************************/
130 static UINT32
131 HxReadAmlOutputFile (
132 UINT8 *Buffer)
134 UINT32 Actual;
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);
143 AslAbort ();
146 return (Actual);
150 /*******************************************************************************
152 * FUNCTION: HxDoHexOutputC
154 * PARAMETERS: None
156 * RETURN: None
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 ******************************************************************************/
164 static void
165 HxDoHexOutputC (
166 void)
168 UINT8 FileData[HEX_TABLE_LINE_SIZE];
169 UINT32 LineLength;
170 UINT32 Offset = 0;
171 UINT32 AmlFileSize;
172 UINT32 i;
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",
182 AmlFileSize);
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);
190 if (!LineLength)
192 break;
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, ",");
209 else
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
241 * PARAMETERS: None
243 * RETURN: None
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 ******************************************************************************/
251 static void
252 HxDoHexOutputAsl (
253 void)
255 UINT8 FileData[HEX_TABLE_LINE_SIZE];
256 UINT32 LineLength;
257 UINT32 Offset = 0;
258 UINT32 AmlFileSize;
259 UINT32 i;
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",
269 AmlFileSize);
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);
277 if (!LineLength)
279 break;
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, ",");
296 else
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
328 * PARAMETERS: None
330 * RETURN: None
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 ******************************************************************************/
338 static void
339 HxDoHexOutputAsm (
340 void)
342 UINT8 FileData[HEX_TABLE_LINE_SIZE];
343 UINT32 LineLength;
344 UINT32 Offset = 0;
345 UINT32 AmlFileSize;
346 UINT32 i;
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",
356 AmlFileSize);
358 while (Offset < AmlFileSize)
360 /* Read enough bytes needed for one output line */
362 LineLength = HxReadAmlOutputFile (FileData);
363 if (!LineLength)
365 break;
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");