1 | /** @file
|
---|
2 | Byte Swap routines for endian-nes conversions.
|
---|
3 |
|
---|
4 | Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
---|
5 | This program and the accompanying materials are licensed and made available under
|
---|
6 | the terms and conditions of the BSD License that accompanies this distribution.
|
---|
7 | The full text of the license may be found at
|
---|
8 | http://opensource.org/licenses/bsd-license.php.
|
---|
9 |
|
---|
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
12 | **/
|
---|
13 | #include <Library/BaseLib.h>
|
---|
14 | #include <LibConfig.h>
|
---|
15 |
|
---|
16 | #include <sys/bswap.h>
|
---|
17 |
|
---|
18 | // Undefine macro versions of the functions to be defined below.
|
---|
19 | #undef bswap16
|
---|
20 | #undef bswap32
|
---|
21 | #undef bswap64
|
---|
22 |
|
---|
23 | /**
|
---|
24 | Switches the endianness of a 16-bit integer.
|
---|
25 |
|
---|
26 | This function swaps the bytes in a 16-bit unsigned value to switch the value
|
---|
27 | from little endian to big endian or vice versa. The byte swapped value is
|
---|
28 | returned.
|
---|
29 |
|
---|
30 | @param Value A 16-bit unsigned value.
|
---|
31 |
|
---|
32 | @return The byte swapped Value.
|
---|
33 |
|
---|
34 | **/
|
---|
35 | uint16_t bswap16(uint16_t Value)
|
---|
36 | {
|
---|
37 | return SwapBytes16(Value);
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | Switches the endianness of a 32-bit integer.
|
---|
42 |
|
---|
43 | This function swaps the bytes in a 32-bit unsigned value to switch the value
|
---|
44 | from little endian to big endian or vice versa. The byte swapped value is
|
---|
45 | returned.
|
---|
46 |
|
---|
47 | @param Value A 32-bit unsigned value.
|
---|
48 |
|
---|
49 | @return The byte swapped Value.
|
---|
50 |
|
---|
51 | **/
|
---|
52 | uint32_t bswap32(uint32_t Value)
|
---|
53 | {
|
---|
54 | return SwapBytes32(Value);
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | Switches the endianness of a 64-bit integer.
|
---|
59 |
|
---|
60 | This function swaps the bytes in a 64-bit unsigned value to switch the value
|
---|
61 | from little endian to big endian or vice versa. The byte swapped value is
|
---|
62 | returned.
|
---|
63 |
|
---|
64 | @param Value A 64-bit unsigned value.
|
---|
65 |
|
---|
66 | @return The byte swapped Value.
|
---|
67 |
|
---|
68 | **/
|
---|
69 | uint64_t bswap64(uint64_t Value)
|
---|
70 | {
|
---|
71 | return SwapBytes64(Value);
|
---|
72 | }
|
---|