diff options
author | Maximilian Brune <maximilian.brune@9elements.com> | 2024-06-14 15:56:06 +0200 |
---|---|---|
committer | Lean Sheng Tan <sheng.tan@9elements.com> | 2024-06-22 03:59:03 +0000 |
commit | 5afdcd9190a83cb3a13e17cb59126bfcf58e739a (patch) | |
tree | e41fa6d93125ec0756fa866e7d711aee7df22d88 /payloads/libpayload/include | |
parent | 854dd9a5d1153fbb7ace2a7619bb98d024e284ce (diff) |
libpayload/include/endian.h: Add 64 bit enc/dec
Add 64 bit encode/decode functions to libpayload, since it is required
in the patch that moves device_tree to commonlib.
Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: I5dba9a7f41147a511ba1250786e7c51ce623e70a
Reviewed-on: https://review.coreboot.org/c/coreboot/+/83082
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'payloads/libpayload/include')
-rw-r--r-- | payloads/libpayload/include/endian.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/payloads/libpayload/include/endian.h b/payloads/libpayload/include/endian.h index 934bb6abba..35fe0fd283 100644 --- a/payloads/libpayload/include/endian.h +++ b/payloads/libpayload/include/endian.h @@ -96,6 +96,16 @@ static inline uint32_t be32dec(const void *pp) (uint32_t)(p[2] << 8) | p[3]); } +static inline uint64_t be64dec(const void *pp) +{ + uint8_t const *p = (uint8_t const *)pp; + + return (((uint64_t)p[0] << 56) | ((uint64_t)p[1] << 48) | + ((uint64_t)p[2] << 40) | ((uint64_t)p[3] << 32) | + ((uint64_t)p[4] << 24) | ((uint64_t)p[5] << 16) | + ((uint64_t)p[6] << 8) | p[7]); +} + static inline uint16_t le16dec(const void *pp) { uint8_t const *p = (uint8_t const *)pp; @@ -111,6 +121,16 @@ static inline uint32_t le32dec(const void *pp) (uint32_t)(p[1] << 8) | p[0]); } +static inline uint64_t le64dec(const void *pp) +{ + uint8_t const *p = (uint8_t const *)pp; + + return (((uint64_t)p[7] << 56) | ((uint64_t)p[6] << 48) | + ((uint64_t)p[5] << 40) | ((uint64_t)p[4] << 32) | + ((uint64_t)p[3] << 24) | ((uint64_t)p[2] << 16) | + ((uint64_t)p[1] << 8) | p[0]); +} + static inline void bebitenc(void *pp, uint32_t u, uint8_t b) { uint8_t *p = (uint8_t *)pp; @@ -130,6 +150,11 @@ static inline void be32enc(void *pp, uint32_t u) bebitenc(pp, u, 4); } +static inline void be64enc(void *pp, uint32_t u) +{ + bebitenc(pp, u, 8); +} + static inline void lebitenc(void *pp, uint32_t u, uint8_t b) { uint8_t *p = (uint8_t *)pp; @@ -149,6 +174,11 @@ static inline void le32enc(void *pp, uint32_t u) lebitenc(pp, u, 4); } +static inline void le64enc(void *pp, uint32_t u) +{ + lebitenc(pp, u, 8); +} + /* Deprecated names (not in glibc / BSD) */ #define htobew(in) htobe16(in) #define htobel(in) htobe32(in) |