Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / alpha / boot / misc.c
blobd6519220270360d2bc4f70e1c7f1a1a98ace0898
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * misc.c
4 *
5 * This is a collection of several routines from gzip-1.0.3
6 * adapted for Linux.
8 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
10 * Modified for ARM Linux by Russell King
12 * Nicolas Pitre <nico@visuaide.com> 1999/04/14 :
13 * For this code to run directly from Flash, all constant variables must
14 * be marked with 'const' and all other variables initialized at run-time
15 * only. This way all non constant variables will end up in the bss segment,
16 * which should point to addresses in RAM and cleared to 0 on start.
17 * This allows for a much quicker boot time.
19 * Modified for Alpha, from the ARM version, by Jay Estabrook 2003.
22 #include <linux/kernel.h>
23 #include <linux/slab.h>
25 #include <linux/uaccess.h>
27 #define memzero(s,n) memset ((s),0,(n))
28 #define puts srm_printk
29 extern long srm_printk(const char *, ...)
30 __attribute__ ((format (printf, 1, 2)));
33 * gzip delarations
35 #define OF(args) args
36 #define STATIC static
38 typedef unsigned char uch;
39 typedef unsigned short ush;
40 typedef unsigned long ulg;
42 #define WSIZE 0x8000 /* Window size must be at least 32k, */
43 /* and a power of two */
45 static uch *inbuf; /* input buffer */
46 static uch *window; /* Sliding window buffer */
48 static unsigned insize; /* valid bytes in inbuf */
49 static unsigned inptr; /* index of next byte to be processed in inbuf */
50 static unsigned outcnt; /* bytes in output buffer */
52 /* gzip flag byte */
53 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
54 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
55 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
56 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
57 #define COMMENT 0x10 /* bit 4 set: file comment present */
58 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
59 #define RESERVED 0xC0 /* bit 6,7: reserved */
61 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
63 /* Diagnostic functions */
64 #ifdef DEBUG
65 # define Assert(cond,msg) {if(!(cond)) error(msg);}
66 # define Trace(x) fprintf x
67 # define Tracev(x) {if (verbose) fprintf x ;}
68 # define Tracevv(x) {if (verbose>1) fprintf x ;}
69 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
70 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
71 #else
72 # define Assert(cond,msg)
73 # define Trace(x)
74 # define Tracev(x)
75 # define Tracevv(x)
76 # define Tracec(c,x)
77 # define Tracecv(c,x)
78 #endif
80 static int fill_inbuf(void);
81 static void flush_window(void);
82 static void error(char *m);
84 static char *input_data;
85 static int input_data_size;
87 static uch *output_data;
88 static ulg output_ptr;
89 static ulg bytes_out;
91 static void error(char *m);
92 static void gzip_mark(void **);
93 static void gzip_release(void **);
95 extern int end;
96 static ulg free_mem_ptr;
97 static ulg free_mem_end_ptr;
99 #define HEAP_SIZE 0x3000
101 #include "../../../lib/inflate.c"
103 /* ===========================================================================
104 * Fill the input buffer. This is called only when the buffer is empty
105 * and at least one byte is really needed.
107 int fill_inbuf(void)
109 if (insize != 0)
110 error("ran out of input data");
112 inbuf = input_data;
113 insize = input_data_size;
115 inptr = 1;
116 return inbuf[0];
119 /* ===========================================================================
120 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
121 * (Used for the decompressed data only.)
123 void flush_window(void)
125 ulg c = crc;
126 unsigned n;
127 uch *in, *out, ch;
129 in = window;
130 out = &output_data[output_ptr];
131 for (n = 0; n < outcnt; n++) {
132 ch = *out++ = *in++;
133 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
135 crc = c;
136 bytes_out += (ulg)outcnt;
137 output_ptr += (ulg)outcnt;
138 outcnt = 0;
139 /* puts("."); */
142 static void error(char *x)
144 puts("\n\n");
145 puts(x);
146 puts("\n\n -- System halted");
148 while(1); /* Halt */
151 unsigned int
152 decompress_kernel(void *output_start,
153 void *input_start,
154 size_t ksize,
155 size_t kzsize)
157 output_data = (uch *)output_start;
158 input_data = (uch *)input_start;
159 input_data_size = kzsize; /* use compressed size */
161 /* FIXME FIXME FIXME */
162 free_mem_ptr = (ulg)output_start + ksize;
163 free_mem_end_ptr = (ulg)output_start + ksize + 0x200000;
164 /* FIXME FIXME FIXME */
166 /* put in temp area to reduce initial footprint */
167 window = malloc(WSIZE);
169 makecrc();
170 /* puts("Uncompressing Linux..."); */
171 gunzip();
172 /* puts(" done, booting the kernel.\n"); */
173 return output_ptr;