Linux Audio

Check our new training course

Loading...
v5.4
 1// SPDX-License-Identifier: GPL-2.0
 2/*
 3 * arch/h8300/boot/compressed/misc.c
 4 *
 5 * This is a collection of several routines from gzip-1.0.3
 6 * adapted for Linux.
 7 *
 8 * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
 9 *
10 * Adapted for h8300 by Yoshinori Sato 2006
11 */
12
13#include <linux/uaccess.h>
14
15/*
16 * gzip declarations
17 */
18
19#define OF(args)  args
20#define STATIC static
21
22#undef memset
23#undef memcpy
24#define memzero(s, n)     memset((s), (0), (n))
25
26extern int _end;
27static unsigned long free_mem_ptr;
28static unsigned long free_mem_end_ptr;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30extern char input_data[];
31extern int input_len;
32extern char output[];
 
 
 
 
 
 
 
 
 
 
 
 
33
34#define HEAP_SIZE             0x10000
35
36#ifdef CONFIG_KERNEL_GZIP
37#include "../../../../lib/decompress_inflate.c"
38#endif
39
40#ifdef CONFIG_KERNEL_LZO
41#include "../../../../lib/decompress_unlzo.c"
42#endif
43
44void *memset(void *s, int c, size_t n)
 
 
 
 
 
45{
46	int i;
47	char *ss = (char *)s;
48
49	for (i = 0; i < n; i++)
50		ss[i] = c;
51	return s;
52}
53
54void *memcpy(void *dest, const void *src, size_t n)
 
55{
56	int i;
57	char *d = (char *)dest, *s = (char *)src;
58
59	for (i = 0; i < n; i++)
60		d[i] = s[i];
61	return dest;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62}
63
64static void error(char *x)
65{
66	while (1)
67		;	/* Halt */
 
 
 
68}
69
 
 
 
 
70void decompress_kernel(void)
71{
 
 
72	free_mem_ptr = (unsigned long)&_end;
73	free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
74
75	__decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error);
 
 
 
76}
v3.1
 
  1/*
  2 * arch/h8300/boot/compressed/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 * Adapted for h8300 by Yoshinori Sato 2006
 10 */
 11
 12#include <asm/uaccess.h>
 13
 14/*
 15 * gzip declarations
 16 */
 17
 18#define OF(args)  args
 19#define STATIC static
 20
 21#undef memset
 22#undef memcpy
 23#define memzero(s, n)     memset ((s), 0, (n))
 24
 25typedef unsigned char  uch;
 26typedef unsigned short ush;
 27typedef unsigned long  ulg;
 28
 29#define WSIZE 0x8000		/* Window size must be at least 32k, */
 30				/* and a power of two */
 31
 32static uch *inbuf;	     /* input buffer */
 33static uch window[WSIZE];    /* Sliding window buffer */
 34
 35static unsigned insize = 0;  /* valid bytes in inbuf */
 36static unsigned inptr = 0;   /* index of next byte to be processed in inbuf */
 37static unsigned outcnt = 0;  /* bytes in output buffer */
 38
 39/* gzip flag byte */
 40#define ASCII_FLAG   0x01 /* bit 0 set: file probably ASCII text */
 41#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
 42#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
 43#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
 44#define COMMENT      0x10 /* bit 4 set: file comment present */
 45#define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
 46#define RESERVED     0xC0 /* bit 6,7:   reserved */
 47
 48#define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf())
 49
 50/* Diagnostic functions */
 51#ifdef DEBUG
 52#  define Assert(cond,msg) {if(!(cond)) error(msg);}
 53#  define Trace(x) fprintf x
 54#  define Tracev(x) {if (verbose) fprintf x ;}
 55#  define Tracevv(x) {if (verbose>1) fprintf x ;}
 56#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
 57#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
 58#else
 59#  define Assert(cond,msg)
 60#  define Trace(x)
 61#  define Tracev(x)
 62#  define Tracevv(x)
 63#  define Tracec(c,x)
 64#  define Tracecv(c,x)
 65#endif
 66
 67static int  fill_inbuf(void);
 68static void flush_window(void);
 69static void error(char *m);
 70
 71extern char input_data[];
 72extern int input_len;
 73
 74static long bytes_out = 0;
 75static uch *output_data;
 76static unsigned long output_ptr = 0;
 77
 78static void error(char *m);
 79
 80int puts(const char *);
 81
 82extern int _text;		/* Defined in vmlinux.lds.S */
 83extern int _end;
 84static unsigned long free_mem_ptr;
 85static unsigned long free_mem_end_ptr;
 86
 87#define HEAP_SIZE             0x10000
 88
 89#include "../../../../lib/inflate.c"
 
 
 90
 91#define SCR *((volatile unsigned char *)0xffff8a)
 92#define TDR *((volatile unsigned char *)0xffff8b)
 93#define SSR *((volatile unsigned char *)0xffff8c)
 94
 95int puts(const char *s)
 96{
 97	return 0;
 98}
 99
100void* memset(void* s, int c, size_t n)
101{
102	int i;
103	char *ss = (char*)s;
104
105	for (i=0;i<n;i++) ss[i] = c;
 
106	return s;
107}
108
109void* memcpy(void* __dest, __const void* __src,
110			    size_t __n)
111{
112	int i;
113	char *d = (char *)__dest, *s = (char *)__src;
114
115	for (i=0;i<__n;i++) d[i] = s[i];
116	return __dest;
117}
118
119/* ===========================================================================
120 * Fill the input buffer. This is called only when the buffer is empty
121 * and at least one byte is really needed.
122 */
123static int fill_inbuf(void)
124{
125	if (insize != 0) {
126		error("ran out of input data");
127	}
128
129	inbuf = input_data;
130	insize = input_len;
131	inptr = 1;
132	return inbuf[0];
133}
134
135/* ===========================================================================
136 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
137 * (Used for the decompressed data only.)
138 */
139static void flush_window(void)
140{
141    ulg c = crc;         /* temporary variable */
142    unsigned n;
143    uch *in, *out, ch;
144
145    in = window;
146    out = &output_data[output_ptr];
147    for (n = 0; n < outcnt; n++) {
148	    ch = *out++ = *in++;
149	    c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
150    }
151    crc = c;
152    bytes_out += (ulg)outcnt;
153    output_ptr += (ulg)outcnt;
154    outcnt = 0;
155}
156
157static void error(char *x)
158{
159	puts("\n\n");
160	puts(x);
161	puts("\n\n -- System halted");
162
163	while(1);	/* Halt */
164}
165
166#define STACK_SIZE (4096)
167long user_stack [STACK_SIZE];
168long* stack_start = &user_stack[STACK_SIZE];
169
170void decompress_kernel(void)
171{
172	output_data = 0;
173	output_ptr = (unsigned long)0x400000;
174	free_mem_ptr = (unsigned long)&_end;
175	free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
176
177	makecrc();
178	puts("Uncompressing Linux... ");
179	gunzip();
180	puts("Ok, booting the kernel.\n");
181}