acpixtract.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer
2 1.1.1.2.2.2 bouyer /******************************************************************************
3 1.1.1.2.2.2 bouyer *
4 1.1.1.2.2.2 bouyer * Module Name: acpixtract - convert ascii ACPI tables to binary
5 1.1.1.2.2.2 bouyer *
6 1.1.1.2.2.2 bouyer *****************************************************************************/
7 1.1.1.2.2.2 bouyer
8 1.1.1.2.2.2 bouyer /*
9 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.2.2 bouyer * All rights reserved.
11 1.1.1.2.2.2 bouyer *
12 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
14 1.1.1.2.2.2 bouyer * are met:
15 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.2.2 bouyer * without modification.
18 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.2.2 bouyer * binary redistribution.
23 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
26 1.1.1.2.2.2 bouyer *
27 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.2.2 bouyer * Software Foundation.
30 1.1.1.2.2.2 bouyer *
31 1.1.1.2.2.2 bouyer * NO WARRANTY
32 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2.2.2 bouyer */
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer #include <stdio.h>
46 1.1.1.2.2.2 bouyer #include <stdlib.h>
47 1.1.1.2.2.2 bouyer #include <string.h>
48 1.1.1.2.2.2 bouyer #include <ctype.h>
49 1.1.1.2.2.2 bouyer
50 1.1.1.2.2.2 bouyer
51 1.1.1.2.2.2 bouyer /* Note: This is a 32-bit program only */
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer #define VERSION 0x20100107
54 1.1.1.2.2.2 bouyer #define FIND_HEADER 0
55 1.1.1.2.2.2 bouyer #define EXTRACT_DATA 1
56 1.1.1.2.2.2 bouyer #define BUFFER_SIZE 256
57 1.1.1.2.2.2 bouyer
58 1.1.1.2.2.2 bouyer
59 1.1.1.2.2.2 bouyer /* Local prototypes */
60 1.1.1.2.2.2 bouyer
61 1.1.1.2.2.2 bouyer static void
62 1.1.1.2.2.2 bouyer CheckAscii (
63 1.1.1.2.2.2 bouyer char *Name,
64 1.1.1.2.2.2 bouyer int Count);
65 1.1.1.2.2.2 bouyer
66 1.1.1.2.2.2 bouyer static void
67 1.1.1.2.2.2 bouyer NormalizeSignature (
68 1.1.1.2.2.2 bouyer char *Signature);
69 1.1.1.2.2.2 bouyer
70 1.1.1.2.2.2 bouyer static unsigned int
71 1.1.1.2.2.2 bouyer GetNextInstance (
72 1.1.1.2.2.2 bouyer char *InputPathname,
73 1.1.1.2.2.2 bouyer char *Signature);
74 1.1.1.2.2.2 bouyer
75 1.1.1.2.2.2 bouyer static int
76 1.1.1.2.2.2 bouyer ExtractTables (
77 1.1.1.2.2.2 bouyer char *InputPathname,
78 1.1.1.2.2.2 bouyer char *Signature,
79 1.1.1.2.2.2 bouyer unsigned int MinimumInstances);
80 1.1.1.2.2.2 bouyer
81 1.1.1.2.2.2 bouyer static size_t
82 1.1.1.2.2.2 bouyer GetTableHeader (
83 1.1.1.2.2.2 bouyer FILE *InputFile,
84 1.1.1.2.2.2 bouyer unsigned char *OutputData);
85 1.1.1.2.2.2 bouyer
86 1.1.1.2.2.2 bouyer static unsigned int
87 1.1.1.2.2.2 bouyer CountTableInstances (
88 1.1.1.2.2.2 bouyer char *InputPathname,
89 1.1.1.2.2.2 bouyer char *Signature);
90 1.1.1.2.2.2 bouyer
91 1.1.1.2.2.2 bouyer static int
92 1.1.1.2.2.2 bouyer ListTables (
93 1.1.1.2.2.2 bouyer char *InputPathname);
94 1.1.1.2.2.2 bouyer
95 1.1.1.2.2.2 bouyer static size_t
96 1.1.1.2.2.2 bouyer ConvertLine (
97 1.1.1.2.2.2 bouyer char *InputLine,
98 1.1.1.2.2.2 bouyer unsigned char *OutputData);
99 1.1.1.2.2.2 bouyer
100 1.1.1.2.2.2 bouyer static void
101 1.1.1.2.2.2 bouyer DisplayUsage (
102 1.1.1.2.2.2 bouyer void);
103 1.1.1.2.2.2 bouyer
104 1.1.1.2.2.2 bouyer
105 1.1.1.2.2.2 bouyer typedef struct acpi_table_header
106 1.1.1.2.2.2 bouyer {
107 1.1.1.2.2.2 bouyer char Signature[4];
108 1.1.1.2.2.2 bouyer int Length;
109 1.1.1.2.2.2 bouyer unsigned char Revision;
110 1.1.1.2.2.2 bouyer unsigned char Checksum;
111 1.1.1.2.2.2 bouyer char OemId[6];
112 1.1.1.2.2.2 bouyer char OemTableId[8];
113 1.1.1.2.2.2 bouyer int OemRevision;
114 1.1.1.2.2.2 bouyer char AslCompilerId[4];
115 1.1.1.2.2.2 bouyer int AslCompilerRevision;
116 1.1.1.2.2.2 bouyer
117 1.1.1.2.2.2 bouyer } ACPI_TABLE_HEADER;
118 1.1.1.2.2.2 bouyer
119 1.1.1.2.2.2 bouyer struct TableInfo
120 1.1.1.2.2.2 bouyer {
121 1.1.1.2.2.2 bouyer unsigned int Signature;
122 1.1.1.2.2.2 bouyer unsigned int Instances;
123 1.1.1.2.2.2 bouyer unsigned int NextInstance;
124 1.1.1.2.2.2 bouyer struct TableInfo *Next;
125 1.1.1.2.2.2 bouyer };
126 1.1.1.2.2.2 bouyer
127 1.1.1.2.2.2 bouyer static struct TableInfo *ListHead = NULL;
128 1.1.1.2.2.2 bouyer static char Filename[16];
129 1.1.1.2.2.2 bouyer static unsigned char Data[16];
130 1.1.1.2.2.2 bouyer
131 1.1.1.2.2.2 bouyer
132 1.1.1.2.2.2 bouyer /******************************************************************************
133 1.1.1.2.2.2 bouyer *
134 1.1.1.2.2.2 bouyer * FUNCTION: DisplayUsage
135 1.1.1.2.2.2 bouyer *
136 1.1.1.2.2.2 bouyer * DESCRIPTION: Usage message
137 1.1.1.2.2.2 bouyer *
138 1.1.1.2.2.2 bouyer ******************************************************************************/
139 1.1.1.2.2.2 bouyer
140 1.1.1.2.2.2 bouyer static void
141 1.1.1.2.2.2 bouyer DisplayUsage (
142 1.1.1.2.2.2 bouyer void)
143 1.1.1.2.2.2 bouyer {
144 1.1.1.2.2.2 bouyer
145 1.1.1.2.2.2 bouyer printf ("Usage: acpixtract [option] <InputFile>\n");
146 1.1.1.2.2.2 bouyer printf ("\nExtract binary ACPI tables from text acpidump output\n");
147 1.1.1.2.2.2 bouyer printf ("Default invocation extracts all DSDTs and SSDTs\n");
148 1.1.1.2.2.2 bouyer printf ("Version %8.8X\n\n", VERSION);
149 1.1.1.2.2.2 bouyer printf ("Options:\n");
150 1.1.1.2.2.2 bouyer printf (" -a Extract all tables, not just DSDT/SSDT\n");
151 1.1.1.2.2.2 bouyer printf (" -l List table summaries, do not extract\n");
152 1.1.1.2.2.2 bouyer printf (" -s<Signature> Extract all tables named <Signature>\n");
153 1.1.1.2.2.2 bouyer printf ("\n");
154 1.1.1.2.2.2 bouyer }
155 1.1.1.2.2.2 bouyer
156 1.1.1.2.2.2 bouyer
157 1.1.1.2.2.2 bouyer /*******************************************************************************
158 1.1.1.2.2.2 bouyer *
159 1.1.1.2.2.2 bouyer * FUNCTION: CheckAscii
160 1.1.1.2.2.2 bouyer *
161 1.1.1.2.2.2 bouyer * PARAMETERS: Name - Ascii string, at least as long as Count
162 1.1.1.2.2.2 bouyer * Count - Number of characters to check
163 1.1.1.2.2.2 bouyer *
164 1.1.1.2.2.2 bouyer * RETURN: None
165 1.1.1.2.2.2 bouyer *
166 1.1.1.2.2.2 bouyer * DESCRIPTION: Ensure that the requested number of characters are printable
167 1.1.1.2.2.2 bouyer * Ascii characters. Sets non-printable and null chars to <space>.
168 1.1.1.2.2.2 bouyer *
169 1.1.1.2.2.2 bouyer ******************************************************************************/
170 1.1.1.2.2.2 bouyer
171 1.1.1.2.2.2 bouyer static void
172 1.1.1.2.2.2 bouyer CheckAscii (
173 1.1.1.2.2.2 bouyer char *Name,
174 1.1.1.2.2.2 bouyer int Count)
175 1.1.1.2.2.2 bouyer {
176 1.1.1.2.2.2 bouyer int i;
177 1.1.1.2.2.2 bouyer
178 1.1.1.2.2.2 bouyer
179 1.1.1.2.2.2 bouyer for (i = 0; i < Count; i++)
180 1.1.1.2.2.2 bouyer {
181 1.1.1.2.2.2 bouyer if (!Name[i] || !isprint ((int) Name[i]))
182 1.1.1.2.2.2 bouyer {
183 1.1.1.2.2.2 bouyer Name[i] = ' ';
184 1.1.1.2.2.2 bouyer }
185 1.1.1.2.2.2 bouyer }
186 1.1.1.2.2.2 bouyer }
187 1.1.1.2.2.2 bouyer
188 1.1.1.2.2.2 bouyer
189 1.1.1.2.2.2 bouyer /*******************************************************************************
190 1.1.1.2.2.2 bouyer *
191 1.1.1.2.2.2 bouyer * FUNCTION: NormalizeSignature
192 1.1.1.2.2.2 bouyer *
193 1.1.1.2.2.2 bouyer * PARAMETERS: Name - Ascii string containing an ACPI signature
194 1.1.1.2.2.2 bouyer *
195 1.1.1.2.2.2 bouyer * RETURN: None
196 1.1.1.2.2.2 bouyer *
197 1.1.1.2.2.2 bouyer * DESCRIPTION: Change "RSD PTR" to "RSDP"
198 1.1.1.2.2.2 bouyer *
199 1.1.1.2.2.2 bouyer ******************************************************************************/
200 1.1.1.2.2.2 bouyer
201 1.1.1.2.2.2 bouyer static void
202 1.1.1.2.2.2 bouyer NormalizeSignature (
203 1.1.1.2.2.2 bouyer char *Signature)
204 1.1.1.2.2.2 bouyer {
205 1.1.1.2.2.2 bouyer
206 1.1.1.2.2.2 bouyer if (!strncmp (Signature, "RSD ", 4))
207 1.1.1.2.2.2 bouyer {
208 1.1.1.2.2.2 bouyer Signature[3] = 'P';
209 1.1.1.2.2.2 bouyer }
210 1.1.1.2.2.2 bouyer }
211 1.1.1.2.2.2 bouyer
212 1.1.1.2.2.2 bouyer
213 1.1.1.2.2.2 bouyer /******************************************************************************
214 1.1.1.2.2.2 bouyer *
215 1.1.1.2.2.2 bouyer * FUNCTION: ConvertLine
216 1.1.1.2.2.2 bouyer *
217 1.1.1.2.2.2 bouyer * PARAMETERS: InputLine - One line from the input acpidump file
218 1.1.1.2.2.2 bouyer * OutputData - Where the converted data is returned
219 1.1.1.2.2.2 bouyer *
220 1.1.1.2.2.2 bouyer * RETURN: The number of bytes actually converted
221 1.1.1.2.2.2 bouyer *
222 1.1.1.2.2.2 bouyer * DESCRIPTION: Convert one line of ascii text binary (up to 16 bytes)
223 1.1.1.2.2.2 bouyer *
224 1.1.1.2.2.2 bouyer ******************************************************************************/
225 1.1.1.2.2.2 bouyer
226 1.1.1.2.2.2 bouyer static size_t
227 1.1.1.2.2.2 bouyer ConvertLine (
228 1.1.1.2.2.2 bouyer char *InputLine,
229 1.1.1.2.2.2 bouyer unsigned char *OutputData)
230 1.1.1.2.2.2 bouyer {
231 1.1.1.2.2.2 bouyer char *End;
232 1.1.1.2.2.2 bouyer int BytesConverted;
233 1.1.1.2.2.2 bouyer int Converted[16];
234 1.1.1.2.2.2 bouyer int i;
235 1.1.1.2.2.2 bouyer
236 1.1.1.2.2.2 bouyer
237 1.1.1.2.2.2 bouyer /* Terminate the input line at the end of the actual data (for sscanf) */
238 1.1.1.2.2.2 bouyer
239 1.1.1.2.2.2 bouyer End = strstr (InputLine + 2, " ");
240 1.1.1.2.2.2 bouyer if (!End)
241 1.1.1.2.2.2 bouyer {
242 1.1.1.2.2.2 bouyer return (0); /* Don't understand the format */
243 1.1.1.2.2.2 bouyer }
244 1.1.1.2.2.2 bouyer *End = 0;
245 1.1.1.2.2.2 bouyer
246 1.1.1.2.2.2 bouyer /*
247 1.1.1.2.2.2 bouyer * Convert one line of table data, of the form:
248 1.1.1.2.2.2 bouyer * <offset>: <up to 16 bytes of hex data> <ASCII representation> <newline>
249 1.1.1.2.2.2 bouyer *
250 1.1.1.2.2.2 bouyer * Example:
251 1.1.1.2.2.2 bouyer * 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08 _SB_LNKD........
252 1.1.1.2.2.2 bouyer */
253 1.1.1.2.2.2 bouyer BytesConverted = sscanf (InputLine,
254 1.1.1.2.2.2 bouyer "%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
255 1.1.1.2.2.2 bouyer &Converted[0], &Converted[1], &Converted[2], &Converted[3],
256 1.1.1.2.2.2 bouyer &Converted[4], &Converted[5], &Converted[6], &Converted[7],
257 1.1.1.2.2.2 bouyer &Converted[8], &Converted[9], &Converted[10], &Converted[11],
258 1.1.1.2.2.2 bouyer &Converted[12], &Converted[13], &Converted[14], &Converted[15]);
259 1.1.1.2.2.2 bouyer
260 1.1.1.2.2.2 bouyer /* Pack converted data into a byte array */
261 1.1.1.2.2.2 bouyer
262 1.1.1.2.2.2 bouyer for (i = 0; i < BytesConverted; i++)
263 1.1.1.2.2.2 bouyer {
264 1.1.1.2.2.2 bouyer OutputData[i] = (unsigned char) Converted[i];
265 1.1.1.2.2.2 bouyer }
266 1.1.1.2.2.2 bouyer
267 1.1.1.2.2.2 bouyer return ((size_t) BytesConverted);
268 1.1.1.2.2.2 bouyer }
269 1.1.1.2.2.2 bouyer
270 1.1.1.2.2.2 bouyer
271 1.1.1.2.2.2 bouyer /******************************************************************************
272 1.1.1.2.2.2 bouyer *
273 1.1.1.2.2.2 bouyer * FUNCTION: GetTableHeader
274 1.1.1.2.2.2 bouyer *
275 1.1.1.2.2.2 bouyer * PARAMETERS: InputFile - Handle for the input acpidump file
276 1.1.1.2.2.2 bouyer * OutputData - Where the table header is returned
277 1.1.1.2.2.2 bouyer *
278 1.1.1.2.2.2 bouyer * RETURN: The actual number of bytes converted
279 1.1.1.2.2.2 bouyer *
280 1.1.1.2.2.2 bouyer * DESCRIPTION: Extract and convert an ACPI table header
281 1.1.1.2.2.2 bouyer *
282 1.1.1.2.2.2 bouyer ******************************************************************************/
283 1.1.1.2.2.2 bouyer
284 1.1.1.2.2.2 bouyer static size_t
285 1.1.1.2.2.2 bouyer GetTableHeader (
286 1.1.1.2.2.2 bouyer FILE *InputFile,
287 1.1.1.2.2.2 bouyer unsigned char *OutputData)
288 1.1.1.2.2.2 bouyer {
289 1.1.1.2.2.2 bouyer size_t BytesConverted;
290 1.1.1.2.2.2 bouyer size_t TotalConverted = 0;
291 1.1.1.2.2.2 bouyer char Buffer[BUFFER_SIZE];
292 1.1.1.2.2.2 bouyer int i;
293 1.1.1.2.2.2 bouyer
294 1.1.1.2.2.2 bouyer
295 1.1.1.2.2.2 bouyer /* Get the full 36 byte header, requires 3 lines */
296 1.1.1.2.2.2 bouyer
297 1.1.1.2.2.2 bouyer for (i = 0; i < 3; i++)
298 1.1.1.2.2.2 bouyer {
299 1.1.1.2.2.2 bouyer if (!fgets (Buffer, BUFFER_SIZE, InputFile))
300 1.1.1.2.2.2 bouyer {
301 1.1.1.2.2.2 bouyer return (TotalConverted);
302 1.1.1.2.2.2 bouyer }
303 1.1.1.2.2.2 bouyer
304 1.1.1.2.2.2 bouyer BytesConverted = ConvertLine (Buffer, OutputData);
305 1.1.1.2.2.2 bouyer TotalConverted += BytesConverted;
306 1.1.1.2.2.2 bouyer OutputData += 16;
307 1.1.1.2.2.2 bouyer
308 1.1.1.2.2.2 bouyer if (BytesConverted != 16)
309 1.1.1.2.2.2 bouyer {
310 1.1.1.2.2.2 bouyer return (TotalConverted);
311 1.1.1.2.2.2 bouyer }
312 1.1.1.2.2.2 bouyer }
313 1.1.1.2.2.2 bouyer
314 1.1.1.2.2.2 bouyer return (TotalConverted);
315 1.1.1.2.2.2 bouyer }
316 1.1.1.2.2.2 bouyer
317 1.1.1.2.2.2 bouyer
318 1.1.1.2.2.2 bouyer /******************************************************************************
319 1.1.1.2.2.2 bouyer *
320 1.1.1.2.2.2 bouyer * FUNCTION: CountTableInstances
321 1.1.1.2.2.2 bouyer *
322 1.1.1.2.2.2 bouyer * PARAMETERS: InputPathname - Filename for acpidump file
323 1.1.1.2.2.2 bouyer * Signature - Requested signature to count
324 1.1.1.2.2.2 bouyer *
325 1.1.1.2.2.2 bouyer * RETURN: The number of instances of the signature
326 1.1.1.2.2.2 bouyer *
327 1.1.1.2.2.2 bouyer * DESCRIPTION: Count the instances of tables with the given signature within
328 1.1.1.2.2.2 bouyer * the input acpidump file.
329 1.1.1.2.2.2 bouyer *
330 1.1.1.2.2.2 bouyer ******************************************************************************/
331 1.1.1.2.2.2 bouyer
332 1.1.1.2.2.2 bouyer static unsigned int
333 1.1.1.2.2.2 bouyer CountTableInstances (
334 1.1.1.2.2.2 bouyer char *InputPathname,
335 1.1.1.2.2.2 bouyer char *Signature)
336 1.1.1.2.2.2 bouyer {
337 1.1.1.2.2.2 bouyer char Buffer[BUFFER_SIZE];
338 1.1.1.2.2.2 bouyer FILE *InputFile;
339 1.1.1.2.2.2 bouyer unsigned int Instances = 0;
340 1.1.1.2.2.2 bouyer
341 1.1.1.2.2.2 bouyer
342 1.1.1.2.2.2 bouyer InputFile = fopen (InputPathname, "rt");
343 1.1.1.2.2.2 bouyer if (!InputFile)
344 1.1.1.2.2.2 bouyer {
345 1.1.1.2.2.2 bouyer printf ("Could not open %s\n", InputPathname);
346 1.1.1.2.2.2 bouyer return (0);
347 1.1.1.2.2.2 bouyer }
348 1.1.1.2.2.2 bouyer
349 1.1.1.2.2.2 bouyer /* Count the number of instances of this signature */
350 1.1.1.2.2.2 bouyer
351 1.1.1.2.2.2 bouyer while (fgets (Buffer, BUFFER_SIZE, InputFile))
352 1.1.1.2.2.2 bouyer {
353 1.1.1.2.2.2 bouyer /* Ignore empty lines and lines that start with a space */
354 1.1.1.2.2.2 bouyer
355 1.1.1.2.2.2 bouyer if ((Buffer[0] == ' ') ||
356 1.1.1.2.2.2 bouyer (Buffer[0] == '\n'))
357 1.1.1.2.2.2 bouyer {
358 1.1.1.2.2.2 bouyer continue;
359 1.1.1.2.2.2 bouyer }
360 1.1.1.2.2.2 bouyer
361 1.1.1.2.2.2 bouyer NormalizeSignature (Buffer);
362 1.1.1.2.2.2 bouyer if (!strncmp (Buffer, Signature, 4))
363 1.1.1.2.2.2 bouyer {
364 1.1.1.2.2.2 bouyer Instances++;
365 1.1.1.2.2.2 bouyer }
366 1.1.1.2.2.2 bouyer }
367 1.1.1.2.2.2 bouyer
368 1.1.1.2.2.2 bouyer fclose (InputFile);
369 1.1.1.2.2.2 bouyer return (Instances);
370 1.1.1.2.2.2 bouyer }
371 1.1.1.2.2.2 bouyer
372 1.1.1.2.2.2 bouyer
373 1.1.1.2.2.2 bouyer /******************************************************************************
374 1.1.1.2.2.2 bouyer *
375 1.1.1.2.2.2 bouyer * FUNCTION: GetNextInstance
376 1.1.1.2.2.2 bouyer *
377 1.1.1.2.2.2 bouyer * PARAMETERS: InputPathname - Filename for acpidump file
378 1.1.1.2.2.2 bouyer * Signature - Requested ACPI signature
379 1.1.1.2.2.2 bouyer *
380 1.1.1.2.2.2 bouyer * RETURN: The next instance number for this signature. Zero if this
381 1.1.1.2.2.2 bouyer * is the first instance of this signature.
382 1.1.1.2.2.2 bouyer *
383 1.1.1.2.2.2 bouyer * DESCRIPTION: Get the next instance number of the specified table. If this
384 1.1.1.2.2.2 bouyer * is the first instance of the table, create a new instance
385 1.1.1.2.2.2 bouyer * block. Note: only SSDT and PSDT tables can have multiple
386 1.1.1.2.2.2 bouyer * instances.
387 1.1.1.2.2.2 bouyer *
388 1.1.1.2.2.2 bouyer ******************************************************************************/
389 1.1.1.2.2.2 bouyer
390 1.1.1.2.2.2 bouyer static unsigned int
391 1.1.1.2.2.2 bouyer GetNextInstance (
392 1.1.1.2.2.2 bouyer char *InputPathname,
393 1.1.1.2.2.2 bouyer char *Signature)
394 1.1.1.2.2.2 bouyer {
395 1.1.1.2.2.2 bouyer struct TableInfo *Info;
396 1.1.1.2.2.2 bouyer
397 1.1.1.2.2.2 bouyer
398 1.1.1.2.2.2 bouyer Info = ListHead;
399 1.1.1.2.2.2 bouyer while (Info)
400 1.1.1.2.2.2 bouyer {
401 1.1.1.2.2.2 bouyer if (*(unsigned int *) Signature == Info->Signature)
402 1.1.1.2.2.2 bouyer {
403 1.1.1.2.2.2 bouyer break;
404 1.1.1.2.2.2 bouyer }
405 1.1.1.2.2.2 bouyer
406 1.1.1.2.2.2 bouyer Info = Info->Next;
407 1.1.1.2.2.2 bouyer }
408 1.1.1.2.2.2 bouyer
409 1.1.1.2.2.2 bouyer if (!Info)
410 1.1.1.2.2.2 bouyer {
411 1.1.1.2.2.2 bouyer /* Signature not found, create new table info block */
412 1.1.1.2.2.2 bouyer
413 1.1.1.2.2.2 bouyer Info = malloc (sizeof (struct TableInfo));
414 1.1.1.2.2.2 bouyer if (!Info)
415 1.1.1.2.2.2 bouyer {
416 1.1.1.2.2.2 bouyer printf ("Could not allocate memory\n");
417 1.1.1.2.2.2 bouyer exit (0);
418 1.1.1.2.2.2 bouyer }
419 1.1.1.2.2.2 bouyer
420 1.1.1.2.2.2 bouyer Info->Signature = *(unsigned int *) Signature;
421 1.1.1.2.2.2 bouyer Info->Instances = CountTableInstances (InputPathname, Signature);
422 1.1.1.2.2.2 bouyer Info->NextInstance = 1;
423 1.1.1.2.2.2 bouyer Info->Next = ListHead;
424 1.1.1.2.2.2 bouyer ListHead = Info;
425 1.1.1.2.2.2 bouyer }
426 1.1.1.2.2.2 bouyer
427 1.1.1.2.2.2 bouyer if (Info->Instances > 1)
428 1.1.1.2.2.2 bouyer {
429 1.1.1.2.2.2 bouyer return (Info->NextInstance++);
430 1.1.1.2.2.2 bouyer }
431 1.1.1.2.2.2 bouyer
432 1.1.1.2.2.2 bouyer return (0);
433 1.1.1.2.2.2 bouyer }
434 1.1.1.2.2.2 bouyer
435 1.1.1.2.2.2 bouyer
436 1.1.1.2.2.2 bouyer /******************************************************************************
437 1.1.1.2.2.2 bouyer *
438 1.1.1.2.2.2 bouyer * FUNCTION: ExtractTables
439 1.1.1.2.2.2 bouyer *
440 1.1.1.2.2.2 bouyer * PARAMETERS: InputPathname - Filename for acpidump file
441 1.1.1.2.2.2 bouyer * Signature - Requested ACPI signature to extract.
442 1.1.1.2.2.2 bouyer * NULL means extract ALL tables.
443 1.1.1.2.2.2 bouyer * MinimumInstances - Min instances that are acceptable
444 1.1.1.2.2.2 bouyer *
445 1.1.1.2.2.2 bouyer * RETURN: Status
446 1.1.1.2.2.2 bouyer *
447 1.1.1.2.2.2 bouyer * DESCRIPTION: Convert text ACPI tables to binary
448 1.1.1.2.2.2 bouyer *
449 1.1.1.2.2.2 bouyer ******************************************************************************/
450 1.1.1.2.2.2 bouyer
451 1.1.1.2.2.2 bouyer static int
452 1.1.1.2.2.2 bouyer ExtractTables (
453 1.1.1.2.2.2 bouyer char *InputPathname,
454 1.1.1.2.2.2 bouyer char *Signature,
455 1.1.1.2.2.2 bouyer unsigned int MinimumInstances)
456 1.1.1.2.2.2 bouyer {
457 1.1.1.2.2.2 bouyer char Buffer[BUFFER_SIZE];
458 1.1.1.2.2.2 bouyer FILE *InputFile;
459 1.1.1.2.2.2 bouyer FILE *OutputFile = NULL;
460 1.1.1.2.2.2 bouyer size_t BytesWritten;
461 1.1.1.2.2.2 bouyer size_t TotalBytesWritten = 0;
462 1.1.1.2.2.2 bouyer size_t BytesConverted;
463 1.1.1.2.2.2 bouyer unsigned int State = FIND_HEADER;
464 1.1.1.2.2.2 bouyer unsigned int FoundTable = 0;
465 1.1.1.2.2.2 bouyer unsigned int Instances = 0;
466 1.1.1.2.2.2 bouyer unsigned int ThisInstance;
467 1.1.1.2.2.2 bouyer char ThisSignature[4];
468 1.1.1.2.2.2 bouyer int Status = 0;
469 1.1.1.2.2.2 bouyer
470 1.1.1.2.2.2 bouyer
471 1.1.1.2.2.2 bouyer /* Open input in text mode, output is in binary mode */
472 1.1.1.2.2.2 bouyer
473 1.1.1.2.2.2 bouyer InputFile = fopen (InputPathname, "rt");
474 1.1.1.2.2.2 bouyer if (!InputFile)
475 1.1.1.2.2.2 bouyer {
476 1.1.1.2.2.2 bouyer printf ("Could not open %s\n", InputPathname);
477 1.1.1.2.2.2 bouyer return (-1);
478 1.1.1.2.2.2 bouyer }
479 1.1.1.2.2.2 bouyer
480 1.1.1.2.2.2 bouyer if (Signature)
481 1.1.1.2.2.2 bouyer {
482 1.1.1.2.2.2 bouyer /* Are there enough instances of the table to continue? */
483 1.1.1.2.2.2 bouyer
484 1.1.1.2.2.2 bouyer NormalizeSignature (Signature);
485 1.1.1.2.2.2 bouyer
486 1.1.1.2.2.2 bouyer Instances = CountTableInstances (InputPathname, Signature);
487 1.1.1.2.2.2 bouyer if (Instances < MinimumInstances)
488 1.1.1.2.2.2 bouyer {
489 1.1.1.2.2.2 bouyer printf ("Table %s was not found in %s\n", Signature, InputPathname);
490 1.1.1.2.2.2 bouyer Status = -1;
491 1.1.1.2.2.2 bouyer goto CleanupAndExit;
492 1.1.1.2.2.2 bouyer }
493 1.1.1.2.2.2 bouyer
494 1.1.1.2.2.2 bouyer if (Instances == 0)
495 1.1.1.2.2.2 bouyer {
496 1.1.1.2.2.2 bouyer goto CleanupAndExit;
497 1.1.1.2.2.2 bouyer }
498 1.1.1.2.2.2 bouyer }
499 1.1.1.2.2.2 bouyer
500 1.1.1.2.2.2 bouyer /* Convert all instances of the table to binary */
501 1.1.1.2.2.2 bouyer
502 1.1.1.2.2.2 bouyer while (fgets (Buffer, BUFFER_SIZE, InputFile))
503 1.1.1.2.2.2 bouyer {
504 1.1.1.2.2.2 bouyer switch (State)
505 1.1.1.2.2.2 bouyer {
506 1.1.1.2.2.2 bouyer case FIND_HEADER:
507 1.1.1.2.2.2 bouyer
508 1.1.1.2.2.2 bouyer /* Ignore empty lines and lines that start with a space */
509 1.1.1.2.2.2 bouyer
510 1.1.1.2.2.2 bouyer if ((Buffer[0] == ' ') ||
511 1.1.1.2.2.2 bouyer (Buffer[0] == '\n'))
512 1.1.1.2.2.2 bouyer {
513 1.1.1.2.2.2 bouyer continue;
514 1.1.1.2.2.2 bouyer }
515 1.1.1.2.2.2 bouyer
516 1.1.1.2.2.2 bouyer NormalizeSignature (Buffer);
517 1.1.1.2.2.2 bouyer strncpy (ThisSignature, Buffer, 4);
518 1.1.1.2.2.2 bouyer
519 1.1.1.2.2.2 bouyer if (Signature)
520 1.1.1.2.2.2 bouyer {
521 1.1.1.2.2.2 bouyer /* Ignore signatures that don't match */
522 1.1.1.2.2.2 bouyer
523 1.1.1.2.2.2 bouyer if (strncmp (ThisSignature, Signature, 4))
524 1.1.1.2.2.2 bouyer {
525 1.1.1.2.2.2 bouyer continue;
526 1.1.1.2.2.2 bouyer }
527 1.1.1.2.2.2 bouyer }
528 1.1.1.2.2.2 bouyer
529 1.1.1.2.2.2 bouyer /*
530 1.1.1.2.2.2 bouyer * Get the instance number for this signature. Only the
531 1.1.1.2.2.2 bouyer * SSDT and PSDT tables can have multiple instances.
532 1.1.1.2.2.2 bouyer */
533 1.1.1.2.2.2 bouyer ThisInstance = GetNextInstance (InputPathname, ThisSignature);
534 1.1.1.2.2.2 bouyer
535 1.1.1.2.2.2 bouyer /* Build an output filename and create/open the output file */
536 1.1.1.2.2.2 bouyer
537 1.1.1.2.2.2 bouyer if (ThisInstance > 0)
538 1.1.1.2.2.2 bouyer {
539 1.1.1.2.2.2 bouyer sprintf (Filename, "%4.4s%u.dat", ThisSignature, ThisInstance);
540 1.1.1.2.2.2 bouyer }
541 1.1.1.2.2.2 bouyer else
542 1.1.1.2.2.2 bouyer {
543 1.1.1.2.2.2 bouyer sprintf (Filename, "%4.4s.dat", ThisSignature);
544 1.1.1.2.2.2 bouyer }
545 1.1.1.2.2.2 bouyer
546 1.1.1.2.2.2 bouyer OutputFile = fopen (Filename, "w+b");
547 1.1.1.2.2.2 bouyer if (!OutputFile)
548 1.1.1.2.2.2 bouyer {
549 1.1.1.2.2.2 bouyer printf ("Could not open %s\n", Filename);
550 1.1.1.2.2.2 bouyer Status = -1;
551 1.1.1.2.2.2 bouyer goto CleanupAndExit;
552 1.1.1.2.2.2 bouyer }
553 1.1.1.2.2.2 bouyer
554 1.1.1.2.2.2 bouyer State = EXTRACT_DATA;
555 1.1.1.2.2.2 bouyer TotalBytesWritten = 0;
556 1.1.1.2.2.2 bouyer FoundTable = 1;
557 1.1.1.2.2.2 bouyer continue;
558 1.1.1.2.2.2 bouyer
559 1.1.1.2.2.2 bouyer case EXTRACT_DATA:
560 1.1.1.2.2.2 bouyer
561 1.1.1.2.2.2 bouyer /* Empty line or non-data line terminates the data */
562 1.1.1.2.2.2 bouyer
563 1.1.1.2.2.2 bouyer if ((Buffer[0] == '\n') ||
564 1.1.1.2.2.2 bouyer (Buffer[0] != ' '))
565 1.1.1.2.2.2 bouyer {
566 1.1.1.2.2.2 bouyer fclose (OutputFile);
567 1.1.1.2.2.2 bouyer OutputFile = NULL;
568 1.1.1.2.2.2 bouyer State = FIND_HEADER;
569 1.1.1.2.2.2 bouyer
570 1.1.1.2.2.2 bouyer printf ("Acpi table [%4.4s] - %u bytes written to %s\n",
571 1.1.1.2.2.2 bouyer ThisSignature, (unsigned int) TotalBytesWritten, Filename);
572 1.1.1.2.2.2 bouyer continue;
573 1.1.1.2.2.2 bouyer }
574 1.1.1.2.2.2 bouyer
575 1.1.1.2.2.2 bouyer /* Convert the ascii data (one line of text) to binary */
576 1.1.1.2.2.2 bouyer
577 1.1.1.2.2.2 bouyer BytesConverted = ConvertLine (Buffer, Data);
578 1.1.1.2.2.2 bouyer
579 1.1.1.2.2.2 bouyer /* Write the binary data */
580 1.1.1.2.2.2 bouyer
581 1.1.1.2.2.2 bouyer BytesWritten = fwrite (Data, 1, BytesConverted, OutputFile);
582 1.1.1.2.2.2 bouyer if (BytesWritten != BytesConverted)
583 1.1.1.2.2.2 bouyer {
584 1.1.1.2.2.2 bouyer printf ("Write error on %s\n", Filename);
585 1.1.1.2.2.2 bouyer fclose (OutputFile);
586 1.1.1.2.2.2 bouyer OutputFile = NULL;
587 1.1.1.2.2.2 bouyer Status = -1;
588 1.1.1.2.2.2 bouyer goto CleanupAndExit;
589 1.1.1.2.2.2 bouyer }
590 1.1.1.2.2.2 bouyer
591 1.1.1.2.2.2 bouyer TotalBytesWritten += BytesConverted;
592 1.1.1.2.2.2 bouyer continue;
593 1.1.1.2.2.2 bouyer
594 1.1.1.2.2.2 bouyer default:
595 1.1.1.2.2.2 bouyer Status = -1;
596 1.1.1.2.2.2 bouyer goto CleanupAndExit;
597 1.1.1.2.2.2 bouyer }
598 1.1.1.2.2.2 bouyer }
599 1.1.1.2.2.2 bouyer
600 1.1.1.2.2.2 bouyer if (!FoundTable)
601 1.1.1.2.2.2 bouyer {
602 1.1.1.2.2.2 bouyer printf ("Table %s was not found in %s\n", Signature, InputPathname);
603 1.1.1.2.2.2 bouyer }
604 1.1.1.2.2.2 bouyer
605 1.1.1.2.2.2 bouyer
606 1.1.1.2.2.2 bouyer CleanupAndExit:
607 1.1.1.2.2.2 bouyer
608 1.1.1.2.2.2 bouyer if (OutputFile)
609 1.1.1.2.2.2 bouyer {
610 1.1.1.2.2.2 bouyer fclose (OutputFile);
611 1.1.1.2.2.2 bouyer if (State == EXTRACT_DATA)
612 1.1.1.2.2.2 bouyer {
613 1.1.1.2.2.2 bouyer /* Received an EOF while extracting data */
614 1.1.1.2.2.2 bouyer
615 1.1.1.2.2.2 bouyer printf ("Acpi table [%4.4s] - %u bytes written to %s\n",
616 1.1.1.2.2.2 bouyer ThisSignature, (unsigned int) TotalBytesWritten, Filename);
617 1.1.1.2.2.2 bouyer }
618 1.1.1.2.2.2 bouyer }
619 1.1.1.2.2.2 bouyer
620 1.1.1.2.2.2 bouyer fclose (InputFile);
621 1.1.1.2.2.2 bouyer return (Status);
622 1.1.1.2.2.2 bouyer }
623 1.1.1.2.2.2 bouyer
624 1.1.1.2.2.2 bouyer
625 1.1.1.2.2.2 bouyer /******************************************************************************
626 1.1.1.2.2.2 bouyer *
627 1.1.1.2.2.2 bouyer * FUNCTION: ListTables
628 1.1.1.2.2.2 bouyer *
629 1.1.1.2.2.2 bouyer * PARAMETERS: InputPathname - Filename for acpidump file
630 1.1.1.2.2.2 bouyer *
631 1.1.1.2.2.2 bouyer * RETURN: Status
632 1.1.1.2.2.2 bouyer *
633 1.1.1.2.2.2 bouyer * DESCRIPTION: Display info for all ACPI tables found in input. Does not
634 1.1.1.2.2.2 bouyer * perform an actual extraction of the tables.
635 1.1.1.2.2.2 bouyer *
636 1.1.1.2.2.2 bouyer ******************************************************************************/
637 1.1.1.2.2.2 bouyer
638 1.1.1.2.2.2 bouyer static int
639 1.1.1.2.2.2 bouyer ListTables (
640 1.1.1.2.2.2 bouyer char *InputPathname)
641 1.1.1.2.2.2 bouyer {
642 1.1.1.2.2.2 bouyer FILE *InputFile;
643 1.1.1.2.2.2 bouyer char Buffer[BUFFER_SIZE];
644 1.1.1.2.2.2 bouyer size_t HeaderSize;
645 1.1.1.2.2.2 bouyer unsigned char Header[48];
646 1.1.1.2.2.2 bouyer int TableCount = 0;
647 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header;
648 1.1.1.2.2.2 bouyer
649 1.1.1.2.2.2 bouyer
650 1.1.1.2.2.2 bouyer /* Open input in text mode, output is in binary mode */
651 1.1.1.2.2.2 bouyer
652 1.1.1.2.2.2 bouyer InputFile = fopen (InputPathname, "rt");
653 1.1.1.2.2.2 bouyer if (!InputFile)
654 1.1.1.2.2.2 bouyer {
655 1.1.1.2.2.2 bouyer printf ("Could not open %s\n", InputPathname);
656 1.1.1.2.2.2 bouyer return (-1);
657 1.1.1.2.2.2 bouyer }
658 1.1.1.2.2.2 bouyer
659 1.1.1.2.2.2 bouyer /* Dump the headers for all tables found in the input file */
660 1.1.1.2.2.2 bouyer
661 1.1.1.2.2.2 bouyer printf ("\nSignature Length Revision OemId OemTableId"
662 1.1.1.2.2.2 bouyer " OemRevision CompilerId CompilerRevision\n\n");
663 1.1.1.2.2.2 bouyer
664 1.1.1.2.2.2 bouyer while (fgets (Buffer, BUFFER_SIZE, InputFile))
665 1.1.1.2.2.2 bouyer {
666 1.1.1.2.2.2 bouyer /* Ignore empty lines and lines that start with a space */
667 1.1.1.2.2.2 bouyer
668 1.1.1.2.2.2 bouyer if ((Buffer[0] == ' ') ||
669 1.1.1.2.2.2 bouyer (Buffer[0] == '\n'))
670 1.1.1.2.2.2 bouyer {
671 1.1.1.2.2.2 bouyer continue;
672 1.1.1.2.2.2 bouyer }
673 1.1.1.2.2.2 bouyer
674 1.1.1.2.2.2 bouyer /* Get the 36 byte header and display the fields */
675 1.1.1.2.2.2 bouyer
676 1.1.1.2.2.2 bouyer HeaderSize = GetTableHeader (InputFile, Header);
677 1.1.1.2.2.2 bouyer if (HeaderSize < 16)
678 1.1.1.2.2.2 bouyer {
679 1.1.1.2.2.2 bouyer continue;
680 1.1.1.2.2.2 bouyer }
681 1.1.1.2.2.2 bouyer
682 1.1.1.2.2.2 bouyer /* RSDP has an oddball signature and header */
683 1.1.1.2.2.2 bouyer
684 1.1.1.2.2.2 bouyer if (!strncmp (TableHeader->Signature, "RSD PTR ", 8))
685 1.1.1.2.2.2 bouyer {
686 1.1.1.2.2.2 bouyer CheckAscii ((char *) &Header[9], 6);
687 1.1.1.2.2.2 bouyer printf ("%8.4s \"%6.6s\"\n", "RSDP", &Header[9]);
688 1.1.1.2.2.2 bouyer TableCount++;
689 1.1.1.2.2.2 bouyer continue;
690 1.1.1.2.2.2 bouyer }
691 1.1.1.2.2.2 bouyer
692 1.1.1.2.2.2 bouyer /* Minimum size for table with standard header */
693 1.1.1.2.2.2 bouyer
694 1.1.1.2.2.2 bouyer if (HeaderSize < 36)
695 1.1.1.2.2.2 bouyer {
696 1.1.1.2.2.2 bouyer continue;
697 1.1.1.2.2.2 bouyer }
698 1.1.1.2.2.2 bouyer
699 1.1.1.2.2.2 bouyer /* Signature and Table length */
700 1.1.1.2.2.2 bouyer
701 1.1.1.2.2.2 bouyer TableCount++;
702 1.1.1.2.2.2 bouyer printf ("%8.4s % 7d", TableHeader->Signature, TableHeader->Length);
703 1.1.1.2.2.2 bouyer
704 1.1.1.2.2.2 bouyer /* FACS has only signature and length */
705 1.1.1.2.2.2 bouyer
706 1.1.1.2.2.2 bouyer if (!strncmp (TableHeader->Signature, "FACS", 4))
707 1.1.1.2.2.2 bouyer {
708 1.1.1.2.2.2 bouyer printf ("\n");
709 1.1.1.2.2.2 bouyer continue;
710 1.1.1.2.2.2 bouyer }
711 1.1.1.2.2.2 bouyer
712 1.1.1.2.2.2 bouyer /* OEM IDs and Compiler IDs */
713 1.1.1.2.2.2 bouyer
714 1.1.1.2.2.2 bouyer CheckAscii (TableHeader->OemId, 6);
715 1.1.1.2.2.2 bouyer CheckAscii (TableHeader->OemTableId, 8);
716 1.1.1.2.2.2 bouyer CheckAscii (TableHeader->AslCompilerId, 4);
717 1.1.1.2.2.2 bouyer
718 1.1.1.2.2.2 bouyer printf (" %2.2X \"%6.6s\" \"%8.8s\" %8.8X \"%4.4s\" %8.8X\n",
719 1.1.1.2.2.2 bouyer TableHeader->Revision, TableHeader->OemId,
720 1.1.1.2.2.2 bouyer TableHeader->OemTableId, TableHeader->OemRevision,
721 1.1.1.2.2.2 bouyer TableHeader->AslCompilerId, TableHeader->AslCompilerRevision);
722 1.1.1.2.2.2 bouyer }
723 1.1.1.2.2.2 bouyer
724 1.1.1.2.2.2 bouyer printf ("\nFound %u ACPI tables [%8.8X]\n", TableCount, VERSION);
725 1.1.1.2.2.2 bouyer fclose (InputFile);
726 1.1.1.2.2.2 bouyer return (0);
727 1.1.1.2.2.2 bouyer }
728 1.1.1.2.2.2 bouyer
729 1.1.1.2.2.2 bouyer
730 1.1.1.2.2.2 bouyer /******************************************************************************
731 1.1.1.2.2.2 bouyer *
732 1.1.1.2.2.2 bouyer * FUNCTION: main
733 1.1.1.2.2.2 bouyer *
734 1.1.1.2.2.2 bouyer * DESCRIPTION: C main function
735 1.1.1.2.2.2 bouyer *
736 1.1.1.2.2.2 bouyer ******************************************************************************/
737 1.1.1.2.2.2 bouyer
738 1.1.1.2.2.2 bouyer int
739 1.1.1.2.2.2 bouyer main (
740 1.1.1.2.2.2 bouyer int argc,
741 1.1.1.2.2.2 bouyer char *argv[])
742 1.1.1.2.2.2 bouyer {
743 1.1.1.2.2.2 bouyer int Status;
744 1.1.1.2.2.2 bouyer
745 1.1.1.2.2.2 bouyer
746 1.1.1.2.2.2 bouyer if (argc < 2)
747 1.1.1.2.2.2 bouyer {
748 1.1.1.2.2.2 bouyer DisplayUsage ();
749 1.1.1.2.2.2 bouyer return (0);
750 1.1.1.2.2.2 bouyer }
751 1.1.1.2.2.2 bouyer
752 1.1.1.2.2.2 bouyer if (argv[1][0] == '-')
753 1.1.1.2.2.2 bouyer {
754 1.1.1.2.2.2 bouyer if (argc < 3)
755 1.1.1.2.2.2 bouyer {
756 1.1.1.2.2.2 bouyer DisplayUsage ();
757 1.1.1.2.2.2 bouyer return (0);
758 1.1.1.2.2.2 bouyer }
759 1.1.1.2.2.2 bouyer
760 1.1.1.2.2.2 bouyer switch (argv[1][1])
761 1.1.1.2.2.2 bouyer {
762 1.1.1.2.2.2 bouyer case 'a':
763 1.1.1.2.2.2 bouyer
764 1.1.1.2.2.2 bouyer /* Extract all tables found */
765 1.1.1.2.2.2 bouyer
766 1.1.1.2.2.2 bouyer return (ExtractTables (argv[2], NULL, 0));
767 1.1.1.2.2.2 bouyer
768 1.1.1.2.2.2 bouyer case 'l':
769 1.1.1.2.2.2 bouyer
770 1.1.1.2.2.2 bouyer /* List tables only, do not extract */
771 1.1.1.2.2.2 bouyer
772 1.1.1.2.2.2 bouyer return (ListTables (argv[2]));
773 1.1.1.2.2.2 bouyer
774 1.1.1.2.2.2 bouyer case 's':
775 1.1.1.2.2.2 bouyer
776 1.1.1.2.2.2 bouyer /* Extract only tables with this signature */
777 1.1.1.2.2.2 bouyer
778 1.1.1.2.2.2 bouyer return (ExtractTables (argv[2], &argv[1][2], 1));
779 1.1.1.2.2.2 bouyer
780 1.1.1.2.2.2 bouyer default:
781 1.1.1.2.2.2 bouyer DisplayUsage ();
782 1.1.1.2.2.2 bouyer return (0);
783 1.1.1.2.2.2 bouyer }
784 1.1.1.2.2.2 bouyer }
785 1.1.1.2.2.2 bouyer
786 1.1.1.2.2.2 bouyer /*
787 1.1.1.2.2.2 bouyer * Default output is the DSDT and all SSDTs. One DSDT is required,
788 1.1.1.2.2.2 bouyer * any SSDTs are optional.
789 1.1.1.2.2.2 bouyer */
790 1.1.1.2.2.2 bouyer Status = ExtractTables (argv[1], "DSDT", 1);
791 1.1.1.2.2.2 bouyer if (Status)
792 1.1.1.2.2.2 bouyer {
793 1.1.1.2.2.2 bouyer return (Status);
794 1.1.1.2.2.2 bouyer }
795 1.1.1.2.2.2 bouyer
796 1.1.1.2.2.2 bouyer Status = ExtractTables (argv[1], "SSDT", 0);
797 1.1.1.2.2.2 bouyer return (Status);
798 1.1.1.2.2.2 bouyer }
799 1.1.1.2.2.2 bouyer
800 1.1.1.2.2.2 bouyer
801