blob: b86e3596918bb4f15fe30aaec244abedd162cfbe [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
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;
Paul Mundtdf8ce252009-07-12 01:37:30 +090033static unsigned char *output;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static void error(char *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37int puts(const char *);
38
39extern int _text; /* Defined in vmlinux.lds.S */
40extern int _end;
41static unsigned long free_mem_ptr;
42static unsigned long free_mem_end_ptr;
43
Paul Mundt07e88e12009-07-11 13:21:19 -040044#ifdef CONFIG_HAVE_KERNEL_BZIP2
45#define HEAP_SIZE 0x400000
46#else
47#define HEAP_SIZE 0x10000
48#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Paul Mundtdf8ce252009-07-12 01:37:30 +090050#ifdef CONFIG_KERNEL_GZIP
51#include "../../../../lib/decompress_inflate.c"
52#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Paul Mundt07e88e12009-07-11 13:21:19 -040054#ifdef CONFIG_KERNEL_BZIP2
55#include "../../../../lib/decompress_bunzip2.c"
56#endif
57
58#ifdef CONFIG_KERNEL_LZMA
59#include "../../../../lib/decompress_unlzma.c"
60#endif
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#ifdef CONFIG_SH_STANDARD_BIOS
63size_t strlen(const char *s)
64{
65 int i = 0;
66
67 while (*s++)
68 i++;
69 return i;
70}
71
72int puts(const char *s)
73{
74 int len = strlen(s);
75 sh_bios_console_write(s, len);
76 return len;
77}
78#else
79int puts(const char *s)
80{
81 /* This should be updated to use the sh-sci routines */
82 return 0;
83}
84#endif
85
86void* memset(void* s, int c, size_t n)
87{
88 int i;
89 char *ss = (char*)s;
90
91 for (i=0;i<n;i++) ss[i] = c;
92 return s;
93}
94
95void* memcpy(void* __dest, __const void* __src,
96 size_t __n)
97{
98 int i;
99 char *d = (char *)__dest, *s = (char *)__src;
100
101 for (i=0;i<__n;i++) d[i] = s[i];
102 return __dest;
103}
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105static void error(char *x)
106{
107 puts("\n\n");
108 puts(x);
109 puts("\n\n -- System halted");
110
111 while(1); /* Halt */
112}
113
114#define STACK_SIZE (4096)
115long user_stack [STACK_SIZE];
116long* stack_start = &user_stack[STACK_SIZE];
117
118void decompress_kernel(void)
119{
Paul Mundtdf8ce252009-07-12 01:37:30 +0900120 unsigned long output_addr;
121
122 output_addr = PHYSADDR((unsigned long)&_text+PAGE_SIZE);
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900123#ifdef CONFIG_29BIT
Paul Mundtdf8ce252009-07-12 01:37:30 +0900124 output_addr |= P2SEG;
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900125#endif
Paul Mundtdf8ce252009-07-12 01:37:30 +0900126
127 output = (unsigned char *)output_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 free_mem_ptr = (unsigned long)&_end;
129 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 puts("Uncompressing Linux... ");
Paul Mundtdf8ce252009-07-12 01:37:30 +0900132 decompress(input_data, input_len, NULL, NULL, output, NULL, error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 puts("Ok, booting the kernel.\n");
134}