RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / arm / boot / compressed / misc.c
blobe653a6d3c8d90dae62ee3da745bfce67c34d27fb
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 #ifdef CONFIG_CPU_V6
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));
55 #elif defined(CONFIG_CPU_V7)
57 static void icedcc_putc(int ch)
59 asm(
60 "wait: mrc p14, 0, pc, c0, c1, 0 \n\
61 bcs wait \n\
62 mcr p14, 0, %0, c0, c5, 0 "
63 : : "r" (ch));
66 #elif defined(CONFIG_CPU_XSCALE)
68 static void icedcc_putc(int ch)
70 int status, i = 0x4000000;
72 do {
73 if (--i < 0)
74 return;
76 asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
77 } while (status & (1 << 28));
79 asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
82 #else
84 static void icedcc_putc(int ch)
86 int status, i = 0x4000000;
88 do {
89 if (--i < 0)
90 return;
92 asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
93 } while (status & 2);
95 asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
98 #endif
100 #define putc(ch) icedcc_putc(ch)
101 #endif
103 static void putstr(const char *ptr)
105 char c;
107 while ((c = *ptr++) != '\0') {
108 if (c == '\n')
109 putc('\r');
110 putc(c);
113 flush();
117 void *memcpy(void *__dest, __const void *__src, size_t __n)
119 int i = 0;
120 unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
122 for (i = __n >> 3; i > 0; i--) {
123 *d++ = *s++;
124 *d++ = *s++;
125 *d++ = *s++;
126 *d++ = *s++;
127 *d++ = *s++;
128 *d++ = *s++;
129 *d++ = *s++;
130 *d++ = *s++;
133 if (__n & 1 << 2) {
134 *d++ = *s++;
135 *d++ = *s++;
136 *d++ = *s++;
137 *d++ = *s++;
140 if (__n & 1 << 1) {
141 *d++ = *s++;
142 *d++ = *s++;
145 if (__n & 1)
146 *d++ = *s++;
148 return __dest;
152 * gzip delarations
154 extern char input_data[];
155 extern char input_data_end[];
157 unsigned char *output_data;
158 unsigned long output_ptr;
160 unsigned long free_mem_ptr;
161 unsigned long free_mem_end_ptr;
163 #ifndef arch_error
164 #define arch_error(x)
165 #endif
167 void error(char *x)
169 arch_error(x);
171 putstr("\n\n");
172 putstr(x);
173 putstr("\n\n -- System halted");
175 while(1); /* Halt */
178 asmlinkage void __div0(void)
180 error("Attempting division by 0!");
183 extern void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
186 unsigned long
187 decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
188 unsigned long free_mem_ptr_end_p,
189 int arch_id)
191 unsigned char *tmp;
193 output_data = (unsigned char *)output_start;
194 free_mem_ptr = free_mem_ptr_p;
195 free_mem_end_ptr = free_mem_ptr_end_p;
196 __machine_arch_type = arch_id;
198 arch_decomp_setup();
200 tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
201 output_ptr = get_unaligned_le32(tmp);
203 putstr("Uncompressing Linux...");
204 do_decompress(input_data, input_data_end - input_data,
205 output_data, error);
206 putstr(" done, booting the kernel.\n");
207 return output_ptr;