aemain.c revision 1.1.1.2.4.2 1 1.1.1.2.4.2 rmind /******************************************************************************
2 1.1.1.2.4.2 rmind *
3 1.1.1.2.4.2 rmind * Module Name: aemain - Main routine for the AcpiExec utility
4 1.1.1.2.4.2 rmind *
5 1.1.1.2.4.2 rmind *****************************************************************************/
6 1.1.1.2.4.2 rmind
7 1.1.1.2.4.2 rmind /*
8 1.1.1.2.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.4.2 rmind * All rights reserved.
10 1.1.1.2.4.2 rmind *
11 1.1.1.2.4.2 rmind * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.4.2 rmind * modification, are permitted provided that the following conditions
13 1.1.1.2.4.2 rmind * are met:
14 1.1.1.2.4.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.4.2 rmind * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.4.2 rmind * without modification.
17 1.1.1.2.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.4.2 rmind * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.4.2 rmind * binary redistribution.
22 1.1.1.2.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.4.2 rmind * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.4.2 rmind * from this software without specific prior written permission.
25 1.1.1.2.4.2 rmind *
26 1.1.1.2.4.2 rmind * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.4.2 rmind * Software Foundation.
29 1.1.1.2.4.2 rmind *
30 1.1.1.2.4.2 rmind * NO WARRANTY
31 1.1.1.2.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.4.2 rmind */
43 1.1.1.2.4.2 rmind
44 1.1.1.2.4.2 rmind #include "aecommon.h"
45 1.1.1.2.4.2 rmind
46 1.1.1.2.4.2 rmind #ifdef _DEBUG
47 1.1.1.2.4.2 rmind #include <crtdbg.h>
48 1.1.1.2.4.2 rmind #endif
49 1.1.1.2.4.2 rmind
50 1.1.1.2.4.2 rmind #define _COMPONENT PARSER
51 1.1.1.2.4.2 rmind ACPI_MODULE_NAME ("aemain")
52 1.1.1.2.4.2 rmind
53 1.1.1.2.4.2 rmind
54 1.1.1.2.4.2 rmind UINT8 AcpiGbl_RegionFillValue = 0;
55 1.1.1.2.4.2 rmind BOOLEAN AcpiGbl_IgnoreErrors = FALSE;
56 1.1.1.2.4.2 rmind BOOLEAN AcpiGbl_DbOpt_NoRegionSupport = FALSE;
57 1.1.1.2.4.2 rmind BOOLEAN AcpiGbl_DebugTimeout = FALSE;
58 1.1.1.2.4.2 rmind
59 1.1.1.2.4.2 rmind static UINT8 AcpiGbl_BatchMode = 0;
60 1.1.1.2.4.2 rmind static char BatchBuffer[128];
61 1.1.1.2.4.2 rmind static AE_TABLE_DESC *AeTableListHead = NULL;
62 1.1.1.2.4.2 rmind
63 1.1.1.2.4.2 rmind #define ASL_MAX_FILES 256
64 1.1.1.2.4.2 rmind static char *FileList[ASL_MAX_FILES];
65 1.1.1.2.4.2 rmind
66 1.1.1.2.4.2 rmind
67 1.1.1.2.4.2 rmind #define AE_SUPPORTED_OPTIONS "?b:d:e:f:gm^ovx:"
68 1.1.1.2.4.2 rmind
69 1.1.1.2.4.2 rmind
70 1.1.1.2.4.2 rmind /******************************************************************************
71 1.1.1.2.4.2 rmind *
72 1.1.1.2.4.2 rmind * FUNCTION: usage
73 1.1.1.2.4.2 rmind *
74 1.1.1.2.4.2 rmind * PARAMETERS: None
75 1.1.1.2.4.2 rmind *
76 1.1.1.2.4.2 rmind * RETURN: None
77 1.1.1.2.4.2 rmind *
78 1.1.1.2.4.2 rmind * DESCRIPTION: Print a usage message
79 1.1.1.2.4.2 rmind *
80 1.1.1.2.4.2 rmind *****************************************************************************/
81 1.1.1.2.4.2 rmind
82 1.1.1.2.4.2 rmind static void
83 1.1.1.2.4.2 rmind usage (void)
84 1.1.1.2.4.2 rmind {
85 1.1.1.2.4.2 rmind printf ("Usage: acpiexec [options] AMLfile1 AMLfile2 ...\n\n");
86 1.1.1.2.4.2 rmind
87 1.1.1.2.4.2 rmind printf ("Where:\n");
88 1.1.1.2.4.2 rmind printf (" -? Display this message\n");
89 1.1.1.2.4.2 rmind printf (" -b <CommandLine> Batch mode command execution\n");
90 1.1.1.2.4.2 rmind printf (" -m [Method] Batch mode method execution. Default=MAIN\n");
91 1.1.1.2.4.2 rmind printf ("\n");
92 1.1.1.2.4.2 rmind
93 1.1.1.2.4.2 rmind printf (" -da Disable method abort on error\n");
94 1.1.1.2.4.2 rmind printf (" -di Disable execution of STA/INI methods during init\n");
95 1.1.1.2.4.2 rmind printf (" -do Disable Operation Region address simulation\n");
96 1.1.1.2.4.2 rmind printf (" -dt Disable allocation tracking (performance)\n");
97 1.1.1.2.4.2 rmind printf ("\n");
98 1.1.1.2.4.2 rmind
99 1.1.1.2.4.2 rmind printf (" -ef Enable display of final memory statistics\n");
100 1.1.1.2.4.2 rmind printf (" -em Enable Interpreter Serialized Mode\n");
101 1.1.1.2.4.2 rmind printf (" -es Enable Interpreter Slack Mode\n");
102 1.1.1.2.4.2 rmind printf (" -et Enable debug semaphore timeout\n");
103 1.1.1.2.4.2 rmind printf ("\n");
104 1.1.1.2.4.2 rmind
105 1.1.1.2.4.2 rmind printf (" -f <Value> Operation Region initialization fill value\n");
106 1.1.1.2.4.2 rmind printf (" -v Verbose initialization output\n");
107 1.1.1.2.4.2 rmind printf (" -x <DebugLevel> Debug output level\n");
108 1.1.1.2.4.2 rmind }
109 1.1.1.2.4.2 rmind
110 1.1.1.2.4.2 rmind
111 1.1.1.2.4.2 rmind /******************************************************************************
112 1.1.1.2.4.2 rmind *
113 1.1.1.2.4.2 rmind * FUNCTION: AcpiDbRunBatchMode
114 1.1.1.2.4.2 rmind *
115 1.1.1.2.4.2 rmind * PARAMETERS: BatchCommandLine - A semicolon separated list of commands
116 1.1.1.2.4.2 rmind * to be executed.
117 1.1.1.2.4.2 rmind * Use only commas to separate elements of
118 1.1.1.2.4.2 rmind * particular command.
119 1.1.1.2.4.2 rmind * RETURN: Status
120 1.1.1.2.4.2 rmind *
121 1.1.1.2.4.2 rmind * DESCRIPTION: For each command of list separated by ';' prepare the command
122 1.1.1.2.4.2 rmind * buffer and pass it to AcpiDbCommandDispatch.
123 1.1.1.2.4.2 rmind *
124 1.1.1.2.4.2 rmind *****************************************************************************/
125 1.1.1.2.4.2 rmind
126 1.1.1.2.4.2 rmind static ACPI_STATUS
127 1.1.1.2.4.2 rmind AcpiDbRunBatchMode (
128 1.1.1.2.4.2 rmind void)
129 1.1.1.2.4.2 rmind {
130 1.1.1.2.4.2 rmind ACPI_STATUS Status;
131 1.1.1.2.4.2 rmind char *Ptr = BatchBuffer;
132 1.1.1.2.4.2 rmind char *Cmd = Ptr;
133 1.1.1.2.4.2 rmind UINT8 Run = 0;
134 1.1.1.2.4.2 rmind
135 1.1.1.2.4.2 rmind
136 1.1.1.2.4.2 rmind AcpiGbl_MethodExecuting = FALSE;
137 1.1.1.2.4.2 rmind AcpiGbl_StepToNextCall = FALSE;
138 1.1.1.2.4.2 rmind
139 1.1.1.2.4.2 rmind while (*Ptr)
140 1.1.1.2.4.2 rmind {
141 1.1.1.2.4.2 rmind if (*Ptr == ',')
142 1.1.1.2.4.2 rmind {
143 1.1.1.2.4.2 rmind /* Convert commas to spaces */
144 1.1.1.2.4.2 rmind *Ptr = ' ';
145 1.1.1.2.4.2 rmind }
146 1.1.1.2.4.2 rmind else if (*Ptr == ';')
147 1.1.1.2.4.2 rmind {
148 1.1.1.2.4.2 rmind *Ptr = '\0';
149 1.1.1.2.4.2 rmind Run = 1;
150 1.1.1.2.4.2 rmind }
151 1.1.1.2.4.2 rmind
152 1.1.1.2.4.2 rmind Ptr++;
153 1.1.1.2.4.2 rmind
154 1.1.1.2.4.2 rmind if (Run || (*Ptr == '\0'))
155 1.1.1.2.4.2 rmind {
156 1.1.1.2.4.2 rmind (void) AcpiDbCommandDispatch (Cmd, NULL, NULL);
157 1.1.1.2.4.2 rmind Run = 0;
158 1.1.1.2.4.2 rmind Cmd = Ptr;
159 1.1.1.2.4.2 rmind }
160 1.1.1.2.4.2 rmind }
161 1.1.1.2.4.2 rmind
162 1.1.1.2.4.2 rmind Status = AcpiTerminate ();
163 1.1.1.2.4.2 rmind return (Status);
164 1.1.1.2.4.2 rmind }
165 1.1.1.2.4.2 rmind
166 1.1.1.2.4.2 rmind
167 1.1.1.2.4.2 rmind /*******************************************************************************
168 1.1.1.2.4.2 rmind *
169 1.1.1.2.4.2 rmind * FUNCTION: FlStrdup
170 1.1.1.2.4.2 rmind *
171 1.1.1.2.4.2 rmind * DESCRIPTION: Local strdup function
172 1.1.1.2.4.2 rmind *
173 1.1.1.2.4.2 rmind ******************************************************************************/
174 1.1.1.2.4.2 rmind
175 1.1.1.2.4.2 rmind static char *
176 1.1.1.2.4.2 rmind FlStrdup (
177 1.1.1.2.4.2 rmind char *String)
178 1.1.1.2.4.2 rmind {
179 1.1.1.2.4.2 rmind char *NewString;
180 1.1.1.2.4.2 rmind
181 1.1.1.2.4.2 rmind
182 1.1.1.2.4.2 rmind NewString = AcpiOsAllocate (strlen (String) + 1);
183 1.1.1.2.4.2 rmind if (!NewString)
184 1.1.1.2.4.2 rmind {
185 1.1.1.2.4.2 rmind return (NULL);
186 1.1.1.2.4.2 rmind }
187 1.1.1.2.4.2 rmind
188 1.1.1.2.4.2 rmind strcpy (NewString, String);
189 1.1.1.2.4.2 rmind return (NewString);
190 1.1.1.2.4.2 rmind }
191 1.1.1.2.4.2 rmind
192 1.1.1.2.4.2 rmind
193 1.1.1.2.4.2 rmind /*******************************************************************************
194 1.1.1.2.4.2 rmind *
195 1.1.1.2.4.2 rmind * FUNCTION: FlSplitInputPathname
196 1.1.1.2.4.2 rmind *
197 1.1.1.2.4.2 rmind * PARAMETERS: InputFilename - The user-specified ASL source file to be
198 1.1.1.2.4.2 rmind * compiled
199 1.1.1.2.4.2 rmind * OutDirectoryPath - Where the directory path prefix is
200 1.1.1.2.4.2 rmind * returned
201 1.1.1.2.4.2 rmind * OutFilename - Where the filename part is returned
202 1.1.1.2.4.2 rmind *
203 1.1.1.2.4.2 rmind * RETURN: Status
204 1.1.1.2.4.2 rmind *
205 1.1.1.2.4.2 rmind * DESCRIPTION: Split the input path into a directory and filename part
206 1.1.1.2.4.2 rmind * 1) Directory part used to open include files
207 1.1.1.2.4.2 rmind * 2) Filename part used to generate output filenames
208 1.1.1.2.4.2 rmind *
209 1.1.1.2.4.2 rmind ******************************************************************************/
210 1.1.1.2.4.2 rmind
211 1.1.1.2.4.2 rmind ACPI_STATUS
212 1.1.1.2.4.2 rmind FlSplitInputPathname (
213 1.1.1.2.4.2 rmind char *InputPath,
214 1.1.1.2.4.2 rmind char **OutDirectoryPath,
215 1.1.1.2.4.2 rmind char **OutFilename)
216 1.1.1.2.4.2 rmind {
217 1.1.1.2.4.2 rmind char *Substring;
218 1.1.1.2.4.2 rmind char *DirectoryPath;
219 1.1.1.2.4.2 rmind char *Filename;
220 1.1.1.2.4.2 rmind
221 1.1.1.2.4.2 rmind
222 1.1.1.2.4.2 rmind *OutDirectoryPath = NULL;
223 1.1.1.2.4.2 rmind *OutFilename = NULL;
224 1.1.1.2.4.2 rmind
225 1.1.1.2.4.2 rmind if (!InputPath)
226 1.1.1.2.4.2 rmind {
227 1.1.1.2.4.2 rmind return (AE_OK);
228 1.1.1.2.4.2 rmind }
229 1.1.1.2.4.2 rmind
230 1.1.1.2.4.2 rmind /* Get the path to the input filename's directory */
231 1.1.1.2.4.2 rmind
232 1.1.1.2.4.2 rmind DirectoryPath = FlStrdup (InputPath);
233 1.1.1.2.4.2 rmind if (!DirectoryPath)
234 1.1.1.2.4.2 rmind {
235 1.1.1.2.4.2 rmind return (AE_NO_MEMORY);
236 1.1.1.2.4.2 rmind }
237 1.1.1.2.4.2 rmind
238 1.1.1.2.4.2 rmind Substring = strrchr (DirectoryPath, '\\');
239 1.1.1.2.4.2 rmind if (!Substring)
240 1.1.1.2.4.2 rmind {
241 1.1.1.2.4.2 rmind Substring = strrchr (DirectoryPath, '/');
242 1.1.1.2.4.2 rmind if (!Substring)
243 1.1.1.2.4.2 rmind {
244 1.1.1.2.4.2 rmind Substring = strrchr (DirectoryPath, ':');
245 1.1.1.2.4.2 rmind }
246 1.1.1.2.4.2 rmind }
247 1.1.1.2.4.2 rmind
248 1.1.1.2.4.2 rmind if (!Substring)
249 1.1.1.2.4.2 rmind {
250 1.1.1.2.4.2 rmind DirectoryPath[0] = 0;
251 1.1.1.2.4.2 rmind Filename = FlStrdup (InputPath);
252 1.1.1.2.4.2 rmind }
253 1.1.1.2.4.2 rmind else
254 1.1.1.2.4.2 rmind {
255 1.1.1.2.4.2 rmind Filename = FlStrdup (Substring + 1);
256 1.1.1.2.4.2 rmind *(Substring+1) = 0;
257 1.1.1.2.4.2 rmind }
258 1.1.1.2.4.2 rmind
259 1.1.1.2.4.2 rmind if (!Filename)
260 1.1.1.2.4.2 rmind {
261 1.1.1.2.4.2 rmind return (AE_NO_MEMORY);
262 1.1.1.2.4.2 rmind }
263 1.1.1.2.4.2 rmind
264 1.1.1.2.4.2 rmind *OutDirectoryPath = DirectoryPath;
265 1.1.1.2.4.2 rmind *OutFilename = Filename;
266 1.1.1.2.4.2 rmind
267 1.1.1.2.4.2 rmind return (AE_OK);
268 1.1.1.2.4.2 rmind }
269 1.1.1.2.4.2 rmind
270 1.1.1.2.4.2 rmind
271 1.1.1.2.4.2 rmind /******************************************************************************
272 1.1.1.2.4.2 rmind *
273 1.1.1.2.4.2 rmind * FUNCTION: AsDoWildcard
274 1.1.1.2.4.2 rmind *
275 1.1.1.2.4.2 rmind * PARAMETERS: DirectoryPathname - Path to parent directory
276 1.1.1.2.4.2 rmind * FileSpecifier - the wildcard specification (*.c, etc.)
277 1.1.1.2.4.2 rmind *
278 1.1.1.2.4.2 rmind * RETURN: Pointer to a list of filenames
279 1.1.1.2.4.2 rmind *
280 1.1.1.2.4.2 rmind * DESCRIPTION: Process files via wildcards. This function is for the Windows
281 1.1.1.2.4.2 rmind * case only.
282 1.1.1.2.4.2 rmind *
283 1.1.1.2.4.2 rmind ******************************************************************************/
284 1.1.1.2.4.2 rmind
285 1.1.1.2.4.2 rmind static char **
286 1.1.1.2.4.2 rmind AsDoWildcard (
287 1.1.1.2.4.2 rmind char *DirectoryPathname,
288 1.1.1.2.4.2 rmind char *FileSpecifier)
289 1.1.1.2.4.2 rmind {
290 1.1.1.2.4.2 rmind #ifdef WIN32
291 1.1.1.2.4.2 rmind void *DirInfo;
292 1.1.1.2.4.2 rmind char *Filename;
293 1.1.1.2.4.2 rmind int FileCount;
294 1.1.1.2.4.2 rmind
295 1.1.1.2.4.2 rmind
296 1.1.1.2.4.2 rmind FileCount = 0;
297 1.1.1.2.4.2 rmind
298 1.1.1.2.4.2 rmind /* Open parent directory */
299 1.1.1.2.4.2 rmind
300 1.1.1.2.4.2 rmind DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY);
301 1.1.1.2.4.2 rmind if (!DirInfo)
302 1.1.1.2.4.2 rmind {
303 1.1.1.2.4.2 rmind /* Either the directory or file does not exist */
304 1.1.1.2.4.2 rmind
305 1.1.1.2.4.2 rmind printf ("File or directory %s%s does not exist\n", DirectoryPathname, FileSpecifier);
306 1.1.1.2.4.2 rmind return (NULL);
307 1.1.1.2.4.2 rmind }
308 1.1.1.2.4.2 rmind
309 1.1.1.2.4.2 rmind /* Process each file that matches the wildcard specification */
310 1.1.1.2.4.2 rmind
311 1.1.1.2.4.2 rmind while ((Filename = AcpiOsGetNextFilename (DirInfo)))
312 1.1.1.2.4.2 rmind {
313 1.1.1.2.4.2 rmind /* Add the filename to the file list */
314 1.1.1.2.4.2 rmind
315 1.1.1.2.4.2 rmind FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1);
316 1.1.1.2.4.2 rmind strcpy (FileList[FileCount], Filename);
317 1.1.1.2.4.2 rmind FileCount++;
318 1.1.1.2.4.2 rmind
319 1.1.1.2.4.2 rmind if (FileCount >= ASL_MAX_FILES)
320 1.1.1.2.4.2 rmind {
321 1.1.1.2.4.2 rmind printf ("Max files reached\n");
322 1.1.1.2.4.2 rmind FileList[0] = NULL;
323 1.1.1.2.4.2 rmind return (FileList);
324 1.1.1.2.4.2 rmind }
325 1.1.1.2.4.2 rmind }
326 1.1.1.2.4.2 rmind
327 1.1.1.2.4.2 rmind /* Cleanup */
328 1.1.1.2.4.2 rmind
329 1.1.1.2.4.2 rmind AcpiOsCloseDirectory (DirInfo);
330 1.1.1.2.4.2 rmind FileList[FileCount] = NULL;
331 1.1.1.2.4.2 rmind return (FileList);
332 1.1.1.2.4.2 rmind
333 1.1.1.2.4.2 rmind #else
334 1.1.1.2.4.2 rmind if (!FileSpecifier)
335 1.1.1.2.4.2 rmind {
336 1.1.1.2.4.2 rmind return (NULL);
337 1.1.1.2.4.2 rmind }
338 1.1.1.2.4.2 rmind
339 1.1.1.2.4.2 rmind /*
340 1.1.1.2.4.2 rmind * Linux/Unix cases - Wildcards are expanded by the shell automatically.
341 1.1.1.2.4.2 rmind * Just return the filename in a null terminated list
342 1.1.1.2.4.2 rmind */
343 1.1.1.2.4.2 rmind FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1);
344 1.1.1.2.4.2 rmind strcpy (FileList[0], FileSpecifier);
345 1.1.1.2.4.2 rmind FileList[1] = NULL;
346 1.1.1.2.4.2 rmind
347 1.1.1.2.4.2 rmind return (FileList);
348 1.1.1.2.4.2 rmind #endif
349 1.1.1.2.4.2 rmind }
350 1.1.1.2.4.2 rmind
351 1.1.1.2.4.2 rmind
352 1.1.1.2.4.2 rmind /******************************************************************************
353 1.1.1.2.4.2 rmind *
354 1.1.1.2.4.2 rmind * FUNCTION: main
355 1.1.1.2.4.2 rmind *
356 1.1.1.2.4.2 rmind * PARAMETERS: argc, argv
357 1.1.1.2.4.2 rmind *
358 1.1.1.2.4.2 rmind * RETURN: Status
359 1.1.1.2.4.2 rmind *
360 1.1.1.2.4.2 rmind * DESCRIPTION: Main routine for AcpiDump utility
361 1.1.1.2.4.2 rmind *
362 1.1.1.2.4.2 rmind *****************************************************************************/
363 1.1.1.2.4.2 rmind
364 1.1.1.2.4.2 rmind int ACPI_SYSTEM_XFACE
365 1.1.1.2.4.2 rmind main (
366 1.1.1.2.4.2 rmind int argc,
367 1.1.1.2.4.2 rmind char **argv)
368 1.1.1.2.4.2 rmind {
369 1.1.1.2.4.2 rmind int j;
370 1.1.1.2.4.2 rmind ACPI_STATUS Status;
371 1.1.1.2.4.2 rmind UINT32 InitFlags;
372 1.1.1.2.4.2 rmind ACPI_TABLE_HEADER *Table = NULL;
373 1.1.1.2.4.2 rmind UINT32 TableCount;
374 1.1.1.2.4.2 rmind AE_TABLE_DESC *TableDesc;
375 1.1.1.2.4.2 rmind char **WildcardList;
376 1.1.1.2.4.2 rmind char *Filename;
377 1.1.1.2.4.2 rmind char *Directory;
378 1.1.1.2.4.2 rmind char *FullPathname;
379 1.1.1.2.4.2 rmind
380 1.1.1.2.4.2 rmind
381 1.1.1.2.4.2 rmind #ifdef _DEBUG
382 1.1.1.2.4.2 rmind _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF |
383 1.1.1.2.4.2 rmind _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
384 1.1.1.2.4.2 rmind #endif
385 1.1.1.2.4.2 rmind
386 1.1.1.2.4.2 rmind printf (ACPI_COMMON_SIGNON ("AML Execution/Debug Utility"));
387 1.1.1.2.4.2 rmind
388 1.1.1.2.4.2 rmind if (argc < 2)
389 1.1.1.2.4.2 rmind {
390 1.1.1.2.4.2 rmind usage ();
391 1.1.1.2.4.2 rmind return (0);
392 1.1.1.2.4.2 rmind }
393 1.1.1.2.4.2 rmind
394 1.1.1.2.4.2 rmind signal (SIGINT, AeCtrlCHandler);
395 1.1.1.2.4.2 rmind
396 1.1.1.2.4.2 rmind /* Init globals */
397 1.1.1.2.4.2 rmind
398 1.1.1.2.4.2 rmind AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
399 1.1.1.2.4.2 rmind AcpiDbgLayer = 0xFFFFFFFF;
400 1.1.1.2.4.2 rmind
401 1.1.1.2.4.2 rmind /* Init ACPI and start debugger thread */
402 1.1.1.2.4.2 rmind
403 1.1.1.2.4.2 rmind Status = AcpiInitializeSubsystem ();
404 1.1.1.2.4.2 rmind AE_CHECK_OK (AcpiInitializeSubsystem, Status);
405 1.1.1.2.4.2 rmind
406 1.1.1.2.4.2 rmind /* Get the command line options */
407 1.1.1.2.4.2 rmind
408 1.1.1.2.4.2 rmind while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch(j)
409 1.1.1.2.4.2 rmind {
410 1.1.1.2.4.2 rmind case 'b':
411 1.1.1.2.4.2 rmind if (strlen (AcpiGbl_Optarg) > 127)
412 1.1.1.2.4.2 rmind {
413 1.1.1.2.4.2 rmind printf ("**** The length of command line (%u) exceeded maximum (127)\n",
414 1.1.1.2.4.2 rmind (UINT32) strlen (AcpiGbl_Optarg));
415 1.1.1.2.4.2 rmind return (-1);
416 1.1.1.2.4.2 rmind }
417 1.1.1.2.4.2 rmind AcpiGbl_BatchMode = 1;
418 1.1.1.2.4.2 rmind strcpy (BatchBuffer, AcpiGbl_Optarg);
419 1.1.1.2.4.2 rmind break;
420 1.1.1.2.4.2 rmind
421 1.1.1.2.4.2 rmind case 'd':
422 1.1.1.2.4.2 rmind switch (AcpiGbl_Optarg[0])
423 1.1.1.2.4.2 rmind {
424 1.1.1.2.4.2 rmind case 'a':
425 1.1.1.2.4.2 rmind AcpiGbl_IgnoreErrors = TRUE;
426 1.1.1.2.4.2 rmind break;
427 1.1.1.2.4.2 rmind
428 1.1.1.2.4.2 rmind case 'i':
429 1.1.1.2.4.2 rmind AcpiGbl_DbOpt_ini_methods = FALSE;
430 1.1.1.2.4.2 rmind break;
431 1.1.1.2.4.2 rmind
432 1.1.1.2.4.2 rmind case 'o':
433 1.1.1.2.4.2 rmind AcpiGbl_DbOpt_NoRegionSupport = TRUE;
434 1.1.1.2.4.2 rmind break;
435 1.1.1.2.4.2 rmind
436 1.1.1.2.4.2 rmind case 't':
437 1.1.1.2.4.2 rmind #ifdef ACPI_DBG_TRACK_ALLOCATIONS
438 1.1.1.2.4.2 rmind AcpiGbl_DisableMemTracking = TRUE;
439 1.1.1.2.4.2 rmind #endif
440 1.1.1.2.4.2 rmind break;
441 1.1.1.2.4.2 rmind
442 1.1.1.2.4.2 rmind default:
443 1.1.1.2.4.2 rmind printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
444 1.1.1.2.4.2 rmind return (-1);
445 1.1.1.2.4.2 rmind }
446 1.1.1.2.4.2 rmind break;
447 1.1.1.2.4.2 rmind
448 1.1.1.2.4.2 rmind case 'e':
449 1.1.1.2.4.2 rmind switch (AcpiGbl_Optarg[0])
450 1.1.1.2.4.2 rmind {
451 1.1.1.2.4.2 rmind case 'f':
452 1.1.1.2.4.2 rmind #ifdef ACPI_DBG_TRACK_ALLOCATIONS
453 1.1.1.2.4.2 rmind AcpiGbl_DisplayFinalMemStats = TRUE;
454 1.1.1.2.4.2 rmind #endif
455 1.1.1.2.4.2 rmind break;
456 1.1.1.2.4.2 rmind
457 1.1.1.2.4.2 rmind case 'm':
458 1.1.1.2.4.2 rmind AcpiGbl_AllMethodsSerialized = TRUE;
459 1.1.1.2.4.2 rmind printf ("Enabling AML Interpreter serialized mode\n");
460 1.1.1.2.4.2 rmind break;
461 1.1.1.2.4.2 rmind
462 1.1.1.2.4.2 rmind case 's':
463 1.1.1.2.4.2 rmind AcpiGbl_EnableInterpreterSlack = TRUE;
464 1.1.1.2.4.2 rmind printf ("Enabling AML Interpreter slack mode\n");
465 1.1.1.2.4.2 rmind break;
466 1.1.1.2.4.2 rmind
467 1.1.1.2.4.2 rmind case 't':
468 1.1.1.2.4.2 rmind AcpiGbl_DebugTimeout = TRUE;
469 1.1.1.2.4.2 rmind break;
470 1.1.1.2.4.2 rmind
471 1.1.1.2.4.2 rmind default:
472 1.1.1.2.4.2 rmind printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
473 1.1.1.2.4.2 rmind return (-1);
474 1.1.1.2.4.2 rmind }
475 1.1.1.2.4.2 rmind break;
476 1.1.1.2.4.2 rmind
477 1.1.1.2.4.2 rmind case 'f':
478 1.1.1.2.4.2 rmind AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
479 1.1.1.2.4.2 rmind break;
480 1.1.1.2.4.2 rmind
481 1.1.1.2.4.2 rmind case 'g':
482 1.1.1.2.4.2 rmind AcpiGbl_DbOpt_tables = TRUE;
483 1.1.1.2.4.2 rmind AcpiGbl_DbFilename = NULL;
484 1.1.1.2.4.2 rmind break;
485 1.1.1.2.4.2 rmind
486 1.1.1.2.4.2 rmind case 'm':
487 1.1.1.2.4.2 rmind AcpiGbl_BatchMode = 2;
488 1.1.1.2.4.2 rmind switch (AcpiGbl_Optarg[0])
489 1.1.1.2.4.2 rmind {
490 1.1.1.2.4.2 rmind case '^':
491 1.1.1.2.4.2 rmind strcpy (BatchBuffer, "MAIN");
492 1.1.1.2.4.2 rmind break;
493 1.1.1.2.4.2 rmind
494 1.1.1.2.4.2 rmind default:
495 1.1.1.2.4.2 rmind strcpy (BatchBuffer, AcpiGbl_Optarg);
496 1.1.1.2.4.2 rmind break;
497 1.1.1.2.4.2 rmind }
498 1.1.1.2.4.2 rmind break;
499 1.1.1.2.4.2 rmind
500 1.1.1.2.4.2 rmind case 'o':
501 1.1.1.2.4.2 rmind AcpiGbl_DbOpt_disasm = TRUE;
502 1.1.1.2.4.2 rmind AcpiGbl_DbOpt_stats = TRUE;
503 1.1.1.2.4.2 rmind break;
504 1.1.1.2.4.2 rmind
505 1.1.1.2.4.2 rmind case 'v':
506 1.1.1.2.4.2 rmind AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
507 1.1.1.2.4.2 rmind break;
508 1.1.1.2.4.2 rmind
509 1.1.1.2.4.2 rmind case 'x':
510 1.1.1.2.4.2 rmind AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0);
511 1.1.1.2.4.2 rmind AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
512 1.1.1.2.4.2 rmind printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
513 1.1.1.2.4.2 rmind break;
514 1.1.1.2.4.2 rmind
515 1.1.1.2.4.2 rmind case '?':
516 1.1.1.2.4.2 rmind case 'h':
517 1.1.1.2.4.2 rmind default:
518 1.1.1.2.4.2 rmind usage();
519 1.1.1.2.4.2 rmind return (-1);
520 1.1.1.2.4.2 rmind }
521 1.1.1.2.4.2 rmind
522 1.1.1.2.4.2 rmind
523 1.1.1.2.4.2 rmind InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
524 1.1.1.2.4.2 rmind if (!AcpiGbl_DbOpt_ini_methods)
525 1.1.1.2.4.2 rmind {
526 1.1.1.2.4.2 rmind InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
527 1.1.1.2.4.2 rmind }
528 1.1.1.2.4.2 rmind
529 1.1.1.2.4.2 rmind /* The remaining arguments are filenames for ACPI tables */
530 1.1.1.2.4.2 rmind
531 1.1.1.2.4.2 rmind if (argv[AcpiGbl_Optind])
532 1.1.1.2.4.2 rmind {
533 1.1.1.2.4.2 rmind AcpiGbl_DbOpt_tables = TRUE;
534 1.1.1.2.4.2 rmind TableCount = 0;
535 1.1.1.2.4.2 rmind
536 1.1.1.2.4.2 rmind /* Get each of the ACPI table files on the command line */
537 1.1.1.2.4.2 rmind
538 1.1.1.2.4.2 rmind while (argv[AcpiGbl_Optind])
539 1.1.1.2.4.2 rmind {
540 1.1.1.2.4.2 rmind /* Split incoming path into a directory/filename combo */
541 1.1.1.2.4.2 rmind
542 1.1.1.2.4.2 rmind Status = FlSplitInputPathname (argv[AcpiGbl_Optind], &Directory, &Filename);
543 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
544 1.1.1.2.4.2 rmind {
545 1.1.1.2.4.2 rmind return (Status);
546 1.1.1.2.4.2 rmind }
547 1.1.1.2.4.2 rmind
548 1.1.1.2.4.2 rmind /* Expand wildcards (Windows only) */
549 1.1.1.2.4.2 rmind
550 1.1.1.2.4.2 rmind WildcardList = AsDoWildcard (Directory, Filename);
551 1.1.1.2.4.2 rmind if (!WildcardList)
552 1.1.1.2.4.2 rmind {
553 1.1.1.2.4.2 rmind return (-1);
554 1.1.1.2.4.2 rmind }
555 1.1.1.2.4.2 rmind
556 1.1.1.2.4.2 rmind while (*WildcardList)
557 1.1.1.2.4.2 rmind {
558 1.1.1.2.4.2 rmind FullPathname = AcpiOsAllocate (
559 1.1.1.2.4.2 rmind strlen (Directory) + strlen (*WildcardList) + 1);
560 1.1.1.2.4.2 rmind
561 1.1.1.2.4.2 rmind /* Construct a full path to the file */
562 1.1.1.2.4.2 rmind
563 1.1.1.2.4.2 rmind strcpy (FullPathname, Directory);
564 1.1.1.2.4.2 rmind strcat (FullPathname, *WildcardList);
565 1.1.1.2.4.2 rmind
566 1.1.1.2.4.2 rmind /* Get one table */
567 1.1.1.2.4.2 rmind
568 1.1.1.2.4.2 rmind Status = AcpiDbReadTableFromFile (FullPathname, &Table);
569 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
570 1.1.1.2.4.2 rmind {
571 1.1.1.2.4.2 rmind printf ("**** Could not get input table %s, %s\n", FullPathname,
572 1.1.1.2.4.2 rmind AcpiFormatException (Status));
573 1.1.1.2.4.2 rmind goto enterloop;
574 1.1.1.2.4.2 rmind }
575 1.1.1.2.4.2 rmind
576 1.1.1.2.4.2 rmind AcpiOsFree (FullPathname);
577 1.1.1.2.4.2 rmind AcpiOsFree (*WildcardList);
578 1.1.1.2.4.2 rmind *WildcardList = NULL;
579 1.1.1.2.4.2 rmind WildcardList++;
580 1.1.1.2.4.2 rmind
581 1.1.1.2.4.2 rmind /*
582 1.1.1.2.4.2 rmind * Ignore an FACS or RSDT, we can't use them.
583 1.1.1.2.4.2 rmind */
584 1.1.1.2.4.2 rmind if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FACS) ||
585 1.1.1.2.4.2 rmind ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_RSDT))
586 1.1.1.2.4.2 rmind {
587 1.1.1.2.4.2 rmind AcpiOsFree (Table);
588 1.1.1.2.4.2 rmind continue;
589 1.1.1.2.4.2 rmind }
590 1.1.1.2.4.2 rmind
591 1.1.1.2.4.2 rmind /* Allocate and link a table descriptor */
592 1.1.1.2.4.2 rmind
593 1.1.1.2.4.2 rmind TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC));
594 1.1.1.2.4.2 rmind TableDesc->Table = Table;
595 1.1.1.2.4.2 rmind TableDesc->Next = AeTableListHead;
596 1.1.1.2.4.2 rmind AeTableListHead = TableDesc;
597 1.1.1.2.4.2 rmind
598 1.1.1.2.4.2 rmind TableCount++;
599 1.1.1.2.4.2 rmind }
600 1.1.1.2.4.2 rmind
601 1.1.1.2.4.2 rmind AcpiGbl_Optind++;
602 1.1.1.2.4.2 rmind }
603 1.1.1.2.4.2 rmind
604 1.1.1.2.4.2 rmind /* Build a local RSDT with all tables and let ACPICA process the RSDT */
605 1.1.1.2.4.2 rmind
606 1.1.1.2.4.2 rmind Status = AeBuildLocalTables (TableCount, AeTableListHead);
607 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
608 1.1.1.2.4.2 rmind {
609 1.1.1.2.4.2 rmind return (-1);
610 1.1.1.2.4.2 rmind }
611 1.1.1.2.4.2 rmind
612 1.1.1.2.4.2 rmind Status = AeInstallTables ();
613 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
614 1.1.1.2.4.2 rmind {
615 1.1.1.2.4.2 rmind printf ("**** Could not load ACPI tables, %s\n", AcpiFormatException (Status));
616 1.1.1.2.4.2 rmind goto enterloop;
617 1.1.1.2.4.2 rmind }
618 1.1.1.2.4.2 rmind
619 1.1.1.2.4.2 rmind /*
620 1.1.1.2.4.2 rmind * Install most of the handlers.
621 1.1.1.2.4.2 rmind * Override some default region handlers, especially SystemMemory
622 1.1.1.2.4.2 rmind */
623 1.1.1.2.4.2 rmind Status = AeInstallEarlyHandlers ();
624 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
625 1.1.1.2.4.2 rmind {
626 1.1.1.2.4.2 rmind goto enterloop;
627 1.1.1.2.4.2 rmind }
628 1.1.1.2.4.2 rmind
629 1.1.1.2.4.2 rmind /*
630 1.1.1.2.4.2 rmind * TBD: Need a way to call this after the "LOAD" command
631 1.1.1.2.4.2 rmind */
632 1.1.1.2.4.2 rmind Status = AcpiEnableSubsystem (InitFlags);
633 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
634 1.1.1.2.4.2 rmind {
635 1.1.1.2.4.2 rmind printf ("**** Could not EnableSubsystem, %s\n", AcpiFormatException (Status));
636 1.1.1.2.4.2 rmind goto enterloop;
637 1.1.1.2.4.2 rmind }
638 1.1.1.2.4.2 rmind
639 1.1.1.2.4.2 rmind Status = AcpiInitializeObjects (InitFlags);
640 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
641 1.1.1.2.4.2 rmind {
642 1.1.1.2.4.2 rmind printf ("**** Could not InitializeObjects, %s\n", AcpiFormatException (Status));
643 1.1.1.2.4.2 rmind goto enterloop;
644 1.1.1.2.4.2 rmind }
645 1.1.1.2.4.2 rmind
646 1.1.1.2.4.2 rmind /*
647 1.1.1.2.4.2 rmind * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
648 1.1.1.2.4.2 rmind * and fixed event handlers
649 1.1.1.2.4.2 rmind */
650 1.1.1.2.4.2 rmind AeInstallLateHandlers ();
651 1.1.1.2.4.2 rmind AeMiscellaneousTests ();
652 1.1.1.2.4.2 rmind }
653 1.1.1.2.4.2 rmind
654 1.1.1.2.4.2 rmind enterloop:
655 1.1.1.2.4.2 rmind
656 1.1.1.2.4.2 rmind if (AcpiGbl_BatchMode == 1)
657 1.1.1.2.4.2 rmind {
658 1.1.1.2.4.2 rmind AcpiDbRunBatchMode ();
659 1.1.1.2.4.2 rmind }
660 1.1.1.2.4.2 rmind else if (AcpiGbl_BatchMode == 2)
661 1.1.1.2.4.2 rmind {
662 1.1.1.2.4.2 rmind AcpiDbExecute (BatchBuffer, NULL, EX_NO_SINGLE_STEP);
663 1.1.1.2.4.2 rmind }
664 1.1.1.2.4.2 rmind else
665 1.1.1.2.4.2 rmind {
666 1.1.1.2.4.2 rmind /* Enter the debugger command loop */
667 1.1.1.2.4.2 rmind
668 1.1.1.2.4.2 rmind AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL);
669 1.1.1.2.4.2 rmind }
670 1.1.1.2.4.2 rmind
671 1.1.1.2.4.2 rmind return (0);
672 1.1.1.2.4.2 rmind }
673 1.1.1.2.4.2 rmind
674