sh: boot: Add proper forward declarations
[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 18
21b86515
GU
19#include "misc.h"
20
1da177e4
LT
21/*
22 * gzip declarations
23 */
24
1da177e4
LT
25#define STATIC static
26
27#undef memset
28#undef memcpy
29#define memzero(s, n) memset ((s), 0, (n))
30
1da177e4
LT
31extern char input_data[];
32extern int input_len;
df8ce259 33static unsigned char *output;
1da177e4 34
1da177e4 35static void error(char *m);
1da177e4
LT
36
37int puts(const char *);
38
39extern int _text; /* Defined in vmlinux.lds.S */
40extern int _end;
41static unsigned long free_mem_ptr;
42static unsigned long free_mem_end_ptr;
43
07e88e1b
PM
44#ifdef CONFIG_HAVE_KERNEL_BZIP2
45#define HEAP_SIZE 0x400000
46#else
47#define HEAP_SIZE 0x10000
48#endif
1da177e4 49
df8ce259
PM
50#ifdef CONFIG_KERNEL_GZIP
51#include "../../../../lib/decompress_inflate.c"
52#endif
1da177e4 53
07e88e1b
PM
54#ifdef CONFIG_KERNEL_BZIP2
55#include "../../../../lib/decompress_bunzip2.c"
56#endif
57
58#ifdef CONFIG_KERNEL_LZMA
59#include "../../../../lib/decompress_unlzma.c"
60#endif
61
50cfa79d
PM
62#ifdef CONFIG_KERNEL_XZ
63#include "../../../../lib/decompress_unxz.c"
64#endif
65
c7b16efb
PM
66#ifdef CONFIG_KERNEL_LZO
67#include "../../../../lib/decompress_unlzo.c"
68#endif
69
1da177e4
LT
70int puts(const char *s)
71{
72 /* This should be updated to use the sh-sci routines */
73 return 0;
74}
1da177e4
LT
75
76void* memset(void* s, int c, size_t n)
77{
78 int i;
79 char *ss = (char*)s;
80
81 for (i=0;i<n;i++) ss[i] = c;
82 return s;
83}
84
85void* memcpy(void* __dest, __const void* __src,
86 size_t __n)
87{
88 int i;
89 char *d = (char *)__dest, *s = (char *)__src;
90
91 for (i=0;i<__n;i++) d[i] = s[i];
92 return __dest;
93}
94
1da177e4
LT
95static void error(char *x)
96{
97 puts("\n\n");
98 puts(x);
99 puts("\n\n -- System halted");
100
101 while(1); /* Halt */
102}
103
7bbaf27d 104const unsigned long __stack_chk_guard = 0x000a0dff;
fb6cc4ac
KC
105
106void __stack_chk_fail(void)
107{
108 error("stack-protector: Kernel stack is corrupted\n");
109}
110
b83b43ff
SRV
111/* Needed because vmlinux.lds.h references this */
112void ftrace_stub(void)
113{
114}
17b251a2
SRV
115void arch_ftrace_ops_list_func(void)
116{
117}
b83b43ff 118
b14c6d42 119#define stackalign 4
b14c6d42 120
1da177e4 121#define STACK_SIZE (4096)
b14c6d42
PM
122long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
123long *stack_start = &user_stack[STACK_SIZE];
1da177e4
LT
124
125void decompress_kernel(void)
126{
df8ce259
PM
127 unsigned long output_addr;
128
8bd642b1 129 output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
d01447b3 130#if defined(CONFIG_29BIT)
df8ce259 131 output_addr |= P2SEG;
d02b08f6 132#endif
df8ce259
PM
133
134 output = (unsigned char *)output_addr;
1da177e4
LT
135 free_mem_ptr = (unsigned long)&_end;
136 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
137
1da177e4 138 puts("Uncompressing Linux... ");
2d3862d2 139 __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
1da177e4
LT
140 puts("Ok, booting the kernel.\n");
141}