misc.c (b22364c8eec89e6b0c081a237f3b6348df87796f) misc.c (59f002964f4e6668a0132cd796b82f7f8a4803f0)
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
14#include <asm/uaccess.h>
15#include <asm/addrspace.h>
16#include <asm/page.h>
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
14#include <asm/uaccess.h>
15#include <asm/addrspace.h>
16#include <asm/page.h>
17#ifdef CONFIG_SH_STANDARD_BIOS
18#include <asm/sh_bios.h>
17#include <asm/sh_bios.h>
19#endif
20
21/*
22 * gzip declarations
23 */
24
18
19/*
20 * gzip declarations
21 */
22
25#define OF(args) args
26#define STATIC static
27
28#undef memset
29#undef memcpy
30#define memzero(s, n) memset ((s), 0, (n))
31
23#define STATIC static
24
25#undef memset
26#undef memcpy
27#define memzero(s, n) memset ((s), 0, (n))
28
32typedef unsigned char uch;
33typedef unsigned short ush;
34typedef unsigned long ulg;
29/* cache.c */
30#define CACHE_ENABLE 0
31#define CACHE_DISABLE 1
32int cache_control(unsigned int command);
35
33
36#define WSIZE 0x8000 /* Window size must be at least 32k, */
37 /* and a power of two */
38
39static uch *inbuf; /* input buffer */
40static uch window[WSIZE]; /* Sliding window buffer */
41
42static unsigned insize = 0; /* valid bytes in inbuf */
43static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
44static unsigned outcnt = 0; /* bytes in output buffer */
45
46/* gzip flag byte */
47#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
48#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
49#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
50#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
51#define COMMENT 0x10 /* bit 4 set: file comment present */
52#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
53#define RESERVED 0xC0 /* bit 6,7: reserved */
54
55#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
56
57/* Diagnostic functions */
58#ifdef DEBUG
59# define Assert(cond,msg) {if(!(cond)) error(msg);}
60# define Trace(x) fprintf x
61# define Tracev(x) {if (verbose) fprintf x ;}
62# define Tracevv(x) {if (verbose>1) fprintf x ;}
63# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
64# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
65#else
66# define Assert(cond,msg)
67# define Trace(x)
68# define Tracev(x)
69# define Tracevv(x)
70# define Tracec(c,x)
71# define Tracecv(c,x)
72#endif
73
74static int fill_inbuf(void);
75static void flush_window(void);
76static void error(char *m);
77static void gzip_mark(void **);
78static void gzip_release(void **);
79
80extern char input_data[];
81extern int input_len;
34extern char input_data[];
35extern int input_len;
36static unsigned char *output;
82
37
83static long bytes_out = 0;
84static uch *output_data;
85static unsigned long output_ptr = 0;
86
87static void *malloc(int size);
88static void free(void *where);
89static void error(char *m);
38static void error(char *m);
90static void gzip_mark(void **);
91static void gzip_release(void **);
92
93int puts(const char *);
94
95extern int _text; /* Defined in vmlinux.lds.S */
96extern int _end;
97static unsigned long free_mem_ptr;
98static unsigned long free_mem_end_ptr;
99
39
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
100#define HEAP_SIZE 0x10000
47#ifdef CONFIG_HAVE_KERNEL_BZIP2
48#define HEAP_SIZE 0x400000
49#else
50#define HEAP_SIZE 0x10000
51#endif
101
52
102#include "../../../../lib/inflate.c"
53#ifdef CONFIG_KERNEL_GZIP
54#include "../../../../lib/decompress_inflate.c"
55#endif
103
56
104static void *malloc(int size)
105{
106 void *p;
57#ifdef CONFIG_KERNEL_BZIP2
58#include "../../../../lib/decompress_bunzip2.c"
59#endif
107
60
108 if (size <0) error("Malloc error");
109 if (free_mem_ptr == 0) error("Memory error");
61#ifdef CONFIG_KERNEL_LZMA
62#include "../../../../lib/decompress_unlzma.c"
63#endif
110
64
111 free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
112
113 p = (void *)free_mem_ptr;
114 free_mem_ptr += size;
115
116 if (free_mem_ptr >= free_mem_end_ptr)
117 error("Out of memory");
118
119 return p;
120}
121
122static void free(void *where)
123{ /* Don't care */
124}
125
126static void gzip_mark(void **ptr)
127{
128 *ptr = (void *) free_mem_ptr;
129}
130
131static void gzip_release(void **ptr)
132{
133 free_mem_ptr = (long) *ptr;
134}
135
136#ifdef CONFIG_SH_STANDARD_BIOS
137size_t strlen(const char *s)
138{
139 int i = 0;
140
141 while (*s++)
142 i++;
143 return i;

--- 27 unchanged lines hidden (view full) ---

171{
172 int i;
173 char *d = (char *)__dest, *s = (char *)__src;
174
175 for (i=0;i<__n;i++) d[i] = s[i];
176 return __dest;
177}
178
65#ifdef CONFIG_SH_STANDARD_BIOS
66size_t strlen(const char *s)
67{
68 int i = 0;
69
70 while (*s++)
71 i++;
72 return i;

--- 27 unchanged lines hidden (view full) ---

100{
101 int i;
102 char *d = (char *)__dest, *s = (char *)__src;
103
104 for (i=0;i<__n;i++) d[i] = s[i];
105 return __dest;
106}
107
179/* ===========================================================================
180 * Fill the input buffer. This is called only when the buffer is empty
181 * and at least one byte is really needed.
182 */
183static int fill_inbuf(void)
184{
185 if (insize != 0) {
186 error("ran out of input data");
187 }
188
189 inbuf = input_data;
190 insize = input_len;
191 inptr = 1;
192 return inbuf[0];
193}
194
195/* ===========================================================================
196 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
197 * (Used for the decompressed data only.)
198 */
199static void flush_window(void)
200{
201 ulg c = crc; /* temporary variable */
202 unsigned n;
203 uch *in, *out, ch;
204
205 in = window;
206 out = &output_data[output_ptr];
207 for (n = 0; n < outcnt; n++) {
208 ch = *out++ = *in++;
209 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
210 }
211 crc = c;
212 bytes_out += (ulg)outcnt;
213 output_ptr += (ulg)outcnt;
214 outcnt = 0;
215}
216
217static void error(char *x)
218{
219 puts("\n\n");
220 puts(x);
221 puts("\n\n -- System halted");
222
223 while(1); /* Halt */
224}
225
108static void error(char *x)
109{
110 puts("\n\n");
111 puts(x);
112 puts("\n\n -- System halted");
113
114 while(1); /* Halt */
115}
116
117#ifdef CONFIG_SUPERH64
118#define stackalign 8
119#else
120#define stackalign 4
121#endif
122
226#define STACK_SIZE (4096)
123#define STACK_SIZE (4096)
227long user_stack [STACK_SIZE];
228long* stack_start = &user_stack[STACK_SIZE];
124long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
125long *stack_start = &user_stack[STACK_SIZE];
229
230void decompress_kernel(void)
231{
126
127void decompress_kernel(void)
128{
232 output_data = 0;
233 output_ptr = P2SEGADDR((unsigned long)&_text+PAGE_SIZE);
129 unsigned long output_addr;
130
131 output_addr = PHYSADDR((unsigned long)&_text+PAGE_SIZE);
132#ifdef CONFIG_29BIT
133 output_addr |= P2SEG;
134#endif
135
136 output = (unsigned char *)output_addr;
234 free_mem_ptr = (unsigned long)&_end;
235 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
236
137 free_mem_ptr = (unsigned long)&_end;
138 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
139
237 makecrc();
238 puts("Uncompressing Linux... ");
140 puts("Uncompressing Linux... ");
239 gunzip();
141 cache_control(CACHE_ENABLE);
142 decompress(input_data, input_len, NULL, NULL, output, NULL, error);
143 cache_control(CACHE_DISABLE);
240 puts("Ok, booting the kernel.\n");
241}
144 puts("Ok, booting the kernel.\n");
145}