2N/A/* xz_config.h - Private includes and definitions for userspace use */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A/*
2N/A * This file is based on code from XZ embedded project
2N/A * http://tukaani.org/xz/embedded.html
2N/A */
2N/A
2N/A#ifndef XZ_CONFIG_H
2N/A#define XZ_CONFIG_H
2N/A
2N/A/* Enable BCJ filter decoders. */
2N/A
2N/A#if defined(GRUB_TARGET_CPU_I386) || defined(GRUB_TARGET_CPU_X86_64)
2N/A #define XZ_DEC_X86
2N/A#endif
2N/A
2N/A#ifdef GRUB_TARGET_CPU_POWERPC
2N/A #define XZ_DEC_POWERPC
2N/A#endif
2N/A
2N/A#ifdef GRUB_TARGET_CPU_IA64
2N/A #define XZ_DEC_IA64
2N/A#endif
2N/A
2N/A#ifdef GRUB_TARGET_CPU_ARM
2N/A #define XZ_DEC_ARM
2N/A#endif
2N/A
2N/A#if 0
2N/A #define XZ_DEC_ARMTHUMB
2N/A#endif
2N/A
2N/A#ifdef GRUB_TARGET_CPU_SPARC
2N/A #define XZ_DEC_SPARC
2N/A#endif
2N/A
2N/A
2N/A#include "xz.h"
2N/A#include <stdlib.h>
2N/A
2N/A#define kmalloc(size, flags) malloc(size)
2N/A#define kfree(ptr) free(ptr)
2N/A#define vmalloc(size) malloc(size)
2N/A#define vfree(ptr) free(ptr)
2N/A
2N/A#define memeq(a, b, size) (memcmp(a, b, size) == 0)
2N/A#define memzero(buf, size) memset(buf, 0, size)
2N/A
2N/A#define min(x, y) ((x) < (y) ? (x) : (y))
2N/A#define min_t(type, x, y) min(x, y)
2N/A
2N/A/*
2N/A * Some functions have been marked with __always_inline to keep the
2N/A * performance reasonable even when the compiler is optimizing for
2N/A * small code size. You may be able to save a few bytes by #defining
2N/A * __always_inline to plain inline, but don't complain if the code
2N/A * becomes slow.
2N/A *
2N/A * NOTE: System headers on GNU/Linux may #define this macro already,
2N/A * so if you want to change it, it you need to #undef it first.
2N/A */
2N/A#ifndef __always_inline
2N/A# ifdef __GNUC__
2N/A# define __always_inline \
2N/A inline __attribute__((__always_inline__))
2N/A# else
2N/A# define __always_inline inline
2N/A# endif
2N/A#endif
2N/A
2N/A/*
2N/A * Some functions are marked to never be inlined to reduce stack usage.
2N/A * If you don't care about stack usage, you may want to modify this so
2N/A * that noinline_for_stack is #defined to be empty even when using GCC.
2N/A * Doing so may save a few bytes in binary size.
2N/A */
2N/A#ifndef noinline_for_stack
2N/A# ifdef __GNUC__
2N/A# define noinline_for_stack __attribute__((__noinline__))
2N/A# else
2N/A# define noinline_for_stack
2N/A# endif
2N/A#endif
2N/A
2N/A/* Inline functions to access unaligned unsigned 32-bit integers */
2N/Astatic inline uint32_t get_unaligned_le32(const uint8_t *buf)
2N/A{
2N/A return (uint32_t)buf[0]
2N/A | ((uint32_t)buf[1] << 8)
2N/A | ((uint32_t)buf[2] << 16)
2N/A | ((uint32_t)buf[3] << 24);
2N/A}
2N/A
2N/Astatic inline uint32_t get_unaligned_be32(const uint8_t *buf)
2N/A{
2N/A return (uint32_t)(buf[0] << 24)
2N/A | ((uint32_t)buf[1] << 16)
2N/A | ((uint32_t)buf[2] << 8)
2N/A | (uint32_t)buf[3];
2N/A}
2N/A
2N/Astatic inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
2N/A{
2N/A buf[0] = (uint8_t)val;
2N/A buf[1] = (uint8_t)(val >> 8);
2N/A buf[2] = (uint8_t)(val >> 16);
2N/A buf[3] = (uint8_t)(val >> 24);
2N/A}
2N/A
2N/Astatic inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
2N/A{
2N/A buf[0] = (uint8_t)(val >> 24);
2N/A buf[1] = (uint8_t)(val >> 16);
2N/A buf[2] = (uint8_t)(val >> 8);
2N/A buf[3] = (uint8_t)val;
2N/A}
2N/A
2N/A/*
2N/A * Use get_unaligned_le32() also for aligned access for simplicity. On
2N/A * little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
2N/A * could save a few bytes in code size.
2N/A */
2N/A#define get_le32 get_unaligned_le32
2N/A
2N/A#endif