Home | History | Annotate | Line # | Download | only in utilities
utexcep.c revision 1.1.1.1.6.2
      1 /*******************************************************************************
      2  *
      3  * Module Name: utexcep - Exception code support
      4  *
      5  ******************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2013, 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 
     45 #define __UTEXCEP_C__
     46 #define EXPORT_ACPI_INTERFACES
     47 
     48 #define ACPI_DEFINE_EXCEPTION_TABLE
     49 #include "acpi.h"
     50 #include "accommon.h"
     51 
     52 
     53 #define _COMPONENT          ACPI_UTILITIES
     54         ACPI_MODULE_NAME    ("utexcep")
     55 
     56 
     57 /*******************************************************************************
     58  *
     59  * FUNCTION:    AcpiFormatException
     60  *
     61  * PARAMETERS:  Status              - The ACPI_STATUS code to be formatted
     62  *
     63  * RETURN:      A string containing the exception text. A valid pointer is
     64  *              always returned.
     65  *
     66  * DESCRIPTION: This function translates an ACPI exception into an ASCII
     67  *              string. Returns "unknown status" string for invalid codes.
     68  *
     69  ******************************************************************************/
     70 
     71 const char *
     72 AcpiFormatException (
     73     ACPI_STATUS             Status)
     74 {
     75     const ACPI_EXCEPTION_INFO   *Exception;
     76 
     77 
     78     ACPI_FUNCTION_ENTRY ();
     79 
     80 
     81     Exception = AcpiUtValidateException (Status);
     82     if (!Exception)
     83     {
     84         /* Exception code was not recognized */
     85 
     86         ACPI_ERROR ((AE_INFO,
     87             "Unknown exception code: 0x%8.8X", Status));
     88 
     89         return ("UNKNOWN_STATUS_CODE");
     90     }
     91 
     92     return (Exception->Name);
     93 }
     94 
     95 ACPI_EXPORT_SYMBOL (AcpiFormatException)
     96 
     97 
     98 /*******************************************************************************
     99  *
    100  * FUNCTION:    AcpiUtValidateException
    101  *
    102  * PARAMETERS:  Status              - The ACPI_STATUS code to be formatted
    103  *
    104  * RETURN:      A string containing the exception text. NULL if exception is
    105  *              not valid.
    106  *
    107  * DESCRIPTION: This function validates and translates an ACPI exception into
    108  *              an ASCII string.
    109  *
    110  ******************************************************************************/
    111 
    112 const ACPI_EXCEPTION_INFO *
    113 AcpiUtValidateException (
    114     ACPI_STATUS             Status)
    115 {
    116     UINT32                      SubStatus;
    117     const ACPI_EXCEPTION_INFO   *Exception = NULL;
    118 
    119 
    120     ACPI_FUNCTION_ENTRY ();
    121 
    122 
    123     /*
    124      * Status is composed of two parts, a "type" and an actual code
    125      */
    126     SubStatus = (Status & ~AE_CODE_MASK);
    127 
    128     switch (Status & AE_CODE_MASK)
    129     {
    130     case AE_CODE_ENVIRONMENTAL:
    131 
    132         if (SubStatus <= AE_CODE_ENV_MAX)
    133         {
    134             Exception = &AcpiGbl_ExceptionNames_Env [SubStatus];
    135         }
    136         break;
    137 
    138     case AE_CODE_PROGRAMMER:
    139 
    140         if (SubStatus <= AE_CODE_PGM_MAX)
    141         {
    142             Exception = &AcpiGbl_ExceptionNames_Pgm [SubStatus];
    143         }
    144         break;
    145 
    146     case AE_CODE_ACPI_TABLES:
    147 
    148         if (SubStatus <= AE_CODE_TBL_MAX)
    149         {
    150             Exception = &AcpiGbl_ExceptionNames_Tbl [SubStatus];
    151         }
    152         break;
    153 
    154     case AE_CODE_AML:
    155 
    156         if (SubStatus <= AE_CODE_AML_MAX)
    157         {
    158             Exception = &AcpiGbl_ExceptionNames_Aml [SubStatus];
    159         }
    160         break;
    161 
    162     case AE_CODE_CONTROL:
    163 
    164         if (SubStatus <= AE_CODE_CTRL_MAX)
    165         {
    166             Exception = &AcpiGbl_ExceptionNames_Ctrl [SubStatus];
    167         }
    168         break;
    169 
    170     default:
    171 
    172         break;
    173     }
    174 
    175     if (!Exception || !Exception->Name)
    176     {
    177         return (NULL);
    178     }
    179 
    180     return (Exception);
    181 }
    182