1*cb565728SJerry Jelinek /******************************************************************************
2*cb565728SJerry Jelinek *
3*cb565728SJerry Jelinek * Module Name: uthex -- Hex/ASCII support functions
4*cb565728SJerry Jelinek *
5*cb565728SJerry Jelinek *****************************************************************************/
6*cb565728SJerry Jelinek
7*cb565728SJerry Jelinek /*
8*cb565728SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
9*cb565728SJerry Jelinek * All rights reserved.
10*cb565728SJerry Jelinek *
11*cb565728SJerry Jelinek * Redistribution and use in source and binary forms, with or without
12*cb565728SJerry Jelinek * modification, are permitted provided that the following conditions
13*cb565728SJerry Jelinek * are met:
14*cb565728SJerry Jelinek * 1. Redistributions of source code must retain the above copyright
15*cb565728SJerry Jelinek * notice, this list of conditions, and the following disclaimer,
16*cb565728SJerry Jelinek * without modification.
17*cb565728SJerry Jelinek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*cb565728SJerry Jelinek * substantially similar to the "NO WARRANTY" disclaimer below
19*cb565728SJerry Jelinek * ("Disclaimer") and any redistribution must be conditioned upon
20*cb565728SJerry Jelinek * including a substantially similar Disclaimer requirement for further
21*cb565728SJerry Jelinek * binary redistribution.
22*cb565728SJerry Jelinek * 3. Neither the names of the above-listed copyright holders nor the names
23*cb565728SJerry Jelinek * of any contributors may be used to endorse or promote products derived
24*cb565728SJerry Jelinek * from this software without specific prior written permission.
25*cb565728SJerry Jelinek *
26*cb565728SJerry Jelinek * Alternatively, this software may be distributed under the terms of the
27*cb565728SJerry Jelinek * GNU General Public License ("GPL") version 2 as published by the Free
28*cb565728SJerry Jelinek * Software Foundation.
29*cb565728SJerry Jelinek *
30*cb565728SJerry Jelinek * NO WARRANTY
31*cb565728SJerry Jelinek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*cb565728SJerry Jelinek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*cb565728SJerry Jelinek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*cb565728SJerry Jelinek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*cb565728SJerry Jelinek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*cb565728SJerry Jelinek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*cb565728SJerry Jelinek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*cb565728SJerry Jelinek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*cb565728SJerry Jelinek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*cb565728SJerry Jelinek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*cb565728SJerry Jelinek * POSSIBILITY OF SUCH DAMAGES.
42*cb565728SJerry Jelinek */
43*cb565728SJerry Jelinek
44*cb565728SJerry Jelinek #include "acpi.h"
45*cb565728SJerry Jelinek #include "accommon.h"
46*cb565728SJerry Jelinek
47*cb565728SJerry Jelinek #define _COMPONENT ACPI_COMPILER
48*cb565728SJerry Jelinek ACPI_MODULE_NAME ("uthex")
49*cb565728SJerry Jelinek
50*cb565728SJerry Jelinek
51*cb565728SJerry Jelinek /* Hex to ASCII conversion table */
52*cb565728SJerry Jelinek
53*cb565728SJerry Jelinek static const char AcpiGbl_HexToAscii[] =
54*cb565728SJerry Jelinek {
55*cb565728SJerry Jelinek '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
56*cb565728SJerry Jelinek };
57*cb565728SJerry Jelinek
58*cb565728SJerry Jelinek
59*cb565728SJerry Jelinek /*******************************************************************************
60*cb565728SJerry Jelinek *
61*cb565728SJerry Jelinek * FUNCTION: AcpiUtHexToAsciiChar
62*cb565728SJerry Jelinek *
63*cb565728SJerry Jelinek * PARAMETERS: Integer - Contains the hex digit
64*cb565728SJerry Jelinek * Position - bit position of the digit within the
65*cb565728SJerry Jelinek * integer (multiple of 4)
66*cb565728SJerry Jelinek *
67*cb565728SJerry Jelinek * RETURN: The converted Ascii character
68*cb565728SJerry Jelinek *
69*cb565728SJerry Jelinek * DESCRIPTION: Convert a hex digit to an Ascii character
70*cb565728SJerry Jelinek *
71*cb565728SJerry Jelinek ******************************************************************************/
72*cb565728SJerry Jelinek
73*cb565728SJerry Jelinek char
AcpiUtHexToAsciiChar(UINT64 Integer,UINT32 Position)74*cb565728SJerry Jelinek AcpiUtHexToAsciiChar (
75*cb565728SJerry Jelinek UINT64 Integer,
76*cb565728SJerry Jelinek UINT32 Position)
77*cb565728SJerry Jelinek {
78*cb565728SJerry Jelinek
79*cb565728SJerry Jelinek return (AcpiGbl_HexToAscii[(Integer >> Position) & 0xF]);
80*cb565728SJerry Jelinek }
81*cb565728SJerry Jelinek
82*cb565728SJerry Jelinek
83*cb565728SJerry Jelinek /*******************************************************************************
84*cb565728SJerry Jelinek *
85*cb565728SJerry Jelinek * FUNCTION: AcpiUtAsciiCharToHex
86*cb565728SJerry Jelinek *
87*cb565728SJerry Jelinek * PARAMETERS: HexChar - Hex character in Ascii
88*cb565728SJerry Jelinek *
89*cb565728SJerry Jelinek * RETURN: The binary value of the ascii/hex character
90*cb565728SJerry Jelinek *
91*cb565728SJerry Jelinek * DESCRIPTION: Perform ascii-to-hex translation
92*cb565728SJerry Jelinek *
93*cb565728SJerry Jelinek ******************************************************************************/
94*cb565728SJerry Jelinek
95*cb565728SJerry Jelinek UINT8
AcpiUtAsciiCharToHex(int HexChar)96*cb565728SJerry Jelinek AcpiUtAsciiCharToHex (
97*cb565728SJerry Jelinek int HexChar)
98*cb565728SJerry Jelinek {
99*cb565728SJerry Jelinek
100*cb565728SJerry Jelinek if (HexChar <= 0x39)
101*cb565728SJerry Jelinek {
102*cb565728SJerry Jelinek return ((UINT8) (HexChar - 0x30));
103*cb565728SJerry Jelinek }
104*cb565728SJerry Jelinek
105*cb565728SJerry Jelinek if (HexChar <= 0x46)
106*cb565728SJerry Jelinek {
107*cb565728SJerry Jelinek return ((UINT8) (HexChar - 0x37));
108*cb565728SJerry Jelinek }
109*cb565728SJerry Jelinek
110*cb565728SJerry Jelinek return ((UINT8) (HexChar - 0x57));
111*cb565728SJerry Jelinek }
112