]> gitweb.factorcode.org Git - factor.git/blob - vm/image.h
Initial import
[factor.git] / vm / image.h
1 #define IMAGE_MAGIC 0x0f0e0d0c
2 #define IMAGE_VERSION 4
3
4 typedef struct {
5         CELL magic;
6         CELL version;
7         /* all pointers in the image file are relocated from
8            relocation_base to here when the image is loaded */
9         CELL data_relocation_base;
10         /* size of heap */
11         CELL data_size;
12         /* code relocation base */
13         CELL code_relocation_base;
14         /* size of code heap */
15         CELL code_size;
16         /* tagged pointer to t singleton */
17         CELL t;
18         /* tagged pointer to bignum 0 */
19         CELL bignum_zero;
20         /* tagged pointer to bignum 1 */
21         CELL bignum_pos_one;
22         /* tagged pointer to bignum -1 */
23         CELL bignum_neg_one;
24         /* Initial user environment */
25         CELL userenv[USER_ENV];
26 } F_HEADER;
27
28 typedef struct {
29         const F_CHAR* image;
30         CELL ds_size, rs_size;
31         CELL gen_count, young_size, aging_size;
32         CELL code_size;
33         bool secure_gc;
34 } F_PARAMETERS;
35
36 void load_image(F_PARAMETERS *p);
37 void init_objects(F_HEADER *h);
38 bool save_image(const F_CHAR *file);
39
40 DECLARE_PRIMITIVE(save_image);
41 DECLARE_PRIMITIVE(save_image_and_exit);
42
43 /* relocation base of currently loaded image's data heap */
44 CELL data_relocation_base;
45
46 INLINE void data_fixup(CELL *cell)
47 {
48         if(immediate_p(*cell))
49                 return;
50
51         F_ZONE *tenured = &data_heap->generations[TENURED];
52         *cell += (tenured->start - data_relocation_base);
53 }
54
55 CELL code_relocation_base;
56
57 INLINE void code_fixup(XT *cell)
58 {
59         CELL value = (CELL)*cell;
60         value += (code_heap.segment->start - code_relocation_base);
61         *cell = (XT)value;
62 }
63
64 void relocate_data();
65 void relocate_code();