License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / arch / sh / boot / compressed / misc.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * arch/sh/boot/compressed/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 * Adapted for SH by Stuart Menefy, Aug 1999
11 *
12 * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
13 */
14
7c0f6ba6 15#include <linux/uaccess.h>
9d4436a6 16#include <asm/addrspace.h>
e2dfb912 17#include <asm/page.h>
1da177e4
LT
18
19/*
20 * gzip declarations
21 */
22
1da177e4
LT
23#define STATIC static
24
25#undef memset
26#undef memcpy
27#define memzero(s, n) memset ((s), 0, (n))
28
b14c6d42
PM
29/* cache.c */
30#define CACHE_ENABLE 0
31#define CACHE_DISABLE 1
32int cache_control(unsigned int command);
1da177e4
LT
33
34extern char input_data[];
35extern int input_len;
df8ce259 36static unsigned char *output;
1da177e4 37
1da177e4 38static void error(char *m);
1da177e4
LT
39
40int puts(const char *);
41
42extern int _text; /* Defined in vmlinux.lds.S */
43extern int _end;
44static unsigned long free_mem_ptr;
45static unsigned long free_mem_end_ptr;
46
07e88e1b
PM
47#ifdef CONFIG_HAVE_KERNEL_BZIP2
48#define HEAP_SIZE 0x400000
49#else
50#define HEAP_SIZE 0x10000
51#endif
1da177e4 52
df8ce259
PM
53#ifdef CONFIG_KERNEL_GZIP
54#include "../../../../lib/decompress_inflate.c"
55#endif
1da177e4 56
07e88e1b
PM
57#ifdef CONFIG_KERNEL_BZIP2
58#include "../../../../lib/decompress_bunzip2.c"
59#endif
60
61#ifdef CONFIG_KERNEL_LZMA
62#include "../../../../lib/decompress_unlzma.c"
63#endif
64
50cfa79d
PM
65#ifdef CONFIG_KERNEL_XZ
66#include "../../../../lib/decompress_unxz.c"
67#endif
68
c7b16efb
PM
69#ifdef CONFIG_KERNEL_LZO
70#include "../../../../lib/decompress_unlzo.c"
71#endif
72
1da177e4
LT
73int puts(const char *s)
74{
75 /* This should be updated to use the sh-sci routines */
76 return 0;
77}
1da177e4
LT
78
79void* memset(void* s, int c, size_t n)
80{
81 int i;
82 char *ss = (char*)s;
83
84 for (i=0;i<n;i++) ss[i] = c;
85 return s;
86}
87
88void* memcpy(void* __dest, __const void* __src,
89 size_t __n)
90{
91 int i;
92 char *d = (char *)__dest, *s = (char *)__src;
93
94 for (i=0;i<__n;i++) d[i] = s[i];
95 return __dest;
96}
97
1da177e4
LT
98static void error(char *x)
99{
100 puts("\n\n");
101 puts(x);
102 puts("\n\n -- System halted");
103
104 while(1); /* Halt */
105}
106
b14c6d42
PM
107#ifdef CONFIG_SUPERH64
108#define stackalign 8
109#else
110#define stackalign 4
111#endif
112
1da177e4 113#define STACK_SIZE (4096)
b14c6d42
PM
114long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
115long *stack_start = &user_stack[STACK_SIZE];
1da177e4
LT
116
117void decompress_kernel(void)
118{
df8ce259
PM
119 unsigned long output_addr;
120
040f43e0
PM
121#ifdef CONFIG_SUPERH64
122 output_addr = (CONFIG_MEMORY_START + 0x2000);
123#else
8bd642b1 124 output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
d01447b3 125#if defined(CONFIG_29BIT)
df8ce259 126 output_addr |= P2SEG;
040f43e0 127#endif
d02b08f6 128#endif
df8ce259
PM
129
130 output = (unsigned char *)output_addr;
1da177e4
LT
131 free_mem_ptr = (unsigned long)&_end;
132 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
133
1da177e4 134 puts("Uncompressing Linux... ");
b14c6d42 135 cache_control(CACHE_ENABLE);
2d3862d2 136 __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
b14c6d42 137 cache_control(CACHE_DISABLE);
1da177e4
LT
138 puts("Ok, booting the kernel.\n");
139}