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