sh: bzip2/lzma zImage support.
[linux-2.6/kvm.git] / arch / sh / boot / compressed / misc_32.c
blobb86e3596918bb4f15fe30aaec244abedd162cfbe
1 /*
2 * arch/sh/boot/compressed/misc.c
4 * This is a collection of several routines from gzip-1.0.3
5 * adapted for Linux.
7 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
9 * Adapted for SH by Stuart Menefy, Aug 1999
11 * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
14 #include <asm/uaccess.h>
15 #include <asm/addrspace.h>
16 #include <asm/page.h>
17 #include <asm/sh_bios.h>
20 * gzip declarations
23 #define STATIC static
25 #undef memset
26 #undef memcpy
27 #define memzero(s, n) memset ((s), 0, (n))
29 static void error(char *m);
31 extern char input_data[];
32 extern int input_len;
33 static unsigned char *output;
35 static void error(char *m);
37 int puts(const char *);
39 extern int _text; /* Defined in vmlinux.lds.S */
40 extern int _end;
41 static unsigned long free_mem_ptr;
42 static unsigned long free_mem_end_ptr;
44 #ifdef CONFIG_HAVE_KERNEL_BZIP2
45 #define HEAP_SIZE 0x400000
46 #else
47 #define HEAP_SIZE 0x10000
48 #endif
50 #ifdef CONFIG_KERNEL_GZIP
51 #include "../../../../lib/decompress_inflate.c"
52 #endif
54 #ifdef CONFIG_KERNEL_BZIP2
55 #include "../../../../lib/decompress_bunzip2.c"
56 #endif
58 #ifdef CONFIG_KERNEL_LZMA
59 #include "../../../../lib/decompress_unlzma.c"
60 #endif
62 #ifdef CONFIG_SH_STANDARD_BIOS
63 size_t strlen(const char *s)
65 int i = 0;
67 while (*s++)
68 i++;
69 return i;
72 int puts(const char *s)
74 int len = strlen(s);
75 sh_bios_console_write(s, len);
76 return len;
78 #else
79 int puts(const char *s)
81 /* This should be updated to use the sh-sci routines */
82 return 0;
84 #endif
86 void* memset(void* s, int c, size_t n)
88 int i;
89 char *ss = (char*)s;
91 for (i=0;i<n;i++) ss[i] = c;
92 return s;
95 void* memcpy(void* __dest, __const void* __src,
96 size_t __n)
98 int i;
99 char *d = (char *)__dest, *s = (char *)__src;
101 for (i=0;i<__n;i++) d[i] = s[i];
102 return __dest;
105 static void error(char *x)
107 puts("\n\n");
108 puts(x);
109 puts("\n\n -- System halted");
111 while(1); /* Halt */
114 #define STACK_SIZE (4096)
115 long user_stack [STACK_SIZE];
116 long* stack_start = &user_stack[STACK_SIZE];
118 void decompress_kernel(void)
120 unsigned long output_addr;
122 output_addr = PHYSADDR((unsigned long)&_text+PAGE_SIZE);
123 #ifdef CONFIG_29BIT
124 output_addr |= P2SEG;
125 #endif
127 output = (unsigned char *)output_addr;
128 free_mem_ptr = (unsigned long)&_end;
129 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
131 puts("Uncompressing Linux... ");
132 decompress(input_data, input_len, NULL, NULL, output, NULL, error);
133 puts("Ok, booting the kernel.\n");