1*c87b03e5Sespie // Build don't link:
2*c87b03e5Sespie // Special g++ Options: -O
3*c87b03e5Sespie // GROUPS passed old-abort
4*c87b03e5Sespie typedef unsigned char uchar;
5*c87b03e5Sespie typedef unsigned short ushort;
6*c87b03e5Sespie typedef unsigned long ulong;
7*c87b03e5Sespie extern int swap_endian;
8*c87b03e5Sespie inline ushort
swapshort(ushort value)9*c87b03e5Sespie swapshort(ushort value)
10*c87b03e5Sespie {
11*c87b03e5Sespie value &= 0xffff;
12*c87b03e5Sespie return ((value << 8) | (value >> 8));
13*c87b03e5Sespie }
14*c87b03e5Sespie struct eshort
15*c87b03e5Sespie {
16*c87b03e5Sespie ushort data;
ushorteshort17*c87b03e5Sespie operator ushort() { return swap_endian ? swapshort(data) : data;}
eshorteshort18*c87b03e5Sespie eshort(ushort t) { data = swap_endian ? swapshort(t) : t;}
eshorteshort19*c87b03e5Sespie eshort() {}
20*c87b03e5Sespie };
21*c87b03e5Sespie inline ulong
swaplong(ulong value)22*c87b03e5Sespie swaplong(ulong value)
23*c87b03e5Sespie {
24*c87b03e5Sespie ulong v = (value << 16) | (value >> 16);
25*c87b03e5Sespie return ((v >> 8) & 0x00ff00ff) | ((v << 8) & 0xff00ff00);
26*c87b03e5Sespie };
27*c87b03e5Sespie struct elong
28*c87b03e5Sespie {
29*c87b03e5Sespie ulong data;
ulongelong30*c87b03e5Sespie operator ulong() { return swap_endian ? swaplong(data) : data;}
elongelong31*c87b03e5Sespie elong(ulong t) { data = swap_endian ? swaplong(t) : t; }
elongelong32*c87b03e5Sespie elong() {}
33*c87b03e5Sespie };
34*c87b03e5Sespie struct digiheader
35*c87b03e5Sespie {
36*c87b03e5Sespie uchar type[2];
37*c87b03e5Sespie eshort soft_version;
38*c87b03e5Sespie eshort lo_boot_rev;
39*c87b03e5Sespie eshort hi_boot_rev;
40*c87b03e5Sespie eshort load_segment;
41*c87b03e5Sespie eshort length;
42*c87b03e5Sespie eshort exec_start;
43*c87b03e5Sespie eshort image_offset;
44*c87b03e5Sespie elong startup_code[2];
45*c87b03e5Sespie elong checksum;
46*c87b03e5Sespie };
47*c87b03e5Sespie extern void uncompress(uchar* buf, ulong len);
48*c87b03e5Sespie extern ulong compress(char* filename, uchar* buffer, ulong);
49*c87b03e5Sespie struct filehdr
50*c87b03e5Sespie {
51*c87b03e5Sespie eshort f_magic;
52*c87b03e5Sespie eshort f_nscns;
53*c87b03e5Sespie elong f_timdat;
54*c87b03e5Sespie elong f_symptr;
55*c87b03e5Sespie elong f_nsyms;
56*c87b03e5Sespie eshort f_opthdr;
57*c87b03e5Sespie eshort f_flags;
58*c87b03e5Sespie };
59*c87b03e5Sespie struct aouthdr
60*c87b03e5Sespie {
61*c87b03e5Sespie eshort magic;
62*c87b03e5Sespie eshort vstamp;
63*c87b03e5Sespie elong tsize;
64*c87b03e5Sespie elong dsize;
65*c87b03e5Sespie elong bsize;
66*c87b03e5Sespie elong entry;
67*c87b03e5Sespie elong text_start;
68*c87b03e5Sespie elong data_start;
69*c87b03e5Sespie elong bss_start;
70*c87b03e5Sespie elong gprmask;
71*c87b03e5Sespie elong cprmask[4];
72*c87b03e5Sespie elong gp_value;
73*c87b03e5Sespie };
74*c87b03e5Sespie struct scnhdr
75*c87b03e5Sespie {
76*c87b03e5Sespie char s_name[8];
77*c87b03e5Sespie elong s_paddr;
78*c87b03e5Sespie elong s_vaddr;
79*c87b03e5Sespie elong s_size;
80*c87b03e5Sespie elong s_scnptr;
81*c87b03e5Sespie elong s_relptr;
82*c87b03e5Sespie elong s_lnnoptr;
83*c87b03e5Sespie eshort s_nreloc;
84*c87b03e5Sespie eshort s_nlnno;
85*c87b03e5Sespie elong s_flags;
86*c87b03e5Sespie };
87*c87b03e5Sespie int file_little_endian;
88*c87b03e5Sespie int host_little_endian;
89*c87b03e5Sespie int swap_endian;
90*c87b03e5Sespie int docheck;
91*c87b03e5Sespie int expand;
92*c87b03e5Sespie ulong memsize;
93*c87b03e5Sespie ulong compression_quality;
94*c87b03e5Sespie char *compressfile;
95*c87b03e5Sespie int debug_level;
96*c87b03e5Sespie extern "C" int getopt (int, char**, char*);
97*c87b03e5Sespie int
main(int argc,char ** argv)98*c87b03e5Sespie main(int argc, char** argv)
99*c87b03e5Sespie {
100*c87b03e5Sespie uchar checksum;
101*c87b03e5Sespie uchar docrc;
102*c87b03e5Sespie ulong len;
103*c87b03e5Sespie ulong maxlen;
104*c87b03e5Sespie int i;
105*c87b03e5Sespie int c;
106*c87b03e5Sespie int magic;
107*c87b03e5Sespie int tsize;
108*c87b03e5Sespie int dsize;
109*c87b03e5Sespie int quality;
110*c87b03e5Sespie char dummy;
111*c87b03e5Sespie uchar* code;
112*c87b03e5Sespie uchar* buf;
113*c87b03e5Sespie char* ap;
114*c87b03e5Sespie digiheader *dh;
115*c87b03e5Sespie compression_quality = 10000;
116*c87b03e5Sespie docheck = 0;
117*c87b03e5Sespie while ((c = getopt(argc, argv, "Ccdf:k:q:x:")) != -1)
118*c87b03e5Sespie {
119*c87b03e5Sespie switch (c)
120*c87b03e5Sespie {
121*c87b03e5Sespie default:
122*c87b03e5Sespie goto usage;
123*c87b03e5Sespie }
124*c87b03e5Sespie }
125*c87b03e5Sespie if ((expand && (docheck || compressfile || quality)) ||
126*c87b03e5Sespie (quality && !compressfile))
127*c87b03e5Sespie {
128*c87b03e5Sespie usage:
129*c87b03e5Sespie return(2);
130*c87b03e5Sespie }
131*c87b03e5Sespie if (compressfile)
132*c87b03e5Sespie {
133*c87b03e5Sespie dh->image_offset = len;
134*c87b03e5Sespie
135*c87b03e5Sespie len += compress(compressfile, code + len, maxlen - len);
136*c87b03e5Sespie }
137*c87b03e5Sespie }
138