]> gitweb.factorcode.org Git - factor.git/blob - vm/cpu-x86.hpp
Merge branch 'hashcash' of git://github.com/martind/factor
[factor.git] / vm / cpu-x86.hpp
1 #include <assert.h>
2
3 namespace factor
4 {
5
6 #define FRAME_RETURN_ADDRESS(frame) *(void **)(frame_successor(frame) + 1)
7
8 inline static void flush_icache(cell start, cell len) {}
9
10 /* In the instruction sequence:
11
12    MOV EBX,...
13    JMP blah
14
15    the offset from the immediate operand to MOV to the instruction after
16    the jump is a cell for the immediate operand, 4 bytes for the JMP
17    destination, and one byte for the JMP opcode. */
18 static const fixnum xt_tail_pic_offset = sizeof(cell) + 4 + 1;
19
20 static const unsigned char call_opcode = 0xe8;
21 static const unsigned char jmp_opcode = 0xe9;
22
23 inline static unsigned char call_site_opcode(cell return_address)
24 {
25         return *(unsigned char *)(return_address - 5);
26 }
27
28 inline static void check_call_site(cell return_address)
29 {
30 #ifdef FACTOR_DEBUG
31         unsigned char opcode = call_site_opcode(return_address);
32         assert(opcode == call_opcode || opcode == jmp_opcode);
33 #endif
34 }
35
36 inline static void *get_call_target(cell return_address)
37 {
38         check_call_site(return_address);
39         return (void *)(*(int *)(return_address - 4) + return_address);
40 }
41
42 inline static void set_call_target(cell return_address, void *target)
43 {
44         check_call_site(return_address);
45         *(int *)(return_address - 4) = ((cell)target - return_address);
46 }
47
48 inline static bool tail_call_site_p(cell return_address)
49 {
50         return call_site_opcode(return_address) == jmp_opcode;
51 }
52
53 /* Defined in assembly */
54 VM_ASM_API void c_to_factor(cell quot);
55 VM_ASM_API void throw_impl(cell quot, stack_frame *rewind_to);
56 VM_ASM_API void lazy_jit_compile(cell quot);
57
58 VM_C_API void set_callstack(stack_frame *to,
59                               stack_frame *from,
60                               cell length,
61                               void *(*memcpy)(void*,const void*, size_t));
62
63 }