1 // SPDX-License-Identifier: GPL-2.0
3 * arch/sh/boot/compressed/misc.c
5 * This is a collection of several routines from gzip-1.0.3
8 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
10 * Adapted for SH by Stuart Menefy, Aug 1999
12 * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
15 #include <linux/uaccess.h>
16 #include <asm/addrspace.h>
29 #define memzero(s, n) memset ((s), 0, (n))
31 extern char input_data
[];
33 static unsigned char *output
;
35 static void error(char *m
);
37 int puts(const char *);
39 extern int _text
; /* Defined in vmlinux.lds.S */
41 static unsigned long free_mem_ptr
;
42 static unsigned long free_mem_end_ptr
;
44 #ifdef CONFIG_HAVE_KERNEL_BZIP2
45 #define HEAP_SIZE 0x400000
47 #define HEAP_SIZE 0x10000
50 #ifdef CONFIG_KERNEL_GZIP
51 #include "../../../../lib/decompress_inflate.c"
54 #ifdef CONFIG_KERNEL_BZIP2
55 #include "../../../../lib/decompress_bunzip2.c"
58 #ifdef CONFIG_KERNEL_LZMA
59 #include "../../../../lib/decompress_unlzma.c"
62 #ifdef CONFIG_KERNEL_XZ
63 #include "../../../../lib/decompress_unxz.c"
66 #ifdef CONFIG_KERNEL_LZO
67 #include "../../../../lib/decompress_unlzo.c"
70 int puts(const char *s
)
72 /* This should be updated to use the sh-sci routines */
76 void* memset(void* s
, int c
, size_t n
)
81 for (i
=0;i
<n
;i
++) ss
[i
] = c
;
85 void* memcpy(void* __dest
, __const
void* __src
,
89 char *d
= (char *)__dest
, *s
= (char *)__src
;
91 for (i
=0;i
<__n
;i
++) d
[i
] = s
[i
];
95 static void error(char *x
)
99 puts("\n\n -- System halted");
104 const unsigned long __stack_chk_guard
= 0x000a0dff;
106 void __stack_chk_fail(void)
108 error("stack-protector: Kernel stack is corrupted\n");
111 /* Needed because vmlinux.lds.h references this */
112 void ftrace_stub(void)
115 void arch_ftrace_ops_list_func(void)
121 #define STACK_SIZE (4096)
122 long __attribute__ ((aligned(stackalign
))) user_stack
[STACK_SIZE
];
123 long *stack_start
= &user_stack
[STACK_SIZE
];
125 void decompress_kernel(void)
127 unsigned long output_addr
;
129 output_addr
= __pa((unsigned long)&_text
+PAGE_SIZE
);
130 #if defined(CONFIG_29BIT)
131 output_addr
|= P2SEG
;
134 output
= (unsigned char *)output_addr
;
135 free_mem_ptr
= (unsigned long)&_end
;
136 free_mem_end_ptr
= free_mem_ptr
+ HEAP_SIZE
;
138 puts("Uncompressing Linux... ");
139 __decompress(input_data
, input_len
, NULL
, NULL
, output
, 0, NULL
, error
);
140 puts("Ok, booting the kernel.\n");