-
Notifications
You must be signed in to change notification settings - Fork 0
/
zloader.c
156 lines (129 loc) · 3.12 KB
/
zloader.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifdef SIM
#include "stdio.h"
#else
typedef int size_t;
extern void tgt_putchar(char c);
int tgt_puts(char *str);
#endif
#include "pmon.bin.c"
#define __init
#define KERN_ERR
#ifndef SIM
#include "memop.c"
char *membase=0xffffffff80000000+(((MEMSIZE<256?MEMSIZE:256)-4)<<20);
static char *sbrk(int size)
{
char *p=membase;
membase +=size;
return p;
}
#include "malloc.c"
#endif
/*
* gzip declarations
*/
#define OF(args) args
#ifndef memzero
#define memzero(s, n) memset ((s), 0, (n))
#endif
typedef unsigned char uch;
typedef unsigned short ush;
typedef unsigned long ulg;
#define INBUFSIZ 4096
#define WSIZE 0x8000 /* window size--must be a power of two, and */
/* at least 32K for zip's deflate method */
static uch *inbuf;
static uch *window;
static unsigned insize; /* valid bytes in inbuf */
static unsigned inptr; /* index of next byte to be processed in inbuf */
static unsigned outcnt; /* bytes in output buffer */
static int exit_code;
static long bytes_out;
static int crd_outfd;
int dest;
#define get_byte() (inbuf[inptr++])
#ifdef SIM
FILE *fpw;
#endif
/* Diagnostic functions (stubbed out) */
#define Assert(cond,msg)
#define Trace(x)
#define Tracev(x)
#define Tracevv(x)
#define Tracec(c,x)
#define Tracecv(c,x)
#define STATIC static
static void flush_window(void);
static void error(char *m);
static void gzip_mark(void **);
static void gzip_release(void **);
#include "inflate.c"
static void __init gzip_mark(void **ptr)
{
}
static void __init gzip_release(void **ptr)
{
}
/* ===========================================================================
* Write the output window window[0..outcnt-1] and update crc and bytes_out.
* (Used for the decompressed data only.)
*/
static void __init flush_window(void)
{
ulg c = crc; /* temporary variable */
unsigned n;
uch *in, ch;
#ifdef SIM
fwrite(window,1,outcnt,fpw);
#else
tgt_putchar('.');
memcpy((void *)dest,window,outcnt);
#endif
dest=dest+outcnt;
in = window;
for (n = 0; n < outcnt; n++) {
ch = *in++;
c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
bytes_out += (ulg)outcnt;
outcnt = 0;
}
static void __init error(char *x)
{
tgt_puts(x);
exit_code = 1;
}
static int __init run_unzip(char *start,long to)
{
int result;
insize = 0; /* valid bytes in inbuf */
inptr = 0; /* index of next byte to be processed in inbuf */
outcnt = 0; /* bytes in output buffer */
exit_code = 0;
bytes_out = 0;
crc = (ulg)0xffffffffL; /* shift register contents */
inbuf = start;
dest = (void *)to;
window = malloc(WSIZE);
if (window == 0) {
tgt_puts("RAMDISK: Couldn't allocate gzip window\n");
free(inbuf);
return -1;
}
makecrc();
result = gunzip();
free(window);
return result;
}
#ifdef SIM
int main(int argc,char **argv)
{
fpw=fopen("tmp.txt","wb");
run_unzip(biosdata,0x80010000);
fclose(fpw);
}
#else
#include "initmips.c"
int read,write,open,close,printf,vsprintf,getenv,tgt_reboot,CpuTertiaryCacheSize,tgt_reboot;
#endif