1 /******************************************************************************
2  *
3  * Module Name: ahdecode - Miscellaneous decoding for acpihelp utility
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #define ACPI_CREATE_PREDEFINED_TABLE
153 #define ACPI_CREATE_RESOURCE_TABLE
154 
155 #include "acpihelp.h"
156 #include "acpredef.h"
157 
158 BOOLEAN                  AslGbl_VerboseErrors = TRUE;
159 
160 /* Local prototypes */
161 
162 static BOOLEAN
163 AhDisplayPredefinedName (
164     char                    *Name,
165     UINT32                  Length);
166 
167 static void
168 AhDisplayPredefinedInfo (
169     char                    *Name);
170 
171 static void
172 AhDoSpecialNames (
173     char                    *Name);
174 
175 static void
176 AhDisplayResourceName (
177     const ACPI_PREDEFINED_INFO  *ThisName);
178 
179 
180 /*******************************************************************************
181  *
182  * FUNCTION:    AhPrintOneField
183  *
184  * PARAMETERS:  Indent              - Indent length for new line(s)
185  *              CurrentPosition     - Position on current line
186  *              MaxPosition         - Max allowed line length
187  *              Field               - Data to output
188  *
189  * RETURN:      Line position after field is written
190  *
191  * DESCRIPTION: Split long lines appropriately for ease of reading.
192  *
193  ******************************************************************************/
194 
195 void
AhPrintOneField(UINT32 Indent,UINT32 CurrentPosition,UINT32 MaxPosition,const char * Field)196 AhPrintOneField (
197     UINT32                  Indent,
198     UINT32                  CurrentPosition,
199     UINT32                  MaxPosition,
200     const char              *Field)
201 {
202     UINT32                  Position;
203     UINT32                  TokenLength;
204     const char              *This;
205     const char              *Next;
206     const char              *Last;
207 
208 
209     This = Field;
210     Position = CurrentPosition;
211 
212     if (Position == 0)
213     {
214         printf ("%*s", (int) Indent, " ");
215         Position = Indent;
216     }
217 
218     Last = This + strlen (This);
219     while ((Next = strpbrk (This, " ")))
220     {
221         TokenLength = Next - This;
222         Position += TokenLength;
223 
224         /* Split long lines */
225 
226         if (Position > MaxPosition)
227         {
228             printf ("\n%*s", (int) Indent, " ");
229             Position = TokenLength;
230         }
231 
232         printf ("%.*s ", (int) TokenLength, This);
233         This = Next + 1;
234     }
235 
236     /* Handle last token on the input line */
237 
238     TokenLength = Last - This;
239     if (TokenLength > 0)
240     {
241         Position += TokenLength;
242         if (Position > MaxPosition)
243         {
244             printf ("\n%*s", (int) Indent, " ");
245         }
246 
247         printf ("%s", This);
248     }
249 }
250 
251 
252 /*******************************************************************************
253  *
254  * FUNCTION:    AhDisplayDirectives
255  *
256  * PARAMETERS:  None
257  *
258  * RETURN:      None
259  *
260  * DESCRIPTION: Display all iASL preprocessor directives.
261  *
262  ******************************************************************************/
263 
264 void
AhDisplayDirectives(void)265 AhDisplayDirectives (
266     void)
267 {
268     const AH_DIRECTIVE_INFO *Info;
269 
270 
271     printf ("iASL Preprocessor Directives\n\n");
272 
273     for (Info = Gbl_PreprocessorDirectives; Info->Name; Info++)
274     {
275         printf ("  %-36s : %s\n", Info->Name, Info->Description);
276     }
277 }
278 
279 
280 /*******************************************************************************
281  *
282  * FUNCTION:    AhFindPredefinedNames (entry point for predefined name search)
283  *
284  * PARAMETERS:  NamePrefix          - Name or prefix to find. Must start with
285  *                                    an underscore. NULL means "find all"
286  *
287  * RETURN:      None
288  *
289  * DESCRIPTION: Find and display all ACPI predefined names that match the
290  *              input name or prefix. Includes the required number of arguments
291  *              and the expected return type, if any.
292  *
293  ******************************************************************************/
294 
295 void
AhFindPredefinedNames(char * NamePrefix)296 AhFindPredefinedNames (
297     char                    *NamePrefix)
298 {
299     UINT32                  Length;
300     BOOLEAN                 Found;
301     char                    Name[ACPI_NAMESEG_SIZE + 1];
302 
303 
304     if (!NamePrefix || (*NamePrefix == '*'))
305     {
306         (void) AhDisplayPredefinedName (NULL, 0);
307         return;
308     }
309 
310     Length = strlen (NamePrefix);
311     if (Length > ACPI_NAMESEG_SIZE)
312     {
313         printf ("%.8s: Predefined name must be 4 characters maximum\n",
314             NamePrefix);
315         return;
316     }
317 
318     /* Construct a local name or name prefix */
319 
320     AcpiUtStrupr (NamePrefix);
321     if (*NamePrefix == '_')
322     {
323         NamePrefix++;
324     }
325 
326     Name[0] = '_';
327     AcpiUtSafeStrncpy (&Name[1], NamePrefix, 4);
328 
329     /* Check for special names such as _Exx, _ACx, etc. */
330 
331     AhDoSpecialNames (Name);
332 
333     /* Lookup and display the name(s) */
334 
335     Found = AhDisplayPredefinedName (Name, Length);
336     if (!Found)
337     {
338         printf ("%s, no matching predefined names\n", Name);
339     }
340 }
341 
342 
343 /*******************************************************************************
344  *
345  * FUNCTION:    AhDoSpecialNames
346  *
347  * PARAMETERS:  Name          - Name or prefix to find
348  *
349  * RETURN:      None
350  *
351  * DESCRIPTION: Detect and handle the "special" names such as _Exx, _ACx, etc.
352  *
353  * Current support:
354  *  _EJx
355  *  _Exx
356  *  _Lxx
357  *  _Qxx
358  *  _Wxx
359  *  _ACx
360  *  _ALx
361  *  _T_x
362  *
363  ******************************************************************************/
364 
365 static void
AhDoSpecialNames(char * Name)366 AhDoSpecialNames (
367     char                    *Name)
368 {
369 
370     /*
371      * Check for the special names that have one or more numeric
372      * suffixes. For example, _Lxx can have 256 different flavors,
373      * from _L00 to _LFF.
374      */
375     switch (Name[1])
376     {
377     case 'E':
378         if (Name[2] == 'J')
379         {
380             if (isdigit ((int) Name[3]) || (Name[3] == 'X'))
381             {
382                 /* _EJx */
383 
384                 Name[3] = 'x';
385                 break;
386             }
387         }
388 
389         ACPI_FALLTHROUGH;
390 
391     case 'L':
392     case 'Q':
393     case 'W':
394         if ((isxdigit ((int) Name[2]) && isxdigit ((int) Name[3]))
395                 ||
396             ((Name[2] == 'X') && (Name[3] == 'X')))
397         {
398             /* _Exx, _Lxx, _Qxx, or _Wxx */
399 
400             Name[2] = 'x';
401             Name[3] = 'x';
402         }
403         break;
404 
405     case 'A':
406         if ((Name[2] == 'C') || (Name[2] == 'L'))
407         {
408             if (isdigit ((int) Name[3]) || (Name[3] == 'X'))
409             {
410                 /* _ACx or _ALx */
411 
412                 Name[3] = 'x';
413             }
414         }
415         break;
416 
417     case 'T':
418         if (Name[2] == '_')
419         {
420             /* _T_x (Reserved for iASL compiler */
421 
422             Name[3] = 'x';
423         }
424         break;
425 
426     default:
427         break;
428     }
429 }
430 
431 
432 /*******************************************************************************
433  *
434  * FUNCTION:    AhDisplayPredefinedName
435  *
436  * PARAMETERS:  Name                - Name or name prefix
437  *
438  * RETURN:      TRUE if any names matched, FALSE otherwise
439  *
440  * DESCRIPTION: Display information about ACPI predefined names that match
441  *              the input name or name prefix.
442  *
443  ******************************************************************************/
444 
445 static BOOLEAN
AhDisplayPredefinedName(char * Name,UINT32 Length)446 AhDisplayPredefinedName (
447     char                    *Name,
448     UINT32                  Length)
449 {
450     const AH_PREDEFINED_NAME    *Info;
451     BOOLEAN                     Found = FALSE;
452     BOOLEAN                     Matched;
453     UINT32                      i = 0;
454 
455 
456     /* Find/display all names that match the input name prefix */
457 
458     for (Info = AslPredefinedInfo; Info->Name; Info++)
459     {
460         if (!Name)
461         {
462             Found = TRUE;
463             printf ("%s: <%s>\n", Info->Name, Info->Description);
464             printf ("%*s%s\n", 6, " ", Info->Action);
465 
466             AhDisplayPredefinedInfo (Info->Name);
467             i++;
468             continue;
469         }
470 
471         Matched = TRUE;
472         for (i = 0; i < Length; i++)
473         {
474             if (Info->Name[i] != Name[i])
475             {
476                 Matched = FALSE;
477                 break;
478             }
479         }
480 
481         if (Matched)
482         {
483             Found = TRUE;
484             printf ("%s: <%s>\n", Info->Name, Info->Description);
485             printf ("%*s%s\n", 6, " ", Info->Action);
486 
487             AhDisplayPredefinedInfo (Info->Name);
488         }
489     }
490 
491     if (!Name)
492     {
493         printf ("\nFound %d Predefined ACPI Names\n", i);
494     }
495     return (Found);
496 }
497 
498 
499 /*******************************************************************************
500  *
501  * FUNCTION:    AhDisplayPredefinedInfo
502  *
503  * PARAMETERS:  Name                - Exact 4-character ACPI name.
504  *
505  * RETURN:      None
506  *
507  * DESCRIPTION: Find the name in the main ACPICA predefined info table and
508  *              display the # of arguments and the return value type.
509  *
510  *              Note: Resource Descriptor field names do not appear in this
511  *              table -- thus, nothing will be displayed for them.
512  *
513  ******************************************************************************/
514 
515 static void
AhDisplayPredefinedInfo(char * Name)516 AhDisplayPredefinedInfo (
517     char                        *Name)
518 {
519     const ACPI_PREDEFINED_INFO  *ThisName;
520 
521 
522     /* NOTE: we check both tables always because there are some dupes */
523 
524     /* Check against the predefined methods first */
525 
526     ThisName = AcpiUtMatchPredefinedMethod (Name);
527     if (ThisName)
528     {
529         AcpiUtDisplayPredefinedMethod (Gbl_Buffer, ThisName, TRUE);
530     }
531 
532     /* Check against the predefined resource descriptor names */
533 
534     ThisName = AcpiUtMatchResourceName (Name);
535     if (ThisName)
536     {
537         AhDisplayResourceName (ThisName);
538     }
539 }
540 
541 
542 /*******************************************************************************
543  *
544  * FUNCTION:    AhDisplayResourceName
545  *
546  * PARAMETERS:  ThisName            - Entry in the predefined method/name table
547  *
548  * RETURN:      None
549  *
550  * DESCRIPTION: Display information about a resource descriptor name.
551  *
552  ******************************************************************************/
553 
554 static void
AhDisplayResourceName(const ACPI_PREDEFINED_INFO * ThisName)555 AhDisplayResourceName (
556     const ACPI_PREDEFINED_INFO  *ThisName)
557 {
558     UINT32                      NumTypes;
559 
560 
561     NumTypes = AcpiUtGetResourceBitWidth (Gbl_Buffer,
562         ThisName->Info.ArgumentList);
563 
564     printf ("      %4.4s resource descriptor field is %s bits wide%s\n",
565         ThisName->Info.Name,
566         Gbl_Buffer,
567         (NumTypes > 1) ? " (depending on descriptor type)" : "");
568 }
569 
570 
571 /*******************************************************************************
572  *
573  * FUNCTION:    AhDisplayDeviceIds
574  *
575  * PARAMETERS:  Name                - Device Hardware ID string.
576  *                                    NULL means "find all"
577  *
578  * RETURN:      None
579  *
580  * DESCRIPTION: Display PNP* and ACPI* device IDs.
581  *
582  ******************************************************************************/
583 
584 void
AhDisplayDeviceIds(char * Name)585 AhDisplayDeviceIds (
586     char                    *Name)
587 {
588     const AH_DEVICE_ID      *Info;
589     UINT32                  Length;
590     BOOLEAN                 Matched;
591     UINT32                  i;
592     BOOLEAN                 Found = FALSE;
593 
594 
595     /* Null input name indicates "display all" */
596 
597     if (!Name || (Name[0] == '*'))
598     {
599         printf ("ACPI and PNP Device/Hardware IDs:\n\n");
600         for (Info = AslDeviceIds; Info->Name; Info++)
601         {
602             printf ("%8s   %s\n", Info->Name, Info->Description);
603         }
604 
605         return;
606     }
607 
608     Length = strlen (Name);
609     if (Length > 8)
610     {
611         printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
612         return;
613     }
614 
615     /* Find/display all names that match the input name prefix */
616 
617     AcpiUtStrupr (Name);
618     for (Info = AslDeviceIds; Info->Name; Info++)
619     {
620         Matched = TRUE;
621         for (i = 0; i < Length; i++)
622         {
623             if (Info->Name[i] != Name[i])
624             {
625                 Matched = FALSE;
626                 break;
627             }
628         }
629 
630         if (Matched)
631         {
632             Found = TRUE;
633             printf ("%8s   %s\n", Info->Name, Info->Description);
634         }
635     }
636 
637     if (!Found)
638     {
639         printf ("%s, Hardware ID not found\n", Name);
640     }
641 }
642 
643 
644 /*******************************************************************************
645  *
646  * FUNCTION:    AhDisplayUuids
647  *
648  * PARAMETERS:  None
649  *
650  * RETURN:      None
651  *
652  * DESCRIPTION: Display all known UUIDs.
653  *
654  ******************************************************************************/
655 
656 void
AhDisplayUuids(void)657 AhDisplayUuids (
658     void)
659 {
660     const AH_UUID           *Info;
661 
662 
663     printf ("ACPI-related UUIDs/GUIDs:\n");
664 
665     /* Display entire table of known ACPI-related UUIDs/GUIDs */
666 
667     for (Info = Gbl_AcpiUuids; Info->Description; Info++)
668     {
669         if (!Info->String) /* Null UUID string means group description */
670         {
671             printf ("\n%36s\n", Info->Description);
672         }
673         else
674         {
675             printf ("%32s : %s\n", Info->Description, Info->String);
676         }
677     }
678 
679     /* Help info on how UUIDs/GUIDs strings are encoded */
680 
681     printf ("\n\nByte encoding of UUID/GUID strings"
682         " into ACPI Buffer objects (use ToUUID from ASL):\n\n");
683 
684     printf ("%32s : %s\n", "Input UUID/GUID String format",
685         "aabbccdd-eeff-gghh-iijj-kkllmmnnoopp");
686 
687     printf ("%32s : %s\n", "Expected output ACPI buffer",
688         "dd,cc,bb,aa, ff,ee, hh,gg, ii,jj, kk,ll,mm,nn,oo,pp");
689 }
690 
691 
692 /*******************************************************************************
693  *
694  * FUNCTION:    AhDisplayTables
695  *
696  * PARAMETERS:  None
697  *
698  * RETURN:      None
699  *
700  * DESCRIPTION: Display all known ACPI tables
701  *
702  ******************************************************************************/
703 
704 void
AhDisplayTables(void)705 AhDisplayTables (
706     void)
707 {
708     const AH_TABLE          *Info;
709     UINT32                  i = 0;
710 
711 
712     printf ("Known/Supported ACPI tables:\n");
713 
714     for (Info = AcpiGbl_SupportedTables; Info->Signature; Info++)
715     {
716         printf ("%8u) %s : %s\n", i + 1, Info->Signature, Info->Description);
717         i++;
718     }
719 
720     printf ("\nTotal %u ACPI tables\n\n", i);
721 }
722 
723 
724 /*******************************************************************************
725  *
726  * FUNCTION:    AhDecodeException
727  *
728  * PARAMETERS:  HexString           - ACPI status string from command line, in
729  *                                    hex. If null, display all exceptions.
730  *
731  * RETURN:      None
732  *
733  * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
734  *
735  ******************************************************************************/
736 
737 void
AhDecodeException(char * HexString)738 AhDecodeException (
739     char                    *HexString)
740 {
741     const ACPI_EXCEPTION_INFO   *ExceptionInfo;
742     UINT32                      Status;
743     UINT32                      i;
744 
745 
746     /*
747      * A null input string means to decode and display all known
748      * exception codes.
749      */
750     if (!HexString)
751     {
752         printf ("All defined ACPICA exception codes:\n\n");
753         AH_DISPLAY_EXCEPTION (0,
754             "AE_OK                        (No error occurred)");
755 
756         /* Display codes in each block of exception types */
757 
758         for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
759         {
760             Status = i;
761             do
762             {
763                 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
764                 if (ExceptionInfo)
765                 {
766                     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
767                 }
768 
769                 Status++;
770 
771             } while (ExceptionInfo);
772         }
773         return;
774     }
775 
776     /* Decode a single user-supplied exception code */
777 
778     Status = strtoul (HexString, NULL, 16);
779     if (!Status)
780     {
781         printf ("%s: Invalid hexadecimal exception code value\n", HexString);
782         return;
783     }
784 
785     if (Status > ACPI_UINT16_MAX)
786     {
787         AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
788         return;
789     }
790 
791     ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
792     if (!ExceptionInfo)
793     {
794         AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
795         return;
796     }
797 
798     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
799 }
800