version 1.30, 1999/08/07 21:40:37
|
version 1.31, 1999/08/29 21:44:46
|
Line 78 char *progname;
|
Line 78 char *progname;
|
char *progname = "gforth"; |
char *progname = "gforth"; |
int optind = 1; |
int optind = 1; |
#endif |
#endif |
|
|
#ifdef HAS_DEBUG |
#ifdef HAS_DEBUG |
static int debug=0; |
static int debug=0; |
|
#else |
|
# define debug 0 |
|
# define perror(x...) |
|
# define fprintf(x...) |
#endif |
#endif |
|
|
ImageHeader *gforth_header; |
ImageHeader *gforth_header; |
|
|
#ifdef MEMCMP_AS_SUBROUTINE |
#ifdef MEMCMP_AS_SUBROUTINE |
Line 122 void relocate(Cell *image, const char *b
|
Line 128 void relocate(Cell *image, const char *b
|
int i=0, j, k, steps=(size/sizeof(Cell))/RELINFOBITS; |
int i=0, j, k, steps=(size/sizeof(Cell))/RELINFOBITS; |
Cell token; |
Cell token; |
char bits; |
char bits; |
/* static char bits[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};*/ |
|
|
|
/* printf("relocating %x[%x]\n", image, size); */ |
/* printf("relocating %x[%x]\n", image, size); */ |
|
|
for(k=0; k<=steps; k++) |
for(k=0; k<=steps; k++) { |
for(j=0, bits=bitstring[k]; j<RELINFOBITS; j++, i++, bits<<=1) { |
for(j=0, bits=bitstring[k]; j<RELINFOBITS; j++, i++, bits<<=1) { |
/* fprintf(stderr,"relocate: image[%d]\n", i);*/ |
/* fprintf(stderr,"relocate: image[%d]\n", i);*/ |
if(bits & (1U << (RELINFOBITS-1))) { |
if(bits & (1U << (RELINFOBITS-1))) { |
Line 156 void relocate(Cell *image, const char *b
|
Line 161 void relocate(Cell *image, const char *b
|
image[i]+=(Cell)image; |
image[i]+=(Cell)image; |
} |
} |
} |
} |
|
} |
((ImageHeader*)(image))->base = (Address) image; |
((ImageHeader*)(image))->base = (Address) image; |
} |
} |
|
|
Line 188 Address verbose_malloc(Cell size)
|
Line 194 Address verbose_malloc(Cell size)
|
Address r; |
Address r; |
/* leave a little room (64B) for stack underflows */ |
/* leave a little room (64B) for stack underflows */ |
if ((r = malloc(size+64))==NULL) { |
if ((r = malloc(size+64))==NULL) { |
#ifdef HAS_DEBUG |
|
perror(progname); |
perror(progname); |
#endif |
|
exit(1); |
exit(1); |
} |
} |
r = (Address)((((Cell)r)+(sizeof(Float)-1))&(-sizeof(Float))); |
r = (Address)((((Cell)r)+(sizeof(Float)-1))&(-sizeof(Float))); |
#ifdef HAS_DEBUG |
|
if (debug) |
if (debug) |
fprintf(stderr, "malloc succeeds, address=$%lx\n", (long)r); |
fprintf(stderr, "malloc succeeds, address=$%lx\n", (long)r); |
#endif |
|
return r; |
return r; |
} |
} |
|
|
Line 208 Address my_alloc(Cell size)
|
Line 210 Address my_alloc(Cell size)
|
Address r; |
Address r; |
|
|
#if defined(MAP_ANON) |
#if defined(MAP_ANON) |
#ifdef HAS_DEBUG |
|
if (debug) |
if (debug) |
fprintf(stderr,"try mmap($%lx, $%lx, ..., MAP_ANON, ...); ", (long)next_address, (long)size); |
fprintf(stderr,"try mmap($%lx, $%lx, ..., MAP_ANON, ...); ", (long)next_address, (long)size); |
#endif |
|
r=mmap(next_address, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); |
r=mmap(next_address, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); |
#else /* !defined(MAP_ANON) */ |
#else /* !defined(MAP_ANON) */ |
/* Ultrix (at least) does not define MAP_FILE and MAP_PRIVATE (both are |
/* Ultrix (at least) does not define MAP_FILE and MAP_PRIVATE (both are |
Line 228 Address my_alloc(Cell size)
|
Line 228 Address my_alloc(Cell size)
|
dev_zero = open("/dev/zero", O_RDONLY); |
dev_zero = open("/dev/zero", O_RDONLY); |
if (dev_zero == -1) { |
if (dev_zero == -1) { |
r = (Address)-1; |
r = (Address)-1; |
#ifdef HAS_DEBUG |
|
if (debug) |
if (debug) |
fprintf(stderr, "open(\"/dev/zero\"...) failed (%s), no mmap; ", |
fprintf(stderr, "open(\"/dev/zero\"...) failed (%s), no mmap; ", |
strerror(errno)); |
strerror(errno)); |
#endif |
|
} else { |
} else { |
#ifdef HAS_DEBUG |
|
if (debug) |
if (debug) |
fprintf(stderr,"try mmap($%lx, $%lx, ..., MAP_FILE, dev_zero, ...); ", (long)next_address, (long)size); |
fprintf(stderr,"try mmap($%lx, $%lx, ..., MAP_FILE, dev_zero, ...); ", (long)next_address, (long)size); |
#endif |
|
r=mmap(next_address, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_FILE|MAP_PRIVATE, dev_zero, 0); |
r=mmap(next_address, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_FILE|MAP_PRIVATE, dev_zero, 0); |
} |
} |
#endif /* !defined(MAP_ANON) */ |
#endif /* !defined(MAP_ANON) */ |
|
|
if (r != (Address)-1) { |
if (r != (Address)-1) { |
#ifdef HAS_DEBUG |
|
if (debug) |
if (debug) |
fprintf(stderr, "success, address=$%lx\n", (long) r); |
fprintf(stderr, "success, address=$%lx\n", (long) r); |
#endif |
|
if (pagesize != 1) |
if (pagesize != 1) |
next_address = (Address)(((((Cell)r)+size-1)&-pagesize)+2*pagesize); /* leave one page unmapped */ |
next_address = (Address)(((((Cell)r)+size-1)&-pagesize)+2*pagesize); /* leave one page unmapped */ |
return r; |
return r; |
} |
} |
#ifdef HAS_DEBUG |
|
if (debug) |
if (debug) |
fprintf(stderr, "failed: %s\n", strerror(errno)); |
fprintf(stderr, "failed: %s\n", strerror(errno)); |
#endif |
|
#endif /* HAVE_MMAP */ |
#endif /* HAVE_MMAP */ |
/* use malloc as fallback */ |
/* use malloc as fallback */ |
return verbose_malloc(size); |
return verbose_malloc(size); |
Line 409 Address loader(FILE *imagefile, char* fi
|
Line 401 Address loader(FILE *imagefile, char* fi
|
preamblesize+=8; |
preamblesize+=8; |
} while(memcmp(magic,"Gforth2",7)); |
} while(memcmp(magic,"Gforth2",7)); |
magic7 = magic[7]; |
magic7 = magic[7]; |
#ifdef HAS_DEBUG |
|
if (debug) { |
if (debug) { |
magic[7]='\0'; |
magic[7]='\0'; |
fprintf(stderr,"Magic found: %s ", magic); |
fprintf(stderr,"Magic found: %s ", magic); |
print_sizes(magic7); |
print_sizes(magic7); |
} |
} |
#endif |
|
|
|
if (magic7 != sizebyte) |
if (magic7 != sizebyte) |
{ |
{ |
Line 437 Address loader(FILE *imagefile, char* fi
|
Line 427 Address loader(FILE *imagefile, char* fi
|
#elif PAGESIZE |
#elif PAGESIZE |
pagesize=PAGESIZE; /* in limits.h according to Gallmeister's POSIX.4 book */ |
pagesize=PAGESIZE; /* in limits.h according to Gallmeister's POSIX.4 book */ |
#endif |
#endif |
#ifdef HAS_DEBUG |
|
if (debug) |
if (debug) |
fprintf(stderr,"pagesize=%ld\n",(unsigned long) pagesize); |
fprintf(stderr,"pagesize=%ld\n",(unsigned long) pagesize); |
#endif |
|
|
|
image = dict_alloc(preamblesize+dictsize+data_offset)+data_offset; |
image = dict_alloc(preamblesize+dictsize+data_offset)+data_offset; |
rewind(imagefile); /* fseek(imagefile,0L,SEEK_SET); */ |
rewind(imagefile); /* fseek(imagefile,0L,SEEK_SET); */ |
Line 502 FILE *openimage(char *fullfilename)
|
Line 490 FILE *openimage(char *fullfilename)
|
char * expfilename = tilde_cstr(fullfilename, strlen(fullfilename), 1); |
char * expfilename = tilde_cstr(fullfilename, strlen(fullfilename), 1); |
|
|
image_file=fopen(expfilename,"rb"); |
image_file=fopen(expfilename,"rb"); |
#ifdef HAS_DEBUG |
|
if (image_file!=NULL && debug) |
if (image_file!=NULL && debug) |
fprintf(stderr, "Opened image file: %s\n", expfilename); |
fprintf(stderr, "Opened image file: %s\n", expfilename); |
#endif |
|
return image_file; |
return image_file; |
} |
} |
|
|