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 | ||
aa0d3bb7 | 21 | #include <linux/compiler.h> /* for inline */ |
df4879fa | 22 | #include <linux/types.h> |
e7db7b42 | 23 | #include <linux/linkage.h> |
1da177e4 | 24 | |
a081568d | 25 | static void putstr(const char *ptr); |
a2302b45 | 26 | extern void error(char *x); |
a081568d | 27 | |
615967b0 | 28 | #include CONFIG_UNCOMPRESS_INCLUDE |
1da177e4 | 29 | |
a081568d | 30 | #ifdef CONFIG_DEBUG_ICEDCC |
7d95ded9 | 31 | |
dfad549d | 32 | #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7) |
7d95ded9 TL |
33 | |
34 | static void icedcc_putc(int ch) | |
35 | { | |
36 | int status, i = 0x4000000; | |
37 | ||
38 | do { | |
39 | if (--i < 0) | |
40 | return; | |
41 | ||
42 | asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status)); | |
43 | } while (status & (1 << 29)); | |
44 | ||
45 | asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch)); | |
46 | } | |
200b7a8d | 47 | |
200b7a8d | 48 | |
c633c3cf JCPV |
49 | #elif defined(CONFIG_CPU_XSCALE) |
50 | ||
51 | static void icedcc_putc(int ch) | |
52 | { | |
53 | int status, i = 0x4000000; | |
54 | ||
55 | do { | |
56 | if (--i < 0) | |
57 | return; | |
58 | ||
59 | asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status)); | |
60 | } while (status & (1 << 28)); | |
61 | ||
62 | asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch)); | |
63 | } | |
7d95ded9 TL |
64 | |
65 | #else | |
66 | ||
de4533a0 RK |
67 | static void icedcc_putc(int ch) |
68 | { | |
69 | int status, i = 0x4000000; | |
70 | ||
71 | do { | |
72 | if (--i < 0) | |
73 | return; | |
74 | ||
b2556da5 | 75 | asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status)); |
de4533a0 RK |
76 | } while (status & 2); |
77 | ||
b2556da5 | 78 | asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch)); |
de4533a0 RK |
79 | } |
80 | ||
7d95ded9 TL |
81 | #endif |
82 | ||
a081568d | 83 | #define putc(ch) icedcc_putc(ch) |
a081568d | 84 | #endif |
1da177e4 | 85 | |
a081568d | 86 | static void putstr(const char *ptr) |
1da177e4 | 87 | { |
a081568d RK |
88 | char c; |
89 | ||
90 | while ((c = *ptr++) != '\0') { | |
91 | if (c == '\n') | |
92 | putc('\r'); | |
93 | putc(c); | |
1da177e4 | 94 | } |
a081568d RK |
95 | |
96 | flush(); | |
1da177e4 LT |
97 | } |
98 | ||
1da177e4 | 99 | /* |
e40f1e9f | 100 | * gzip declarations |
1da177e4 | 101 | */ |
1da177e4 LT |
102 | extern char input_data[]; |
103 | extern char input_data_end[]; | |
104 | ||
5de813b6 | 105 | unsigned char *output_data; |
1da177e4 | 106 | |
5de813b6 RK |
107 | unsigned long free_mem_ptr; |
108 | unsigned long free_mem_end_ptr; | |
1da177e4 | 109 | |
f8c905d3 BD |
110 | #ifndef arch_error |
111 | #define arch_error(x) | |
112 | #endif | |
113 | ||
5de813b6 | 114 | void error(char *x) |
1da177e4 | 115 | { |
f8c905d3 BD |
116 | arch_error(x); |
117 | ||
1da177e4 LT |
118 | putstr("\n\n"); |
119 | putstr(x); | |
120 | putstr("\n\n -- System halted"); | |
121 | ||
122 | while(1); /* Halt */ | |
123 | } | |
124 | ||
e7db7b42 AT |
125 | asmlinkage void __div0(void) |
126 | { | |
127 | error("Attempting division by 0!"); | |
128 | } | |
129 | ||
8779657d KC |
130 | unsigned long __stack_chk_guard; |
131 | ||
132 | void __stack_chk_guard_setup(void) | |
133 | { | |
134 | __stack_chk_guard = 0x000a0dff; | |
135 | } | |
136 | ||
137 | void __stack_chk_fail(void) | |
138 | { | |
139 | error("stack-protector: Kernel stack is corrupted\n"); | |
140 | } | |
141 | ||
ccc1c7c6 | 142 | extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x)); |
5de813b6 | 143 | |
1da177e4 | 144 | |
e40f1e9f | 145 | void |
e7db7b42 AT |
146 | decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p, |
147 | unsigned long free_mem_ptr_end_p, | |
148 | int arch_id) | |
1da177e4 | 149 | { |
ccc1c7c6 | 150 | int ret; |
e7db7b42 | 151 | |
8779657d KC |
152 | __stack_chk_guard_setup(); |
153 | ||
e7db7b42 | 154 | output_data = (unsigned char *)output_start; |
1da177e4 | 155 | free_mem_ptr = free_mem_ptr_p; |
2d6ffcca | 156 | free_mem_end_ptr = free_mem_ptr_end_p; |
1da177e4 LT |
157 | __machine_arch_type = arch_id; |
158 | ||
159 | arch_decomp_setup(); | |
160 | ||
1da177e4 | 161 | putstr("Uncompressing Linux..."); |
ccc1c7c6 NP |
162 | ret = do_decompress(input_data, input_data_end - input_data, |
163 | output_data, error); | |
164 | if (ret) | |
165 | error("decompressor returned an error"); | |
166 | else | |
167 | putstr(" done, booting the kernel.\n"); | |
1da177e4 | 168 | } |