]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* |
3 | * misc.c | |
4 | * | |
5 | * This is a collection of several routines from gzip-1.0.3 | |
6 | * adapted for Linux. | |
7 | * | |
8 | * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 | |
9 | * | |
10 | * Modified for ARM Linux by Russell King | |
11 | * | |
12 | * Nicolas Pitre <nico@visuaide.com> 1999/04/14 : | |
13 | * For this code to run directly from Flash, all constant variables must | |
14 | * be marked with 'const' and all other variables initialized at run-time | |
15 | * only. This way all non constant variables will end up in the bss segment, | |
16 | * which should point to addresses in RAM and cleared to 0 on start. | |
17 | * This allows for a much quicker boot time. | |
18 | */ | |
19 | ||
20 | unsigned int __machine_arch_type; | |
21 | ||
aa0d3bb7 | 22 | #include <linux/compiler.h> /* for inline */ |
df4879fa | 23 | #include <linux/types.h> |
e7db7b42 | 24 | #include <linux/linkage.h> |
1da177e4 | 25 | |
a081568d | 26 | static void putstr(const char *ptr); |
a2302b45 | 27 | extern void error(char *x); |
a081568d | 28 | |
615967b0 | 29 | #include CONFIG_UNCOMPRESS_INCLUDE |
1da177e4 | 30 | |
a081568d | 31 | #ifdef CONFIG_DEBUG_ICEDCC |
7d95ded9 | 32 | |
dfad549d | 33 | #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7) |
7d95ded9 TL |
34 | |
35 | static void icedcc_putc(int ch) | |
36 | { | |
37 | int status, i = 0x4000000; | |
38 | ||
39 | do { | |
40 | if (--i < 0) | |
41 | return; | |
42 | ||
43 | asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status)); | |
44 | } while (status & (1 << 29)); | |
45 | ||
46 | asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch)); | |
47 | } | |
200b7a8d | 48 | |
200b7a8d | 49 | |
c633c3cf JCPV |
50 | #elif defined(CONFIG_CPU_XSCALE) |
51 | ||
52 | static void icedcc_putc(int ch) | |
53 | { | |
54 | int status, i = 0x4000000; | |
55 | ||
56 | do { | |
57 | if (--i < 0) | |
58 | return; | |
59 | ||
60 | asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status)); | |
61 | } while (status & (1 << 28)); | |
62 | ||
63 | asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch)); | |
64 | } | |
7d95ded9 TL |
65 | |
66 | #else | |
67 | ||
de4533a0 RK |
68 | static void icedcc_putc(int ch) |
69 | { | |
70 | int status, i = 0x4000000; | |
71 | ||
72 | do { | |
73 | if (--i < 0) | |
74 | return; | |
75 | ||
b2556da5 | 76 | asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status)); |
de4533a0 RK |
77 | } while (status & 2); |
78 | ||
b2556da5 | 79 | asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch)); |
de4533a0 RK |
80 | } |
81 | ||
7d95ded9 TL |
82 | #endif |
83 | ||
a081568d | 84 | #define putc(ch) icedcc_putc(ch) |
a081568d | 85 | #endif |
1da177e4 | 86 | |
a081568d | 87 | static void putstr(const char *ptr) |
1da177e4 | 88 | { |
a081568d RK |
89 | char c; |
90 | ||
91 | while ((c = *ptr++) != '\0') { | |
92 | if (c == '\n') | |
93 | putc('\r'); | |
94 | putc(c); | |
1da177e4 | 95 | } |
a081568d RK |
96 | |
97 | flush(); | |
1da177e4 LT |
98 | } |
99 | ||
1da177e4 | 100 | /* |
e40f1e9f | 101 | * gzip declarations |
1da177e4 | 102 | */ |
1da177e4 LT |
103 | extern char input_data[]; |
104 | extern char input_data_end[]; | |
105 | ||
5de813b6 | 106 | unsigned char *output_data; |
1da177e4 | 107 | |
5de813b6 RK |
108 | unsigned long free_mem_ptr; |
109 | unsigned long free_mem_end_ptr; | |
1da177e4 | 110 | |
f8c905d3 BD |
111 | #ifndef arch_error |
112 | #define arch_error(x) | |
113 | #endif | |
114 | ||
5de813b6 | 115 | void error(char *x) |
1da177e4 | 116 | { |
f8c905d3 BD |
117 | arch_error(x); |
118 | ||
1da177e4 LT |
119 | putstr("\n\n"); |
120 | putstr(x); | |
121 | putstr("\n\n -- System halted"); | |
122 | ||
123 | while(1); /* Halt */ | |
124 | } | |
125 | ||
e7db7b42 AT |
126 | asmlinkage void __div0(void) |
127 | { | |
128 | error("Attempting division by 0!"); | |
129 | } | |
130 | ||
8779657d KC |
131 | unsigned long __stack_chk_guard; |
132 | ||
133 | void __stack_chk_guard_setup(void) | |
134 | { | |
135 | __stack_chk_guard = 0x000a0dff; | |
136 | } | |
137 | ||
138 | void __stack_chk_fail(void) | |
139 | { | |
140 | error("stack-protector: Kernel stack is corrupted\n"); | |
141 | } | |
142 | ||
ccc1c7c6 | 143 | extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x)); |
5de813b6 | 144 | |
1da177e4 | 145 | |
e40f1e9f | 146 | void |
e7db7b42 AT |
147 | decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p, |
148 | unsigned long free_mem_ptr_end_p, | |
149 | int arch_id) | |
1da177e4 | 150 | { |
ccc1c7c6 | 151 | int ret; |
e7db7b42 | 152 | |
8779657d KC |
153 | __stack_chk_guard_setup(); |
154 | ||
e7db7b42 | 155 | output_data = (unsigned char *)output_start; |
1da177e4 | 156 | free_mem_ptr = free_mem_ptr_p; |
2d6ffcca | 157 | free_mem_end_ptr = free_mem_ptr_end_p; |
1da177e4 LT |
158 | __machine_arch_type = arch_id; |
159 | ||
160 | arch_decomp_setup(); | |
161 | ||
1da177e4 | 162 | putstr("Uncompressing Linux..."); |
ccc1c7c6 NP |
163 | ret = do_decompress(input_data, input_data_end - input_data, |
164 | output_data, error); | |
165 | if (ret) | |
166 | error("decompressor returned an error"); | |
167 | else | |
168 | putstr(" done, booting the kernel.\n"); | |
1da177e4 | 169 | } |