aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Bradley <wmb@laptop.org>2017-06-17 07:50:29 -1000
committerMitch Bradley <wmb@laptop.org>2017-06-17 07:50:29 -1000
commitff78edcbed215404a5453262bc73c460a94c05b0 (patch)
tree923145a41f62bddddf74c7a5545d2aac4b4950dd
parentbaa58e60fa72ecd6c7832d0160e84a12c51d6ef3 (diff)
downloadcforth-ff78edcbed215404a5453262bc73c460a94c05b0.tar.gz
Fixed word size problem in makebi.c
It caused failures with 64-bit embedded images.
-rwxr-xr-xsrc/cforth/embed/makebi.c31
-rwxr-xr-xsrc/cforth/forth.h2
2 files changed, 16 insertions, 17 deletions
diff --git a/src/cforth/embed/makebi.c b/src/cforth/embed/makebi.c
index fa70ffa..0be0ad6 100755
--- a/src/cforth/embed/makebi.c
+++ b/src/cforth/embed/makebi.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include "config.h"
int
test_little_endian()
@@ -8,12 +9,12 @@ test_little_endian()
return *(char *)&cell == 1;
}
-void longs_to_file(char *filename, FILE *infile, int len, int *dsizep, int *usizep)
+void cells_to_file(char *filename, FILE *infile, int len, u_cell *dsizep, u_cell *usizep)
{
FILE *outfile;
- int val;
+ u_cell val;
int le;
- int i;
+ int i, j;
if ((outfile = fopen(filename, "w")) == 0) {
fprintf(stderr, "Can't open output file %s\n", filename);
@@ -23,16 +24,13 @@ void longs_to_file(char *filename, FILE *infile, int len, int *dsizep, int *usiz
le = test_little_endian();
for (i=0; i<8; i++) {
- if (le) {
- val = (unsigned char)fgetc(infile);
- val |= ((unsigned char)fgetc(infile) << 8);
- val |= ((unsigned char)fgetc(infile) << 16);
- val |= ((unsigned char)fgetc(infile) << 24);
- } else {
- val = ((unsigned char)fgetc(infile) << 24);
- val |= ((unsigned char)fgetc(infile) << 16);
- val |= ((unsigned char)fgetc(infile) << 8);
- val |= (unsigned char)fgetc(infile);
+ val = 0;
+ for (j=0; j<sizeof(val); j++) {
+ if (le) {
+ val = (val>>8) | ((u_cell)(unsigned char)fgetc(infile) << ((sizeof(val) - 1)*8));
+ } else {
+ val = (val<<8) | (unsigned char)fgetc(infile);
+ }
}
if (i == 3) {
*dsizep = val;
@@ -40,7 +38,7 @@ void longs_to_file(char *filename, FILE *infile, int len, int *dsizep, int *usiz
if (i == 5) {
*usizep = val;
}
- fprintf(outfile, "0x%08x, ", val);
+ fprintf(outfile, "0x%tx, ", val);
}
fputc('\n', outfile);
fclose(outfile);
@@ -75,7 +73,8 @@ int main(argc, argv)
{
char *dictionary_file;
FILE *infile;
- int dictsize, uasize;
+ // int dictsize, uasize;
+ u_cell dictsize, uasize;
if(argc != 2)
dictionary_file = "forth.dic";
@@ -87,7 +86,7 @@ int main(argc, argv)
exit(1);
}
- longs_to_file("dicthdr.h", infile, 8, &dictsize, &uasize);
+ cells_to_file("dicthdr.h", infile, 8, &dictsize, &uasize);
bytes_to_file("dict.h", infile, dictsize);
bytes_to_file("userarea.h", infile, uasize);
diff --git a/src/cforth/forth.h b/src/cforth/forth.h
index 8e5a71e..7e6fd56 100755
--- a/src/cforth/forth.h
+++ b/src/cforth/forth.h
@@ -18,7 +18,7 @@ struct voc_t {
#define vocabulary_t struct voc_t
struct header {
- cell magic, serial, dstart, dsize, ustart, usize, entry, res1;
+ u_cell magic, serial, dstart, dsize, ustart, usize, entry, res1;
};
extern struct header file_hdr;
extern const struct header builtin_hdr;