]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * misc.c | |
3 | * | |
4 | * This is a collection of several routines from gzip-1.0.3 | |
5 | * adapted for Linux. | |
6 | * | |
7 | * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 | |
8 | * | |
9 | * Modified for ARM Linux by Russell King | |
10 | * | |
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. | |
17 | */ | |
18 | ||
19 | unsigned int __machine_arch_type; | |
20 | ||
e7db7b42 AT |
21 | #define _LINUX_STRING_H_ |
22 | ||
aa0d3bb7 RR |
23 | #include <linux/compiler.h> /* for inline */ |
24 | #include <linux/types.h> /* for size_t */ | |
25 | #include <linux/stddef.h> /* for NULL */ | |
e7db7b42 | 26 | #include <linux/linkage.h> |
5de813b6 | 27 | #include <asm/string.h> |
e7db7b42 AT |
28 | |
29 | #include <asm/unaligned.h> | |
1da177e4 | 30 | |
1da177e4 LT |
31 | #ifdef STANDALONE_DEBUG |
32 | #define putstr printf | |
a081568d | 33 | #else |
1da177e4 | 34 | |
a081568d RK |
35 | static void putstr(const char *ptr); |
36 | ||
a09e64fb | 37 | #include <mach/uncompress.h> |
1da177e4 | 38 | |
a081568d | 39 | #ifdef CONFIG_DEBUG_ICEDCC |
7d95ded9 TL |
40 | |
41 | #ifdef CONFIG_CPU_V6 | |
42 | ||
43 | static void icedcc_putc(int ch) | |
44 | { | |
45 | int status, i = 0x4000000; | |
46 | ||
47 | do { | |
48 | if (--i < 0) | |
49 | return; | |
50 | ||
51 | asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status)); | |
52 | } while (status & (1 << 29)); | |
53 | ||
54 | asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch)); | |
55 | } | |
200b7a8d TL |
56 | |
57 | #elif defined(CONFIG_CPU_V7) | |
58 | ||
59 | static void icedcc_putc(int ch) | |
60 | { | |
61 | asm( | |
62 | "wait: mrc p14, 0, pc, c0, c1, 0 \n\ | |
63 | bcs wait \n\ | |
64 | mcr p14, 0, %0, c0, c5, 0 " | |
65 | : : "r" (ch)); | |
66 | } | |
67 | ||
c633c3cf JCPV |
68 | #elif defined(CONFIG_CPU_XSCALE) |
69 | ||
70 | static void icedcc_putc(int ch) | |
71 | { | |
72 | int status, i = 0x4000000; | |
73 | ||
74 | do { | |
75 | if (--i < 0) | |
76 | return; | |
77 | ||
78 | asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status)); | |
79 | } while (status & (1 << 28)); | |
80 | ||
81 | asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch)); | |
82 | } | |
7d95ded9 TL |
83 | |
84 | #else | |
85 | ||
de4533a0 RK |
86 | static void icedcc_putc(int ch) |
87 | { | |
88 | int status, i = 0x4000000; | |
89 | ||
90 | do { | |
91 | if (--i < 0) | |
92 | return; | |
93 | ||
b2556da5 | 94 | asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status)); |
de4533a0 RK |
95 | } while (status & 2); |
96 | ||
b2556da5 | 97 | asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch)); |
de4533a0 RK |
98 | } |
99 | ||
7d95ded9 TL |
100 | #endif |
101 | ||
a081568d | 102 | #define putc(ch) icedcc_putc(ch) |
a081568d | 103 | #endif |
1da177e4 | 104 | |
a081568d | 105 | static void putstr(const char *ptr) |
1da177e4 | 106 | { |
a081568d RK |
107 | char c; |
108 | ||
109 | while ((c = *ptr++) != '\0') { | |
110 | if (c == '\n') | |
111 | putc('\r'); | |
112 | putc(c); | |
1da177e4 | 113 | } |
a081568d RK |
114 | |
115 | flush(); | |
1da177e4 LT |
116 | } |
117 | ||
118 | #endif | |
119 | ||
5de813b6 | 120 | void *memcpy(void *__dest, __const void *__src, size_t __n) |
1da177e4 LT |
121 | { |
122 | int i = 0; | |
123 | unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src; | |
124 | ||
125 | for (i = __n >> 3; i > 0; i--) { | |
126 | *d++ = *s++; | |
127 | *d++ = *s++; | |
128 | *d++ = *s++; | |
129 | *d++ = *s++; | |
130 | *d++ = *s++; | |
131 | *d++ = *s++; | |
132 | *d++ = *s++; | |
133 | *d++ = *s++; | |
134 | } | |
135 | ||
136 | if (__n & 1 << 2) { | |
137 | *d++ = *s++; | |
138 | *d++ = *s++; | |
139 | *d++ = *s++; | |
140 | *d++ = *s++; | |
141 | } | |
142 | ||
143 | if (__n & 1 << 1) { | |
144 | *d++ = *s++; | |
145 | *d++ = *s++; | |
146 | } | |
147 | ||
148 | if (__n & 1) | |
149 | *d++ = *s++; | |
150 | ||
151 | return __dest; | |
152 | } | |
153 | ||
154 | /* | |
155 | * gzip delarations | |
156 | */ | |
1da177e4 LT |
157 | extern char input_data[]; |
158 | extern char input_data_end[]; | |
159 | ||
5de813b6 RK |
160 | unsigned char *output_data; |
161 | unsigned long output_ptr; | |
1da177e4 | 162 | |
5de813b6 RK |
163 | unsigned long free_mem_ptr; |
164 | unsigned long free_mem_end_ptr; | |
1da177e4 | 165 | |
f8c905d3 BD |
166 | #ifndef arch_error |
167 | #define arch_error(x) | |
168 | #endif | |
169 | ||
5de813b6 | 170 | void error(char *x) |
1da177e4 | 171 | { |
f8c905d3 BD |
172 | arch_error(x); |
173 | ||
1da177e4 LT |
174 | putstr("\n\n"); |
175 | putstr(x); | |
176 | putstr("\n\n -- System halted"); | |
177 | ||
178 | while(1); /* Halt */ | |
179 | } | |
180 | ||
e7db7b42 AT |
181 | asmlinkage void __div0(void) |
182 | { | |
183 | error("Attempting division by 0!"); | |
184 | } | |
185 | ||
5de813b6 RK |
186 | extern void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x)); |
187 | ||
1da177e4 LT |
188 | #ifndef STANDALONE_DEBUG |
189 | ||
e7db7b42 AT |
190 | unsigned long |
191 | decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p, | |
192 | unsigned long free_mem_ptr_end_p, | |
193 | int arch_id) | |
1da177e4 | 194 | { |
e7db7b42 AT |
195 | unsigned char *tmp; |
196 | ||
197 | output_data = (unsigned char *)output_start; | |
1da177e4 | 198 | free_mem_ptr = free_mem_ptr_p; |
2d6ffcca | 199 | free_mem_end_ptr = free_mem_ptr_end_p; |
1da177e4 LT |
200 | __machine_arch_type = arch_id; |
201 | ||
202 | arch_decomp_setup(); | |
203 | ||
e7db7b42 AT |
204 | tmp = (unsigned char *) (((unsigned long)input_data_end) - 4); |
205 | output_ptr = get_unaligned_le32(tmp); | |
206 | ||
1da177e4 | 207 | putstr("Uncompressing Linux..."); |
5de813b6 RK |
208 | do_decompress(input_data, input_data_end - input_data, |
209 | output_data, error); | |
1da177e4 LT |
210 | putstr(" done, booting the kernel.\n"); |
211 | return output_ptr; | |
212 | } | |
213 | #else | |
214 | ||
215 | char output_buffer[1500*1024]; | |
216 | ||
217 | int main() | |
218 | { | |
219 | output_data = output_buffer; | |
220 | ||
1da177e4 | 221 | putstr("Uncompressing Linux..."); |
e7db7b42 AT |
222 | decompress(input_data, input_data_end - input_data, |
223 | NULL, NULL, output_data, NULL, error); | |
1da177e4 LT |
224 | putstr("done.\n"); |
225 | return 0; | |
226 | } | |
227 | #endif |