Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | ||
7c0f6ba6 | 14 | #include <linux/uaccess.h> |
9d4436a6 | 15 | #include <asm/addrspace.h> |
e2dfb912 | 16 | #include <asm/page.h> |
1da177e4 LT |
17 | |
18 | /* | |
19 | * gzip declarations | |
20 | */ | |
21 | ||
1da177e4 LT |
22 | #define STATIC static |
23 | ||
24 | #undef memset | |
25 | #undef memcpy | |
26 | #define memzero(s, n) memset ((s), 0, (n)) | |
27 | ||
b14c6d42 PM |
28 | /* cache.c */ |
29 | #define CACHE_ENABLE 0 | |
30 | #define CACHE_DISABLE 1 | |
31 | int cache_control(unsigned int command); | |
1da177e4 LT |
32 | |
33 | extern char input_data[]; | |
34 | extern int input_len; | |
df8ce259 | 35 | static unsigned char *output; |
1da177e4 | 36 | |
1da177e4 | 37 | static void error(char *m); |
1da177e4 LT |
38 | |
39 | int puts(const char *); | |
40 | ||
41 | extern int _text; /* Defined in vmlinux.lds.S */ | |
42 | extern int _end; | |
43 | static unsigned long free_mem_ptr; | |
44 | static unsigned long free_mem_end_ptr; | |
45 | ||
07e88e1b PM |
46 | #ifdef CONFIG_HAVE_KERNEL_BZIP2 |
47 | #define HEAP_SIZE 0x400000 | |
48 | #else | |
49 | #define HEAP_SIZE 0x10000 | |
50 | #endif | |
1da177e4 | 51 | |
df8ce259 PM |
52 | #ifdef CONFIG_KERNEL_GZIP |
53 | #include "../../../../lib/decompress_inflate.c" | |
54 | #endif | |
1da177e4 | 55 | |
07e88e1b PM |
56 | #ifdef CONFIG_KERNEL_BZIP2 |
57 | #include "../../../../lib/decompress_bunzip2.c" | |
58 | #endif | |
59 | ||
60 | #ifdef CONFIG_KERNEL_LZMA | |
61 | #include "../../../../lib/decompress_unlzma.c" | |
62 | #endif | |
63 | ||
50cfa79d PM |
64 | #ifdef CONFIG_KERNEL_XZ |
65 | #include "../../../../lib/decompress_unxz.c" | |
66 | #endif | |
67 | ||
c7b16efb PM |
68 | #ifdef CONFIG_KERNEL_LZO |
69 | #include "../../../../lib/decompress_unlzo.c" | |
70 | #endif | |
71 | ||
1da177e4 LT |
72 | int puts(const char *s) |
73 | { | |
74 | /* This should be updated to use the sh-sci routines */ | |
75 | return 0; | |
76 | } | |
1da177e4 LT |
77 | |
78 | void* memset(void* s, int c, size_t n) | |
79 | { | |
80 | int i; | |
81 | char *ss = (char*)s; | |
82 | ||
83 | for (i=0;i<n;i++) ss[i] = c; | |
84 | return s; | |
85 | } | |
86 | ||
87 | void* memcpy(void* __dest, __const void* __src, | |
88 | size_t __n) | |
89 | { | |
90 | int i; | |
91 | char *d = (char *)__dest, *s = (char *)__src; | |
92 | ||
93 | for (i=0;i<__n;i++) d[i] = s[i]; | |
94 | return __dest; | |
95 | } | |
96 | ||
1da177e4 LT |
97 | static void error(char *x) |
98 | { | |
99 | puts("\n\n"); | |
100 | puts(x); | |
101 | puts("\n\n -- System halted"); | |
102 | ||
103 | while(1); /* Halt */ | |
104 | } | |
105 | ||
b14c6d42 PM |
106 | #ifdef CONFIG_SUPERH64 |
107 | #define stackalign 8 | |
108 | #else | |
109 | #define stackalign 4 | |
110 | #endif | |
111 | ||
1da177e4 | 112 | #define STACK_SIZE (4096) |
b14c6d42 PM |
113 | long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE]; |
114 | long *stack_start = &user_stack[STACK_SIZE]; | |
1da177e4 LT |
115 | |
116 | void decompress_kernel(void) | |
117 | { | |
df8ce259 PM |
118 | unsigned long output_addr; |
119 | ||
040f43e0 PM |
120 | #ifdef CONFIG_SUPERH64 |
121 | output_addr = (CONFIG_MEMORY_START + 0x2000); | |
122 | #else | |
8bd642b1 | 123 | output_addr = __pa((unsigned long)&_text+PAGE_SIZE); |
d01447b3 | 124 | #if defined(CONFIG_29BIT) |
df8ce259 | 125 | output_addr |= P2SEG; |
040f43e0 | 126 | #endif |
d02b08f6 | 127 | #endif |
df8ce259 PM |
128 | |
129 | output = (unsigned char *)output_addr; | |
1da177e4 LT |
130 | free_mem_ptr = (unsigned long)&_end; |
131 | free_mem_end_ptr = free_mem_ptr + HEAP_SIZE; | |
132 | ||
1da177e4 | 133 | puts("Uncompressing Linux... "); |
b14c6d42 | 134 | cache_control(CACHE_ENABLE); |
2d3862d2 | 135 | __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error); |
b14c6d42 | 136 | cache_control(CACHE_DISABLE); |
1da177e4 LT |
137 | puts("Ok, booting the kernel.\n"); |
138 | } |