1 From 4594630ec2e6a33efce3047a86b08fa170b75848 Mon Sep 17 00:00:00 2001
2 From: Al Stone <ahs3@redhat.com>
3 Date: Thu, 15 Oct 2020 11:53:33 -0600
4 Subject: [PATCH 01/45] Add in basic infrastructure for big-endian support
6 This adds in some basic functions -- AcpiUtReadUint32(), for example,
7 to read a UINT32 value in little-endian form and return it in host-native
8 format -- along with AcpiUtWriteUint() that writes out an integer in
9 host-native format as a little-endian value.
11 But, to do that, I'm adding the functions in a new file: utendian.c. So,
12 the header files need fixing, and the makefiles need to be sure to compile
13 the new code. Further, UtIsBigEndianMachine() needed to be moved out of
14 compiler/aslutils.c so it could be used in the new functions and avoid
15 having to do some conditional compilation depending on endian-ness.
17 However, this sets things up for the future, where endian-aware code can
18 be added as the need is uncovered. For now, these functions cover all of
19 the cases I know about.
21 Signed-off-by: Al Stone <ahs3@redhat.com>
23 generate/unix/acpibin/Makefile | 1 +
24 generate/unix/acpidump/Makefile | 1 +
25 generate/unix/acpiexamples/Makefile | 1 +
26 generate/unix/acpiexec/Makefile | 1 +
27 generate/unix/acpihelp/Makefile | 1 +
28 generate/unix/iasl/Makefile | 1 +
29 source/compiler/aslcompiler.h | 4 -
30 source/compiler/aslutils.c | 27 ---
31 source/components/utilities/utendian.c | 236 +++++++++++++++++++++++++
32 source/include/acmacros.h | 56 ------
33 source/include/acutils.h | 32 ++++
34 source/include/platform/aclinux.h | 1 +
35 12 files changed, 275 insertions(+), 87 deletions(-)
36 create mode 100644 source/components/utilities/utendian.c
38 Index: acpica-unix2-20220331/generate/unix/acpibin/Makefile
39 ===================================================================
40 --- acpica-unix2-20220331.orig/generate/unix/acpibin/Makefile
41 +++ acpica-unix2-20220331/generate/unix/acpibin/Makefile
42 @@ -37,6 +37,7 @@ OBJECTS = \
46 + $(OBJDIR)/utendian.o\
50 Index: acpica-unix2-20220331/generate/unix/acpidump/Makefile
51 ===================================================================
52 --- acpica-unix2-20220331.orig/generate/unix/acpidump/Makefile
53 +++ acpica-unix2-20220331/generate/unix/acpidump/Makefile
54 @@ -36,6 +36,7 @@ OBJECTS = \
55 $(OBJDIR)/osunixdir.o\
56 $(OBJDIR)/osunixmap.o\
58 + $(OBJDIR)/utendian.o\
62 Index: acpica-unix2-20220331/generate/unix/acpiexamples/Makefile
63 ===================================================================
64 --- acpica-unix2-20220331.orig/generate/unix/acpiexamples/Makefile
65 +++ acpica-unix2-20220331/generate/unix/acpiexamples/Makefile
66 @@ -139,6 +139,7 @@ OBJECTS = \
70 + $(OBJDIR)/utendian.o\
74 Index: acpica-unix2-20220331/generate/unix/acpiexec/Makefile
75 ===================================================================
76 --- acpica-unix2-20220331.orig/generate/unix/acpiexec/Makefile
77 +++ acpica-unix2-20220331/generate/unix/acpiexec/Makefile
78 @@ -214,6 +214,7 @@ OBJECTS = \
82 + $(OBJDIR)/utendian.o\
86 Index: acpica-unix2-20220331/generate/unix/acpihelp/Makefile
87 ===================================================================
88 --- acpica-unix2-20220331.orig/generate/unix/acpihelp/Makefile
89 +++ acpica-unix2-20220331/generate/unix/acpihelp/Makefile
90 @@ -45,6 +45,7 @@ OBJECTS = \
94 + $(OBJDIR)/utendian.o\
98 Index: acpica-unix2-20220331/generate/unix/iasl/Makefile
99 ===================================================================
100 --- acpica-unix2-20220331.orig/generate/unix/iasl/Makefile
101 +++ acpica-unix2-20220331/generate/unix/iasl/Makefile
102 @@ -225,6 +225,7 @@ OBJECTS = \
104 $(OBJDIR)/utdecode.o\
105 $(OBJDIR)/utdelete.o\
106 + $(OBJDIR)/utendian.o\
109 $(OBJDIR)/utglobal.o\
110 Index: acpica-unix2-20220331/source/compiler/aslcompiler.h
111 ===================================================================
112 --- acpica-unix2-20220331.orig/source/compiler/aslcompiler.h
113 +++ acpica-unix2-20220331/source/compiler/aslcompiler.h
114 @@ -1120,10 +1120,6 @@ BOOLEAN
119 -UtIsBigEndianMachine (
123 UtQueryForOverwrite (
125 Index: acpica-unix2-20220331/source/compiler/aslutils.c
126 ===================================================================
127 --- acpica-unix2-20220331.orig/source/compiler/aslutils.c
128 +++ acpica-unix2-20220331/source/compiler/aslutils.c
129 @@ -73,33 +73,6 @@ UtDisplayErrorSummary (
131 /*******************************************************************************
133 - * FUNCTION: UtIsBigEndianMachine
137 - * RETURN: TRUE if machine is big endian
138 - * FALSE if machine is little endian
140 - * DESCRIPTION: Detect whether machine is little endian or big endian.
142 - ******************************************************************************/
145 -UtIsBigEndianMachine (
151 - } Overlay = {0xFF000000};
154 - return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
158 -/*******************************************************************************
160 * FUNCTION: UtIsIdInteger
162 * PARAMETERS: Pointer to an ACPI ID (HID, CID) string
163 Index: acpica-unix2-20220331/source/components/utilities/utendian.c
164 ===================================================================
166 +++ acpica-unix2-20220331/source/components/utilities/utendian.c
168 +/******************************************************************************
170 + * Module Name: utendian -- byte swapping support for other-endianness
172 + *****************************************************************************/
174 +/*****************************************************************************
176 + * Copyright (c) 2020, Al Stone <ahs3@redhat.com>
178 + * Redistribution and use in source and binary forms, with or without
179 + * modification, are permitted provided that the following conditions
181 + * 1. Redistributions of source code must retain the above copyright
182 + * notice, this list of conditions, and the following disclaimer,
183 + * without modification.
184 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
185 + * substantially similar to the "NO WARRANTY" disclaimer below
186 + * ("Disclaimer") and any redistribution must be conditioned upon
187 + * including a substantially similar Disclaimer requirement for further
188 + * binary redistribution.
189 + * 3. Neither the names of the above-listed copyright holders nor the names
190 + * of any contributors may be used to endorse or promote products derived
191 + * from this software without specific prior written permission.
193 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
194 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
195 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
197 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
198 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
199 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
200 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
201 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
202 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
203 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
205 + * Alternatively, you may choose to be licensed under the terms of the
206 + * GNU General Public License ("GPL") version 2 as published by the Free
207 + * Software Foundation.
209 + *****************************************************************************/
212 +#include "accommon.h"
214 +#define _COMPONENT ACPI_COMPILER
215 + ACPI_MODULE_NAME ("utendian")
218 + * Endianness support functions.
220 + * Ultimately, everything in ACPI tables or AML must be in little-endian
221 + * format. However, we sometimes find it necessary to run on a big-endian
222 + * machine and create or read those little-endian values. This is a small
223 + * libary of functions to make that easier, and more visible.
227 +/*******************************************************************************
229 + * FUNCTION: UtIsBigEndianMachine
233 + * RETURN: TRUE if machine is big endian
234 + * FALSE if machine is little endian
236 + * DESCRIPTION: Detect whether machine is little endian or big endian.
238 + ******************************************************************************/
241 +UtIsBigEndianMachine (
247 + } Overlay = {0xFF000000};
250 + return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
254 +/*******************************************************************************
256 + * FUNCTION: AcpiUtReadUint16
258 + * PARAMETERS: Src - location containing the little-endian
261 + * RETURN: UINT16 value in host-native form
263 + * DESCRIPTION: Read a UINT16 little-endian value from a given location
264 + * and return it in host-native form
266 + ******************************************************************************/
273 + UINT8 *Dst = (UINT8 *) &Result;
274 + UINT8 *Src = (UINT8 *) SrcPtr;
276 + if (!UtIsBigEndianMachine())
278 + return (*(UINT16 *) SrcPtr);
287 +/*******************************************************************************
289 + * FUNCTION: AcpiUtReadUint32
291 + * PARAMETERS: Src - location containing the little-endian
294 + * RETURN: UINT32 value in host-native form
296 + * DESCRIPTION: Read a UINT32 little-endian value from a given location
297 + * and return it in host-native form
299 + ******************************************************************************/
306 + UINT8 *Dst = (UINT8 *) &Result;
307 + UINT8 *Src = (UINT8 *) SrcPtr;
309 + if (!UtIsBigEndianMachine())
311 + return (*(UINT32 *) SrcPtr);
322 +/*******************************************************************************
324 + * FUNCTION: AcpiUtReadUint64
326 + * PARAMETERS: Src - location containing the little-endian
329 + * RETURN: UINT64 value in host-native form
331 + * DESCRIPTION: Read a UINT64 little-endian value from a given location
332 + * and return it in host-native form
334 + ******************************************************************************/
341 + UINT8 *Dst = (UINT8 *) &Result;
342 + UINT8 *Src = (UINT8 *) SrcPtr;
344 + if (!UtIsBigEndianMachine())
346 + return (*(UINT64 *) SrcPtr);
361 +/*******************************************************************************
363 + * FUNCTION: AcpiUtWriteUint
365 + * PARAMETERS: DstPtr - where to place the retrieved value
366 + * DstLength - space in bytes for this int type
367 + * SrcPtr - where the little-endian value lives
368 + * SrcLength - space in bytes for this int type
372 + * DESCRIPTION: Write a host-native integer value of the given size, and
373 + * store it in the location specified in little-endian form.
374 + * Given the amount of integer type casting done, this general
375 + * version seems the most useful (vs 32->32, 32->16, 16->32,
378 + ******************************************************************************/
384 + const void *SrcPtr,
385 + const int SrcLength)
387 + UINT8 *Dst = (UINT8 *) DstPtr;
388 + UINT8 *Src = (UINT8 *) SrcPtr;
392 + if (!UtIsBigEndianMachine())
394 + Length = SrcLength > DstLength ? DstLength : SrcLength;
395 + memcpy (Dst, Src, Length);
399 + Length = SrcLength >= DstLength ? DstLength : SrcLength;
400 + for (ii = 0; ii < Length; ii++)
401 + Dst[ii] = Src[SrcLength - ii - 1];
404 Index: acpica-unix2-20220331/source/include/acmacros.h
405 ===================================================================
406 --- acpica-unix2-20220331.orig/source/include/acmacros.h
407 +++ acpica-unix2-20220331/source/include/acmacros.h
409 * If the hardware supports the transfer of unaligned data, just do the store.
410 * Otherwise, we have to move one byte at a time.
412 -#ifdef ACPI_BIG_ENDIAN
414 - * Macros for big-endian machines
417 -/* These macros reverse the bytes during the move, converting little-endian to big endian */
419 - /* Big Endian <== Little Endian */
420 - /* Hi...Lo Lo...Hi */
421 -/* 16-bit source, 16/32/64 destination */
423 -#define ACPI_MOVE_16_TO_16(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\
424 - (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];}
426 -#define ACPI_MOVE_16_TO_32(d, s) {(*(UINT32 *)(void *)(d))=0;\
427 - ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
428 - ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
430 -#define ACPI_MOVE_16_TO_64(d, s) {(*(UINT64 *)(void *)(d))=0;\
431 - ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
432 - ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
434 -/* 32-bit source, 16/32/64 destination */
436 -#define ACPI_MOVE_32_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */
438 -#define ACPI_MOVE_32_TO_32(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\
439 - (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\
440 - (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
441 - (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
443 -#define ACPI_MOVE_32_TO_64(d, s) {(*(UINT64 *)(void *)(d))=0;\
444 - ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
445 - ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
446 - ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
447 - ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
449 -/* 64-bit source, 16/32/64 destination */
451 -#define ACPI_MOVE_64_TO_16(d, s) ACPI_MOVE_16_TO_16(d, s) /* Truncate to 16 */
453 -#define ACPI_MOVE_64_TO_32(d, s) ACPI_MOVE_32_TO_32(d, s) /* Truncate to 32 */
455 -#define ACPI_MOVE_64_TO_64(d, s) {(( UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\
456 - (( UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\
457 - (( UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\
458 - (( UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\
459 - (( UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
460 - (( UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
461 - (( UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
462 - (( UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
465 - * Macros for little-endian machines
468 #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
471 (( UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\
472 (( UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];}
478 Index: acpica-unix2-20220331/source/include/acutils.h
479 ===================================================================
480 --- acpica-unix2-20220331.orig/source/include/acutils.h
481 +++ acpica-unix2-20220331/source/include/acutils.h
482 @@ -1167,4 +1167,36 @@ AcpiUtConvertUuidToString (
488 + * utendian -- byte-swapping for big-endian support
492 +UtIsBigEndianMachine (
495 +#if defined(ACPI_ASL_COMPILER) || defined(ACPI_EXEC_APP) || \
496 + defined(ACPI_HELP_APP) || defined(ACPI_DUMP_APP) || \
497 + defined(ACPI_EXAMPLE_APP) || defined(ACPI_BIN_APP)
514 + const void *SrcPtr,
515 + const int SrcLength);
518 #endif /* _ACUTILS_H */
519 Index: acpica-unix2-20220331/source/include/platform/aclinux.h
520 ===================================================================
521 --- acpica-unix2-20220331.orig/source/include/platform/aclinux.h
522 +++ acpica-unix2-20220331/source/include/platform/aclinux.h
525 #ifdef ACPI_USE_STANDARD_HEADERS
530 /* Define/disable kernel-specific declarators */