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