1
/* xz_config.h - Private includes and definitions for userspace use */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2010 Free Software Foundation, Inc.
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.
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.
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/>.
20
* This file is based on code from XZ embedded project
21
* http://tukaani.org/xz/embedded.html
27
/* Enable BCJ filter decoders. */
29
#if defined(__i386__) || defined(__x86_64__)
34
#define XZ_DEC_POWERPC
46
#define XZ_DEC_ARMTHUMB
57
#define kmalloc(size, flags) malloc(size)
58
#define kfree(ptr) free(ptr)
59
#define vmalloc(size) malloc(size)
60
#define vfree(ptr) free(ptr)
62
#define memeq(a, b, size) (memcmp(a, b, size) == 0)
63
#define memzero(buf, size) memset(buf, 0, size)
65
#define min(x, y) ((x) < (y) ? (x) : (y))
66
#define min_t(type, x, y) min(x, y)
69
* Some functions have been marked with __always_inline to keep the
70
* performance reasonable even when the compiler is optimizing for
71
* small code size. You may be able to save a few bytes by #defining
72
* __always_inline to plain inline, but don't complain if the code
75
* NOTE: System headers on GNU/Linux may #define this macro already,
76
* so if you want to change it, it you need to #undef it first.
78
#ifndef __always_inline
80
# define __always_inline \
81
inline __attribute__((__always_inline__))
83
# define __always_inline inline
88
* Some functions are marked to never be inlined to reduce stack usage.
89
* If you don't care about stack usage, you may want to modify this so
90
* that noinline_for_stack is #defined to be empty even when using GCC.
91
* Doing so may save a few bytes in binary size.
93
#ifndef noinline_for_stack
95
# define noinline_for_stack __attribute__((__noinline__))
97
# define noinline_for_stack
101
/* Inline functions to access unaligned unsigned 32-bit integers */
102
static inline uint32_t get_unaligned_le32(const uint8_t *buf)
104
return (uint32_t)buf[0]
105
| ((uint32_t)buf[1] << 8)
106
| ((uint32_t)buf[2] << 16)
107
| ((uint32_t)buf[3] << 24);
110
static inline uint32_t get_unaligned_be32(const uint8_t *buf)
112
return (uint32_t)(buf[0] << 24)
113
| ((uint32_t)buf[1] << 16)
114
| ((uint32_t)buf[2] << 8)
118
static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
120
buf[0] = (uint8_t)val;
121
buf[1] = (uint8_t)(val >> 8);
122
buf[2] = (uint8_t)(val >> 16);
123
buf[3] = (uint8_t)(val >> 24);
126
static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
128
buf[0] = (uint8_t)(val >> 24);
129
buf[1] = (uint8_t)(val >> 16);
130
buf[2] = (uint8_t)(val >> 8);
131
buf[3] = (uint8_t)val;
135
* Use get_unaligned_le32() also for aligned access for simplicity. On
136
* little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
137
* could save a few bytes in code size.
139
#define get_le32 get_unaligned_le32