]> gitweb.factorcode.org Git - factor.git/blob - vm/code_block.hpp
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / code_block.hpp
1 namespace factor
2 {
3
4 enum relocation_type {
5         /* arg is a primitive number */
6         RT_PRIMITIVE,
7         /* arg is a literal table index, holding an array pair (symbol/dll) */
8         RT_DLSYM,
9         /* a pointer to a compiled word reference */
10         RT_DISPATCH,
11         /* a word or quotation's general entry point */
12         RT_XT,
13         /* a word's PIC entry point */
14         RT_XT_PIC,
15         /* a word's tail-call PIC entry point */
16         RT_XT_PIC_TAIL,
17         /* current offset */
18         RT_HERE,
19         /* current code block */
20         RT_THIS,
21         /* immediate literal */
22         RT_IMMEDIATE,
23         /* address of stack_chain var */
24         RT_STACK_CHAIN,
25         /* untagged fixnum literal */
26         RT_UNTAGGED,
27         /* address of megamorphic_cache_hits var */
28         RT_MEGAMORPHIC_CACHE_HITS,
29 };
30
31 enum relocation_class {
32         /* absolute address in a 64-bit location */
33         RC_ABSOLUTE_CELL,
34         /* absolute address in a 32-bit location */
35         RC_ABSOLUTE,
36         /* relative address in a 32-bit location */
37         RC_RELATIVE,
38         /* absolute address in a PowerPC LIS/ORI sequence */
39         RC_ABSOLUTE_PPC_2_2,
40         /* absolute address in a PowerPC LWZ instruction */
41         RC_ABSOLUTE_PPC_2,
42         /* relative address in a PowerPC LWZ/STW/BC instruction */
43         RC_RELATIVE_PPC_2,
44         /* relative address in a PowerPC B/BL instruction */
45         RC_RELATIVE_PPC_3,
46         /* relative address in an ARM B/BL instruction */
47         RC_RELATIVE_ARM_3,
48         /* pointer to address in an ARM LDR/STR instruction */
49         RC_INDIRECT_ARM,
50         /* pointer to address in an ARM LDR/STR instruction offset by 8 bytes */
51         RC_INDIRECT_ARM_PC
52 };
53
54 static const cell rel_absolute_ppc_2_mask = 0xffff;
55 static const cell rel_relative_ppc_2_mask = 0xfffc;
56 static const cell rel_relative_ppc_3_mask = 0x3fffffc;
57 static const cell rel_indirect_arm_mask = 0xfff;
58 static const cell rel_relative_arm_3_mask = 0xffffff;
59
60 /* code relocation table consists of a table of entries for each fixup */
61 typedef u32 relocation_entry;
62
63 void flush_icache_for(code_block *compiled);
64
65 typedef void (*relocation_iterator)(relocation_entry rel, cell index, code_block *compiled);
66
67 void iterate_relocations(code_block *compiled, relocation_iterator iter);
68
69 void store_address_in_code_block(cell klass, cell offset, fixnum absolute_value);
70
71 void relocate_code_block(code_block *compiled);
72
73 void update_literal_references(code_block *compiled);
74
75 void copy_literal_references(code_block *compiled);
76
77 void update_word_references(code_block *compiled);
78
79 void update_literal_and_word_references(code_block *compiled);
80
81 void mark_code_block(code_block *compiled);
82
83 void mark_active_blocks(context *stacks);
84
85 void mark_object_code_block(object *scan);
86
87 void relocate_code_block(code_block *relocating);
88
89 inline static bool stack_traces_p()
90 {
91         return userenv[STACK_TRACES_ENV] != F;
92 }
93
94 code_block *add_code_block(cell type, cell code, cell labels, cell relocation, cell literals);
95
96 }