]> gitweb.factorcode.org Git - factor.git/blob - vm/cpu-x86.hpp
audio.engine.test: cleanup using
[factor.git] / vm / cpu-x86.hpp
1 namespace factor {
2
3 #define CALLSTACK_BOTTOM(ctx) \
4   (ctx->callstack_seg->end - sizeof(cell) * 5)
5
6 inline static void flush_icache(cell start, cell len) { (void)start; (void)len; }
7
8 // In the instruction sequence:
9
10 // MOV EBX,...
11 // JMP blah
12
13 // the offset from the immediate operand to MOV to the instruction after
14 // the jump is a cell for the immediate operand, 4 bytes for the JMP
15 // destination, and one byte for the JMP opcode.
16 static const fixnum xt_tail_pic_offset = 4 + 1;
17
18 static const unsigned char call_opcode = 0xe8;
19 static const unsigned char jmp_opcode = 0xe9;
20
21 inline static unsigned char call_site_opcode(cell return_address) {
22   return *(unsigned char*)(return_address - 5);
23 }
24
25 inline static void check_call_site(cell return_address) {
26   unsigned char opcode = call_site_opcode(return_address);
27   FACTOR_ASSERT(opcode == call_opcode || opcode == jmp_opcode);
28   (void)opcode; // suppress warning when compiling without assertions
29 }
30
31 inline static void* get_call_target(cell return_address) {
32   check_call_site(return_address);
33   return (void*)(*(int*)(return_address - 4) + return_address);
34 }
35
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 }