]> gitweb.factorcode.org Git - factor.git/blob - vm/instruction_operands.hpp
Put brackets around ipv6 addresses in `inet6 present`
[factor.git] / vm / instruction_operands.hpp
1 namespace factor {
2
3 enum relocation_type {
4   // arg is a literal table index, holding a pair (symbol/dll)
5   RT_DLSYM,
6   // a word or quotation's general entry point
7   RT_ENTRY_POINT,
8   // a word's PIC entry point
9   RT_ENTRY_POINT_PIC,
10   // a word's tail-call PIC entry point
11   RT_ENTRY_POINT_PIC_TAIL,
12   // current offset
13   RT_HERE,
14   // current code block
15   RT_THIS,
16   // data heap literal
17   RT_LITERAL,
18   // untagged fixnum literal
19   RT_UNTAGGED,
20   // address of megamorphic_cache_hits var
21   RT_MEGAMORPHIC_CACHE_HITS,
22   // address of vm object
23   RT_VM,
24   // value of vm->cards_offset
25   RT_CARDS_OFFSET,
26   // value of vm->decks_offset
27   RT_DECKS_OFFSET,
28   RT_UNUSED,
29   // arg is a literal table index, holding a pair (symbol/dll)
30   RT_DLSYM_TOC,
31   // address of inline_cache_miss function. This is a separate
32   // relocation to reduce compile time and size for PICs.
33   RT_INLINE_CACHE_MISS,
34   // address of safepoint page in code heap
35   RT_SAFEPOINT
36 };
37
38 enum relocation_class {
39   // absolute address in a pointer-width location
40   RC_ABSOLUTE_CELL,
41   // absolute address in a 4 byte location
42   RC_ABSOLUTE,
43   // relative address in a 4 byte location
44   RC_RELATIVE,
45   // absolute address in a PowerPC LIS/ORI sequence
46   RC_ABSOLUTE_PPC_2_2,
47   // absolute address in a PowerPC LWZ instruction
48   RC_ABSOLUTE_PPC_2,
49   // relative address in a PowerPC LWZ/STW/BC instruction
50   RC_RELATIVE_PPC_2_PC,
51   // relative address in a PowerPC B/BL instruction
52   RC_RELATIVE_PPC_3_PC,
53   // relative address in an ARM B/BL instruction
54   RC_RELATIVE_ARM_3,
55   // pointer to address in an ARM LDR/STR instruction
56   RC_INDIRECT_ARM,
57   // pointer to address in an ARM LDR/STR instruction offset by 8 bytes
58   RC_INDIRECT_ARM_PC,
59   // absolute address in a 2 byte location
60   RC_ABSOLUTE_2,
61   // absolute address in a 1 byte location
62   RC_ABSOLUTE_1,
63   // absolute address in a PowerPC LIS/ORI/SLDI/ORIS/ORI sequence
64   RC_ABSOLUTE_PPC_2_2_2_2,
65 };
66
67 static const cell rel_absolute_ppc_2_mask = 0x0000ffff;
68 static const cell rel_relative_ppc_2_mask = 0x0000fffc;
69 static const cell rel_relative_ppc_3_mask = 0x03fffffc;
70 static const cell rel_indirect_arm_mask = 0x00000fff;
71 static const cell rel_relative_arm_3_mask = 0x00ffffff;
72
73 // code relocation table consists of a table of entries for each fixup
74 struct relocation_entry {
75   uint32_t value;
76
77   explicit relocation_entry(uint32_t value) : value(value) {}
78
79   relocation_entry(relocation_type rel_type, relocation_class rel_class,
80                    cell offset) {
81     value = (uint32_t)((rel_type << 28) | (rel_class << 24) | offset);
82   }
83
84   relocation_type type() {
85     return (relocation_type)((value & 0xf0000000) >> 28);
86   }
87
88   relocation_class klass() {
89     return (relocation_class)((value & 0x0f000000) >> 24);
90   }
91
92   cell offset() { return (value & 0x00ffffff); }
93
94   int number_of_parameters() {
95     switch (type()) {
96       case RT_VM:
97         return 1;
98       case RT_DLSYM:
99       case RT_DLSYM_TOC:
100         return 2;
101       case RT_ENTRY_POINT:
102       case RT_ENTRY_POINT_PIC:
103       case RT_ENTRY_POINT_PIC_TAIL:
104       case RT_LITERAL:
105       case RT_HERE:
106       case RT_UNTAGGED:
107       case RT_THIS:
108       case RT_MEGAMORPHIC_CACHE_HITS:
109       case RT_CARDS_OFFSET:
110       case RT_DECKS_OFFSET:
111       case RT_INLINE_CACHE_MISS:
112       case RT_SAFEPOINT:
113         return 0;
114       default:
115         critical_error("Bad rel type in number_of_parameters()", type());
116         return -1; // Can't happen
117     }
118   }
119 };
120
121 struct instruction_operand {
122   relocation_entry rel;
123   code_block* compiled;
124   cell index;
125   cell pointer;
126
127   instruction_operand(relocation_entry rel, code_block* compiled,
128                       cell index);
129
130   fixnum load_value_2_2();
131   fixnum load_value_2_2_2_2();
132   fixnum load_value_masked(cell mask, cell bits, cell shift);
133   fixnum load_value(cell relative_to);
134   code_block* load_code_block();
135
136   void store_value_2_2(fixnum value);
137   void store_value_2_2_2_2(fixnum value);
138   void store_value_masked(fixnum value, cell mask, cell shift);
139   void store_value(fixnum value);
140 };
141
142 }