blob: 09b7b7cd24f9dd562b34b910632a94d3e94c819f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Paul Mundta23ba432007-11-28 20:19:38 +09002 * arch/sh/boot/compressed/misc_64.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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 SHmedia from sh by Stuart Menefy, May 2002
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/uaccess.h>
13
14/* cache.c */
15#define CACHE_ENABLE 0
16#define CACHE_DISABLE 1
17int cache_control(unsigned int command);
18
19/*
20 * gzip declarations
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#define STATIC static
24
25#undef memset
26#undef memcpy
27#define memzero(s, n) memset ((s), 0, (n))
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static void error(char *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31extern char input_data[];
32extern int input_len;
33
Paul Mundtdf8ce252009-07-12 01:37:30 +090034static unsigned char *output_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static void puts(const char *);
37
38extern int _text; /* Defined in vmlinux.lds.S */
39extern int _end;
40static unsigned long free_mem_ptr;
41static unsigned long free_mem_end_ptr;
42
Paul Mundt07e88e12009-07-11 13:21:19 -040043#ifdef CONFIG_HAVE_KERNEL_BZIP2
44#define HEAP_SIZE 0x400000
45#else
46#define HEAP_SIZE 0x10000
47#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Paul Mundtdf8ce252009-07-12 01:37:30 +090049#ifdef CONFIG_KERNEL_GZIP
50#include "../../../../lib/decompress_inflate.c"
51#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Paul Mundt07e88e12009-07-11 13:21:19 -040053#ifdef CONFIG_KERNEL_BZIP2
54#include "../../../../lib/decompress_bunzip2.c"
55#endif
56
57#ifdef CONFIG_KERNEL_LZMA
58#include "../../../../lib/decompress_unlzma.c"
59#endif
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061void puts(const char *s)
62{
63}
64
65void *memset(void *s, int c, size_t n)
66{
67 int i;
68 char *ss = (char *) s;
69
70 for (i = 0; i < n; i++)
71 ss[i] = c;
72 return s;
73}
74
75void *memcpy(void *__dest, __const void *__src, size_t __n)
76{
77 int i;
78 char *d = (char *) __dest, *s = (char *) __src;
79
80 for (i = 0; i < __n; i++)
81 d[i] = s[i];
82 return __dest;
83}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static void error(char *x)
86{
87 puts("\n\n");
88 puts(x);
89 puts("\n\n -- System halted");
90
91 while (1) ; /* Halt */
92}
93
94#define STACK_SIZE (4096)
95long __attribute__ ((aligned(8))) user_stack[STACK_SIZE];
96long *stack_start = &user_stack[STACK_SIZE];
97
98void decompress_kernel(void)
99{
Paul Mundtdf8ce252009-07-12 01:37:30 +0900100 output_data = (unsigned char *) (CONFIG_MEMORY_START + 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 free_mem_ptr = (unsigned long) &_end;
102 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 puts("Uncompressing Linux... ");
105 cache_control(CACHE_ENABLE);
Paul Mundtdf8ce252009-07-12 01:37:30 +0900106 decompress(input_data, input_len, NULL, NULL, output_data, NULL, error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 cache_control(CACHE_DISABLE);
Paul Mundtdf8ce252009-07-12 01:37:30 +0900108 puts("Ok, booting the kernel.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}