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