0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <linux/kernel.h>
0023 #include <linux/slab.h>
0024
0025 #include <linux/uaccess.h>
0026
0027 #define memzero(s,n) memset ((s),0,(n))
0028 #define puts srm_printk
0029 extern long srm_printk(const char *, ...)
0030 __attribute__ ((format (printf, 1, 2)));
0031
0032
0033
0034
0035 #define OF(args) args
0036 #define STATIC static
0037
0038 typedef unsigned char uch;
0039 typedef unsigned short ush;
0040 typedef unsigned long ulg;
0041
0042 #define WSIZE 0x8000
0043
0044
0045 static uch *inbuf;
0046 static uch *window;
0047
0048 static unsigned insize;
0049 static unsigned inptr;
0050 static unsigned outcnt;
0051
0052
0053 #define ASCII_FLAG 0x01
0054 #define CONTINUATION 0x02
0055 #define EXTRA_FIELD 0x04
0056 #define ORIG_NAME 0x08
0057 #define COMMENT 0x10
0058 #define ENCRYPTED 0x20
0059 #define RESERVED 0xC0
0060
0061 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
0062
0063
0064 #ifdef DEBUG
0065 # define Assert(cond,msg) {if(!(cond)) error(msg);}
0066 # define Trace(x) fprintf x
0067 # define Tracev(x) {if (verbose) fprintf x ;}
0068 # define Tracevv(x) {if (verbose>1) fprintf x ;}
0069 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
0070 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
0071 #else
0072 # define Assert(cond,msg)
0073 # define Trace(x)
0074 # define Tracev(x)
0075 # define Tracevv(x)
0076 # define Tracec(c,x)
0077 # define Tracecv(c,x)
0078 #endif
0079
0080 static int fill_inbuf(void);
0081 static void flush_window(void);
0082 static void error(char *m);
0083
0084 static char *input_data;
0085 static int input_data_size;
0086
0087 static uch *output_data;
0088 static ulg output_ptr;
0089 static ulg bytes_out;
0090
0091 static void error(char *m);
0092 static void gzip_mark(void **);
0093 static void gzip_release(void **);
0094
0095 extern int end;
0096 static ulg free_mem_ptr;
0097 static ulg free_mem_end_ptr;
0098
0099 #define HEAP_SIZE 0x3000
0100
0101 #include "../../../lib/inflate.c"
0102
0103
0104
0105
0106
0107 int fill_inbuf(void)
0108 {
0109 if (insize != 0)
0110 error("ran out of input data");
0111
0112 inbuf = input_data;
0113 insize = input_data_size;
0114
0115 inptr = 1;
0116 return inbuf[0];
0117 }
0118
0119
0120
0121
0122
0123 void flush_window(void)
0124 {
0125 ulg c = crc;
0126 unsigned n;
0127 uch *in, *out, ch;
0128
0129 in = window;
0130 out = &output_data[output_ptr];
0131 for (n = 0; n < outcnt; n++) {
0132 ch = *out++ = *in++;
0133 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
0134 }
0135 crc = c;
0136 bytes_out += (ulg)outcnt;
0137 output_ptr += (ulg)outcnt;
0138 outcnt = 0;
0139
0140 }
0141
0142 static void error(char *x)
0143 {
0144 puts("\n\n");
0145 puts(x);
0146 puts("\n\n -- System halted");
0147
0148 while(1);
0149 }
0150
0151 unsigned int
0152 decompress_kernel(void *output_start,
0153 void *input_start,
0154 size_t ksize,
0155 size_t kzsize)
0156 {
0157 output_data = (uch *)output_start;
0158 input_data = (uch *)input_start;
0159 input_data_size = kzsize;
0160
0161
0162 free_mem_ptr = (ulg)output_start + ksize;
0163 free_mem_end_ptr = (ulg)output_start + ksize + 0x200000;
0164
0165
0166
0167 window = malloc(WSIZE);
0168
0169 makecrc();
0170
0171 gunzip();
0172
0173 return output_ptr;
0174 }