aboutsummaryrefslogtreecommitdiffstats
path: root/arch/xtensa/boot/lib/zmem.c
diff options
context:
space:
mode:
authorChris Zankel <czankel@tensilica.com>2005-06-24 01:01:12 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-24 03:05:21 -0400
commit4bedea94545165364618d403d03b61d797acba0b (patch)
tree04626bb71e0fb5ea5c5d5aa4fedc813301bea6a6 /arch/xtensa/boot/lib/zmem.c
parent8e1a6dd2fddcc73c9e933758361e3d9c076c688a (diff)
[PATCH] xtensa: Architecture support for Tensilica Xtensa Part 2
The attached patches provides part 2 of an architecture implementation for the Tensilica Xtensa CPU series. Signed-off-by: Chris Zankel <chris@zankel.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/xtensa/boot/lib/zmem.c')
-rw-r--r--arch/xtensa/boot/lib/zmem.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/arch/xtensa/boot/lib/zmem.c b/arch/xtensa/boot/lib/zmem.c
new file mode 100644
index 000000000000..7848f126d67d
--- /dev/null
+++ b/arch/xtensa/boot/lib/zmem.c
@@ -0,0 +1,87 @@
1#include "zlib.h"
2
3/* bits taken from ppc */
4
5extern void *avail_ram, *end_avail;
6
7void exit (void)
8{
9 for (;;);
10}
11
12void *zalloc(void *x, unsigned items, unsigned size)
13{
14 void *p = avail_ram;
15
16 size *= items;
17 size = (size + 7) & -8;
18 avail_ram += size;
19 if (avail_ram > end_avail) {
20 //puts("oops... out of memory\n");
21 //pause();
22 exit ();
23 }
24 return p;
25}
26
27void zfree(void *x, void *addr, unsigned nb)
28{
29}
30
31
32#define HEAD_CRC 2
33#define EXTRA_FIELD 4
34#define ORIG_NAME 8
35#define COMMENT 0x10
36#define RESERVED 0xe0
37
38#define DEFLATED 8
39
40void gunzip (void *dst, int dstlen, unsigned char *src, int *lenp)
41{
42 z_stream s;
43 int r, i, flags;
44
45 /* skip header */
46
47 i = 10;
48 flags = src[3];
49 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
50 //puts("bad gzipped data\n");
51 exit();
52 }
53 if ((flags & EXTRA_FIELD) != 0)
54 i = 12 + src[10] + (src[11] << 8);
55 if ((flags & ORIG_NAME) != 0)
56 while (src[i++] != 0)
57 ;
58 if ((flags & COMMENT) != 0)
59 while (src[i++] != 0)
60 ;
61 if ((flags & HEAD_CRC) != 0)
62 i += 2;
63 if (i >= *lenp) {
64 //puts("gunzip: ran out of data in header\n");
65 exit();
66 }
67
68 s.zalloc = zalloc;
69 s.zfree = zfree;
70 r = inflateInit2(&s, -MAX_WBITS);
71 if (r != Z_OK) {
72 //puts("inflateInit2 returned "); puthex(r); puts("\n");
73 exit();
74 }
75 s.next_in = src + i;
76 s.avail_in = *lenp - i;
77 s.next_out = dst;
78 s.avail_out = dstlen;
79 r = inflate(&s, Z_FINISH);
80 if (r != Z_OK && r != Z_STREAM_END) {
81 //puts("inflate returned "); puthex(r); puts("\n");
82 exit();
83 }
84 *lenp = s.next_out - (unsigned char *) dst;
85 inflateEnd(&s);
86}
87