From b2d7e331e2b5cb9899a13e5e105e96d2632da995 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 14 Aug 2011 11:41:19 +0200 Subject: [PATCH] Add helper functions for easier unaligned memory access. * include/grub/types.h (grub_get_unaligned16): New function. (grub_get_unaligned32): Likewise. (grub_get_unaligned64): Likewise. --- ChangeLog.lzo | 8 ++++++++ include/grub/types.h | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/ChangeLog.lzo b/ChangeLog.lzo index 6f5191db2..701715747 100644 --- a/ChangeLog.lzo +++ b/ChangeLog.lzo @@ -1,3 +1,11 @@ +2001-08-14 Szymon Janc + + Add helper functions for easier unaligned memory access. + + * include/grub/types.h (grub_get_unaligned16): New function. + (grub_get_unaligned32): Likewise. + (grub_get_unaligned64): Likewise. + 2011-08-14 Szymon Janc Import minilzo library for LZO decompression support. diff --git a/include/grub/types.h b/include/grub/types.h index 32d255d40..f057dd3d3 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -222,4 +222,31 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t x) # define grub_cpu_to_le32_compile_time(x) ((grub_uint32_t) (x)) #endif /* ! WORDS_BIGENDIAN */ +static inline grub_uint16_t grub_get_unaligned16(void *ptr) +{ + struct + { + grub_uint16_t d; + } __attribute__((packed)) *dd = ptr; + return dd->d; +} + +static inline grub_uint32_t grub_get_unaligned32(void *ptr) +{ + struct + { + grub_uint32_t d; + } __attribute__((packed)) *dd = ptr; + return dd->d; +} + +static inline grub_uint64_t grub_get_unaligned64(void *ptr) +{ + struct + { + grub_uint64_t d; + } __attribute__((packed)) *dd = ptr; + return dd->d; +} + #endif /* ! GRUB_TYPES_HEADER */