2 * Definitions and wrapper functions for kernel decompressor
4 * Copyright IBM Corp. 2010
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
9 #include <asm/uaccess.h>
22 #define memzero(s, n) memset((s), 0, (n))
24 /* Symbols defined by linker scripts */
25 extern char input_data
[];
27 extern char _text
, _end
;
28 extern char _bss
, _ebss
;
30 static void error(char *m
);
32 static unsigned long free_mem_ptr
;
33 static unsigned long free_mem_end_ptr
;
35 #ifdef CONFIG_HAVE_KERNEL_BZIP2
36 #define HEAP_SIZE 0x400000
38 #define HEAP_SIZE 0x10000
41 #ifdef CONFIG_KERNEL_GZIP
42 #include "../../../../lib/decompress_inflate.c"
45 #ifdef CONFIG_KERNEL_BZIP2
46 #include "../../../../lib/decompress_bunzip2.c"
49 #ifdef CONFIG_KERNEL_LZMA
50 #include "../../../../lib/decompress_unlzma.c"
53 #ifdef CONFIG_KERNEL_LZO
54 #include "../../../../lib/decompress_unlzo.c"
57 extern _sclp_print_early(const char *);
59 int puts(const char *s
)
65 void *memset(void *s
, int c
, size_t n
)
70 return __builtin_memset(s
, 0, n
);
80 void *memcpy(void *__dest
, __const
void *__src
, size_t __n
)
82 return __builtin_memcpy(__dest
, __src
, __n
);
85 void *memmove(void *__dest
, __const
void *__src
, size_t __n
)
91 return __builtin_memcpy(__dest
, __src
, __n
);
99 static void error(char *x
)
101 unsigned long long psw
= 0x000a0000deadbeefULL
;
105 puts("\n\n -- System halted");
107 asm volatile("lpsw %0" : : "Q" (psw
));
111 * Safe guard the ipl parameter block against a memory area that will be
112 * overwritten. The validity check for the ipl parameter block is complex
113 * (see cio_get_iplinfo and ipl_save_parameters) but if the pointer to
114 * the ipl parameter block intersects with the passed memory area we can
115 * safely assume that we can read from that memory. In that case just copy
116 * the memory to IPL_PARMBLOCK_ORIGIN even if there is no ipl parameter
119 static void check_ipl_parmblock(void *start
, unsigned long size
)
123 src
= (void *)(unsigned long) S390_lowcore
.ipl_parmblock_ptr
;
124 if (src
+ PAGE_SIZE
<= start
|| src
>= start
+ size
)
126 dst
= (void *) IPL_PARMBLOCK_ORIGIN
;
127 memmove(dst
, src
, PAGE_SIZE
);
128 S390_lowcore
.ipl_parmblock_ptr
= IPL_PARMBLOCK_ORIGIN
;
131 unsigned long decompress_kernel(void)
133 unsigned long output_addr
;
134 unsigned char *output
;
136 check_ipl_parmblock((void *) 0, (unsigned long) output
+ SZ__bss_start
);
137 memset(&_bss
, 0, &_ebss
- &_bss
);
138 free_mem_ptr
= (unsigned long)&_end
;
139 free_mem_end_ptr
= free_mem_ptr
+ HEAP_SIZE
;
140 output
= (unsigned char *) ((free_mem_end_ptr
+ 4095UL) & -4096UL);
142 #ifdef CONFIG_BLK_DEV_INITRD
144 * Move the initrd right behind the end of the decompressed
147 if (INITRD_START
&& INITRD_SIZE
&&
148 INITRD_START
< (unsigned long) output
+ SZ__bss_start
) {
149 check_ipl_parmblock(output
+ SZ__bss_start
,
150 INITRD_START
+ INITRD_SIZE
);
151 memmove(output
+ SZ__bss_start
,
152 (void *) INITRD_START
, INITRD_SIZE
);
153 INITRD_START
= (unsigned long) output
+ SZ__bss_start
;
157 puts("Uncompressing Linux... ");
158 decompress(input_data
, input_len
, NULL
, NULL
, output
, NULL
, error
);
159 puts("Ok, booting the kernel.\n");
160 return (unsigned long) output
;