summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--makeheader.pl8
-rw-r--r--squeeze.c87
-rw-r--r--squeeze.h2
4 files changed, 80 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index 10ea41f..5b79ada 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,10 @@ export PERL
MAKEHEADER = $(PERL) makeheader.pl
+CC := gcc
+
+CFLAGS := $(CFLAGS) -g -O0
+
clean:
$(RM) squeeze squeeze.o unsqueeze.o unsqrm.o
$(RM) unsqueeze1.h unsqrm1.h unsqueeze.bin unsqrm.bin
@@ -19,8 +23,10 @@ distclean: clean
squeeze: squeeze.o
+ $(CC) $(CFLAGS) -o $@ $^
squeeze.o: squeeze.c unsqueeze1.h unsqrm1.h
+ $(CC) $(CFLAGS) -o $@ -c $<
unsqrm1.h: unsqrm.bin
$(MAKEHEADER) unsqueeze_base unsqueeze_limit unsqueeze_end $< $@
@@ -29,10 +35,10 @@ unsqueeze1.h: unsqueeze.bin
$(MAKEHEADER) UnSqueeze_UnSqueezeBase '' UnSqueeze_UnSqueezeLimit $< $@
unsqueeze.bin: unsqueeze.o
- arm-unknown-riscos-objcopy -O binary -j 'M2$$$$Code' $< $@
+ $(SDK_PATH)arm-unknown-riscos-objcopy -O binary -j 'M2$$$$Code' $< $@
unsqrm.bin: unsqrm.o
- arm-unknown-riscos-objcopy -O binary -j unsqueeze $< $@
+ $(SDK_PATH)arm-unknown-riscos-objcopy -O binary -j unsqueeze $< $@
%.o:%.s
$(SDK_PATH)asasm -o $@ -elf -32 $<
diff --git a/makeheader.pl b/makeheader.pl
index 2e2c426..58d587e 100644
--- a/makeheader.pl
+++ b/makeheader.pl
@@ -8,11 +8,13 @@ my $perl = $ENV{PERL};
my $output_text = `$perl bin2c.pl THINGY < $infilename`;
-$output_text =~ s/THINGY\[\]/$basename\[\]/;
+$output_text =~ s/unsigned char THINGY\[\]/const unsigned char $basename\[\]/;
-$output_text =~ s/unsigned int THINGY_len = (\d+)/unsigned char $endname = $basename + $1/;
+my $objlen = ($output_text =~ /unsigned int THINGY_len = (\d+)/)[0];
-my $repltext = "unsigned char $midname = $endname - 4;";
+$output_text =~ s/unsigned int THINGY_len = (\d+)/const unsigned char \*$endname = $basename + $1/;
+
+my $repltext = "const unsigned char \*$midname = $basename + $objlen - 4;";
$repltext = "" if ($midname eq '');
$output_text =~ s/int THINGY_mtime = \d+;/$repltext/;
diff --git a/squeeze.c b/squeeze.c
index 169f275..ea0122c 100644
--- a/squeeze.c
+++ b/squeeze.c
@@ -26,6 +26,9 @@
07-Mar-91 add recognition of MOV R0, R0 as well as BLNV $0
*/
+#include <stdint.h>
+#include <inttypes.h>
+
#ifdef __STDC__
# include <string.h>
# include <stdlib.h>
@@ -50,10 +53,10 @@ typedef struct {
} _kernel_osfile_block;
#endif
-#include "CLX/err.h"
-#include "CLX/host.h"
-#include "CLX/hash.h"
-#include "CLX/wholefls.h"
+//#include "CLX/err.h"
+//#include "CLX/host.h"
+//#include "CLX/hash.h"
+//#include "CLX/wholefls.h"
#ifndef __riscos
#include <limits.h>
@@ -110,6 +113,42 @@ static int force;
static clock_t lastticks;
/*
+ * CLX ickyness
+ */
+
+#define err_fail(X...) do { fprintf(stderr, X); fprintf(stderr, "\n"); exit(EXIT_FAILURE); } while(0)
+#define err_report(X...) do { fprintf(stderr, X); fprintf(stderr, "\n"); } while (0)
+char host_dir_sep_char() { return '/'; }
+
+int wf_load(char *filename, void *ptr, int len)
+{
+ FILE *f;
+ f = fopen(filename, "rb");
+ if (f == NULL)
+ return -1;
+ if (fread(ptr, 1, len, f) != len) {
+ fclose(f);
+ return -1;
+ }
+ fclose(f);
+ return 0;
+}
+
+int wf_save(char *filename, void *ptr, int len)
+{
+ FILE *f;
+ f = fopen(filename, "wb");
+ if (f == NULL)
+ return -1;
+ if (fwrite(ptr, 1, len, f) != len) {
+ fclose(f);
+ return -1;
+ }
+ fclose(f);
+ return 0;
+}
+
+/*
* Veneer on file-handling.
*/
@@ -256,7 +295,7 @@ typedef struct InfoChunk {
} InfoChunk;
static Info *align(Info *p, int n)
-{ int x = (int)p;
+{ intptr_t x = (intptr_t)p;
x += (n - 1); x -= (x % n); return (Info *)x;
}
@@ -304,7 +343,7 @@ static Info *newinfo(Info *next, word v)
chunk = (InfoChunk *)xalloc(CHUNKSIZE, "InfoChunk");
chunk->next = curchunk;
chunk->free = p = align(chunk->chunks, 8);
- chunk->limit = (Info *)(((int)chunk) + CHUNKSIZE - sizeof(Info));
+ chunk->limit = (Info *)(((intptr_t)chunk) + CHUNKSIZE - sizeof(Info));
curchunk = chunk;
}
chunk->free = (p + 1);
@@ -561,7 +600,7 @@ static char *encode(word *base, word *limit, Info **fshorts, Info **flongs,
w = code[0]; ENCODEVALUE(w, nib0, p);
*p++ = (nib0 | (nib1 << 4));
if (buf != NULL) {
- idx = ((int)code - (int)base - 12 - (p - buf));
+ idx = ((intptr_t)code - (intptr_t)base - 12 - (p - buf));
if (idx > 0) { h->bytestomove = (p - buf); }
if ((idx > 256) || (p - buf > ENCSIZE - 16)) {
/*
@@ -620,13 +659,13 @@ static char *encodetable(VTable *tab, int threebytes, char *out)
}
static char *writeunsqueeze(char *out, int execoffset)
-{ int base, limit;
+{ intptr_t base, limit;
word *p;
int n, rotr, op;
/* UnSqueeze_FindUnSqueezeCode(&base, &limit); */
- base = (int)&UnSqueeze_UnSqueezeBase;
- limit = (int)&UnSqueeze_UnSqueezeLimit;
+ base = (intptr_t)&UnSqueeze_UnSqueezeBase[6*4];
+ limit = (intptr_t)&UnSqueeze_UnSqueezeLimit[0];
n = limit - base;
memcpy(out, (void *)base, n); out += n;
/*
@@ -650,7 +689,7 @@ static char *writeunsqueeze(char *out, int execoffset)
return((char *)p);
}
-static char *compresscode(word *code, int size, int execoffset)
+static char *compresscode(word *code, intptr_t size, int execoffset)
/*
* Returns NULL if no compression, else pointer to top of compressed thing.
*/
@@ -665,7 +704,7 @@ static char *compresscode(word *code, int size, int execoffset)
size += 7; size &= ~7; /* round up to an even number of words */
limit = (word *)((char *)code + size);
countwords(code, limit, &freqs);
- if (verbose > 1) printf("-- counted %d bytes in %d csec\n", size, ticks());
+ if (verbose > 1) printf("-- counted %" PRIdPTR " bytes in %d csec\n", size, ticks());
/*
* Allocate the VTables here to avoid nasty storage interactions, which
* can lose us some chunks if we're not careful.
@@ -725,7 +764,7 @@ static char *compresscode(word *code, int size, int execoffset)
header.nlongs = longs->size;
xfree(longs);
/* now word-align before the header words */
- while (((int)pos & 3) != 0) *pos++ = 0;
+ while (((intptr_t)pos & 3) != 0) *pos++ = 0;
header.encodedtabs = (pos - tabstart);
if (verbose > 1)
fprintf(stderr, "-- decode tables occupy %d bytes\n", header.encodedtabs);
@@ -740,7 +779,7 @@ static char *compresscode(word *code, int size, int execoffset)
pos = writeunsqueeze(pos, execoffset);
pos += sprintf(pos, "rcc %s\n", Module_MajorVersion);
/* Pad size to be 15 mod 16 */
- while ((((int)pos - (int)code) & 0xf) != 0xf) *pos++ = ' ';
+ while ((((intptr_t)pos - (intptr_t)code) & 0xf) != 0xf) *pos++ = ' ';
return(pos);
}
@@ -786,7 +825,8 @@ static void arthurise(_kernel_osfile_block *info, int type)
static int squeeze(char *in, char *out)
{ _kernel_osfile_block info;
- int rc, size, t, squeezed, isdata;
+ int rc, t, squeezed, isdata;
+ intptr_t size;
void *load;
datahdr *d;
word *code;
@@ -811,8 +851,8 @@ static int squeeze(char *in, char *out)
if ((info.load & 0xffffff00) == 0xfffffa00) { /* Module */
int header_size;
- header_size = (int)&unsqueeze_limit - (int)&unsqueeze_base;
- unsqueeze_end = size;
+ header_size = (intptr_t)&unsqueeze_limit[0] - (intptr_t)&unsqueeze_base[0];
+ unsqueeze_end = (void *)size;
size += header_size;
code = xalloc(size+DATABYTES+8, "code");
d = (datahdr *)code; code += DATAWORDS;
@@ -841,10 +881,10 @@ static int squeeze(char *in, char *out)
d->load = info.load; d->exec = info.exec; d->size = size;
}
}
- if (verbose > 1) fprintf(stderr, "-- loaded %d bytes in %d csec\n", size, ticks());
+ if (verbose > 1) fprintf(stderr, "-- loaded %" PRIdPTR " bytes in %d csec\n", size, ticks());
t = clock();
- if (isdata) top = compresscode(code, size, -DATABYTES + 4);
+ if (isdata) top = compresscode(code, size, (-DATABYTES) + 4);
else top = compress(code, size, info.exec - info.load);
if (top != NULL) {
@@ -857,8 +897,8 @@ static int squeeze(char *in, char *out)
info.exec = info.load;
rc = (top - (char *)code);
if (verbose) {
- fprintf(stderr, "-- compressed size %d is %d%% of %d\n", rc, (rc*100)/size, size);
- fprintf(stderr, "-- compression took %d csec, %d bytes/cpusec\n", t, (size*100)/(t?t:1));
+ fprintf(stderr, "-- compressed size %d is %" PRIdPTR "%% of %" PRIdPTR "\n", rc, (rc*100)/size, size);
+ fprintf(stderr, "-- compression took %d csec, %" PRIdPTR " bytes/cpusec\n", t, (size*100)/(t?t:1));
}
squeezed = 1;
} else {
@@ -903,6 +943,11 @@ static void handle_escape(int signo)
exit(EXIT_FAILURE);
}
+
+#define err_init(X)
+#define host_init()
+#define hash_cistrcmp strcmp
+
static void initialise(void)
{
signal(SIGINT, handle_escape);
diff --git a/squeeze.h b/squeeze.h
index 920bfb7..1368a81 100644
--- a/squeeze.h
+++ b/squeeze.h
@@ -47,7 +47,7 @@ typedef struct datahdr {
word size;
} datahdr;
-#define DATABYTES sizeof(datahdr)
+#define DATABYTES ((int)(sizeof(datahdr)))
#define DATAWORDS (DATABYTES / sizeof(int))
#define DATAMAGIC 0x213542
#define SQUEEZED 0xffffea00