Val   _lib7_runtime_make_codechunk_executable   (Task* task,  Val arg)   {
    //=======================================
    //
    // Mythryl type:  (rw_vector_of_one_byte_unts::Rw_Vector, Int) -> (Chunk -> Chunk)	// The Int is the entrypoint offset within the bytevector of executable machine code -- currently always zero in practice.
    //
    // Turn a previously constructed machine-code bytvector into a closure.
    // This requires that we flush the I-cache. (This is a no-op on intel32.)
    //
    // This fn gets bound as   make_executable   in:
    //
    //     src/lib/compiler/execution/code-segments/code-segment.pkg


    Val   seq        =  GET_TUPLE_SLOT_AS_VAL( arg, 0 );
    int   entrypoint =  GET_TUPLE_SLOT_AS_INT( arg, 1 );			// In practice entrypoint is currently always zero.

    char* code =  GET_VECTOR_DATACHUNK_AS( char*, seq );

    Val_Sized_Unt nbytes		/* This variable is unused on some platforms, so suppress 'unused var' compiler warning: */   __attribute__((unused))
        =
        GET_VECTOR_LENGTH( seq );

    flush_instruction_cache( code, nbytes );					// flush_instruction_cache is a no-op on intel32
										// flush_instruction_cache	def in    src/c/h/flush-instruction-cache-system-dependent.h 
    Val	             result;
    REC_ALLOC1(task, result, PTR_CAST( Val, code + entrypoint));
    return           result;
}
示例#2
0
文件: c-calls.c 项目: xyproto/smlnj
PVT ml_val_t recAlloc1(ml_state_t *msp,ml_val_t v)
{
    ml_val_t ret;

    REC_ALLOC1(msp,ret,v);
    return ret;
}
示例#3
0
文件: mkexec.c 项目: jes5199/mythryl
lib7_val_t   _lib7_runtime_mkexec   (   lib7_state_t*   lib7_state,
                                          lib7_val_t      arg
                                      )
{
    /* _lib7_runtime_mkexec : rw_unt8_vector.Rw_Vector * int -> (chunk -> chunk)
     *
     * Turn a previously allocated code chunk into a closure.
     * This requires that we flush the I-cache.
     */

    lib7_val_t   seq        = REC_SEL(   arg, 0);
    int           entrypoint = REC_SELINT(arg, 1);

    char*	  code       = GET_SEQ_DATAPTR( char, seq );
    Word_t	  nbytes     = GET_SEQ_LEN(           seq );

    FlushICache (code, nbytes);

    {   lib7_val_t	        result;
        REC_ALLOC1(lib7_state, result, PTR_CtoLib7(code + entrypoint));
        return                  result;
    }
}
示例#4
0
文件: globals.c 项目: jes5199/mythryl
void   allocate_globals   (lib7_state_t* lib7_state)
{
    lib7_val_t	RunVec;
    lib7_val_t    CStruct;

#ifdef SIZES_C64_LIB732
    PatchAddresses ();
#endif

    /* Allocate the RunVec: */
#define RUNVEC_SZ	12
    LIB7_AllocWrite(lib7_state,  0, MAKE_DESC(RUNVEC_SZ, DTAG_record));
    LIB7_AllocWrite(lib7_state,  1, PTR_CtoLib7(array_v+1));
    LIB7_AllocWrite(lib7_state,  2, PTR_CtoLib7(bind_cfun_v+1));
    LIB7_AllocWrite(lib7_state,  3, PTR_CtoLib7(callc_v+1));
    LIB7_AllocWrite(lib7_state,  4, PTR_CtoLib7(create_b_v+1));
    LIB7_AllocWrite(lib7_state,  5, PTR_CtoLib7(create_r_v+1));
    LIB7_AllocWrite(lib7_state,  6, PTR_CtoLib7(create_s_v+1));
    LIB7_AllocWrite(lib7_state,  7, PTR_CtoLib7(create_v_v+1));
    LIB7_AllocWrite(lib7_state,  8, PTR_CtoLib7(floor_v+1));
    LIB7_AllocWrite(lib7_state,  9, PTR_CtoLib7(logb_v+1));
    LIB7_AllocWrite(lib7_state, 10, PTR_CtoLib7(scalb_v+1));
    LIB7_AllocWrite(lib7_state, 11, PTR_CtoLib7(try_lock_v+1));
    LIB7_AllocWrite(lib7_state, 12, PTR_CtoLib7(unlock_v+1));
    RunVec = LIB7_Alloc(lib7_state, RUNVEC_SZ);

    /* Allocate the CStruct: */
#define CSTRUCT_SZ	12
    LIB7_AllocWrite(lib7_state,  0, MAKE_DESC(CSTRUCT_SZ, DTAG_record));
    LIB7_AllocWrite(lib7_state,  1, RunVec);
    LIB7_AllocWrite(lib7_state,  2, DivId);
    LIB7_AllocWrite(lib7_state,  3, OverflowId);
    LIB7_AllocWrite(lib7_state,  4, SysErrId);
    LIB7_AllocWrite(lib7_state,  5, ProfCurrent);		/* prof_current in src/lib/core/init/runtime-system.api		*/
    LIB7_AllocWrite(lib7_state,  6, PollEvent);			/* poll_event	in src/lib/core/init/runtime-system.api		*/
    LIB7_AllocWrite(lib7_state,  7, PollFreq);			/* poll_freq	in src/lib/core/init/runtime-system.api		*/
    LIB7_AllocWrite(lib7_state,  8, Lib7PollHandler);		/* poll_handler	in src/lib/core/init/runtime-system.api		*/
    LIB7_AllocWrite(lib7_state,  9, ActiveProcs);		/* active_procs	in src/lib/core/init/runtime-system.api		*/
    LIB7_AllocWrite(lib7_state, 10, PervasiveStruct);		/* pstruct	in src/lib/core/init/runtime-system.api		*/
    LIB7_AllocWrite(lib7_state, 11, Lib7SignalHandler);		/* sighandler	in src/lib/core/init/runtime-system.api		*/
    LIB7_AllocWrite(lib7_state, 12, LIB7_vector0);		/* vector0	in src/lib/core/init/runtime-system.api		*/
    CStruct = LIB7_Alloc(lib7_state, CSTRUCT_SZ);

    /* Allocate 1-elem SRECORD just containing the CStruct: */
    REC_ALLOC1(lib7_state, runtimeCompileUnit, CStruct);

#ifdef ASM_MATH
#define MATHVEC_SZ	8
    LIB7_AllocWrite(lib7_state,  0, MAKE_DESC(MATHVEC_SZ, DTAG_record));
    LIB7_AllocWrite(lib7_state,  1, LnId);
    LIB7_AllocWrite(lib7_state,  2, SqrtId);
    LIB7_AllocWrite(lib7_state,  3, PTR_CtoLib7(arctan_v+1));
    LIB7_AllocWrite(lib7_state,  4, PTR_CtoLib7(cos_v+1));
    LIB7_AllocWrite(lib7_state,  5, PTR_CtoLib7(exp_v+1));
    LIB7_AllocWrite(lib7_state,  6, PTR_CtoLib7(ln_v+1));
    LIB7_AllocWrite(lib7_state,  7, PTR_CtoLib7(sin_v+1));
    LIB7_AllocWrite(lib7_state,  8, PTR_CtoLib7(sqrt_v+1));
    MathVec = LIB7_Alloc(lib7_state, MATHVEC_SZ);
#endif

}          /* allocate_globals */