]> gitweb.factorcode.org Git - factor.git/blob - vm/cpu-ppc.hpp
Fix compile error in cpu-ppc.hpp
[factor.git] / vm / cpu-ppc.hpp
1 namespace factor
2 {
3
4 #define FACTOR_CPU_STRING "ppc"
5 #define VM_ASM_API VM_C_API
6
7 register cell ds asm("r13");
8 register cell rs asm("r14");
9
10 /* In the instruction sequence:
11
12    LOAD32 r3,...
13    B blah
14
15    the offset from the immediate operand to LOAD32 to the instruction after
16    the branch is two instructions. */
17 static const fixnum xt_tail_pic_offset = 4 * 2;
18
19 inline static void check_call_site(cell return_address)
20 {
21 #ifdef FACTOR_DEBUG
22         cell insn = *(cell *)return_address;
23         /* Check that absolute bit is 0 */
24         assert((insn & 0x2) == 0x0);
25         /* Check that instruction is branch */
26         assert((insn >> 26) == 0x12);
27 #endif
28 }
29
30 static const cell b_mask = 0x3fffffc;
31
32 inline static void *get_call_target(cell return_address)
33 {
34         return_address -= sizeof(cell);
35         check_call_site(return_address);
36
37         cell insn = *(cell *)return_address;
38         cell unsigned_addr = (insn & b_mask);
39         fixnum signed_addr = (fixnum)(unsigned_addr << 6) >> 6;
40         return (void *)(signed_addr + return_address);
41 }
42
43 inline static void set_call_target(cell return_address, void *target)
44 {
45         return_address -= sizeof(cell);
46         check_call_site(return_address);
47
48         cell insn = *(cell *)return_address;
49
50         fixnum relative_address = ((cell)target - return_address);
51         insn = ((insn & ~b_mask) | (relative_address & b_mask));
52         *(cell *)return_address = insn;
53
54         /* Flush the cache line containing the call we just patched */
55         __asm__ __volatile__ ("icbi 0, %0\n" "sync\n"::"r" (return_address):);
56 }
57
58 inline static bool tail_call_site_p(cell return_address)
59 {
60         return_address -= sizeof(cell);
61         cell insn = *(cell *)return_address;
62         return (insn & 0x1) == 0;
63 }
64
65 /* Defined in assembly */
66 VM_ASM_API void c_to_factor(cell quot);
67 VM_ASM_API void throw_impl(cell quot, stack_frame *rewind);
68 VM_ASM_API void lazy_jit_compile(cell quot);
69 VM_ASM_API void flush_icache(cell start, cell len);
70
71 VM_ASM_API void set_callstack(stack_frame *to,
72                                stack_frame *from,
73                                cell length,
74                                void *(*memcpy)(void*,const void*, size_t));
75
76 }