vm: store stack frame size in code blocks
Change modify-code-heap primitive so it takes a sixth element in each array for the frame size.db4
parent
fe767253a1
commit
e21f316583
|
@ -107,7 +107,8 @@ M: ##dispatch generate-insn
|
|||
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 )
|
||||
[
|
||||
|
|
|
@ -9,6 +9,7 @@ IN: bootstrap.x86
|
|||
|
||||
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 ;
|
||||
|
|
|
@ -5,6 +5,7 @@ cpu.x86.assembler.operands kernel layouts namespaces parser
|
|||
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 } ;
|
||||
|
|
|
@ -7,6 +7,7 @@ IN: bootstrap.x86
|
|||
|
||||
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 } ;
|
||||
|
|
|
@ -102,8 +102,6 @@ big-endian off
|
|||
0 RET
|
||||
] \ signal-handler define-sub-primitive
|
||||
|
||||
: leaf-frame-size ( -- n ) 4 bootstrap-cells ;
|
||||
|
||||
[| |
|
||||
jit-signal-handler-prolog :> frame-size
|
||||
jit-save-context
|
||||
|
@ -111,7 +109,7 @@ big-endian off
|
|||
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
|
||||
|
||||
[| |
|
||||
|
|
|
@ -399,7 +399,9 @@ code_block *factor_vm::allot_code_block(cell size, code_block_type type)
|
|||
}
|
||||
|
||||
/* 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);
|
||||
|
@ -431,6 +433,8 @@ code_block *factor_vm::add_code_block(code_block_type type, cell code_, cell lab
|
|||
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
|
||||
|
|
|
@ -4,10 +4,16 @@ namespace factor
|
|||
/* 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
|
||||
{
|
||||
|
@ -37,9 +43,7 @@ struct code_block
|
|||
cell size() const
|
||||
{
|
||||
cell size = header & ~7;
|
||||
#ifdef FACTOR_DEBUG
|
||||
FACTOR_ASSERT(size > 0);
|
||||
#endif
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
|
@ -231,6 +231,7 @@ void factor_vm::primitive_modify_code_heap()
|
|||
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,
|
||||
|
@ -239,7 +240,8 @@ void factor_vm::primitive_modify_code_heap()
|
|||
word.value(),
|
||||
relocation,
|
||||
parameters,
|
||||
literals);
|
||||
literals,
|
||||
frame_size);
|
||||
|
||||
word->entry_point = compiled->entry_point();
|
||||
}
|
||||
|
|
|
@ -3,4 +3,9 @@ namespace factor
|
|||
|
||||
#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;
|
||||
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler)
|
|||
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;
|
||||
|
|
|
@ -417,7 +417,9 @@ struct code_block_printer {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -16,17 +16,13 @@ struct free_heap_block
|
|||
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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -143,7 +143,8 @@ code_block *jit::to_code_block()
|
|||
owner.value(),
|
||||
relocation.elements.value(),
|
||||
parameters.elements.value(),
|
||||
literals.elements.value());
|
||||
literals.elements.value(),
|
||||
JIT_FRAME_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,4 +27,10 @@ inline static void uap_clear_fpu_status(void *uap)
|
|||
#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;
|
||||
|
||||
}
|
||||
|
|
|
@ -73,4 +73,9 @@ inline static void uap_clear_fpu_status(void *uap)
|
|||
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;
|
||||
|
||||
}
|
||||
|
|
|
@ -8,4 +8,9 @@ namespace factor
|
|||
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -577,7 +577,9 @@ struct factor_vm
|
|||
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) { }
|
||||
|
|
Loading…
Reference in New Issue