added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / arch / sh / boot / compressed / misc_64.c
blob2941657e18aafe3aad77352c574100771864728d
1 /*
2 * arch/sh/boot/compressed/misc_64.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 SHmedia from sh by Stuart Menefy, May 2002
12 #include <asm/uaccess.h>
14 /* cache.c */
15 #define CACHE_ENABLE 0
16 #define CACHE_DISABLE 1
17 int cache_control(unsigned int command);
20 * gzip declarations
23 #define OF(args) args
24 #define STATIC static
26 #undef memset
27 #undef memcpy
28 #define memzero(s, n) memset ((s), 0, (n))
30 typedef unsigned char uch;
31 typedef unsigned short ush;
32 typedef unsigned long ulg;
34 #define WSIZE 0x8000 /* Window size must be at least 32k, */
35 /* and a power of two */
37 static uch *inbuf; /* input buffer */
38 static uch window[WSIZE]; /* Sliding window buffer */
40 static unsigned insize = 0; /* valid bytes in inbuf */
41 static unsigned inptr = 0; /* index of next byte to be processed in inbuf */
42 static unsigned outcnt = 0; /* bytes in output buffer */
44 /* gzip flag byte */
45 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
46 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
47 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
48 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
49 #define COMMENT 0x10 /* bit 4 set: file comment present */
50 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
51 #define RESERVED 0xC0 /* bit 6,7: reserved */
53 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
55 /* Diagnostic functions */
56 #ifdef DEBUG
57 # define Assert(cond,msg) {if(!(cond)) error(msg);}
58 # define Trace(x) fprintf x
59 # define Tracev(x) {if (verbose) fprintf x ;}
60 # define Tracevv(x) {if (verbose>1) fprintf x ;}
61 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
62 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
63 #else
64 # define Assert(cond,msg)
65 # define Trace(x)
66 # define Tracev(x)
67 # define Tracevv(x)
68 # define Tracec(c,x)
69 # define Tracecv(c,x)
70 #endif
72 static int fill_inbuf(void);
73 static void flush_window(void);
74 static void error(char *m);
76 extern char input_data[];
77 extern int input_len;
79 static long bytes_out = 0;
80 static uch *output_data;
81 static unsigned long output_ptr = 0;
83 static void error(char *m);
85 static void puts(const char *);
87 extern int _text; /* Defined in vmlinux.lds.S */
88 extern int _end;
89 static unsigned long free_mem_ptr;
90 static unsigned long free_mem_end_ptr;
92 #define HEAP_SIZE 0x10000
94 #include "../../../../lib/inflate.c"
96 void puts(const char *s)
100 void *memset(void *s, int c, size_t n)
102 int i;
103 char *ss = (char *) s;
105 for (i = 0; i < n; i++)
106 ss[i] = c;
107 return s;
110 void *memcpy(void *__dest, __const void *__src, size_t __n)
112 int i;
113 char *d = (char *) __dest, *s = (char *) __src;
115 for (i = 0; i < __n; i++)
116 d[i] = s[i];
117 return __dest;
120 /* ===========================================================================
121 * Fill the input buffer. This is called only when the buffer is empty
122 * and at least one byte is really needed.
124 static int fill_inbuf(void)
126 if (insize != 0) {
127 error("ran out of input data\n");
130 inbuf = input_data;
131 insize = input_len;
132 inptr = 1;
133 return inbuf[0];
136 /* ===========================================================================
137 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
138 * (Used for the decompressed data only.)
140 static void flush_window(void)
142 ulg c = crc; /* temporary variable */
143 unsigned n;
144 uch *in, *out, ch;
146 in = window;
147 out = &output_data[output_ptr];
148 for (n = 0; n < outcnt; n++) {
149 ch = *out++ = *in++;
150 c = crc_32_tab[((int) c ^ ch) & 0xff] ^ (c >> 8);
152 crc = c;
153 bytes_out += (ulg) outcnt;
154 output_ptr += (ulg) outcnt;
155 outcnt = 0;
156 puts(".");
159 static void error(char *x)
161 puts("\n\n");
162 puts(x);
163 puts("\n\n -- System halted");
165 while (1) ; /* Halt */
168 #define STACK_SIZE (4096)
169 long __attribute__ ((aligned(8))) user_stack[STACK_SIZE];
170 long *stack_start = &user_stack[STACK_SIZE];
172 void decompress_kernel(void)
174 output_data = (uch *) (CONFIG_MEMORY_START + 0x2000);
175 free_mem_ptr = (unsigned long) &_end;
176 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
178 makecrc();
179 puts("Uncompressing Linux... ");
180 cache_control(CACHE_ENABLE);
181 gunzip();
182 puts("\n");
184 #if 0
185 /* When booting from ROM may want to do something like this if the
186 * boot loader doesn't.
189 /* Set up the parameters and command line */
191 volatile unsigned int *parambase =
192 (int *) (CONFIG_MEMORY_START + 0x1000);
194 parambase[0] = 0x1; /* MOUNT_ROOT_RDONLY */
195 parambase[1] = 0x0; /* RAMDISK_FLAGS */
196 parambase[2] = 0x0200; /* ORIG_ROOT_DEV */
197 parambase[3] = 0x0; /* LOADER_TYPE */
198 parambase[4] = 0x0; /* INITRD_START */
199 parambase[5] = 0x0; /* INITRD_SIZE */
200 parambase[6] = 0;
202 strcpy((char *) ((int) parambase + 0x100),
203 "console=ttySC0,38400");
205 #endif
207 puts("Ok, booting the kernel.\n");
209 cache_control(CACHE_DISABLE);