]> gitweb.factorcode.org Git - factor.git/blob - vm/code_block.hpp
Merge Phil Dawes' VM work
[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         /* address of vm object*/
30         RT_VM,
31 };
32
33 enum relocation_class {
34         /* absolute address in a 64-bit location */
35         RC_ABSOLUTE_CELL,
36         /* absolute address in a 32-bit location */
37         RC_ABSOLUTE,
38         /* relative address in a 32-bit location */
39         RC_RELATIVE,
40         /* absolute address in a PowerPC LIS/ORI sequence */
41         RC_ABSOLUTE_PPC_2_2,
42         /* absolute address in a PowerPC LWZ instruction */
43         RC_ABSOLUTE_PPC_2,
44         /* relative address in a PowerPC LWZ/STW/BC instruction */
45         RC_RELATIVE_PPC_2,
46         /* relative address in a PowerPC B/BL instruction */
47         RC_RELATIVE_PPC_3,
48         /* relative address in an ARM B/BL instruction */
49         RC_RELATIVE_ARM_3,
50         /* pointer to address in an ARM LDR/STR instruction */
51         RC_INDIRECT_ARM,
52         /* pointer to address in an ARM LDR/STR instruction offset by 8 bytes */
53         RC_INDIRECT_ARM_PC
54 };
55
56 static const cell rel_absolute_ppc_2_mask = 0xffff;
57 static const cell rel_relative_ppc_2_mask = 0xfffc;
58 static const cell rel_relative_ppc_3_mask = 0x3fffffc;
59 static const cell rel_indirect_arm_mask = 0xfff;
60 static const cell rel_relative_arm_3_mask = 0xffffff;
61
62 /* code relocation table consists of a table of entries for each fixup */
63 typedef u32 relocation_entry;
64
65 struct factorvm;
66
67 typedef void (*relocation_iterator)(relocation_entry rel, cell index, code_block *compiled, factorvm *vm);
68
69 // callback functions
70 void relocate_code_block(code_block *compiled, factorvm *myvm);
71 void copy_literal_references(code_block *compiled, factorvm *myvm);
72 void update_word_references(code_block *compiled, factorvm *myvm);
73 void update_literal_and_word_references(code_block *compiled, factorvm *myvm);
74
75 }