| int die_on_signal=0; |
int die_on_signal=0; |
| #ifndef INCLUDE_IMAGE |
#ifndef INCLUDE_IMAGE |
| static int clear_dictionary=0; |
static int clear_dictionary=0; |
| static size_t pagesize=0; |
UCell pagesize=1; |
| char *progname; |
char *progname; |
| #else |
#else |
| char *progname = "gforth"; |
char *progname = "gforth"; |
| int optind = 1; |
int optind = 1; |
| #endif |
#endif |
| static int debug=0; |
static int debug=0; |
| |
ImageHeader *gforth_header; |
| |
|
| /* image file format: |
/* image file format: |
| * "#! binary-path -i\n" (e.g., "#! /usr/local/bin/gforth-0.4.0 -i\n") |
* "#! binary-path -i\n" (e.g., "#! /usr/local/bin/gforth-0.4.0 -i\n") |
| * bit 0: endian, big=0, little=1. |
* bit 0: endian, big=0, little=1. |
| * The magic are always 8 octets, no matter what the native AU/character size is |
* The magic are always 8 octets, no matter what the native AU/character size is |
| * padding to max alignment (no padding necessary on current machines) |
* padding to max alignment (no padding necessary on current machines) |
| * ImageHeader structure (see below) |
* ImageHeader structure (see forth.h) |
| * data (size in ImageHeader.image_size) |
* data (size in ImageHeader.image_size) |
| * tags ((if relocatable, 1 bit/data cell) |
* tags ((if relocatable, 1 bit/data cell) |
| * |
* |
| * If the word is <CF(DOESJUMP), it's a primitive |
* If the word is <CF(DOESJUMP), it's a primitive |
| */ |
*/ |
| |
|
| typedef struct { |
|
| Address base; /* base address of image (0 if relocatable) */ |
|
| UCell checksum; /* checksum of ca's to protect against some |
|
| incompatible binary/executable combinations |
|
| (0 if relocatable) */ |
|
| UCell image_size; /* all sizes in bytes */ |
|
| UCell dict_size; |
|
| UCell data_stack_size; |
|
| UCell fp_stack_size; |
|
| UCell return_stack_size; |
|
| UCell locals_stack_size; |
|
| Xt *boot_entry; /* initial ip for booting (in BOOT) */ |
|
| Xt *throw_entry; /* ip after signal (in THROW) */ |
|
| Cell unused1; /* possibly tib stack size */ |
|
| Cell unused2; |
|
| Address data_stack_base; /* this and the following fields are initialized by the loader */ |
|
| Address fp_stack_base; |
|
| Address return_stack_base; |
|
| Address locals_stack_base; |
|
| } ImageHeader; |
|
| /* the image-header is created in main.fs */ |
|
| |
|
| void relocate(Cell *image, const char *bitstring, int size, Label symbols[]) |
void relocate(Cell *image, const char *bitstring, int size, Label symbols[]) |
| { |
{ |
| int i=0, j, k, steps=(size/sizeof(Cell))/RELINFOBITS; |
int i=0, j, k, steps=(size/sizeof(Cell))/RELINFOBITS; |
| if (r != (Address)-1) { |
if (r != (Address)-1) { |
| if (debug) |
if (debug) |
| fprintf(stderr, "success, address=$%lx\n", (long) r); |
fprintf(stderr, "success, address=$%lx\n", (long) r); |
| if (pagesize != 0) |
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; |
| } |
} |
| m=1024*1024*1024; |
m=1024*1024*1024; |
| else if (strcmp(endp,"T")==0) { |
else if (strcmp(endp,"T")==0) { |
| #if (SIZEOF_CHAR_P > 4) |
#if (SIZEOF_CHAR_P > 4) |
| m=1024*1024*1024*1024; |
m=1024L*1024*1024*1024; |
| #else |
#else |
| fprintf(stderr,"%s: size specification \"%s\" too large for this machine\n", progname, endp); |
fprintf(stderr,"%s: size specification \"%s\" too large for this machine\n", progname, endp); |
| exit(1); |
exit(1); |
| image_file = open_image_file(imagename, path); |
image_file = open_image_file(imagename, path); |
| image = loader(image_file, imagename); |
image = loader(image_file, imagename); |
| #endif |
#endif |
| |
gforth_header=(ImageHeader *)image; /* used in SIGSEGV handler */ |
| |
|
| { |
{ |
| char path2[strlen(path)+1]; |
char path2[strlen(path)+1]; |