1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 259f00296SPaul Mundt /* 359f00296SPaul Mundt * arch/sh/boot/compressed/misc.c 459f00296SPaul Mundt * 559f00296SPaul Mundt * This is a collection of several routines from gzip-1.0.3 659f00296SPaul Mundt * adapted for Linux. 759f00296SPaul Mundt * 859f00296SPaul Mundt * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 959f00296SPaul Mundt * 1059f00296SPaul Mundt * Adapted for SH by Stuart Menefy, Aug 1999 1159f00296SPaul Mundt * 1259f00296SPaul Mundt * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000 1359f00296SPaul Mundt */ 1459f00296SPaul Mundt 157c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 1659f00296SPaul Mundt #include <asm/addrspace.h> 1759f00296SPaul Mundt #include <asm/page.h> 1859f00296SPaul Mundt 1959f00296SPaul Mundt /* 2059f00296SPaul Mundt * gzip declarations 2159f00296SPaul Mundt */ 2259f00296SPaul Mundt 2359f00296SPaul Mundt #define STATIC static 2459f00296SPaul Mundt 2559f00296SPaul Mundt #undef memset 2659f00296SPaul Mundt #undef memcpy 2759f00296SPaul Mundt #define memzero(s, n) memset ((s), 0, (n)) 2859f00296SPaul Mundt 2959f00296SPaul Mundt /* cache.c */ 3059f00296SPaul Mundt #define CACHE_ENABLE 0 3159f00296SPaul Mundt #define CACHE_DISABLE 1 3259f00296SPaul Mundt int cache_control(unsigned int command); 3359f00296SPaul Mundt 3459f00296SPaul Mundt extern char input_data[]; 3559f00296SPaul Mundt extern int input_len; 3659f00296SPaul Mundt static unsigned char *output; 3759f00296SPaul Mundt 3859f00296SPaul Mundt static void error(char *m); 3959f00296SPaul Mundt 4059f00296SPaul Mundt int puts(const char *); 4159f00296SPaul Mundt 4259f00296SPaul Mundt extern int _text; /* Defined in vmlinux.lds.S */ 4359f00296SPaul Mundt extern int _end; 4459f00296SPaul Mundt static unsigned long free_mem_ptr; 4559f00296SPaul Mundt static unsigned long free_mem_end_ptr; 4659f00296SPaul Mundt 4759f00296SPaul Mundt #ifdef CONFIG_HAVE_KERNEL_BZIP2 4859f00296SPaul Mundt #define HEAP_SIZE 0x400000 4959f00296SPaul Mundt #else 5059f00296SPaul Mundt #define HEAP_SIZE 0x10000 5159f00296SPaul Mundt #endif 5259f00296SPaul Mundt 5359f00296SPaul Mundt #ifdef CONFIG_KERNEL_GZIP 5459f00296SPaul Mundt #include "../../../../lib/decompress_inflate.c" 5559f00296SPaul Mundt #endif 5659f00296SPaul Mundt 5759f00296SPaul Mundt #ifdef CONFIG_KERNEL_BZIP2 5859f00296SPaul Mundt #include "../../../../lib/decompress_bunzip2.c" 5959f00296SPaul Mundt #endif 6059f00296SPaul Mundt 6159f00296SPaul Mundt #ifdef CONFIG_KERNEL_LZMA 6259f00296SPaul Mundt #include "../../../../lib/decompress_unlzma.c" 6359f00296SPaul Mundt #endif 6459f00296SPaul Mundt 6550cfa79dSPaul Mundt #ifdef CONFIG_KERNEL_XZ 6650cfa79dSPaul Mundt #include "../../../../lib/decompress_unxz.c" 6750cfa79dSPaul Mundt #endif 6850cfa79dSPaul Mundt 69c7b16efbSPaul Mundt #ifdef CONFIG_KERNEL_LZO 70c7b16efbSPaul Mundt #include "../../../../lib/decompress_unlzo.c" 71c7b16efbSPaul Mundt #endif 72c7b16efbSPaul Mundt 7359f00296SPaul Mundt int puts(const char *s) 7459f00296SPaul Mundt { 7559f00296SPaul Mundt /* This should be updated to use the sh-sci routines */ 7659f00296SPaul Mundt return 0; 7759f00296SPaul Mundt } 7859f00296SPaul Mundt 7959f00296SPaul Mundt void* memset(void* s, int c, size_t n) 8059f00296SPaul Mundt { 8159f00296SPaul Mundt int i; 8259f00296SPaul Mundt char *ss = (char*)s; 8359f00296SPaul Mundt 8459f00296SPaul Mundt for (i=0;i<n;i++) ss[i] = c; 8559f00296SPaul Mundt return s; 8659f00296SPaul Mundt } 8759f00296SPaul Mundt 8859f00296SPaul Mundt void* memcpy(void* __dest, __const void* __src, 8959f00296SPaul Mundt size_t __n) 9059f00296SPaul Mundt { 9159f00296SPaul Mundt int i; 9259f00296SPaul Mundt char *d = (char *)__dest, *s = (char *)__src; 9359f00296SPaul Mundt 9459f00296SPaul Mundt for (i=0;i<__n;i++) d[i] = s[i]; 9559f00296SPaul Mundt return __dest; 9659f00296SPaul Mundt } 9759f00296SPaul Mundt 9859f00296SPaul Mundt static void error(char *x) 9959f00296SPaul Mundt { 10059f00296SPaul Mundt puts("\n\n"); 10159f00296SPaul Mundt puts(x); 10259f00296SPaul Mundt puts("\n\n -- System halted"); 10359f00296SPaul Mundt 10459f00296SPaul Mundt while(1); /* Halt */ 10559f00296SPaul Mundt } 10659f00296SPaul Mundt 1077bbaf27dSHuacai Chen const unsigned long __stack_chk_guard = 0x000a0dff; 108fb6cc4acSKees Cook 109fb6cc4acSKees Cook void __stack_chk_fail(void) 110fb6cc4acSKees Cook { 111fb6cc4acSKees Cook error("stack-protector: Kernel stack is corrupted\n"); 112fb6cc4acSKees Cook } 113fb6cc4acSKees Cook 114b83b43ffSSteven Rostedt (VMware) /* Needed because vmlinux.lds.h references this */ 115b83b43ffSSteven Rostedt (VMware) void ftrace_stub(void) 116b83b43ffSSteven Rostedt (VMware) { 117b83b43ffSSteven Rostedt (VMware) } 118b83b43ffSSteven Rostedt (VMware) 11959f00296SPaul Mundt #ifdef CONFIG_SUPERH64 12059f00296SPaul Mundt #define stackalign 8 12159f00296SPaul Mundt #else 12259f00296SPaul Mundt #define stackalign 4 12359f00296SPaul Mundt #endif 12459f00296SPaul Mundt 12559f00296SPaul Mundt #define STACK_SIZE (4096) 12659f00296SPaul Mundt long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE]; 12759f00296SPaul Mundt long *stack_start = &user_stack[STACK_SIZE]; 12859f00296SPaul Mundt 12959f00296SPaul Mundt void decompress_kernel(void) 13059f00296SPaul Mundt { 13159f00296SPaul Mundt unsigned long output_addr; 13259f00296SPaul Mundt 133040f43e0SPaul Mundt #ifdef CONFIG_SUPERH64 134040f43e0SPaul Mundt output_addr = (CONFIG_MEMORY_START + 0x2000); 135040f43e0SPaul Mundt #else 1368bd642b1SMatt Fleming output_addr = __pa((unsigned long)&_text+PAGE_SIZE); 137d01447b3SPaul Mundt #if defined(CONFIG_29BIT) 13859f00296SPaul Mundt output_addr |= P2SEG; 13959f00296SPaul Mundt #endif 140040f43e0SPaul Mundt #endif 14159f00296SPaul Mundt 14259f00296SPaul Mundt output = (unsigned char *)output_addr; 14359f00296SPaul Mundt free_mem_ptr = (unsigned long)&_end; 14459f00296SPaul Mundt free_mem_end_ptr = free_mem_ptr + HEAP_SIZE; 14559f00296SPaul Mundt 14659f00296SPaul Mundt puts("Uncompressing Linux... "); 14759f00296SPaul Mundt cache_control(CACHE_ENABLE); 1482d3862d2SYinghai Lu __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error); 14959f00296SPaul Mundt cache_control(CACHE_DISABLE); 15059f00296SPaul Mundt puts("Ok, booting the kernel.\n"); 15159f00296SPaul Mundt } 152