]> gitweb.factorcode.org Git - factor.git/blob - vm/code_block.h
Merge branch 'master' into experimental
[factor.git] / vm / code_block.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 void flush_icache_for(F_CODE_BLOCK *compiled);
59
60 typedef void (*RELOCATION_ITERATOR)(F_REL *rel, F_CODE_BLOCK *compiled);
61
62 void iterate_relocations(F_CODE_BLOCK *compiled, RELOCATION_ITERATOR iter);
63
64 void store_address_in_code_block(CELL class, CELL offset, F_FIXNUM absolute_value);
65
66 void relocate_code_block(F_CODE_BLOCK *compiled);
67
68 void update_literal_references(F_CODE_BLOCK *compiled);
69
70 void copy_literal_references(F_CODE_BLOCK *compiled);
71
72 void update_word_references(F_CODE_BLOCK *compiled);
73
74 void mark_code_block(F_CODE_BLOCK *compiled);
75
76 void mark_active_blocks(F_CONTEXT *stacks);
77
78 void mark_object_code_block(CELL scan);
79
80 void relocate_code_block(F_CODE_BLOCK *relocating);
81
82 CELL compiled_code_format(void);
83
84 bool stack_traces_p(void);
85
86 F_CODE_BLOCK *add_compiled_block(
87         CELL type,
88         F_ARRAY *code,
89         F_ARRAY *labels,
90         CELL relocation,
91         CELL literals);