]> gitweb.factorcode.org Git - factor.git/blob - vm/code_heap.h
Merge branch 'master' into experimental (untested!)
[factor.git] / vm / code_heap.h
1 typedef enum {
2         /* arg is a primitive number */
3         RT_PRIMITIVE,
4         /* arg is a literal table index, holding an array pair (symbol/dll) */
5         RT_DLSYM,
6         /* a pointer to a compiled word reference */
7         RT_DISPATCH,
8         /* a compiled word reference */
9         RT_XT,
10         /* current offset */
11         RT_HERE,
12         /* a local label */
13         RT_LABEL,
14         /* immediate literal */
15         RT_IMMEDIATE,
16         /* address of stack_chain var */
17         RT_STACK_CHAIN
18 } F_RELTYPE;
19
20 typedef enum {
21         /* absolute address in a 64-bit location */
22         RC_ABSOLUTE_CELL,
23         /* absolute address in a 32-bit location */
24         RC_ABSOLUTE,
25         /* relative address in a 32-bit location */
26         RC_RELATIVE,
27         /* relative address in a PowerPC LIS/ORI sequence */
28         RC_ABSOLUTE_PPC_2_2,
29         /* relative address in a PowerPC LWZ/STW/BC instruction */
30         RC_RELATIVE_PPC_2,
31         /* relative address in a PowerPC B/BL instruction */
32         RC_RELATIVE_PPC_3,
33         /* relative address in an ARM B/BL instruction */
34         RC_RELATIVE_ARM_3,
35         /* pointer to address in an ARM LDR/STR instruction */
36         RC_INDIRECT_ARM,
37         /* pointer to address in an ARM LDR/STR instruction offset by 8 bytes */
38         RC_INDIRECT_ARM_PC
39 } F_RELCLASS;
40
41 #define REL_RELATIVE_PPC_2_MASK 0xfffc
42 #define REL_RELATIVE_PPC_3_MASK 0x3fffffc
43 #define REL_INDIRECT_ARM_MASK 0xfff
44 #define REL_RELATIVE_ARM_3_MASK 0xffffff
45
46 /* the rel type is built like a cell to avoid endian-specific code in
47 the compiler */
48 #define REL_TYPE(r) ((r)->type & 0x000000ff)
49 #define REL_CLASS(r) (((r)->type & 0x0000ff00) >> 8)
50 #define REL_ARGUMENT(r) (((r)->type & 0xffff0000) >> 16)
51
52 /* code relocation consists of a table of entries for each fixup */
53 typedef struct {
54         unsigned int type;
55         unsigned int offset;
56 } F_REL;
57
58 #define CREF(array,i) ((CELL)(array) + CELLS * (i))
59
60 void apply_relocation(CELL class, CELL offset, F_FIXNUM absolute_value);
61
62 void relocate_code_block(F_COMPILED *relocating, CELL code_start, CELL literals_start);
63
64 void default_word_code(F_WORD *word, bool relocate);
65
66 void set_word_code(F_WORD *word, F_COMPILED *compiled);
67
68 F_COMPILED *add_compiled_block(
69         CELL type,
70         F_ARRAY *code,
71         F_ARRAY *labels,
72         CELL relocation,
73         F_ARRAY *literals);
74
75 CELL compiled_code_format(void);
76 bool stack_traces_p(void);
77
78 void primitive_modify_code_heap(void);