dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / acpi / common / utexcep.c
blob5be8efd5f273a592e0ee13a4a7b8a8d3b3e4b32e
1 /*******************************************************************************
3 * Module Name: utexcep - Exception code support
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #define EXPORT_ACPI_INTERFACES
46 #define ACPI_DEFINE_EXCEPTION_TABLE
47 #include "acpi.h"
48 #include "accommon.h"
51 #define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utexcep")
55 /*******************************************************************************
57 * FUNCTION: AcpiFormatException
59 * PARAMETERS: Status - The ACPI_STATUS code to be formatted
61 * RETURN: A string containing the exception text. A valid pointer is
62 * always returned.
64 * DESCRIPTION: This function translates an ACPI exception into an ASCII
65 * string. Returns "unknown status" string for invalid codes.
67 ******************************************************************************/
69 const char *
70 AcpiFormatException (
71 ACPI_STATUS Status)
73 const ACPI_EXCEPTION_INFO *Exception;
76 ACPI_FUNCTION_ENTRY ();
79 Exception = AcpiUtValidateException (Status);
80 if (!Exception)
82 /* Exception code was not recognized */
84 ACPI_ERROR ((AE_INFO,
85 "Unknown exception code: 0x%8.8X", Status));
87 return ("UNKNOWN_STATUS_CODE");
90 return (Exception->Name);
93 ACPI_EXPORT_SYMBOL (AcpiFormatException)
96 /*******************************************************************************
98 * FUNCTION: AcpiUtValidateException
100 * PARAMETERS: Status - The ACPI_STATUS code to be formatted
102 * RETURN: A string containing the exception text. NULL if exception is
103 * not valid.
105 * DESCRIPTION: This function validates and translates an ACPI exception into
106 * an ASCII string.
108 ******************************************************************************/
110 const ACPI_EXCEPTION_INFO *
111 AcpiUtValidateException (
112 ACPI_STATUS Status)
114 UINT32 SubStatus;
115 const ACPI_EXCEPTION_INFO *Exception = NULL;
118 ACPI_FUNCTION_ENTRY ();
122 * Status is composed of two parts, a "type" and an actual code
124 SubStatus = (Status & ~AE_CODE_MASK);
126 switch (Status & AE_CODE_MASK)
128 case AE_CODE_ENVIRONMENTAL:
130 if (SubStatus <= AE_CODE_ENV_MAX)
132 Exception = &AcpiGbl_ExceptionNames_Env [SubStatus];
134 break;
136 case AE_CODE_PROGRAMMER:
138 if (SubStatus <= AE_CODE_PGM_MAX)
140 Exception = &AcpiGbl_ExceptionNames_Pgm [SubStatus];
142 break;
144 case AE_CODE_ACPI_TABLES:
146 if (SubStatus <= AE_CODE_TBL_MAX)
148 Exception = &AcpiGbl_ExceptionNames_Tbl [SubStatus];
150 break;
152 case AE_CODE_AML:
154 if (SubStatus <= AE_CODE_AML_MAX)
156 Exception = &AcpiGbl_ExceptionNames_Aml [SubStatus];
158 break;
160 case AE_CODE_CONTROL:
162 if (SubStatus <= AE_CODE_CTRL_MAX)
164 Exception = &AcpiGbl_ExceptionNames_Ctrl [SubStatus];
166 break;
168 default:
170 break;
173 if (!Exception || !Exception->Name)
175 return (NULL);
178 return (Exception);