]>
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 | } | |
c633c3cf JCPV |
56 | #elif defined(CONFIG_CPU_XSCALE) |
57 | ||
58 | static void icedcc_putc(int ch) | |
59 | { | |
60 | int status, i = 0x4000000; | |
61 | ||
62 | do { | |
63 | if (--i < 0) | |
64 | return; | |
65 | ||
66 | asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status)); | |
67 | } while (status & (1 << 28)); | |
68 | ||
69 | asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch)); | |
70 | } | |
7d95ded9 TL |
71 | |
72 | #else | |
73 | ||
de4533a0 RK |
74 | static void icedcc_putc(int ch) |
75 | { | |
76 | int status, i = 0x4000000; | |
77 | ||
78 | do { | |
79 | if (--i < 0) | |
80 | return; | |
81 | ||
b2556da5 | 82 | asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status)); |
de4533a0 RK |
83 | } while (status & 2); |
84 | ||
b2556da5 | 85 | asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch)); |
de4533a0 RK |
86 | } |
87 | ||
7d95ded9 TL |
88 | #endif |
89 | ||
a081568d RK |
90 | #define putc(ch) icedcc_putc(ch) |
91 | #define flush() do { } while (0) | |
92 | #endif | |
1da177e4 | 93 | |
a081568d | 94 | static void putstr(const char *ptr) |
1da177e4 | 95 | { |
a081568d RK |
96 | char c; |
97 | ||
98 | while ((c = *ptr++) != '\0') { | |
99 | if (c == '\n') | |
100 | putc('\r'); | |
101 | putc(c); | |
1da177e4 | 102 | } |
a081568d RK |
103 | |
104 | flush(); | |
1da177e4 LT |
105 | } |
106 | ||
107 | #endif | |
108 | ||
5de813b6 | 109 | void *memcpy(void *__dest, __const void *__src, size_t __n) |
1da177e4 LT |
110 | { |
111 | int i = 0; | |
112 | unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src; | |
113 | ||
114 | for (i = __n >> 3; i > 0; i--) { | |
115 | *d++ = *s++; | |
116 | *d++ = *s++; | |
117 | *d++ = *s++; | |
118 | *d++ = *s++; | |
119 | *d++ = *s++; | |
120 | *d++ = *s++; | |
121 | *d++ = *s++; | |
122 | *d++ = *s++; | |
123 | } | |
124 | ||
125 | if (__n & 1 << 2) { | |
126 | *d++ = *s++; | |
127 | *d++ = *s++; | |
128 | *d++ = *s++; | |
129 | *d++ = *s++; | |
130 | } | |
131 | ||
132 | if (__n & 1 << 1) { | |
133 | *d++ = *s++; | |
134 | *d++ = *s++; | |
135 | } | |
136 | ||
137 | if (__n & 1) | |
138 | *d++ = *s++; | |
139 | ||
140 | return __dest; | |
141 | } | |
142 | ||
143 | /* | |
144 | * gzip delarations | |
145 | */ | |
1da177e4 LT |
146 | extern char input_data[]; |
147 | extern char input_data_end[]; | |
148 | ||
5de813b6 RK |
149 | unsigned char *output_data; |
150 | unsigned long output_ptr; | |
1da177e4 | 151 | |
5de813b6 RK |
152 | unsigned long free_mem_ptr; |
153 | unsigned long free_mem_end_ptr; | |
1da177e4 | 154 | |
f8c905d3 BD |
155 | #ifndef arch_error |
156 | #define arch_error(x) | |
157 | #endif | |
158 | ||
5de813b6 | 159 | void error(char *x) |
1da177e4 | 160 | { |
f8c905d3 BD |
161 | arch_error(x); |
162 | ||
1da177e4 LT |
163 | putstr("\n\n"); |
164 | putstr(x); | |
165 | putstr("\n\n -- System halted"); | |
166 | ||
167 | while(1); /* Halt */ | |
168 | } | |
169 | ||
e7db7b42 AT |
170 | asmlinkage void __div0(void) |
171 | { | |
172 | error("Attempting division by 0!"); | |
173 | } | |
174 | ||
5de813b6 RK |
175 | extern void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x)); |
176 | ||
1da177e4 LT |
177 | #ifndef STANDALONE_DEBUG |
178 | ||
e7db7b42 AT |
179 | unsigned long |
180 | decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p, | |
181 | unsigned long free_mem_ptr_end_p, | |
182 | int arch_id) | |
1da177e4 | 183 | { |
e7db7b42 AT |
184 | unsigned char *tmp; |
185 | ||
186 | output_data = (unsigned char *)output_start; | |
1da177e4 | 187 | free_mem_ptr = free_mem_ptr_p; |
2d6ffcca | 188 | free_mem_end_ptr = free_mem_ptr_end_p; |
1da177e4 LT |
189 | __machine_arch_type = arch_id; |
190 | ||
191 | arch_decomp_setup(); | |
192 | ||
e7db7b42 AT |
193 | tmp = (unsigned char *) (((unsigned long)input_data_end) - 4); |
194 | output_ptr = get_unaligned_le32(tmp); | |
195 | ||
1da177e4 | 196 | putstr("Uncompressing Linux..."); |
5de813b6 RK |
197 | do_decompress(input_data, input_data_end - input_data, |
198 | output_data, error); | |
1da177e4 LT |
199 | putstr(" done, booting the kernel.\n"); |
200 | return output_ptr; | |
201 | } | |
202 | #else | |
203 | ||
204 | char output_buffer[1500*1024]; | |
205 | ||
206 | int main() | |
207 | { | |
208 | output_data = output_buffer; | |
209 | ||
1da177e4 | 210 | putstr("Uncompressing Linux..."); |
e7db7b42 AT |
211 | decompress(input_data, input_data_end - input_data, |
212 | NULL, NULL, output_data, NULL, error); | |
1da177e4 LT |
213 | putstr("done.\n"); |
214 | return 0; | |
215 | } | |
216 | #endif |