xz_config.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* xz_config.h - Private includes and definitions for userspace use */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2010 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /*
  20. * This file is based on code from XZ embedded project
  21. * http://tukaani.org/xz/embedded.html
  22. */
  23. #ifndef XZ_CONFIG_H
  24. #define XZ_CONFIG_H
  25. /* Enable BCJ filter decoders. */
  26. #ifndef GRUB_EMBED_DECOMPRESSOR
  27. #define XZ_DEC_X86
  28. #define XZ_DEC_POWERPC
  29. #define XZ_DEC_IA64
  30. #define XZ_DEC_ARM
  31. #define XZ_DEC_ARMTHUMB
  32. #define XZ_DEC_SPARC
  33. #else
  34. #if defined(__i386__) || defined(__x86_64__)
  35. #define XZ_DEC_X86
  36. #endif
  37. #ifdef __powerpc__
  38. #define XZ_DEC_POWERPC
  39. #endif
  40. #ifdef __ia64__
  41. #define XZ_DEC_IA64
  42. #endif
  43. #ifdef __arm__
  44. #define XZ_DEC_ARM
  45. #endif
  46. #ifdef __arm__
  47. #define XZ_DEC_ARMTHUMB
  48. #endif
  49. #ifdef __sparc__
  50. #define XZ_DEC_SPARC
  51. #endif
  52. #endif
  53. #include "xz.h"
  54. #include <stdlib.h>
  55. #define kmalloc(size, flags) malloc(size)
  56. #define kfree(ptr) free(ptr)
  57. #define vmalloc(size) malloc(size)
  58. #define vfree(ptr) free(ptr)
  59. #define memeq(a, b, size) (memcmp(a, b, size) == 0)
  60. #define memzero(buf, size) memset(buf, 0, size)
  61. #define min(x, y) ((x) < (y) ? (x) : (y))
  62. #define min_t(type, x, y) min(x, y)
  63. /*
  64. * Some functions have been marked with __always_inline to keep the
  65. * performance reasonable even when the compiler is optimizing for
  66. * small code size. You may be able to save a few bytes by #defining
  67. * __always_inline to plain inline, but don't complain if the code
  68. * becomes slow.
  69. *
  70. * NOTE: System headers on GNU/Linux may #define this macro already,
  71. * so if you want to change it, it you need to #undef it first.
  72. */
  73. #ifndef __always_inline
  74. # ifdef __GNUC__
  75. # define __always_inline \
  76. inline __attribute__((__always_inline__))
  77. # else
  78. # define __always_inline inline
  79. # endif
  80. #endif
  81. /*
  82. * Some functions are marked to never be inlined to reduce stack usage.
  83. * If you don't care about stack usage, you may want to modify this so
  84. * that noinline_for_stack is #defined to be empty even when using GCC.
  85. * Doing so may save a few bytes in binary size.
  86. */
  87. #ifndef noinline_for_stack
  88. # ifdef __GNUC__
  89. # define noinline_for_stack __attribute__((__noinline__))
  90. # else
  91. # define noinline_for_stack
  92. # endif
  93. #endif
  94. /* Inline functions to access unaligned unsigned 32-bit integers */
  95. static inline uint32_t get_unaligned_le32(const uint8_t *buf)
  96. {
  97. return (uint32_t)buf[0]
  98. | ((uint32_t)buf[1] << 8)
  99. | ((uint32_t)buf[2] << 16)
  100. | ((uint32_t)buf[3] << 24);
  101. }
  102. static inline uint32_t get_unaligned_be32(const uint8_t *buf)
  103. {
  104. return (uint32_t)(buf[0] << 24)
  105. | ((uint32_t)buf[1] << 16)
  106. | ((uint32_t)buf[2] << 8)
  107. | (uint32_t)buf[3];
  108. }
  109. static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
  110. {
  111. buf[0] = (uint8_t)val;
  112. buf[1] = (uint8_t)(val >> 8);
  113. buf[2] = (uint8_t)(val >> 16);
  114. buf[3] = (uint8_t)(val >> 24);
  115. }
  116. static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
  117. {
  118. buf[0] = (uint8_t)(val >> 24);
  119. buf[1] = (uint8_t)(val >> 16);
  120. buf[2] = (uint8_t)(val >> 8);
  121. buf[3] = (uint8_t)val;
  122. }
  123. /*
  124. * Use get_unaligned_le32() also for aligned access for simplicity. On
  125. * little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
  126. * could save a few bytes in code size.
  127. */
  128. #define get_le32 get_unaligned_le32
  129. #endif