diff --git a/rtl/x86_jit.pas b/rtl/x86_jit.pas index cb61f93d..8313762e 100644 --- a/rtl/x86_jit.pas +++ b/rtl/x86_jit.pas @@ -345,9 +345,13 @@ type APltCount :Integer; // Allocator:t_jit_builder_allocator; + // + on_error:procedure(const Msg:RawByteString;userdata:Pointer); register; + on_udata:Pointer; // Function Alloc(Size:ptruint):Pointer; Procedure Free; + procedure Assert(value:Boolean;const Msg:RawByteString=''); inline; Function _new_chunk(start:QWORD):p_jit_code_chunk; procedure _end_chunk(__end:QWORD); procedure _add(const ji:t_jit_instruction;min_isize:Byte=0); @@ -1430,6 +1434,18 @@ begin Allocator.Free; end; +procedure t_jit_builder.Assert(value:Boolean;const Msg:RawByteString=''); inline; +begin + if (not value) then + begin + if (on_error<>nil) then + begin + on_error(Msg,on_udata); + end; + System.Assert(value,Msg); + end; +end; + // Function t_jit_builder._new_chunk(start:QWORD):p_jit_code_chunk; @@ -1470,7 +1486,7 @@ begin if (ACodeChunkCurr=nil) then begin _new_chunk(0); - Assert(ACodeChunkCurr<>nil) + Assert(ACodeChunkCurr<>nil); end; i_size:=ji.AInstructionSize; diff --git a/sys/jit/kern_jit.pas b/sys/jit/kern_jit.pas index 7129456a..63db5781 100644 --- a/sys/jit/kern_jit.pas +++ b/sys/jit/kern_jit.pas @@ -2134,6 +2134,34 @@ begin end; end; +procedure on_builder_error(const Msg:RawByteString;userdata:Pointer); register; +var + ctx:p_jit_context2; +begin + ctx:=userdata; + + with ctx^ do + begin + Writeln('original------------------------':32,' ','0x',HexStr(ptr_curr)); + print_disassemble(code,dis.CodeIdx); + Writeln('original------------------------':32,' ','0x',HexStr(ptr_next)); + + Writeln('builder error:', + din.OpCode.Prefix,',', + din.OpCode.Opcode,',', + din.OpCode.Suffix,' ', + din.Operand[1].Size,' ', + din.Operand[2].Size); + + Writeln('opcode=$',HexStr(dis.opcode,8),' ', + 'MIndex=',dis.ModRM.Index,' ', + 'SimdOp=',dis.SimdOpcode,':',SCODES[dis.SimdOpcode],' ', + 'mm=',MCODES[dis.mm and 3],':',dis.mm); + + end; + +end; + var _print_stat:Integer=0; @@ -2168,6 +2196,13 @@ var begin Result:=nil; + //init error cbs + with ctx.builder do + begin + on_error:=@on_builder_error; + on_udata:=@ctx; + end; + if (cmDontScanRipRel in ctx.modes) then begin //dont scan rip relative @@ -2374,20 +2409,24 @@ begin begin print_error_td('Unhandled jit opcode!'); - Writeln('original------------------------':32,' ','0x',HexStr(ctx.ptr_curr)); - print_disassemble(ctx.code,dis.CodeIdx); - Writeln('original------------------------':32,' ','0x',HexStr(ctx.ptr_next)); + with ctx do + begin + Writeln('original------------------------':32,' ','0x',HexStr(ptr_curr)); + print_disassemble(code,dis.CodeIdx); + Writeln('original------------------------':32,' ','0x',HexStr(ptr_next)); - Writeln('Unhandled jit:', - ctx.din.OpCode.Prefix,',', - ctx.din.OpCode.Opcode,',', - ctx.din.OpCode.Suffix,' ', - ctx.din.Operand[1].Size,' ', - ctx.din.Operand[2].Size); - Writeln('opcode=$',HexStr(ctx.dis.opcode,8),' ', - 'MIndex=',ctx.dis.ModRM.Index,' ', - 'SimdOp=',ctx.dis.SimdOpcode,':',SCODES[ctx.dis.SimdOpcode],' ', - 'mm=',ctx.dis.mm,':',MCODES[ctx.dis.mm and 3]); + Writeln('Unhandled jit:', + din.OpCode.Prefix,',', + din.OpCode.Opcode,',', + din.OpCode.Suffix,' ', + din.Operand[1].Size,' ', + din.Operand[2].Size); + + Writeln('opcode=$',HexStr(dis.opcode,8),' ', + 'MIndex=',dis.ModRM.Index,' ', + 'SimdOp=',dis.SimdOpcode,':',SCODES[dis.SimdOpcode],' ', + 'mm=',MCODES[dis.mm and 3],':',dis.mm); + end; Assert(false); end; diff --git a/sys/jit/kern_jit_ctx.pas b/sys/jit/kern_jit_ctx.pas index 0785d80f..de72b82c 100644 --- a/sys/jit/kern_jit_ctx.pas +++ b/sys/jit/kern_jit_ctx.pas @@ -181,7 +181,7 @@ const OPERAND_BYTES:array[TOperandSize] of Word=(0,1,2,4,8,6,10,16,32,64,512); SCODES:array[TSimdOpcode] of Byte=(0,0,1,3,2); - MCODES:array[0..3] of PChar=('','0F','0F38','0F3A'); + MCODES:array[0..3] of PChar=('_','0x0F','0x0F38','0x0F3A'); function GetFrameOffset(const RegValue:TRegValue):Integer; function GetFrameOffset(const r:TOperand):Integer;