Change modify-code-heap primitive so it takes a sixth element in each array for the frame size.
label-table get
] B{ } make
dup check-fixup
- ] call 5 narray ; inline
+ cfg get stack-frame>> [ total-size>> ] [ 0 ] if*
+ ] call 6 narray ; inline
: generate ( cfg -- code )
[
4 \ cell set
+: leaf-stack-frame-size ( -- n ) 4 bootstrap-cells ;
: stack-frame-size ( -- n ) 8 bootstrap-cells ;
: shift-arg ( -- reg ) ECX ;
: div-arg ( -- reg ) EAX ;
sequences system vocabs ;
IN: bootstrap.x86
+: leaf-stack-frame-size ( -- n ) 4 bootstrap-cells ;
: stack-frame-size ( -- n ) 4 bootstrap-cells ;
: nv-regs ( -- seq ) { RBX R12 R13 R14 R15 } ;
: volatile-regs ( -- seq ) { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ;
DEFER: stack-reg
+: leaf-stack-frame-size ( -- n ) 4 bootstrap-cells ;
: stack-frame-size ( -- n ) 8 bootstrap-cells ;
: nv-regs ( -- seq ) { RBX RSI RDI R12 R13 R14 R15 } ;
: volatile-regs ( -- seq ) { RAX RCX RDX R8 R9 R10 R11 } ;
0 RET
] \ signal-handler define-sub-primitive
-: leaf-frame-size ( -- n ) 4 bootstrap-cells ;
-
[| |
jit-signal-handler-prolog :> frame-size
jit-save-context
temp0 CALL
frame-size jit-signal-handler-epilog
! Pop the fake leaf frame along with our return address
- leaf-frame-size bootstrap-cell - RET
+ leaf-stack-frame-size bootstrap-cell - RET
] \ leaf-signal-handler define-sub-primitive
[| |
}
/* Might GC */
-code_block *factor_vm::add_code_block(code_block_type type, cell code_, cell labels_, cell owner_, cell relocation_, cell parameters_, cell literals_)
+code_block *factor_vm::add_code_block(code_block_type type, cell code_, cell labels_,
+ cell owner_, cell relocation_, cell parameters_, cell literals_,
+ cell frame_size_untagged)
{
data_root<byte_array> code(code_,this);
data_root<object> labels(labels_,this);
if(to_boolean(labels.value()))
fixup_labels(labels.as<array>().untagged(),compiled);
+ compiled->stack_frame_size = frame_size_untagged;
+
/* Once we are ready, fill in literal and word references in this code
block's instruction operands. In most cases this is done right after this
method returns, except when compiling words with the non-optimizing
/* The compiled code heap is structured into blocks. */
struct code_block
{
+ // header format (bits indexed with least significant as zero):
+ // bit 0 : free?
+ // bits 1- 2: type (as a code_block_type)
+ // bits 4- : code size / 16
cell header;
cell owner; /* tagged pointer to word, quotation or f */
cell parameters; /* tagged pointer to array or f */
cell relocation; /* tagged pointer to byte-array or f */
+ cell stack_frame_size;
+ cell pad;
bool free_p() const
{
cell size() const
{
cell size = header & ~7;
-#ifdef FACTOR_DEBUG
FACTOR_ASSERT(size > 0);
-#endif
return size;
}
cell relocation = array_nth(compiled_data,2);
cell labels = array_nth(compiled_data,3);
cell code = array_nth(compiled_data,4);
+ cell frame_size = untag_fixnum(array_nth(compiled_data,5));
code_block *compiled = add_code_block(
code_block_optimized,
word.value(),
relocation,
parameters,
- literals);
+ literals,
+ frame_size);
word->entry_point = compiled->entry_point();
}
#define FACTOR_CPU_STRING "x86.32"
+/* Must match the leaf-stack-frame-size stack-frame-size constants in
+cpu/x86/32/bootstrap.factor */
+static const unsigned LEAF_FRAME_SIZE = 16;
+static const unsigned JIT_FRAME_SIZE = 32;
+
}
code_block *leaf_block = code->code_block_for_address(*pc);
FACTOR_ASSERT(leaf_block != NULL);
- cell newsp = *sp - 4*sizeof(cell);
+ cell newsp = *sp - LEAF_FRAME_SIZE;
*(cell*)(newsp + 3*sizeof(cell)) = 4*sizeof(cell);
*(cell*)(newsp + 2*sizeof(cell)) = (cell)leaf_block->entry_point();
*(cell*) newsp = *pc;
std::cout << std::hex << (cell)scan << std::dec << " ";
std::cout << std::hex << size << std::dec << " ";
- std::cout << status << std::endl;
+ std::cout << status << " ";
+ std::cout << "stack frame " << scan->stack_frame_size;
+ std::cout << std::endl;
}
}
};
cell size() const
{
cell size = header & ~7;
-#ifdef FACTOR_DEBUG
FACTOR_ASSERT(size > 0);
-#endif
return size;
}
void make_free(cell size)
{
-#ifdef FACTOR_DEBUG
FACTOR_ASSERT(size > 0);
-#endif
header = size | 1;
}
};
owner.value(),
relocation.elements.value(),
parameters.elements.value(),
- literals.elements.value());
+ literals.elements.value(),
+ JIT_FRAME_SIZE);
}
}
#define FUNCTION_TOC_POINTER(ptr) ptr
#define UAP_STACK_POINTER_TYPE greg_t
+
+/* Must match the leaf-stack-frame-size and stack-frame-size constants
+in basis/cpu/x86/64/unix/bootstrap.factor */
+static const unsigned LEAF_FRAME_SIZE = 32;
+static const unsigned JIT_FRAME_SIZE = 32;
+
}
mach_clear_fpu_status(UAP_FS(uap));
}
+/* Must match the leaf-stack-frame-size and stack-frame-size constants
+in basis/cpu/x86/64/unix/bootstrap.factor */
+static const unsigned LEAF_FRAME_SIZE = 32;
+static const unsigned JIT_FRAME_SIZE = 32;
+
}
#define MXCSR(ctx) (ctx)->MxCsr
+/* Must match the leaf-stack-frame-size and stack-frame-size constants
+in basis/cpu/x86/64/windows/bootstrap.factor */
+
+static const unsigned LEAF_FRAME_SIZE = 32;
+static const unsigned JIT_FRAME_SIZE = 64;
}
void initialize_code_block(code_block *compiled);
void fixup_labels(array *labels, code_block *compiled);
code_block *allot_code_block(cell size, code_block_type type);
- code_block *add_code_block(code_block_type type, cell code_, cell labels_, cell owner_, cell relocation_, cell parameters_, cell literals_);
+ code_block *add_code_block(code_block_type type, cell code_, cell labels_,
+ cell owner_, cell relocation_, cell parameters_, cell literals_,
+ cell frame_size_untagged);
//code heap
inline void check_code_pointer(cell ptr) { }