4 * $Id: misc.c,v 1.6 2003/10/27 08:04:31 starvik Exp $
6 * This is a collection of several routines from gzip-1.0.3
9 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
10 * puts by Nick Holloway 1993, better puts by Martin Mares 1995
11 * adoptation for Linux/CRIS Axis Communications AB, 1999
15 /* where the piggybacked kernel image expects itself to live.
16 * it is the same address we use when we network load an uncompressed
17 * image into DRAM, and it is the address the kernel is linked to live
21 #define KERNEL_LOAD_ADR 0x40004000
23 #include <linux/config.h>
25 #include <linux/types.h>
26 #include <asm/arch/svinto.h>
35 void* memset(void* s
, int c
, size_t n
);
36 void* memcpy(void* __dest
, __const
void* __src
,
39 #define memzero(s, n) memset ((s), 0, (n))
42 typedef unsigned char uch
;
43 typedef unsigned short ush
;
44 typedef unsigned long ulg
;
46 #define WSIZE 0x8000 /* Window size must be at least 32k, */
47 /* and a power of two */
49 static uch
*inbuf
; /* input buffer */
50 static uch window
[WSIZE
]; /* Sliding window buffer */
52 unsigned inptr
= 0; /* index of next byte to be processed in inbuf
53 * After decompression it will contain the
54 * compressed size, and head.S will read it.
57 static unsigned outcnt
= 0; /* bytes in output buffer */
60 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
61 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
62 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
63 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
64 #define COMMENT 0x10 /* bit 4 set: file comment present */
65 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
66 #define RESERVED 0xC0 /* bit 6,7: reserved */
68 #define get_byte() inbuf[inptr++]
70 /* Diagnostic functions */
72 # define Assert(cond,msg) {if(!(cond)) error(msg);}
73 # define Trace(x) fprintf x
74 # define Tracev(x) {if (verbose) fprintf x ;}
75 # define Tracevv(x) {if (verbose>1) fprintf x ;}
76 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
77 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
79 # define Assert(cond,msg)
87 static int fill_inbuf(void);
88 static void flush_window(void);
89 static void error(char *m
);
90 static void gzip_mark(void **);
91 static void gzip_release(void **);
93 extern char *input_data
; /* lives in head.S */
95 static long bytes_out
= 0;
96 static uch
*output_data
;
97 static unsigned long output_ptr
= 0;
99 static void *malloc(int size
);
100 static void free(void *where
);
101 static void error(char *m
);
102 static void gzip_mark(void **);
103 static void gzip_release(void **);
105 static void puts(const char *);
107 /* the "heap" is put directly after the BSS ends, at end */
110 static long free_mem_ptr
= (long)&end
;
112 #include "../../../../../lib/inflate.c"
114 static void *malloc(int size
)
118 if (size
<0) error("Malloc error");
120 free_mem_ptr
= (free_mem_ptr
+ 3) & ~3; /* Align */
122 p
= (void *)free_mem_ptr
;
123 free_mem_ptr
+= size
;
128 static void free(void *where
)
132 static void gzip_mark(void **ptr
)
134 *ptr
= (void *) free_mem_ptr
;
137 static void gzip_release(void **ptr
)
139 free_mem_ptr
= (long) *ptr
;
142 /* decompressor info and error messages to serial console */
147 #ifndef CONFIG_ETRAX_DEBUG_PORT_NULL
149 #ifdef CONFIG_ETRAX_DEBUG_PORT0
150 while(!(*R_SERIAL0_STATUS
& (1 << 5))) ;
151 *R_SERIAL0_TR_DATA
= *s
++;
153 #ifdef CONFIG_ETRAX_DEBUG_PORT1
154 while(!(*R_SERIAL1_STATUS
& (1 << 5))) ;
155 *R_SERIAL1_TR_DATA
= *s
++;
157 #ifdef CONFIG_ETRAX_DEBUG_PORT2
158 while(!(*R_SERIAL2_STATUS
& (1 << 5))) ;
159 *R_SERIAL2_TR_DATA
= *s
++;
161 #ifdef CONFIG_ETRAX_DEBUG_PORT3
162 while(!(*R_SERIAL3_STATUS
& (1 << 5))) ;
163 *R_SERIAL3_TR_DATA
= *s
++;
170 memset(void* s
, int c
, size_t n
)
175 for (i
=0;i
<n
;i
++) ss
[i
] = c
;
179 memcpy(void* __dest
, __const
void* __src
,
183 char *d
= (char *)__dest
, *s
= (char *)__src
;
185 for (i
=0;i
<__n
;i
++) d
[i
] = s
[i
];
188 /* ===========================================================================
189 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
190 * (Used for the decompressed data only.)
196 ulg c
= crc
; /* temporary variable */
201 out
= &output_data
[output_ptr
];
202 for (n
= 0; n
< outcnt
; n
++) {
204 c
= crc_32_tab
[((int)c
^ ch
) & 0xff] ^ (c
>> 8);
207 bytes_out
+= (ulg
)outcnt
;
208 output_ptr
+= (ulg
)outcnt
;
217 puts("\n\n -- System halted\n");
223 setup_normal_output_buffer()
225 output_data
= (char *)KERNEL_LOAD_ADR
;
233 /* input_data is set in head.S */
236 #ifdef CONFIG_ETRAX_DEBUG_PORT0
238 *R_SERIAL0_BAUD
= 0x99;
239 *R_SERIAL0_TR_CTRL
= 0x40;
241 #ifdef CONFIG_ETRAX_DEBUG_PORT1
243 *R_SERIAL1_BAUD
= 0x99;
244 *R_SERIAL1_TR_CTRL
= 0x40;
246 #ifdef CONFIG_ETRAX_DEBUG_PORT2
247 *R_GEN_CONFIG
= 0x08;
249 *R_SERIAL2_BAUD
= 0x99;
250 *R_SERIAL2_TR_CTRL
= 0x40;
252 #ifdef CONFIG_ETRAX_DEBUG_PORT3
253 *R_GEN_CONFIG
= 0x100;
255 *R_SERIAL3_BAUD
= 0x99;
256 *R_SERIAL3_TR_CTRL
= 0x40;
259 setup_normal_output_buffer();
263 __asm__
volatile ("move vr,%0" : "=rm" (revision
));
266 puts("You need an ETRAX 100LX to run linux 2.6\n");
270 puts("Uncompressing Linux...\n");
272 puts("Done. Now booting the kernel.\n");