xen: cleancache shim to Xen Transcendent Memory
[linux-2.6/next.git] / arch / arm / boot / compressed / misc.c
blob2df38263124c2676e0b0ec62a95de05a1e2ad891
1 /*
2 * misc.c
3 *
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 * Modified for ARM Linux by Russell King
11 * Nicolas Pitre <nico@visuaide.com> 1999/04/14 :
12 * For this code to run directly from Flash, all constant variables must
13 * be marked with 'const' and all other variables initialized at run-time
14 * only. This way all non constant variables will end up in the bss segment,
15 * which should point to addresses in RAM and cleared to 0 on start.
16 * This allows for a much quicker boot time.
19 unsigned int __machine_arch_type;
21 #define _LINUX_STRING_H_
23 #include <linux/compiler.h> /* for inline */
24 #include <linux/types.h> /* for size_t */
25 #include <linux/stddef.h> /* for NULL */
26 #include <linux/linkage.h>
27 #include <asm/string.h>
29 #include <asm/unaligned.h>
32 static void putstr(const char *ptr);
33 extern void error(char *x);
35 #include <mach/uncompress.h>
37 #ifdef CONFIG_DEBUG_ICEDCC
39 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
41 static void icedcc_putc(int ch)
43 int status, i = 0x4000000;
45 do {
46 if (--i < 0)
47 return;
49 asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status));
50 } while (status & (1 << 29));
52 asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch));
56 #elif defined(CONFIG_CPU_XSCALE)
58 static void icedcc_putc(int ch)
60 int status, i = 0x4000000;
62 do {
63 if (--i < 0)
64 return;
66 asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
67 } while (status & (1 << 28));
69 asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
72 #else
74 static void icedcc_putc(int ch)
76 int status, i = 0x4000000;
78 do {
79 if (--i < 0)
80 return;
82 asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
83 } while (status & 2);
85 asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
88 #endif
90 #define putc(ch) icedcc_putc(ch)
91 #endif
93 static void putstr(const char *ptr)
95 char c;
97 while ((c = *ptr++) != '\0') {
98 if (c == '\n')
99 putc('\r');
100 putc(c);
103 flush();
107 void *memcpy(void *__dest, __const void *__src, size_t __n)
109 int i = 0;
110 unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
112 for (i = __n >> 3; i > 0; i--) {
113 *d++ = *s++;
114 *d++ = *s++;
115 *d++ = *s++;
116 *d++ = *s++;
117 *d++ = *s++;
118 *d++ = *s++;
119 *d++ = *s++;
120 *d++ = *s++;
123 if (__n & 1 << 2) {
124 *d++ = *s++;
125 *d++ = *s++;
126 *d++ = *s++;
127 *d++ = *s++;
130 if (__n & 1 << 1) {
131 *d++ = *s++;
132 *d++ = *s++;
135 if (__n & 1)
136 *d++ = *s++;
138 return __dest;
142 * gzip delarations
144 extern char input_data[];
145 extern char input_data_end[];
147 unsigned char *output_data;
148 unsigned long output_ptr;
150 unsigned long free_mem_ptr;
151 unsigned long free_mem_end_ptr;
153 #ifndef arch_error
154 #define arch_error(x)
155 #endif
157 void error(char *x)
159 arch_error(x);
161 putstr("\n\n");
162 putstr(x);
163 putstr("\n\n -- System halted");
165 while(1); /* Halt */
168 asmlinkage void __div0(void)
170 error("Attempting division by 0!");
173 extern void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
176 unsigned long
177 decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
178 unsigned long free_mem_ptr_end_p,
179 int arch_id)
181 unsigned char *tmp;
183 output_data = (unsigned char *)output_start;
184 free_mem_ptr = free_mem_ptr_p;
185 free_mem_end_ptr = free_mem_ptr_end_p;
186 __machine_arch_type = arch_id;
188 arch_decomp_setup();
190 tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
191 output_ptr = get_unaligned_le32(tmp);
193 putstr("Uncompressing Linux...");
194 do_decompress(input_data, input_data_end - input_data,
195 output_data, error);
196 putstr(" done, booting the kernel.\n");
197 return output_ptr;