linux/arch/unicore32/boot/compressed/misc.c
<<
>>
Prefs
   1/*
   2 * linux/arch/unicore32/boot/compressed/misc.c
   3 *
   4 * Code specific to PKUnity SoC and UniCore ISA
   5 *
   6 * Copyright (C) 2001-2010 GUAN Xue-tao
   7 *
   8 * This program is free software; you can redistribute it and/or modify
   9 * it under the terms of the GNU General Public License version 2 as
  10 * published by the Free Software Foundation.
  11 */
  12
  13#include <asm/unaligned.h>
  14#include <mach/uncompress.h>
  15
  16/*
  17 * gzip delarations
  18 */
  19unsigned char *output_data;
  20unsigned long output_ptr;
  21
  22unsigned int free_mem_ptr;
  23unsigned int free_mem_end_ptr;
  24
  25#define STATIC static
  26#define STATIC_RW_DATA  /* non-static please */
  27
  28/*
  29 * arch-dependent implementations
  30 */
  31#ifndef ARCH_HAVE_DECOMP_ERROR
  32#define arch_decomp_error(x)
  33#endif
  34
  35#ifndef ARCH_HAVE_DECOMP_SETUP
  36#define arch_decomp_setup()
  37#endif
  38
  39#ifndef ARCH_HAVE_DECOMP_PUTS
  40#define arch_decomp_puts(p)
  41#endif
  42
  43void *memcpy(void *dest, const void *src, size_t n)
  44{
  45        int i = 0;
  46        unsigned char *d = (unsigned char *)dest, *s = (unsigned char *)src;
  47
  48        for (i = n >> 3; i > 0; i--) {
  49                *d++ = *s++;
  50                *d++ = *s++;
  51                *d++ = *s++;
  52                *d++ = *s++;
  53                *d++ = *s++;
  54                *d++ = *s++;
  55                *d++ = *s++;
  56                *d++ = *s++;
  57        }
  58
  59        if (n & 1 << 2) {
  60                *d++ = *s++;
  61                *d++ = *s++;
  62                *d++ = *s++;
  63                *d++ = *s++;
  64        }
  65
  66        if (n & 1 << 1) {
  67                *d++ = *s++;
  68                *d++ = *s++;
  69        }
  70
  71        if (n & 1)
  72                *d++ = *s++;
  73
  74        return dest;
  75}
  76
  77void error(char *x)
  78{
  79        arch_decomp_puts("\n\n");
  80        arch_decomp_puts(x);
  81        arch_decomp_puts("\n\n -- System halted");
  82
  83        arch_decomp_error(x);
  84
  85        for (;;)
  86                ; /* Halt */
  87}
  88
  89/* Heap size should be adjusted for different decompress method */
  90#ifdef CONFIG_KERNEL_GZIP
  91#include "../../../../lib/decompress_inflate.c"
  92#endif
  93
  94#ifdef CONFIG_KERNEL_BZIP2
  95#include "../../../../lib/decompress_bunzip2.c"
  96#endif
  97
  98#ifdef CONFIG_KERNEL_LZO
  99#include "../../../../lib/decompress_unlzo.c"
 100#endif
 101
 102#ifdef CONFIG_KERNEL_LZMA
 103#include "../../../../lib/decompress_unlzma.c"
 104#endif
 105
 106unsigned long decompress_kernel(unsigned long output_start,
 107                unsigned long free_mem_ptr_p,
 108                unsigned long free_mem_ptr_end_p)
 109{
 110        unsigned char *tmp;
 111
 112        output_data             = (unsigned char *)output_start;
 113        free_mem_ptr            = free_mem_ptr_p;
 114        free_mem_end_ptr        = free_mem_ptr_end_p;
 115
 116        arch_decomp_setup();
 117
 118        tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
 119        output_ptr = get_unaligned_le32(tmp);
 120
 121        arch_decomp_puts("Uncompressing Linux...");
 122        __decompress(input_data, input_data_end - input_data, NULL, NULL,
 123                        output_data, 0, NULL, error);
 124        arch_decomp_puts(" done, booting the kernel.\n");
 125        return output_ptr;
 126}
 127