]> git.pld-linux.org Git - packages/acpica.git/blob - 0001-Add-in-basic-infrastructure-for-big-endian-support.patch
- added verbose patch not to hide compiler command line, disable stripping on install
[packages/acpica.git] / 0001-Add-in-basic-infrastructure-for-big-endian-support.patch
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
5
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.
10
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.
16
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.
20
21 Signed-off-by: Al Stone <ahs3@redhat.com>
22 ---
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
37
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 = \
43         $(OBJDIR)/utcache.o\
44         $(OBJDIR)/utdebug.o\
45         $(OBJDIR)/utdecode.o\
46 +       $(OBJDIR)/utendian.o\
47         $(OBJDIR)/utexcep.o\
48         $(OBJDIR)/utglobal.o\
49         $(OBJDIR)/utlock.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\
57         $(OBJDIR)/osunixxf.o\
58 +       $(OBJDIR)/utendian.o\
59         $(OBJDIR)/tbprint.o\
60         $(OBJDIR)/tbxfroot.o\
61         $(OBJDIR)/utascii.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 = \
67         $(OBJDIR)/utdebug.o\
68         $(OBJDIR)/utdecode.o\
69         $(OBJDIR)/utdelete.o\
70 +       $(OBJDIR)/utendian.o\
71         $(OBJDIR)/uterror.o\
72         $(OBJDIR)/uteval.o\
73         $(OBJDIR)/utexcep.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 = \
79         $(OBJDIR)/utdebug.o\
80         $(OBJDIR)/utdecode.o\
81         $(OBJDIR)/utdelete.o\
82 +       $(OBJDIR)/utendian.o\
83         $(OBJDIR)/uterror.o\
84         $(OBJDIR)/uteval.o\
85         $(OBJDIR)/utexcep.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 = \
91         $(OBJDIR)/getopt.o\
92         $(OBJDIR)/osunixxf.o\
93         $(OBJDIR)/utdebug.o\
94 +       $(OBJDIR)/utendian.o\
95         $(OBJDIR)/utexcep.o\
96         $(OBJDIR)/utglobal.o\
97         $(OBJDIR)/uthex.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 = \
103         $(OBJDIR)/utdebug.o\
104         $(OBJDIR)/utdecode.o\
105         $(OBJDIR)/utdelete.o\
106 +       $(OBJDIR)/utendian.o\
107         $(OBJDIR)/uterror.o\
108         $(OBJDIR)/utexcep.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
115  UtIsIdInteger (
116      UINT8                   *Target);
117  
118 -UINT8
119 -UtIsBigEndianMachine (
120 -    void);
121 -
122  BOOLEAN
123  UtQueryForOverwrite (
124      char                    *Pathname);
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 (
130  
131  /*******************************************************************************
132   *
133 - * FUNCTION:    UtIsBigEndianMachine
134 - *
135 - * PARAMETERS:  None
136 - *
137 - * RETURN:      TRUE if machine is big endian
138 - *              FALSE if machine is little endian
139 - *
140 - * DESCRIPTION: Detect whether machine is little endian or big endian.
141 - *
142 - ******************************************************************************/
143 -
144 -UINT8
145 -UtIsBigEndianMachine (
146 -    void)
147 -{
148 -    union {
149 -        UINT32              Integer;
150 -        UINT8               Bytes[4];
151 -    } Overlay =                 {0xFF000000};
152 -
153 -
154 -    return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
155 -}
156 -
157 -
158 -/*******************************************************************************
159 - *
160   * FUNCTION:    UtIsIdInteger
161   *
162   * PARAMETERS:  Pointer to an ACPI ID (HID, CID) string
163 Index: acpica-unix2-20220331/source/components/utilities/utendian.c
164 ===================================================================
165 --- /dev/null
166 +++ acpica-unix2-20220331/source/components/utilities/utendian.c
167 @@ -0,0 +1,236 @@
168 +/******************************************************************************
169 + *
170 + * Module Name: utendian -- byte swapping support for other-endianness
171 + *
172 + *****************************************************************************/
173 +
174 +/*****************************************************************************
175 + *
176 + * Copyright (c) 2020, Al Stone <ahs3@redhat.com>
177 + *
178 + * Redistribution and use in source and binary forms, with or without
179 + * modification, are permitted provided that the following conditions
180 + * are met:
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.
192 + *
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.
204 + *
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.
208 + *
209 + *****************************************************************************/
210 +
211 +#include "acpi.h"
212 +#include "accommon.h"
213 +
214 +#define _COMPONENT          ACPI_COMPILER
215 +        ACPI_MODULE_NAME    ("utendian")
216 +
217 +/*
218 + * Endianness support functions.
219 + *
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.
224 + *
225 + */
226 +
227 +/*******************************************************************************
228 + *
229 + * FUNCTION:    UtIsBigEndianMachine
230 + *
231 + * PARAMETERS:  None
232 + *
233 + * RETURN:      TRUE if machine is big endian
234 + *              FALSE if machine is little endian
235 + *
236 + * DESCRIPTION: Detect whether machine is little endian or big endian.
237 + *
238 + ******************************************************************************/
239 +
240 +UINT8
241 +UtIsBigEndianMachine (
242 +    void)
243 +{
244 +    union {
245 +        UINT32              Integer;
246 +        UINT8               Bytes[4];
247 +    } Overlay =                 {0xFF000000};
248 +
249 +
250 +    return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */
251 +}
252 +
253 +
254 +/*******************************************************************************
255 + *
256 + * FUNCTION:    AcpiUtReadUint16
257 + *
258 + * PARAMETERS:  Src         - location containing the little-endian
259 + *                                    value
260 + *
261 + * RETURN:      UINT16 value in host-native form
262 + *
263 + * DESCRIPTION: Read a UINT16 little-endian value from a given location
264 + *              and return it in host-native form
265 + *
266 + ******************************************************************************/
267 +
268 +UINT16
269 +AcpiUtReadUint16 (
270 +    void                    *SrcPtr)
271 +{
272 +    UINT16                  Result = 0;
273 +    UINT8                   *Dst = (UINT8 *) &Result;
274 +    UINT8                   *Src = (UINT8 *) SrcPtr;
275 +
276 +    if (!UtIsBigEndianMachine())
277 +    {
278 +        return (*(UINT16 *) SrcPtr);
279 +    }
280 +
281 +    Dst[0] = Src[1];
282 +    Dst[1] = Src[0];
283 +
284 +    return (Result);
285 +}
286 +
287 +/*******************************************************************************
288 + *
289 + * FUNCTION:    AcpiUtReadUint32
290 + *
291 + * PARAMETERS:  Src         - location containing the little-endian
292 + *                                    value
293 + *
294 + * RETURN:      UINT32 value in host-native form
295 + *
296 + * DESCRIPTION: Read a UINT32 little-endian value from a given location
297 + *              and return it in host-native form
298 + *
299 + ******************************************************************************/
300 +
301 +UINT32
302 +AcpiUtReadUint32 (
303 +    void                    *SrcPtr)
304 +{
305 +    UINT32                  Result = 0;
306 +    UINT8                   *Dst = (UINT8 *) &Result;
307 +    UINT8                   *Src = (UINT8 *) SrcPtr;
308 +
309 +    if (!UtIsBigEndianMachine())
310 +    {
311 +        return (*(UINT32 *) SrcPtr);
312 +    }
313 +
314 +    Dst[0] = Src[3];
315 +    Dst[1] = Src[2];
316 +    Dst[2] = Src[1];
317 +    Dst[3] = Src[0];
318 +
319 +    return (Result);
320 +}
321 +
322 +/*******************************************************************************
323 + *
324 + * FUNCTION:    AcpiUtReadUint64
325 + *
326 + * PARAMETERS:  Src         - location containing the little-endian
327 + *                                    value
328 + *
329 + * RETURN:      UINT64 value in host-native form
330 + *
331 + * DESCRIPTION: Read a UINT64 little-endian value from a given location
332 + *              and return it in host-native form
333 + *
334 + ******************************************************************************/
335 +
336 +UINT64
337 +AcpiUtReadUint64 (
338 +    void                    *SrcPtr)
339 +{
340 +    UINT64                  Result = 0;
341 +    UINT8                   *Dst = (UINT8 *) &Result;
342 +    UINT8                   *Src = (UINT8 *) SrcPtr;
343 +
344 +    if (!UtIsBigEndianMachine())
345 +    {
346 +        return (*(UINT64 *) SrcPtr);
347 +    }
348 +
349 +    Dst[0] = Src[7];
350 +    Dst[1] = Src[6];
351 +    Dst[2] = Src[5];
352 +    Dst[3] = Src[4];
353 +    Dst[4] = Src[3];
354 +    Dst[5] = Src[2];
355 +    Dst[6] = Src[1];
356 +    Dst[7] = Src[0];
357 +
358 +    return (Result);
359 +}
360 +
361 +/*******************************************************************************
362 + *
363 + * FUNCTION:    AcpiUtWriteUint
364 + *
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
369 + *
370 + * RETURN:      None.
371 + *
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,
376 + *              ad infinitum)
377 + *
378 + ******************************************************************************/
379 +
380 +void
381 +AcpiUtWriteUint (
382 +    void                    *DstPtr,
383 +    int                     DstLength,
384 +    const void              *SrcPtr,
385 +    const int               SrcLength)
386 +{
387 +    UINT8                   *Dst = (UINT8 *) DstPtr;
388 +    UINT8                   *Src = (UINT8 *) SrcPtr;
389 +    int                      Length;
390 +    int                      ii;
391 +
392 +    if (!UtIsBigEndianMachine())
393 +    {
394 +        Length = SrcLength > DstLength ? DstLength : SrcLength;
395 +        memcpy (Dst, Src, Length);
396 +       return;
397 +    }
398 +
399 +    Length = SrcLength >= DstLength ? DstLength : SrcLength;
400 +    for (ii = 0; ii < Length; ii++)
401 +        Dst[ii] = Src[SrcLength - ii - 1];
402 +
403 +}
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
408 @@ -76,61 +76,6 @@
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.
411   */
412 -#ifdef ACPI_BIG_ENDIAN
413 -/*
414 - * Macros for big-endian machines
415 - */
416 -
417 -/* These macros reverse the bytes during the move, converting little-endian to big endian */
418 -
419 -                                                     /* Big Endian      <==        Little Endian */
420 -                                                     /*  Hi...Lo                     Lo...Hi     */
421 -/* 16-bit source, 16/32/64 destination */
422 -
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];}
425 -
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];}
429 -
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];}
433 -
434 -/* 32-bit source, 16/32/64 destination */
435 -
436 -#define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
437 -
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];}
442 -
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];}
448 -
449 -/* 64-bit source, 16/32/64 destination */
450 -
451 -#define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
452 -
453 -#define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
454 -
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];}
463 -#else
464 -/*
465 - * Macros for little-endian machines
466 - */
467  
468  #ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
469  
470 @@ -193,7 +138,6 @@
471                                           ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\
472                                           ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];}
473  #endif
474 -#endif
475  
476  
477  /*
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 (
483      char                    *OutString);
484  #endif
485  
486 +
487 +/*
488 + * utendian -- byte-swapping for big-endian support
489 + */
490 +
491 +UINT8
492 +UtIsBigEndianMachine (
493 +    void);
494 +
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)
498 +UINT32
499 +AcpiUtReadUint32 (
500 +    void                    *SrcPtr);
501 +
502 +UINT16
503 +AcpiUtReadUint16 (
504 +    void                    *SrcPtr);
505 +
506 +UINT64
507 +AcpiUtReadUint64 (
508 +    void                    *SrcPtr);
509 +
510 +void  
511 +AcpiUtWriteUint (
512 +    void                    *DstPtr,
513 +    int                     DstLength,
514 +    const void              *SrcPtr,
515 +    const int               SrcLength);
516 +#endif
517 +
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
523 @@ -203,6 +203,7 @@
524  
525  #ifdef ACPI_USE_STANDARD_HEADERS
526  #include <unistd.h>
527 +#include <endian.h>
528  #endif
529  
530  /* Define/disable kernel-specific declarators */
This page took 0.108103 seconds and 3 git commands to generate.