1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/kernel.h>
22
23#include <asm/uaccess.h>
24
25#define memzero(s,n) memset ((s),0,(n))
26#define puts srm_printk
27extern long srm_printk(const char *, ...)
28 __attribute__ ((format (printf, 1, 2)));
29
30
31
32
33#define OF(args) args
34#define STATIC static
35
36typedef unsigned char uch;
37typedef unsigned short ush;
38typedef unsigned long ulg;
39
40#define WSIZE 0x8000
41
42
43static uch *inbuf;
44static uch *window;
45
46static unsigned insize;
47static unsigned inptr;
48static unsigned outcnt;
49
50
51#define ASCII_FLAG 0x01
52#define CONTINUATION 0x02
53#define EXTRA_FIELD 0x04
54#define ORIG_NAME 0x08
55#define COMMENT 0x10
56#define ENCRYPTED 0x20
57#define RESERVED 0xC0
58
59#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
60
61
62#ifdef DEBUG
63# define Assert(cond,msg) {if(!(cond)) error(msg);}
64# define Trace(x) fprintf x
65# define Tracev(x) {if (verbose) fprintf x ;}
66# define Tracevv(x) {if (verbose>1) fprintf x ;}
67# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
68# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
69#else
70# define Assert(cond,msg)
71# define Trace(x)
72# define Tracev(x)
73# define Tracevv(x)
74# define Tracec(c,x)
75# define Tracecv(c,x)
76#endif
77
78static int fill_inbuf(void);
79static void flush_window(void);
80static void error(char *m);
81
82static char *input_data;
83static int input_data_size;
84
85static uch *output_data;
86static ulg output_ptr;
87static ulg bytes_out;
88
89static void error(char *m);
90static void gzip_mark(void **);
91static void gzip_release(void **);
92
93extern int end;
94static ulg free_mem_ptr;
95static ulg free_mem_end_ptr;
96
97#define HEAP_SIZE 0x3000
98
99#include "../../../lib/inflate.c"
100
101
102
103
104
105int fill_inbuf(void)
106{
107 if (insize != 0)
108 error("ran out of input data");
109
110 inbuf = input_data;
111 insize = input_data_size;
112
113 inptr = 1;
114 return inbuf[0];
115}
116
117
118
119
120
121void flush_window(void)
122{
123 ulg c = crc;
124 unsigned n;
125 uch *in, *out, ch;
126
127 in = window;
128 out = &output_data[output_ptr];
129 for (n = 0; n < outcnt; n++) {
130 ch = *out++ = *in++;
131 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
132 }
133 crc = c;
134 bytes_out += (ulg)outcnt;
135 output_ptr += (ulg)outcnt;
136 outcnt = 0;
137
138}
139
140static void error(char *x)
141{
142 puts("\n\n");
143 puts(x);
144 puts("\n\n -- System halted");
145
146 while(1);
147}
148
149unsigned int
150decompress_kernel(void *output_start,
151 void *input_start,
152 size_t ksize,
153 size_t kzsize)
154{
155 output_data = (uch *)output_start;
156 input_data = (uch *)input_start;
157 input_data_size = kzsize;
158
159
160 free_mem_ptr = (ulg)output_start + ksize;
161 free_mem_end_ptr = (ulg)output_start + ksize + 0x200000;
162
163
164
165 window = malloc(WSIZE);
166
167 makecrc();
168
169 gunzip();
170
171 return output_ptr;
172}
173