]> gitweb.factorcode.org Git - factor.git/blob - vm/cpu-arm.hpp
vm: Add a bunch of half-baked arm files. Also fix some .h issues.
[factor.git] / vm / cpu-arm.hpp
1 namespace factor {
2
3 #define CALLSTACK_BOTTOM(ctx) (ctx->callstack_seg->end - sizeof(cell) * 5) // omg
4
5 // void c_to_factor(cell quot);
6 // void lazy_jit_compile(cell quot);
7
8 static const fixnum xt_tail_pic_offset = 4 + 1; // or 4 or whatever else...
9
10
11 static const unsigned char call_opcode = 0xe8; // omg, these are x86 values
12 static const unsigned char jmp_opcode = 0xe9; // omg
13
14 static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 64; // omg
15
16
17 // omg
18 inline static unsigned char call_site_opcode(cell return_address) {
19   return *(unsigned char*)(return_address - 5);
20 }
21
22 // omg
23 inline static void check_call_site(cell return_address) {
24   unsigned char opcode = call_site_opcode(return_address);
25   FACTOR_ASSERT(opcode == call_opcode || opcode == jmp_opcode);
26   (void)opcode; // suppress warning when compiling without assertions
27 }
28
29 // omg
30 inline static void* get_call_target(cell return_address) {
31   check_call_site(return_address);
32   return (void*)(*(int*)(return_address - 4) + return_address);
33 }
34
35 // omg
36 inline static void set_call_target(cell return_address, cell target) {
37   check_call_site(return_address);
38   *(int*)(return_address - 4) = (uint32_t)(target - return_address);
39 }
40
41 inline static bool tail_call_site_p(cell return_address) {
42   switch (call_site_opcode(return_address)) {
43     case jmp_opcode:
44       return true;
45     case call_opcode:
46       return false;
47     default:
48       abort();
49       return false;
50   }
51 }
52
53 // inline static unsigned int fpu_status(unsigned int status) {
54 //   unsigned int r = 0;
55
56 //   if (status & 0x01)
57 //     r |= FP_TRAP_INVALID_OPERATION;
58 //   if (status & 0x04)
59 //     r |= FP_TRAP_ZERO_DIVIDE;
60 //   if (status & 0x08)
61 //     r |= FP_TRAP_OVERFLOW;
62 //   if (status & 0x10)
63 //     r |= FP_TRAP_UNDERFLOW;
64 //   if (status & 0x20)
65 //     r |= FP_TRAP_INEXACT;
66
67 //   return r;
68 // }
69
70 }