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