int32 Compile_ReConfigureLogicInBlock ( BlockInfo * bi, int32 overwriteFlag ) { if ( CfrTil_GetState ( _CfrTil_, OPTIMIZE_ON | INLINE_ON ) ) { byte * saveHere = Here ; if ( bi->LogicCode ) // && ( bi->LogicCodeWord->Symbol->Category & CATEGORY_LOGIC ) ) { //if ( bi->LogicCodeWord->StackPushRegisterCode ) SetHere ( bi->LogicCodeWord->StackPushRegisterCode ) ; //else SetHere ( bi->LogicCode ) ; // compile RET within the block bi at the SpecialCode // standard compile of logic is overwritten for optimize and inline if ( overwriteFlag ) { _Compile_Return ( ) ; bi->bp_Last = Here ; _Compile_Noop ( ) ; // adjust so Disassemble doesn't get an "invalid" insn; we overwrite a 3 byte insn ( 0fb6c0 : movzx eax, al ) with RET NOP NOP _Compile_Noop ( ) ; SetHere ( saveHere ) ; } return true ; } } return false ; }
void _DObject_ValueDefinition_Init ( Word * word, uint32 value, uint64 ctype, uint64 funcType, byte * function, int arg ) // using a variable that is a type or a function { word->W_PtrToValue = & word->W_Value ; word->W_Value = value ; if ( GetState ( _Context_->Compiler0, LC_ARG_PARSING | PREFIX_ARG_PARSING ) ) word->W_StartCharRlIndex = _Context_->Lexer0->TokenStart_ReadLineIndex ; if ( funcType & BLOCK ) { word->Definition = ( block ) ( function ? function : ( byte* ) value ) ; //_OptimizeJumps ( ( byte* ) value ) ; // this comes to play (only(?)) with unoptimized code word->CodeStart = ( byte* ) word->Definition ; if ( ( word->CodeStart < ( byte* ) _Q_CodeByteArray->BA_Data ) || ( word->CodeStart > ( byte* ) _Q_CodeByteArray->bp_Last ) ) word->S_CodeSize = 0 ; // ?!? not quite accurate else word->S_CodeSize = Here - word->CodeStart ; // for use by inline } else { ByteArray * svcs = _Q_CodeByteArray ; _Compiler_SetCompilingSpace ( ( byte* ) "ObjectSpace" ) ; // same problem as namespace ; this can be called in the middle of compiling another word word->Coding = Here ; word->CodeStart = Here ; word->Definition = ( block ) Here ; if ( arg ) _DObject_C_StartupCompiledWords_DefInit ( function, arg ) ; else if ( ctype & C_PREFIX_RTL_ARGS ) { _Compile_Stack_Push ( DSP, ( int32 ) word ) ; Compile_Call ( ( byte* ) function ) ; } else Compile_Call ( ( byte* ) DataObject_Run ) ; _Compile_Return ( ) ; word->S_CodeSize = Here - word->CodeStart ; // for use by inline Set_CompilerSpace ( svcs ) ; } }
void _Compile_CpuState_Save ( CpuState * cpu ) { // push order for pushad // nb : intel stacks grow down toward lesser memory by subtracting from ESP to push and adding to pop // SoftwareDevelopersManual-253665.pdf, section 6.2 // registers are pushed in this order ... // eax, ecx, edx, ebx, esp, ebp, esi, edi _Compile_PushAD ( ) ; // get flags first _Compile_PushFD ( ) ; _Compile_MoveImm_To_Reg ( EAX, 0, CELL ) ; _Compile_PopToReg ( EAX ) ; //_Compile_Lahf ( ) ; // doesn't work with core 2 duo _Compile_MoveImm_To_Reg ( ECX, ( int32 ) & cpu->EFlags, CELL ) ; _Compile_Move_Reg_To_Rm ( ECX, 0, EAX ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Edi, CELL ) ; _Compile_PopToReg ( ECX ) ; _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Esi, CELL ) ; _Compile_PopToReg ( ECX ) ; _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Ebp, CELL ) ; _Compile_PopToReg ( ECX ) ; _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Esp, CELL ) ; _Compile_PopToReg ( ECX ) ; _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Ebx, CELL ) ; _Compile_PopToReg ( ECX ) ; _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Edx, CELL ) ; _Compile_PopToReg ( ECX ) ; _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Ecx, CELL ) ; _Compile_PopToReg ( ECX ) ; _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Eax, CELL ) ; _Compile_PopToReg ( ECX ) ; _Compile_Move_Reg_To_Rm ( EAX, 0, ECX ) ; _Compile_Return ( ) ; // x86 - return opcode }
void _Compile_CpuState_Restore ( CpuState * cpu ) { // push order for pushad // nb : intel stacks grow down toward lesser memory by subtracting from ESP to push and adding to pop // SoftwareDevelopersManual-253665.pdf, section 6.2 // registers are pushed in this order ... // eax, ecx, edx, ebx, esp, ebp, esi, edi //int32 saveEAX = cpu->Eax ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Edi, CELL ) ; _Compile_Move_Rm_To_Reg ( EDI, EAX, 0 ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Esi, CELL ) ; _Compile_Move_Rm_To_Reg ( ESI, EAX, 0 ) ; #if 0 // ebp & esp should n't be restored _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Ebp, CELL ) ; _Compile_Move_Rm_To_Reg ( EBP, EAX, 0 ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Esp, CELL ) ; _Compile_Move_Rm_To_Reg ( ESP, EAX, 0 ) ; #endif _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Ebx, CELL ) ; _Compile_Move_Rm_To_Reg ( EBX, EAX, 0 ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Edx, CELL ) ; _Compile_Move_Rm_To_Reg ( EDX, EAX, 0 ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->EFlags, CELL ) ; _Compile_Move_Rm_To_Reg ( EAX, EAX, 0 ) ; //_Compile_Sahf ( ) ; // store al to eflags ?? doesn't work ?? core 2 duo ?? _Compile_PushReg ( EAX ) ; _Compile_PopFD ( ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Ecx, CELL ) ; _Compile_Move_Rm_To_Reg ( ECX, EAX, 0 ) ; _Compile_MoveImm_To_Reg ( EAX, ( int32 ) & cpu->Eax, CELL ) ; //_Compile_MoveImm_To_Reg ( EAX, ( int32 ) & saveEAX, CELL ) ; _Compile_Move_Rm_To_Reg ( EAX, EAX, 0 ) ; _Compile_Return ( ) ; // x86 - return opcode }
void _CfrTil_EndBlock1 ( BlockInfo * bi ) { Compiler * compiler = _Context_->Compiler0 ; if ( _Stack_IsEmpty ( compiler->BlockStack ) ) { _CfrTil_InstallGotoCallPoints_Keyed ( bi, GI_RETURN ) ; if ( compiler->NumberOfRegisterVariables && ( compiler->NumberOfStackVariables == 1 ) && Compiler_GetState ( compiler, ( RETURN_TOS | RETURN_EAX ) ) ) { bi->bp_First = bi->Start ; if ( Compiler_GetState ( compiler, RETURN_EAX ) ) { Compile_Move_EAX_To_TOS ( DSP ) ; } } else if ( _Compiler_IsFrameNecessary ( compiler ) && ( ! GetState ( compiler, DONT_REMOVE_STACK_VARIABLES ) ) ) { if ( Compiler_GetState ( compiler, SAVE_ESP ) ) // SAVE_ESP is set by 'return' { _ESP_Setup ( ) ; bi->bp_First = bi->FrameStart ; } else bi->bp_First = bi->AfterEspSave ; // 3 : after ESP_Save code in frame setup code _Compiler_RemoveLocalFrame ( compiler ) ; } else { bi->bp_First = bi->Start ; } } _Compile_Return ( ) ; _DataStack_Push ( ( int32 ) bi->bp_First ) ; bi->bp_Last = Here ; _SetOffsetForCallOrJump ( bi->JumpOffset, Here, 0 ) ; }