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