OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [armnommu/] [boot/] [compressed/] [misc.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
/*
2
 * 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
 
10
#include <asm/segment.h>
11
#include <asm/arch/uncompress.h>
12
#include <asm/proc/uncompress.h>
13
 
14
#ifdef STANDALONE_DEBUG
15
#define puts printf
16
#endif
17
 
18
#define __ptr_t void *
19
 
20
/*
21
 * Optimised C version of memzero for the ARM.
22
 */
23
extern __inline__ __ptr_t __memzero (__ptr_t s, size_t n)
24
{
25
        union { void *vp; unsigned long *ulp; unsigned char *ucp; } u;
26
        int i;
27
 
28
        u.vp = s;
29
 
30
        for (i = n >> 5; i > 0; i--) {
31
                *u.ulp++ = 0;
32
                *u.ulp++ = 0;
33
                *u.ulp++ = 0;
34
                *u.ulp++ = 0;
35
                *u.ulp++ = 0;
36
                *u.ulp++ = 0;
37
                *u.ulp++ = 0;
38
                *u.ulp++ = 0;
39
        }
40
 
41
        if (n & 1 << 4) {
42
                *u.ulp++ = 0;
43
                *u.ulp++ = 0;
44
                *u.ulp++ = 0;
45
                *u.ulp++ = 0;
46
        }
47
 
48
        if (n & 1 << 3) {
49
                *u.ulp++ = 0;
50
                *u.ulp++ = 0;
51
        }
52
 
53
        if (n & 1 << 2)
54
                *u.ulp++ = 0;
55
 
56
        if (n & 1 << 1) {
57
                *u.ucp++ = 0;
58
                *u.ucp++ = 0;
59
        }
60
 
61
        if (n & 1)
62
                *u.ucp++ = 0;
63
        return s;
64
}
65
 
66
#define memzero(s,n) __memzero(s,n)
67
 
68
extern __inline__ __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src,
69
                            size_t __n)
70
{
71
        int i = 0;
72
        unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
73
 
74
        for (i = __n >> 3; i > 0; i--) {
75
                *d++ = *s++;
76
                *d++ = *s++;
77
                *d++ = *s++;
78
                *d++ = *s++;
79
                *d++ = *s++;
80
                *d++ = *s++;
81
                *d++ = *s++;
82
                *d++ = *s++;
83
        }
84
 
85
        if (__n & 1 << 2) {
86
                *d++ = *s++;
87
                *d++ = *s++;
88
                *d++ = *s++;
89
                *d++ = *s++;
90
        }
91
 
92
        if (__n & 1 << 1) {
93
                *d++ = *s++;
94
                *d++ = *s++;
95
        }
96
 
97
        if (__n & 1)
98
                *d++ = *s++;
99
 
100
        return __dest;
101
}
102
 
103
/*
104
 * gzip delarations
105
 */
106
#define OF(args)  args
107
#define STATIC static
108
 
109
typedef unsigned char  uch;
110
typedef unsigned short ush;
111
typedef unsigned long  ulg;
112
 
113
#define WSIZE 0x8000            /* Window size must be at least 32k, */
114
                                /* and a power of two */
115
 
116
static uch *inbuf;              /* input buffer */
117
static uch window[WSIZE];       /* Sliding window buffer */
118
 
119
static unsigned insize;         /* valid bytes in inbuf */
120
static unsigned inptr;          /* index of next byte to be processed in inbuf */
121
static unsigned outcnt;         /* bytes in output buffer */
122
 
123
/* gzip flag byte */
124
#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
125
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
126
#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
127
#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
128
#define COMMENT      0x10 /* bit 4 set: file comment present */
129
#define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
130
#define RESERVED     0xC0 /* bit 6,7:   reserved */
131
 
132
#define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf())
133
 
134
/* Diagnostic functions */
135
#ifdef DEBUG
136
#  define Assert(cond,msg) {if(!(cond)) error(msg);}
137
#  define Trace(x) fprintf x
138
#  define Tracev(x) {if (verbose) fprintf x ;}
139
#  define Tracevv(x) {if (verbose>1) fprintf x ;}
140
#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
141
#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
142
#else
143
#  define Assert(cond,msg)
144
#  define Trace(x)
145
#  define Tracev(x)
146
#  define Tracevv(x)
147
#  define Tracec(c,x)
148
#  define Tracecv(c,x)
149
#endif
150
 
151
static int  fill_inbuf(void);
152
static void flush_window(void);
153
static void error(char *m);
154
static void gzip_mark(void **);
155
static void gzip_release(void **);
156
 
157
extern char input_data[], input_end[];
158
 
159
static uch *output_data;
160
static ulg output_ptr;
161
static ulg bytes_out;
162
 
163
static void *malloc(int size);
164
static void free(void *where);
165
static void error(char *m);
166
static void gzip_mark(void **);
167
static void gzip_release(void **);
168
 
169
static void puts(const char *);
170
 
171
extern int end;
172
static ulg free_mem_ptr;
173
static ulg free_mem_ptr_end;
174
 
175
#define HEAP_SIZE 0x2000
176
 
177
#include "../../../../lib/inflate.c"
178
 
179
#ifndef STANDALONE_DEBUG
180
static void *malloc(int size)
181
{
182
        void *p;
183
 
184
        if (size <0) error("Malloc error\n");
185
        if (free_mem_ptr <= 0) error("Memory error\n");
186
 
187
        free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
188
 
189
        p = (void *)free_mem_ptr;
190
        free_mem_ptr += size;
191
 
192
        if (free_mem_ptr >= free_mem_ptr_end)
193
                error("Out of memory");
194
        return p;
195
}
196
 
197
static void free(void *where)
198
{ /* gzip_mark & gzip_release do the free */
199
}
200
 
201
static void gzip_mark(void **ptr)
202
{
203
        *ptr = (void *) free_mem_ptr;
204
}
205
 
206
static void gzip_release(void **ptr)
207
{
208
        free_mem_ptr = (long) *ptr;
209
}
210
#else
211
static void gzip_mark(void **ptr)
212
{
213
}
214
 
215
static void gzip_release(void **ptr)
216
{
217
}
218
#endif
219
 
220
/* ===========================================================================
221
 * Fill the input buffer. This is called only when the buffer is empty
222
 * and at least one byte is really needed.
223
 */
224
int fill_inbuf()
225
{
226
        if (insize != 0)
227
                error("ran out of input data\n");
228
 
229
        inbuf = input_data;
230
        insize = input_end - input_data;
231
        inptr = 1;
232
        return inbuf[0];
233
}
234
 
235
/* ===========================================================================
236
 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
237
 * (Used for the decompressed data only.)
238
 */
239
void flush_window()
240
{
241
        ulg c = crc;
242
        unsigned n;
243
        uch *in, *out, ch;
244
 
245
        in = window;
246
        out = &output_data[output_ptr];
247
        for (n = 0; n < outcnt; n++) {
248
                ch = *out++ = *in++;
249
                c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
250
        }
251
        crc = c;
252
        bytes_out += (ulg)outcnt;
253
        output_ptr += (ulg)outcnt;
254
        outcnt = 0;
255
}
256
 
257
static void error(char *x)
258
{
259
        int ptr;
260
 
261
        puts("\n\n");
262
        puts(x);
263
        puts("\n\n -- System halted");
264
 
265
        while(1);       /* Halt */
266
}
267
 
268
#define STACK_SIZE (4096)
269
 
270
ulg user_stack [STACK_SIZE];
271
 
272
#ifndef STANDALONE_DEBUG
273
 
274
ulg decompress_kernel(ulg output_start)
275
{
276
        free_mem_ptr = (ulg)&end;
277
        free_mem_ptr_end = output_start;
278
 
279
        proc_decomp_setup ();
280
        arch_decomp_setup ();
281
 
282
        output_data = (uch *)output_start;      /* Points to kernel start */
283
 
284
        makecrc();
285
        puts("Uncompressing Linux...");
286
        gunzip();
287
        puts("done.\nNow booting the kernel\n");
288
        return output_ptr;
289
}
290
#else
291
 
292
char output_buffer[1024*1024];
293
 
294
int main()
295
{
296
        output_data = output_buffer;
297
 
298
        makecrc();
299
        puts("Uncompressing Linux...");
300
        gunzip();
301
        puts("done.\n");
302
        return 0;
303
}
304
#endif
305
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.