<< "vocab:bootstrap/assembler/x86.windows.factor" parse-file suffix! >> call
: jit-install-seh ( -- )
+ ! VM pointer must be in vm-reg already
! Create a new exception record and store it in the TIB.
! Clobbers tib-temp.
! Align stack
ESP 3 bootstrap-cells ADD
- ! Exception handler address filled in by callback.cpp
- tib-temp 0 MOV rc-absolute-cell rel-exception-handler
+ tib-temp EBX 50 vm-special-object-offset [+] MOV
+ tib-temp tib-temp alien-offset [+] MOV
tib-temp PUSH
+
! No next handler
0 PUSH
! This is the new exception handler
: rel-megamorphic-cache-hits ( class -- )
rt-megamorphic-cache-hits add-relocation ;
-: rel-exception-handler ( class -- )
- rt-exception-handler add-relocation ;
-
: rel-inline-cache-miss ( class -- )
rt-inline-cache-miss add-relocation ;
: array-start-offset ( -- n ) 2 array type-number slot-offset ; inline
: callstack-length-offset ( -- n ) 1 \ callstack type-number slot-offset ; inline
: callstack-top-offset ( -- n ) 2 \ callstack type-number slot-offset ; inline
-: vm-context-offset ( -- n ) 0 bootstrap-cells ; inline
-: vm-spare-context-offset ( -- n ) 1 bootstrap-cells ; inline
-: vm-signal-handler-addr-offset ( -- n ) 8 bootstrap-cells ; inline
-: vm-fault-flag-offset ( -- n ) 9 bootstrap-cells ; inline
: context-callstack-top-offset ( -- n ) 0 bootstrap-cells ; inline
: context-callstack-bottom-offset ( -- n ) 1 bootstrap-cells ; inline
: context-datastack-offset ( -- n ) 2 bootstrap-cells ; inline
: segment-start-offset ( -- n ) 0 bootstrap-cells ; inline
: segment-end-offset ( -- n ) 2 bootstrap-cells ; inline
+! Offsets in vm struct
+: vm-context-offset ( -- n ) 0 bootstrap-cells ; inline
+: vm-spare-context-offset ( -- n ) 1 bootstrap-cells ; inline
+: vm-signal-handler-addr-offset ( -- n ) 8 bootstrap-cells ; inline
+: vm-fault-flag-offset ( -- n ) 9 bootstrap-cells ; inline
+: vm-special-object-offset ( n -- offset )
+ ! Can't reuse the one in compiler.cfg.intrinsics.misc :(
+ bootstrap-cells 10 bootstrap-cells + ;
+
! Relocation classes
CONSTANT: rc-absolute-cell 0
CONSTANT: rc-absolute 1
CONSTANT: rt-vm 9
CONSTANT: rt-cards-offset 10
CONSTANT: rt-decks-offset 11
-CONSTANT: rt-exception-handler 12
CONSTANT: rt-dlsym-toc 13
CONSTANT: rt-inline-cache-miss 14
CONSTANT: rt-safepoint 15
callbacks = new callback_heap(size, this);
}
-bool callback_heap::setup_seh_p() {
-#if defined(WINDOWS) && defined(FACTOR_X86)
- return true;
-#else
- return false;
-#endif
-}
-
bool callback_heap::return_takes_param_p() {
#if defined(FACTOR_X86) || defined(FACTOR_AMD64)
return true;
return instruction_operand(entry, stub, 0);
}
-void callback_heap::store_callback_operand(code_block* stub, cell index) {
- instruction_operand op = callback_operand(stub, index);
- op.store_value(parent->compute_external_address(op));
-}
-
void callback_heap::store_callback_operand(code_block* stub, cell index,
cell value) {
- callback_operand(stub, index).store_value(value);
+ instruction_operand op = callback_operand(stub, index);
+ op.store_value(value);
}
void callback_heap::update(code_block* stub) {
- store_callback_operand(stub, setup_seh_p() ? 2 : 1,
- callback_entry_point(stub));
+ store_callback_operand(stub, 1, callback_entry_point(stub));
stub->flush_icache();
}
code_block* callback_heap::add(cell owner, cell return_rewind) {
+
+ /* code_template is a 2-tuple where the first element contains the
+ relocations and the second a byte array of compiled assembly
+ code. The code assumes that there are four relocations on x86 and
+ three on ppc. */
tagged<array> code_template(parent->special_objects[CALLBACK_STUB]);
tagged<byte_array> insns(array_nth(code_template.untagged(), 1));
cell size = array_capacity(insns.untagged());
/* Store VM pointer */
store_callback_operand(stub, 0, (cell)parent);
- cell index;
-
- if (setup_seh_p()) {
- store_callback_operand(stub, 1);
- index = 1;
- } else
- index = 0;
-
/* Store VM pointer */
- store_callback_operand(stub, index + 2, (cell) parent);
+ store_callback_operand(stub, 2, (cell) parent);
/* On x86, the RET instruction takes an argument which depends on
the callback's calling convention */
if (return_takes_param_p())
- store_callback_operand(stub, index + 3, return_rewind);
+ store_callback_operand(stub, 3, return_rewind);
update(stub);
return w->entry_point;
}
- bool setup_seh_p();
bool return_takes_param_p();
instruction_operand callback_operand(code_block* stub, cell index);
- void store_callback_operand(code_block* stub, cell index);
void store_callback_operand(code_block* stub, cell index, cell value);
-
void update(code_block* stub);
-
code_block* add(cell owner, cell return_rewind);
-
void update();
};
return cards_offset;
case RT_DECKS_OFFSET:
return decks_offset;
-#ifdef WINDOWS
- case RT_EXCEPTION_HANDLER:
- return (cell)&factor::exception_handler;
-#endif
#ifdef FACTOR_PPC
case RT_DLSYM_TOC:
return compute_dlsym_address(parameters, index, true);
{OBJ_VM_COMPILE_TIME, (cell)FACTOR_COMPILE_TIME},
{OBJ_VM_COMPILER, (cell)FACTOR_COMPILER_VERSION},
{OBJ_VM_GIT_LABEL, (cell)FACTOR_STRINGIZE(FACTOR_GIT_LABEL)},
- {OBJ_VM_VERSION, (cell)FACTOR_STRINGIZE(FACTOR_VERSION)}
+ {OBJ_VM_VERSION, (cell)FACTOR_STRINGIZE(FACTOR_VERSION)},
+#if defined(WINDOWS)
+ {UNUSED1, (cell)&factor::exception_handler}
+#endif
};
int n_items = sizeof(aliens) / sizeof(cell[2]);
for (int n = 0; n < n_items; n++) {
case RT_MEGAMORPHIC_CACHE_HITS:
case RT_CARDS_OFFSET:
case RT_DECKS_OFFSET:
- case RT_EXCEPTION_HANDLER:
case RT_INLINE_CACHE_MISS:
case RT_SAFEPOINT:
return 0;