sh: bzip2/lzma zImage support.
[linux-2.6/kvm.git] / arch / sh / boot / compressed / misc_64.c
blob09b7b7cd24f9dd562b34b910632a94d3e94c819f
1 /*
2 * arch/sh/boot/compressed/misc_64.c
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
9 * Adapted for SHmedia from sh by Stuart Menefy, May 2002
12 #include <asm/uaccess.h>
14 /* cache.c */
15 #define CACHE_ENABLE 0
16 #define CACHE_DISABLE 1
17 int cache_control(unsigned int command);
20 * gzip declarations
23 #define STATIC static
25 #undef memset
26 #undef memcpy
27 #define memzero(s, n) memset ((s), 0, (n))
29 static void error(char *m);
31 extern char input_data[];
32 extern int input_len;
34 static unsigned char *output_data;
36 static void puts(const char *);
38 extern int _text; /* Defined in vmlinux.lds.S */
39 extern int _end;
40 static unsigned long free_mem_ptr;
41 static unsigned long free_mem_end_ptr;
43 #ifdef CONFIG_HAVE_KERNEL_BZIP2
44 #define HEAP_SIZE 0x400000
45 #else
46 #define HEAP_SIZE 0x10000
47 #endif
49 #ifdef CONFIG_KERNEL_GZIP
50 #include "../../../../lib/decompress_inflate.c"
51 #endif
53 #ifdef CONFIG_KERNEL_BZIP2
54 #include "../../../../lib/decompress_bunzip2.c"
55 #endif
57 #ifdef CONFIG_KERNEL_LZMA
58 #include "../../../../lib/decompress_unlzma.c"
59 #endif
61 void puts(const char *s)
65 void *memset(void *s, int c, size_t n)
67 int i;
68 char *ss = (char *) s;
70 for (i = 0; i < n; i++)
71 ss[i] = c;
72 return s;
75 void *memcpy(void *__dest, __const void *__src, size_t __n)
77 int i;
78 char *d = (char *) __dest, *s = (char *) __src;
80 for (i = 0; i < __n; i++)
81 d[i] = s[i];
82 return __dest;
85 static void error(char *x)
87 puts("\n\n");
88 puts(x);
89 puts("\n\n -- System halted");
91 while (1) ; /* Halt */
94 #define STACK_SIZE (4096)
95 long __attribute__ ((aligned(8))) user_stack[STACK_SIZE];
96 long *stack_start = &user_stack[STACK_SIZE];
98 void decompress_kernel(void)
100 output_data = (unsigned char *) (CONFIG_MEMORY_START + 0x2000);
101 free_mem_ptr = (unsigned long) &_end;
102 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
104 puts("Uncompressing Linux... ");
105 cache_control(CACHE_ENABLE);
106 decompress(input_data, input_len, NULL, NULL, output_data, NULL, error);
107 cache_control(CACHE_DISABLE);
108 puts("Ok, booting the kernel.\n");