aemain.c revision 1.1.1.16 1 /******************************************************************************
2 *
3 * Module Name: aemain - Main routine for the AcpiExec utility
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2018, Intel Corp.
9 * All rights reserved.
10 *
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.
25 *
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.
29 *
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.
42 */
43
44 #include "aecommon.h"
45
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("aemain")
48
49
50 /*
51 * Main routine for the ACPI user-space execution utility.
52 *
53 * Portability note: The utility depends upon the host for command-line
54 * wildcard support - it is not implemented locally. For example:
55 *
56 * Linux/Unix systems: Shell expands wildcards automatically.
57 *
58 * Windows: The setargv.obj module must be linked in to automatically
59 * expand wildcards.
60 */
61
62 /* Local prototypes */
63
64 static int
65 AeDoOptions (
66 int argc,
67 char **argv);
68
69
70 #define AE_BUFFER_SIZE 1024
71 #define ASL_MAX_FILES 256
72
73 /* Execution modes */
74
75 #define AE_MODE_COMMAND_LOOP 0 /* Normal command execution loop */
76 #define AE_MODE_BATCH_MULTIPLE 1 /* -b option to execute a command line */
77 #define AE_MODE_BATCH_SINGLE 2 /* -m option to execute a single control method */
78
79
80 /* Globals */
81
82 BOOLEAN AcpiGbl_UseLocalFaultHandler = TRUE;
83 BOOLEAN AcpiGbl_VerboseHandlers = FALSE;
84 UINT8 AcpiGbl_RegionFillValue = 0;
85 BOOLEAN AcpiGbl_IgnoreErrors = FALSE;
86 BOOLEAN AcpiGbl_AbortLoopOnTimeout = FALSE;
87 BOOLEAN AcpiGbl_DbOpt_NoRegionSupport = FALSE;
88 UINT8 AcpiGbl_UseHwReducedFadt = FALSE;
89 BOOLEAN AcpiGbl_DoInterfaceTests = FALSE;
90 BOOLEAN AcpiGbl_LoadTestTables = FALSE;
91 BOOLEAN AcpiGbl_AeLoadOnly = FALSE;
92 static UINT8 AcpiGbl_ExecutionMode = AE_MODE_COMMAND_LOOP;
93 static char BatchBuffer[AE_BUFFER_SIZE]; /* Batch command buffer */
94 INIT_FILE_ENTRY *AcpiGbl_InitEntries = NULL;
95 UINT32 AcpiGbl_InitFileLineCount = 0;
96
97 #define ACPIEXEC_NAME "AML Execution/Debug Utility"
98 #define AE_SUPPORTED_OPTIONS "?b:d:e:f^ghlm^rt^v^:x:"
99
100
101 /* Stubs for the disassembler */
102
103 void
104 MpSaveGpioInfo (
105 ACPI_PARSE_OBJECT *Op,
106 AML_RESOURCE *Resource,
107 UINT32 PinCount,
108 UINT16 *PinList,
109 char *DeviceName)
110 {
111 }
112
113 void
114 MpSaveSerialInfo (
115 ACPI_PARSE_OBJECT *Op,
116 AML_RESOURCE *Resource,
117 char *DeviceName)
118 {
119 }
120
121
122 /******************************************************************************
123 *
124 * FUNCTION: usage
125 *
126 * PARAMETERS: None
127 *
128 * RETURN: None
129 *
130 * DESCRIPTION: Print a usage message
131 *
132 *****************************************************************************/
133
134 static void
135 usage (
136 void)
137 {
138
139 ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ...");
140
141 ACPI_OPTION ("-b \"CommandLine\"", "Batch mode command line execution (cmd1;cmd2;...)");
142 ACPI_OPTION ("-h -?", "Display this help message");
143 ACPI_OPTION ("-m [Method]", "Batch mode method execution. Default=MAIN");
144 printf ("\n");
145
146 ACPI_OPTION ("-da", "Disable method abort on error");
147 ACPI_OPTION ("-df", "Disable Local fault handler");
148 ACPI_OPTION ("-di", "Disable execution of STA/INI methods during init");
149 ACPI_OPTION ("-do", "Disable Operation Region address simulation");
150 ACPI_OPTION ("-dp", "Disable loading DSDT/SSDT as a control method\n"
151 " (enable legacy grouping of module-level code)");
152 ACPI_OPTION ("-dr", "Disable repair of method return values");
153 ACPI_OPTION ("-ds", "Disable method auto-serialization");
154 ACPI_OPTION ("-dt", "Disable allocation tracking (performance)");
155 printf ("\n");
156
157 ACPI_OPTION ("-ed", "Enable timer output for Debug Object");
158 ACPI_OPTION ("-ef", "Enable display of final memory statistics");
159 ACPI_OPTION ("-ei", "Enable additional tests for ACPICA interfaces");
160 ACPI_OPTION ("-el", "Enable loading of additional test tables");
161 ACPI_OPTION ("-eo", "Enable object evaluation log");
162 ACPI_OPTION ("-es", "Enable Interpreter Slack Mode");
163 ACPI_OPTION ("-et", "Enable debug semaphore timeout");
164 printf ("\n");
165
166 ACPI_OPTION ("-fi <File>", "Specify namespace initialization file");
167 ACPI_OPTION ("-fv <Value>", "Operation Region initialization fill value");
168 printf ("\n");
169
170 ACPI_OPTION ("-l", "Load tables and namespace only");
171 ACPI_OPTION ("-r", "Use hardware-reduced FADT V5");
172 ACPI_OPTION ("-te", "Exit loop on timeout instead of aborting method");
173 ACPI_OPTION ("-to <Seconds>", "Set timeout period for AML while loops");
174 printf ("\n");
175
176 ACPI_OPTION ("-v", "Display version information");
177 ACPI_OPTION ("-vd", "Display build date and time");
178 ACPI_OPTION ("-vh", "Verbose exception handler output");
179 ACPI_OPTION ("-vi", "Verbose initialization output");
180 ACPI_OPTION ("-vr", "Verbose region handler output");
181 ACPI_OPTION ("-x <DebugLevel>", "Debug output level");
182
183 printf ("\n From within the interactive mode, use '?' or \"help\" to see\n"
184 " a list of available AML Debugger commands\n");
185 }
186
187
188 /******************************************************************************
189 *
190 * FUNCTION: AeDoOptions
191 *
192 * PARAMETERS: argc/argv - Standard argc/argv
193 *
194 * RETURN: Status
195 *
196 * DESCRIPTION: Command line option processing
197 *
198 *****************************************************************************/
199
200 static int
201 AeDoOptions (
202 int argc,
203 char **argv)
204 {
205 int j;
206 UINT32 Temp;
207
208
209 while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j)
210 {
211 case 'b':
212
213 if (strlen (AcpiGbl_Optarg) > (AE_BUFFER_SIZE -1))
214 {
215 printf ("**** The length of command line (%u) exceeded maximum (%d)\n",
216 (UINT32) strlen (AcpiGbl_Optarg), (AE_BUFFER_SIZE -1));
217 return (-1);
218 }
219 AcpiGbl_ExecutionMode = AE_MODE_BATCH_MULTIPLE;
220 strcpy (BatchBuffer, AcpiGbl_Optarg);
221 break;
222
223 case 'd':
224
225 switch (AcpiGbl_Optarg[0])
226 {
227 case 'a':
228
229 AcpiGbl_IgnoreErrors = TRUE;
230 break;
231
232 case 'f':
233
234 AcpiGbl_UseLocalFaultHandler = FALSE;
235 break;
236
237 case 'i':
238
239 AcpiGbl_DbOpt_NoIniMethods = TRUE;
240 break;
241
242 case 'o':
243
244 AcpiGbl_DbOpt_NoRegionSupport = TRUE;
245 break;
246
247 case 'p':
248
249 AcpiGbl_ExecuteTablesAsMethods = FALSE;
250 break;
251
252 case 'r':
253
254 AcpiGbl_DisableAutoRepair = TRUE;
255 break;
256
257 case 's':
258
259 AcpiGbl_AutoSerializeMethods = FALSE;
260 break;
261
262 case 't':
263
264 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
265 AcpiGbl_DisableMemTracking = TRUE;
266 #endif
267 break;
268
269 default:
270
271 printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
272 return (-1);
273 }
274 break;
275
276 case 'e':
277
278 switch (AcpiGbl_Optarg[0])
279 {
280 case 'd':
281
282 AcpiGbl_DisplayDebugTimer = TRUE;
283 break;
284
285 case 'f':
286
287 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
288 AcpiGbl_DisplayFinalMemStats = TRUE;
289 #endif
290 break;
291
292 case 'i':
293
294 AcpiGbl_DoInterfaceTests = TRUE;
295 break;
296
297 case 'l':
298
299 AcpiGbl_LoadTestTables = TRUE;
300 break;
301
302 case 'o':
303
304 AcpiDbgLevel |= ACPI_LV_EVALUATION;
305 AcpiGbl_DbConsoleDebugLevel |= ACPI_LV_EVALUATION;
306 break;
307
308 case 's':
309
310 AcpiGbl_EnableInterpreterSlack = TRUE;
311 printf ("Enabling AML Interpreter slack mode\n");
312 break;
313
314 case 't':
315
316 AcpiGbl_DebugTimeout = TRUE;
317 break;
318
319 default:
320
321 printf ("Unknown option: -e%s\n", AcpiGbl_Optarg);
322 return (-1);
323 }
324 break;
325
326 case 'f':
327
328 switch (AcpiGbl_Optarg[0])
329 {
330 case 'v': /* -fv: region fill value */
331
332 if (AcpiGetoptArgument (argc, argv))
333 {
334 return (-1);
335 }
336
337 AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0);
338 break;
339
340 case 'i': /* -fi: specify initialization file */
341
342 if (AcpiGetoptArgument (argc, argv))
343 {
344 return (-1);
345 }
346
347 if (AeOpenInitializationFile (AcpiGbl_Optarg))
348 {
349 return (-1);
350 }
351 break;
352
353 default:
354
355 printf ("Unknown option: -f%s\n", AcpiGbl_Optarg);
356 return (-1);
357 }
358 break;
359
360 case 'g':
361
362 AcpiGbl_DbFilename = NULL;
363 break;
364
365 case 'h':
366 case '?':
367
368 usage();
369 return (1);
370
371 case 'l':
372
373 AcpiGbl_AeLoadOnly = TRUE;
374 break;
375
376 case 'm':
377
378 AcpiGbl_ExecutionMode = AE_MODE_BATCH_SINGLE;
379 switch (AcpiGbl_Optarg[0])
380 {
381 case '^':
382
383 strcpy (BatchBuffer, "MAIN");
384 break;
385
386 default:
387
388 strcpy (BatchBuffer, AcpiGbl_Optarg);
389 break;
390 }
391 break;
392
393 case 'r':
394
395 AcpiGbl_UseHwReducedFadt = TRUE;
396 printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n");
397 break;
398
399 case 't':
400
401 switch (AcpiGbl_Optarg[0])
402 {
403 case 'o': /* -to: Set loop timeout in seconds */
404
405 if (AcpiGetoptArgument (argc, argv))
406 {
407 return (-1);
408 }
409
410 Temp = strtoul (AcpiGbl_Optarg, NULL, 0);
411 if (!Temp || (Temp > ACPI_UINT16_MAX))
412 {
413 printf ("%s: Invalid loop timeout value\n",
414 AcpiGbl_Optarg);
415 return (-1);
416 }
417
418 AcpiGbl_MaxLoopIterations = (UINT16) Temp;
419 printf ("Automatic loop timeout after %u seconds\n",
420 AcpiGbl_MaxLoopIterations);
421 break;
422
423 case 'e':
424
425 AcpiGbl_AbortLoopOnTimeout = TRUE;
426 break;
427
428 default:
429
430 printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
431 return (-1);
432 }
433 break;
434
435 case 'v':
436
437 switch (AcpiGbl_Optarg[0])
438 {
439 case '^': /* -v: (Version): signon already emitted, just exit */
440
441 return (1);
442
443 case 'd':
444
445 printf (ACPI_COMMON_BUILD_TIME);
446 return (1);
447
448 case 'h':
449
450 AcpiGbl_VerboseHandlers = TRUE;
451 break;
452
453 case 'i':
454
455 AcpiDbgLevel |= ACPI_LV_INIT_NAMES;
456 break;
457
458 case 'r':
459
460 AcpiGbl_DisplayRegionAccess = TRUE;
461 break;
462
463 default:
464
465 printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
466 return (-1);
467 }
468 break;
469
470 case 'x':
471
472 AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16);
473 AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel;
474 printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel);
475 break;
476
477 default:
478
479 usage();
480 return (-1);
481 }
482
483 return (0);
484 }
485
486
487 /******************************************************************************
488 *
489 * FUNCTION: main
490 *
491 * PARAMETERS: argc, argv
492 *
493 * RETURN: Status
494 *
495 * DESCRIPTION: Main routine for AcpiExec utility
496 *
497 *****************************************************************************/
498
499 int ACPI_SYSTEM_XFACE
500 main (
501 int argc,
502 char **argv)
503 {
504 ACPI_NEW_TABLE_DESC *ListHead = NULL;
505 ACPI_STATUS Status;
506 UINT32 InitFlags;
507 int ExitCode = 0;
508
509
510 ACPI_DEBUG_INITIALIZE (); /* For debug version only */
511
512 signal (SIGINT, AeSignalHandler);
513
514 /* Init debug globals */
515
516 AcpiDbgLevel = ACPI_NORMAL_DEFAULT;
517 AcpiDbgLayer = 0xFFFFFFFF;
518
519 /* Module-level code. Use new architecture */
520
521 AcpiGbl_ExecuteTablesAsMethods = TRUE;
522
523 /*
524 * Initialize ACPICA and start debugger thread.
525 *
526 * NOTE: After ACPICA initialization, AcpiTerminate MUST be called
527 * before this procedure exits -- otherwise, the console may be
528 * left in an incorrect state.
529 */
530 Status = AcpiInitializeSubsystem ();
531 ACPI_CHECK_OK (AcpiInitializeSubsystem, Status);
532 if (ACPI_FAILURE (Status))
533 {
534 goto ErrorExit;
535 }
536
537 /* Use a shorter timeout value for acpiexec */
538
539 AcpiGbl_MaxLoopIterations = 1;
540
541 /* Initialize the AML debugger */
542
543 Status = AcpiInitializeDebugger ();
544 ACPI_CHECK_OK (AcpiInitializeDebugger, Status);
545 if (ACPI_FAILURE (Status))
546 {
547 goto ErrorExit;
548 }
549
550 printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME));
551 if (argc < 2)
552 {
553 usage ();
554 goto NormalExit;
555 }
556
557 /* Get the command line options */
558
559 ExitCode = AeDoOptions (argc, argv);
560 if (ExitCode)
561 {
562 if (ExitCode > 0)
563 {
564 ExitCode = 0;
565 }
566
567 goto ErrorExit;
568 }
569
570 if (AcpiGbl_UseLocalFaultHandler)
571 {
572 signal (SIGSEGV, AeSignalHandler);
573 }
574
575 AeProcessInitFile();
576
577 /* The remaining arguments are filenames for ACPI tables */
578
579 if (!argv[AcpiGbl_Optind])
580 {
581 goto EnterDebugger;
582 }
583
584 AcpiGbl_CstyleDisassembly = FALSE; /* Not supported for AcpiExec */
585
586 /* Get each of the ACPI table files on the command line */
587
588 while (argv[AcpiGbl_Optind])
589 {
590 /* Get all ACPI AML tables in this file */
591
592 Status = AcGetAllTablesFromFile (argv[AcpiGbl_Optind],
593 ACPI_GET_ALL_TABLES, &ListHead);
594 if (ACPI_FAILURE (Status))
595 {
596 ExitCode = -1;
597 goto ErrorExit;
598 }
599
600 AcpiGbl_Optind++;
601 }
602
603 printf ("\n");
604
605 /* Build a local RSDT with all tables and let ACPICA process the RSDT */
606
607 Status = AeBuildLocalTables (ListHead);
608 if (ACPI_FAILURE (Status))
609 {
610 goto ErrorExit;
611 }
612
613 /* Install all of the ACPI tables */
614
615 Status = AeInstallTables ();
616 if (ACPI_FAILURE (Status))
617 {
618 printf ("**** Could not install ACPI tables, %s\n",
619 AcpiFormatException (Status));
620 goto EnterDebugger;
621 }
622
623 /*
624 * Install most of the handlers (Regions, Notify, Table, etc.)
625 * Override the default region handlers, especially SystemMemory,
626 * which is simulated in this utility.
627 */
628 Status = AeInstallEarlyHandlers ();
629 if (ACPI_FAILURE (Status))
630 {
631 goto EnterDebugger;
632 }
633
634 Status = AeLoadTables ();
635
636 /*
637 * Exit namespace initialization for the "load namespace only" option.
638 * No control methods will be executed. However, still enter the
639 * the debugger.
640 */
641 if (AcpiGbl_AeLoadOnly)
642 {
643 goto EnterDebugger;
644 }
645
646 if (ACPI_FAILURE (Status))
647 {
648 printf ("**** Could not load ACPI tables, %s\n",
649 AcpiFormatException (Status));
650 goto EnterDebugger;
651 }
652
653 /* Setup initialization flags for ACPICA */
654
655 InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE);
656 if (AcpiGbl_DbOpt_NoIniMethods)
657 {
658 InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
659 }
660
661 /*
662 * Main initialization for ACPICA subsystem
663 * TBD: Need a way to call this after the ACPI table "LOAD" command?
664 *
665 * NOTE: This initialization does not match the _Lxx and _Exx methods
666 * to individual GPEs, as there are no real GPEs when the hardware
667 * is simulated - because there is no namespace until AeLoadTables is
668 * executed. This may have to change if AcpiExec is ever run natively
669 * on actual hardware (such as under UEFI).
670 */
671 Status = AcpiEnableSubsystem (InitFlags);
672 if (ACPI_FAILURE (Status))
673 {
674 printf ("**** Could not EnableSubsystem, %s\n",
675 AcpiFormatException (Status));
676 goto EnterDebugger;
677 }
678
679 /*
680 * Install handlers for "device driver" space IDs (EC,SMBus, etc.)
681 * and fixed event handlers
682 */
683 AeInstallLateHandlers ();
684
685 /* Finish the ACPICA initialization */
686
687 Status = AcpiInitializeObjects (InitFlags);
688 if (ACPI_FAILURE (Status))
689 {
690 printf ("**** Could not InitializeObjects, %s\n",
691 AcpiFormatException (Status));
692 goto EnterDebugger;
693 }
694
695 AeMiscellaneousTests ();
696
697
698 EnterDebugger:
699
700 /* Exit if error above and we are in one of the batch modes */
701
702 if (ACPI_FAILURE (Status) && (AcpiGbl_ExecutionMode > 0))
703 {
704 goto ErrorExit;
705 }
706
707 /* Run a batch command or enter the command loop */
708
709 switch (AcpiGbl_ExecutionMode)
710 {
711 default:
712 case AE_MODE_COMMAND_LOOP:
713
714 AcpiRunDebugger (NULL);
715 break;
716
717 case AE_MODE_BATCH_MULTIPLE:
718
719 AcpiRunDebugger (BatchBuffer);
720 break;
721
722 case AE_MODE_BATCH_SINGLE:
723
724 AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP);
725 break;
726 }
727
728 /* Shut down the debugger and ACPICA */
729
730 AcpiTerminateDebugger ();
731
732 /* re-enable debug output for AcpiTerminate output */
733
734 AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT;
735
736 NormalExit:
737 ExitCode = 0;
738
739 ErrorExit:
740 (void) AcpiTerminate ();
741 AcDeleteTableList (ListHead);
742 AcpiOsFree (AcpiGbl_InitEntries);
743 return (ExitCode);
744 }
745