aslhex.c revision 1.1.1.4 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: aslhex - ASCII hex output file generation (C, ASM, and ASL)
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.4 christos * Copyright (C) 2000 - 2016, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "aslcompiler.h"
45 1.1 christos
46 1.1 christos #define _COMPONENT ACPI_COMPILER
47 1.1 christos ACPI_MODULE_NAME ("ashex")
48 1.1 christos
49 1.1 christos /*
50 1.1 christos * This module emits ASCII hex output files in either C, ASM, or ASL format
51 1.1 christos */
52 1.1 christos
53 1.1 christos /* Local prototypes */
54 1.1 christos
55 1.1 christos static void
56 1.1 christos HxDoHexOutputC (
57 1.1 christos void);
58 1.1 christos
59 1.1 christos static void
60 1.1 christos HxDoHexOutputAsl (
61 1.1 christos void);
62 1.1 christos
63 1.1 christos static void
64 1.1 christos HxDoHexOutputAsm (
65 1.1 christos void);
66 1.1 christos
67 1.1 christos static UINT32
68 1.1 christos HxReadAmlOutputFile (
69 1.1 christos UINT8 *Buffer);
70 1.1 christos
71 1.1 christos
72 1.1 christos /*******************************************************************************
73 1.1 christos *
74 1.1 christos * FUNCTION: HxDoHexOutput
75 1.1 christos *
76 1.1 christos * PARAMETERS: None
77 1.1 christos *
78 1.1 christos * RETURN: None
79 1.1 christos *
80 1.1 christos * DESCRIPTION: Create the hex output file. Note: data is obtained by reading
81 1.1 christos * the entire AML output file that was previously generated.
82 1.1 christos *
83 1.1 christos ******************************************************************************/
84 1.1 christos
85 1.1 christos void
86 1.1 christos HxDoHexOutput (
87 1.1 christos void)
88 1.1 christos {
89 1.1 christos
90 1.1 christos switch (Gbl_HexOutputFlag)
91 1.1 christos {
92 1.1 christos case HEX_OUTPUT_C:
93 1.1 christos
94 1.1 christos HxDoHexOutputC ();
95 1.1 christos break;
96 1.1 christos
97 1.1 christos case HEX_OUTPUT_ASM:
98 1.1 christos
99 1.1 christos HxDoHexOutputAsm ();
100 1.1 christos break;
101 1.1 christos
102 1.1 christos case HEX_OUTPUT_ASL:
103 1.1 christos
104 1.1 christos HxDoHexOutputAsl ();
105 1.1 christos break;
106 1.1 christos
107 1.1 christos default:
108 1.1 christos
109 1.1 christos /* No other output types supported */
110 1.1 christos
111 1.1 christos break;
112 1.1 christos }
113 1.1 christos }
114 1.1 christos
115 1.1 christos
116 1.1 christos /*******************************************************************************
117 1.1 christos *
118 1.1 christos * FUNCTION: HxReadAmlOutputFile
119 1.1 christos *
120 1.1 christos * PARAMETERS: Buffer - Where to return data
121 1.1 christos *
122 1.1 christos * RETURN: None
123 1.1 christos *
124 1.1 christos * DESCRIPTION: Read a line of the AML output prior to formatting the data
125 1.1 christos *
126 1.1 christos ******************************************************************************/
127 1.1 christos
128 1.1 christos static UINT32
129 1.1 christos HxReadAmlOutputFile (
130 1.1 christos UINT8 *Buffer)
131 1.1 christos {
132 1.1 christos UINT32 Actual;
133 1.1 christos
134 1.1 christos
135 1.1 christos Actual = fread (Buffer, 1, HEX_TABLE_LINE_SIZE,
136 1.1 christos Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
137 1.1 christos
138 1.1 christos if (ferror (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle))
139 1.1 christos {
140 1.1 christos FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
141 1.1 christos AslAbort ();
142 1.1 christos }
143 1.1 christos
144 1.1 christos return (Actual);
145 1.1 christos }
146 1.1 christos
147 1.1 christos
148 1.1 christos /*******************************************************************************
149 1.1 christos *
150 1.1 christos * FUNCTION: HxDoHexOutputC
151 1.1 christos *
152 1.1 christos * PARAMETERS: None
153 1.1 christos *
154 1.1 christos * RETURN: None
155 1.1 christos *
156 1.1 christos * DESCRIPTION: Create the hex output file. This is the same data as the AML
157 1.1 christos * output file, but formatted into hex/ascii bytes suitable for
158 1.1 christos * inclusion into a C source file.
159 1.1 christos *
160 1.1 christos ******************************************************************************/
161 1.1 christos
162 1.1 christos static void
163 1.1 christos HxDoHexOutputC (
164 1.1 christos void)
165 1.1 christos {
166 1.1 christos UINT8 FileData[HEX_TABLE_LINE_SIZE];
167 1.1 christos UINT32 LineLength;
168 1.1 christos UINT32 Offset = 0;
169 1.1 christos UINT32 AmlFileSize;
170 1.1 christos UINT32 i;
171 1.1 christos
172 1.1 christos
173 1.1 christos /* Get AML size, seek back to start */
174 1.1 christos
175 1.1 christos AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
176 1.1 christos FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
177 1.1 christos
178 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
179 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
180 1.1 christos AmlFileSize);
181 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
182 1.1 christos
183 1.1 christos while (Offset < AmlFileSize)
184 1.1 christos {
185 1.1 christos /* Read enough bytes needed for one output line */
186 1.1 christos
187 1.1 christos LineLength = HxReadAmlOutputFile (FileData);
188 1.1 christos if (!LineLength)
189 1.1 christos {
190 1.1 christos break;
191 1.1 christos }
192 1.1 christos
193 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
194 1.1 christos
195 1.1 christos for (i = 0; i < LineLength; i++)
196 1.1 christos {
197 1.1 christos /*
198 1.1 christos * Print each hex byte.
199 1.1 christos * Add a comma until the very last byte of the AML file
200 1.1 christos * (Some C compilers complain about a trailing comma)
201 1.1 christos */
202 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
203 1.1 christos if ((Offset + i + 1) < AmlFileSize)
204 1.1 christos {
205 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
206 1.1 christos }
207 1.1 christos else
208 1.1 christos {
209 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
210 1.1 christos }
211 1.1 christos }
212 1.1 christos
213 1.1 christos /* Add fill spaces if needed for last line */
214 1.1 christos
215 1.1 christos if (LineLength < HEX_TABLE_LINE_SIZE)
216 1.1 christos {
217 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
218 1.1 christos 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
219 1.1 christos }
220 1.1 christos
221 1.1 christos /* Emit the offset and ascii dump for the entire line */
222 1.1 christos
223 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
224 1.1 christos LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
225 1.1.1.4 christos
226 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
227 1.1 christos HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
228 1.1 christos
229 1.1 christos Offset += LineLength;
230 1.1 christos }
231 1.1 christos
232 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
233 1.1 christos }
234 1.1 christos
235 1.1 christos
236 1.1 christos /*******************************************************************************
237 1.1 christos *
238 1.1 christos * FUNCTION: HxDoHexOutputAsl
239 1.1 christos *
240 1.1 christos * PARAMETERS: None
241 1.1 christos *
242 1.1 christos * RETURN: None
243 1.1 christos *
244 1.1 christos * DESCRIPTION: Create the hex output file. This is the same data as the AML
245 1.1 christos * output file, but formatted into hex/ascii bytes suitable for
246 1.1 christos * inclusion into a C source file.
247 1.1 christos *
248 1.1 christos ******************************************************************************/
249 1.1 christos
250 1.1 christos static void
251 1.1 christos HxDoHexOutputAsl (
252 1.1 christos void)
253 1.1 christos {
254 1.1 christos UINT8 FileData[HEX_TABLE_LINE_SIZE];
255 1.1 christos UINT32 LineLength;
256 1.1 christos UINT32 Offset = 0;
257 1.1 christos UINT32 AmlFileSize;
258 1.1 christos UINT32 i;
259 1.1 christos
260 1.1 christos
261 1.1 christos /* Get AML size, seek back to start */
262 1.1 christos
263 1.1 christos AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
264 1.1 christos FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
265 1.1 christos
266 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n");
267 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
268 1.1 christos AmlFileSize);
269 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " Name (BUF1, Buffer()\n {\n");
270 1.1 christos
271 1.1 christos while (Offset < AmlFileSize)
272 1.1 christos {
273 1.1 christos /* Read enough bytes needed for one output line */
274 1.1 christos
275 1.1 christos LineLength = HxReadAmlOutputFile (FileData);
276 1.1 christos if (!LineLength)
277 1.1 christos {
278 1.1 christos break;
279 1.1 christos }
280 1.1 christos
281 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
282 1.1 christos
283 1.1 christos for (i = 0; i < LineLength; i++)
284 1.1 christos {
285 1.1 christos /*
286 1.1 christos * Print each hex byte.
287 1.1 christos * Add a comma until the very last byte of the AML file
288 1.1 christos * (Some C compilers complain about a trailing comma)
289 1.1 christos */
290 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
291 1.1 christos if ((Offset + i + 1) < AmlFileSize)
292 1.1 christos {
293 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
294 1.1 christos }
295 1.1 christos else
296 1.1 christos {
297 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
298 1.1 christos }
299 1.1 christos }
300 1.1 christos
301 1.1 christos /* Add fill spaces if needed for last line */
302 1.1 christos
303 1.1 christos if (LineLength < HEX_TABLE_LINE_SIZE)
304 1.1 christos {
305 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
306 1.1 christos 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
307 1.1 christos }
308 1.1 christos
309 1.1 christos /* Emit the offset and ascii dump for the entire line */
310 1.1 christos
311 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
312 1.1 christos LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
313 1.1.1.4 christos
314 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
315 1.1 christos HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
316 1.1 christos
317 1.1 christos Offset += LineLength;
318 1.1 christos }
319 1.1 christos
320 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " })\n");
321 1.1 christos }
322 1.1 christos
323 1.1 christos
324 1.1 christos /*******************************************************************************
325 1.1 christos *
326 1.1 christos * FUNCTION: HxDoHexOutputAsm
327 1.1 christos *
328 1.1 christos * PARAMETERS: None
329 1.1 christos *
330 1.1 christos * RETURN: None
331 1.1 christos *
332 1.1 christos * DESCRIPTION: Create the hex output file. This is the same data as the AML
333 1.1 christos * output file, but formatted into hex/ascii bytes suitable for
334 1.1 christos * inclusion into a ASM source file.
335 1.1 christos *
336 1.1 christos ******************************************************************************/
337 1.1 christos
338 1.1 christos static void
339 1.1 christos HxDoHexOutputAsm (
340 1.1 christos void)
341 1.1 christos {
342 1.1 christos UINT8 FileData[HEX_TABLE_LINE_SIZE];
343 1.1 christos UINT32 LineLength;
344 1.1 christos UINT32 Offset = 0;
345 1.1 christos UINT32 AmlFileSize;
346 1.1 christos UINT32 i;
347 1.1 christos
348 1.1 christos
349 1.1 christos /* Get AML size, seek back to start */
350 1.1 christos
351 1.1 christos AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
352 1.1 christos FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
353 1.1 christos
354 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n");
355 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n",
356 1.1 christos AmlFileSize);
357 1.1 christos
358 1.1 christos while (Offset < AmlFileSize)
359 1.1 christos {
360 1.1 christos /* Read enough bytes needed for one output line */
361 1.1 christos
362 1.1 christos LineLength = HxReadAmlOutputFile (FileData);
363 1.1 christos if (!LineLength)
364 1.1 christos {
365 1.1 christos break;
366 1.1 christos }
367 1.1 christos
368 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " db ");
369 1.1 christos
370 1.1 christos for (i = 0; i < LineLength; i++)
371 1.1 christos {
372 1.1 christos /*
373 1.1 christos * Print each hex byte.
374 1.1 christos * Add a comma until the last byte of the line
375 1.1 christos */
376 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]);
377 1.1 christos if ((i + 1) < LineLength)
378 1.1 christos {
379 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
380 1.1 christos }
381 1.1 christos }
382 1.1 christos
383 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
384 1.1 christos
385 1.1 christos /* Add fill spaces if needed for last line */
386 1.1 christos
387 1.1 christos if (LineLength < HEX_TABLE_LINE_SIZE)
388 1.1 christos {
389 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
390 1.1 christos 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
391 1.1 christos }
392 1.1 christos
393 1.1 christos /* Emit the offset and ascii dump for the entire line */
394 1.1 christos
395 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, " ; %8.8X", Offset);
396 1.1 christos LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
397 1.1.1.4 christos
398 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
399 1.1 christos
400 1.1 christos Offset += LineLength;
401 1.1 christos }
402 1.1 christos
403 1.1 christos FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
404 1.1 christos }
405