blob: 4b319e9e4f886278647c1d4137a18029358e81d0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/boot/compressed/misc.c
3 *
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 SH by Stuart Menefy, Aug 1999
10 *
11 * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
12 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/uaccess.h>
Yoshinori Sato9d4436a2006-11-05 15:40:13 +090015#include <asm/addrspace.h>
Paul Mundte2dfb912006-12-12 08:53:29 +090016#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/sh_bios.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
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
Paul Mundtb14c6d42009-07-11 13:30:38 -040029/* cache.c */
30#define CACHE_ENABLE 0
31#define CACHE_DISABLE 1
32int cache_control(unsigned int command);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34extern char input_data[];
35extern int input_len;
Paul Mundtdf8ce252009-07-12 01:37:30 +090036static unsigned char *output;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static void error(char *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40int puts(const char *);
41
42extern int _text; /* Defined in vmlinux.lds.S */
43extern int _end;
44static unsigned long free_mem_ptr;
45static unsigned long free_mem_end_ptr;
46
Paul Mundt07e88e12009-07-11 13:21:19 -040047#ifdef CONFIG_HAVE_KERNEL_BZIP2
48#define HEAP_SIZE 0x400000
49#else
50#define HEAP_SIZE 0x10000
51#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Paul Mundtdf8ce252009-07-12 01:37:30 +090053#ifdef CONFIG_KERNEL_GZIP
54#include "../../../../lib/decompress_inflate.c"
55#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Paul Mundt07e88e12009-07-11 13:21:19 -040057#ifdef CONFIG_KERNEL_BZIP2
58#include "../../../../lib/decompress_bunzip2.c"
59#endif
60
61#ifdef CONFIG_KERNEL_LZMA
62#include "../../../../lib/decompress_unlzma.c"
63#endif
64
Paul Mundtc7b16ef2010-01-13 13:29:19 +090065#ifdef CONFIG_KERNEL_LZO
66#include "../../../../lib/decompress_unlzo.c"
67#endif
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#ifdef CONFIG_SH_STANDARD_BIOS
70size_t strlen(const char *s)
71{
72 int i = 0;
73
74 while (*s++)
75 i++;
76 return i;
77}
78
79int puts(const char *s)
80{
81 int len = strlen(s);
82 sh_bios_console_write(s, len);
83 return len;
84}
85#else
86int puts(const char *s)
87{
88 /* This should be updated to use the sh-sci routines */
89 return 0;
90}
91#endif
92
93void* memset(void* s, int c, size_t n)
94{
95 int i;
96 char *ss = (char*)s;
97
98 for (i=0;i<n;i++) ss[i] = c;
99 return s;
100}
101
102void* memcpy(void* __dest, __const void* __src,
103 size_t __n)
104{
105 int i;
106 char *d = (char *)__dest, *s = (char *)__src;
107
108 for (i=0;i<__n;i++) d[i] = s[i];
109 return __dest;
110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static void error(char *x)
113{
114 puts("\n\n");
115 puts(x);
116 puts("\n\n -- System halted");
117
118 while(1); /* Halt */
119}
120
Paul Mundtb14c6d42009-07-11 13:30:38 -0400121#ifdef CONFIG_SUPERH64
122#define stackalign 8
123#else
124#define stackalign 4
125#endif
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define STACK_SIZE (4096)
Paul Mundtb14c6d42009-07-11 13:30:38 -0400128long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
129long *stack_start = &user_stack[STACK_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131void decompress_kernel(void)
132{
Paul Mundtdf8ce252009-07-12 01:37:30 +0900133 unsigned long output_addr;
134
Paul Mundt040f43e2009-07-11 13:36:25 -0400135#ifdef CONFIG_SUPERH64
136 output_addr = (CONFIG_MEMORY_START + 0x2000);
137#else
Matt Fleming8bd642b2009-10-06 21:22:24 +0000138 output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900139#ifdef CONFIG_29BIT
Paul Mundtdf8ce252009-07-12 01:37:30 +0900140 output_addr |= P2SEG;
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900141#endif
Paul Mundt040f43e2009-07-11 13:36:25 -0400142#endif
Paul Mundtdf8ce252009-07-12 01:37:30 +0900143
144 output = (unsigned char *)output_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 free_mem_ptr = (unsigned long)&_end;
146 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 puts("Uncompressing Linux... ");
Paul Mundtb14c6d42009-07-11 13:30:38 -0400149 cache_control(CACHE_ENABLE);
Paul Mundtdf8ce252009-07-12 01:37:30 +0900150 decompress(input_data, input_len, NULL, NULL, output, NULL, error);
Paul Mundtb14c6d42009-07-11 13:30:38 -0400151 cache_control(CACHE_DISABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 puts("Ok, booting the kernel.\n");
153}