1271440Sjkim/****************************************************************************** 2271440Sjkim * 3271440Sjkim * Module Name: uthex -- Hex/ASCII support functions 4271440Sjkim * 5271440Sjkim *****************************************************************************/ 6271440Sjkim 7271440Sjkim/* 8281075Sdim * Copyright (C) 2000 - 2015, Intel Corp. 9271440Sjkim * All rights reserved. 10271440Sjkim * 11271440Sjkim * Redistribution and use in source and binary forms, with or without 12271440Sjkim * modification, are permitted provided that the following conditions 13271440Sjkim * are met: 14271440Sjkim * 1. Redistributions of source code must retain the above copyright 15271440Sjkim * notice, this list of conditions, and the following disclaimer, 16271440Sjkim * without modification. 17271440Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18271440Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19271440Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20271440Sjkim * including a substantially similar Disclaimer requirement for further 21271440Sjkim * binary redistribution. 22271440Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23271440Sjkim * of any contributors may be used to endorse or promote products derived 24271440Sjkim * from this software without specific prior written permission. 25271440Sjkim * 26271440Sjkim * Alternatively, this software may be distributed under the terms of the 27271440Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28271440Sjkim * Software Foundation. 29271440Sjkim * 30271440Sjkim * NO WARRANTY 31271440Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32271440Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33271440Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34271440Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35271440Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36271440Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37271440Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38271440Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39271440Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40271440Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41271440Sjkim * POSSIBILITY OF SUCH DAMAGES. 42271440Sjkim */ 43271440Sjkim 44272444Sjkim#include <contrib/dev/acpica/include/acpi.h> 45272444Sjkim#include <contrib/dev/acpica/include/accommon.h> 46271440Sjkim 47271440Sjkim#define _COMPONENT ACPI_COMPILER 48271440Sjkim ACPI_MODULE_NAME ("uthex") 49271440Sjkim 50271440Sjkim 51271440Sjkim/* Hex to ASCII conversion table */ 52271440Sjkim 53271440Sjkimstatic char AcpiGbl_HexToAscii[] = 54271440Sjkim{ 55271440Sjkim '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' 56271440Sjkim}; 57271440Sjkim 58271440Sjkim 59271440Sjkim/******************************************************************************* 60271440Sjkim * 61271440Sjkim * FUNCTION: AcpiUtHexToAsciiChar 62271440Sjkim * 63271440Sjkim * PARAMETERS: Integer - Contains the hex digit 64271440Sjkim * Position - bit position of the digit within the 65271440Sjkim * integer (multiple of 4) 66271440Sjkim * 67271440Sjkim * RETURN: The converted Ascii character 68271440Sjkim * 69271440Sjkim * DESCRIPTION: Convert a hex digit to an Ascii character 70271440Sjkim * 71271440Sjkim ******************************************************************************/ 72271440Sjkim 73271440Sjkimchar 74271440SjkimAcpiUtHexToAsciiChar ( 75271440Sjkim UINT64 Integer, 76271440Sjkim UINT32 Position) 77271440Sjkim{ 78271440Sjkim 79271440Sjkim return (AcpiGbl_HexToAscii[(Integer >> Position) & 0xF]); 80271440Sjkim} 81271440Sjkim 82271440Sjkim 83271440Sjkim/******************************************************************************* 84271440Sjkim * 85284460Sjkim * FUNCTION: AcpiUtAsciiCharToHex 86271440Sjkim * 87284460Sjkim * PARAMETERS: HexChar - Hex character in Ascii 88271440Sjkim * 89271440Sjkim * RETURN: The binary value of the ascii/hex character 90271440Sjkim * 91271440Sjkim * DESCRIPTION: Perform ascii-to-hex translation 92271440Sjkim * 93271440Sjkim ******************************************************************************/ 94271440Sjkim 95271440SjkimUINT8 96271440SjkimAcpiUtAsciiCharToHex ( 97271440Sjkim int HexChar) 98271440Sjkim{ 99271440Sjkim 100271440Sjkim if (HexChar <= 0x39) 101271440Sjkim { 102271440Sjkim return ((UINT8) (HexChar - 0x30)); 103271440Sjkim } 104271440Sjkim 105271440Sjkim if (HexChar <= 0x46) 106271440Sjkim { 107271440Sjkim return ((UINT8) (HexChar - 0x37)); 108271440Sjkim } 109271440Sjkim 110271440Sjkim return ((UINT8) (HexChar - 0x57)); 111271440Sjkim} 112