mirror of https://github.com/red-prig/fpPS4.git
This commit is contained in:
parent
5b28cfd604
commit
4026082028
|
@ -1080,7 +1080,6 @@ begin
|
|||
|
||||
ctx.ptr_curr:=ptr;
|
||||
|
||||
//adec.Disassemble(ptr,ACodeBytes,ACode);
|
||||
dis.Disassemble(dm64,ptr,din);
|
||||
|
||||
ctx.ptr_next:=ptr;
|
||||
|
@ -1089,7 +1088,7 @@ begin
|
|||
OPX_Invalid..OPX_GroupP:
|
||||
begin
|
||||
//invalid
|
||||
writeln('invalid:0x',HexStr(ctx.ptr_curr));
|
||||
writeln('invalid1:0x',HexStr(ctx.ptr_curr));
|
||||
|
||||
_invalid:
|
||||
|
||||
|
@ -1101,10 +1100,12 @@ begin
|
|||
|
||||
ctx.mark_chunk(fpInvalid);
|
||||
|
||||
link_curr:=ctx.builder.get_curr_label.after;
|
||||
ctx.builder.ud2;
|
||||
|
||||
link_curr:=ctx.builder.get_curr_label.before;
|
||||
link_next:=ctx.builder.get_curr_label.after;
|
||||
|
||||
cb:=@op_invalid;
|
||||
ctx.trim:=True;
|
||||
goto _next; //trim
|
||||
end;
|
||||
|
@ -1115,7 +1116,7 @@ begin
|
|||
(din.ParseFlags * [preF3,preF2] <> []) or
|
||||
is_invalid(din) then
|
||||
begin
|
||||
writeln('invalid:0x',HexStr(ctx.ptr_curr));
|
||||
writeln('invalid2:0x',HexStr(ctx.ptr_curr));
|
||||
goto _invalid;
|
||||
end;
|
||||
|
||||
|
@ -1301,7 +1302,10 @@ begin
|
|||
_next:
|
||||
|
||||
//debug
|
||||
if (cb<>@op_invalid) then
|
||||
begin
|
||||
op_debug_info(ctx);
|
||||
end;
|
||||
//debug
|
||||
|
||||
//resolve forward links
|
||||
|
@ -1321,7 +1325,7 @@ begin
|
|||
//label exist in current blob
|
||||
if not ctx.trim then
|
||||
begin
|
||||
link_new:=ctx.get_link(ptr);
|
||||
link_new:=ctx.get_link(ctx.ptr_next);
|
||||
|
||||
if (link_new<>nil_link) then
|
||||
begin
|
||||
|
@ -1333,9 +1337,9 @@ begin
|
|||
|
||||
//entry exist in another blob
|
||||
if not ctx.trim then
|
||||
if exist_entry(ptr) then
|
||||
if exist_entry(ctx.ptr_next) then
|
||||
begin
|
||||
op_set_r14_imm(ctx,Int64(ptr));
|
||||
op_set_r14_imm(ctx,Int64(ctx.ptr_next));
|
||||
//
|
||||
op_jmp_dispatcher(ctx);
|
||||
//
|
||||
|
|
|
@ -304,10 +304,10 @@ var
|
|||
begin
|
||||
if (dst=nil) then Exit;
|
||||
|
||||
if (ptype=fpCall) then
|
||||
if (get_chunk_ptype=fpData) then
|
||||
begin
|
||||
ptype:=fpData;
|
||||
case get_chunk_ptype of
|
||||
fpData :if (ptype=fpCall) then ptype:=fpData;
|
||||
fpInvalid:ptype:=fpInvalid;
|
||||
else;
|
||||
end;
|
||||
|
||||
node.dst:=dst;
|
||||
|
|
|
@ -441,6 +441,102 @@ begin
|
|||
Result:=Integer(n1^.hash>n2^.hash)-Integer(n1^.hash<n2^.hash);
|
||||
end;
|
||||
|
||||
procedure build_chunk(var ctx:t_jit_context2;blob:p_jit_dynamic;start,__end,count:QWORD);
|
||||
var
|
||||
hash :QWORD;
|
||||
|
||||
original:QWORD;
|
||||
recompil:QWORD;
|
||||
|
||||
jcode:t_jit_dynamic.p_jcode_chunk;
|
||||
table:t_jit_dynamic.p_instr_len;
|
||||
|
||||
clabel:t_jit_context2.p_label;
|
||||
|
||||
link_prev:t_jit_i_link;
|
||||
link_curr:t_jit_i_link;
|
||||
link_next:t_jit_i_link;
|
||||
|
||||
prev:Pointer;
|
||||
curr:Pointer;
|
||||
next:Pointer;
|
||||
begin
|
||||
jcode:=nil;
|
||||
table:=nil;
|
||||
|
||||
if (count=0) then Exit;
|
||||
|
||||
hash:=MurmurHash64A(Pointer(start),__end-start,$010CA1C0DE);
|
||||
|
||||
clabel:=ctx.get_label(Pointer(start));
|
||||
|
||||
jcode:=blob^.new_chunk(count);
|
||||
|
||||
jcode^.start:=start;
|
||||
jcode^.__end:=__end;
|
||||
jcode^.dest :=QWORD(blob^.base)+clabel^.link_curr.offset;
|
||||
jcode^.hash :=hash ;
|
||||
|
||||
table:=@jcode^.table;
|
||||
|
||||
count:=0;
|
||||
curr:=Pointer(start);
|
||||
|
||||
prev:=nil;
|
||||
link_prev:=nil_link;
|
||||
|
||||
//get table
|
||||
while (QWORD(curr)<__end) do
|
||||
begin
|
||||
clabel:=ctx.get_label(curr);
|
||||
|
||||
next:=clabel^.next;
|
||||
|
||||
link_curr:=clabel^.link_curr;
|
||||
link_next:=clabel^.link_next;
|
||||
|
||||
if (link_prev<>nil_link) then
|
||||
begin
|
||||
if (link_prev.offset<>link_curr.offset) then
|
||||
begin
|
||||
Writeln('oaddr:',HexStr(curr),'..',HexStr(next),' prev:',HexStr(prev));
|
||||
Writeln('table:',HexStr(blob^.base+link_prev.offset),'<>',HexStr(blob^.base+link_curr.offset));
|
||||
|
||||
print_disassemble(blob^.base+link_prev.offset,link_next.offset-link_prev.offset);
|
||||
|
||||
Assert(False);
|
||||
end;
|
||||
end;
|
||||
|
||||
original:=QWORD(next)-QWORD(curr);
|
||||
recompil:=link_next.offset-link_curr.offset;
|
||||
|
||||
if (original>255) or (recompil>255) then
|
||||
begin
|
||||
Writeln('0x',HexStr(curr));
|
||||
Writeln(original,':',recompil);
|
||||
Assert(False);
|
||||
end;
|
||||
|
||||
table[count].original:=Byte(original);
|
||||
table[count].recompil:=Byte(recompil);
|
||||
|
||||
{
|
||||
writeln('|0x',HexStr(curr),'..',HexStr(next),
|
||||
':0x',HexStr(link_curr.offset,8),'..',HexStr(link_next.offset,8),
|
||||
':',count);
|
||||
}
|
||||
|
||||
prev:=curr;
|
||||
link_prev:=link_next;
|
||||
|
||||
Inc(count);
|
||||
curr:=next;
|
||||
end;
|
||||
|
||||
//writeln('[0x',HexStr(start,16),':0x',HexStr(__end,16),':',count);
|
||||
end;
|
||||
|
||||
procedure build(var ctx:t_jit_context2);
|
||||
var
|
||||
addr:Pointer;
|
||||
|
@ -452,15 +548,8 @@ var
|
|||
|
||||
start:QWORD;
|
||||
__end:QWORD;
|
||||
hash :QWORD;
|
||||
count:QWORD;
|
||||
|
||||
original:QWORD;
|
||||
recompil:QWORD;
|
||||
|
||||
jcode:t_jit_dynamic.p_jcode_chunk;
|
||||
table:t_jit_dynamic.p_instr_len;
|
||||
|
||||
clabel:t_jit_context2.p_label;
|
||||
|
||||
link_prev:t_jit_i_link;
|
||||
|
@ -498,12 +587,8 @@ begin
|
|||
|
||||
start:=0;
|
||||
__end:=0;
|
||||
hash :=0;
|
||||
count:=0;
|
||||
|
||||
jcode:=nil;
|
||||
table:=nil;
|
||||
|
||||
//copy chunks
|
||||
chunk:=TAILQ_FIRST(@ctx.builder.ACodeChunkList);
|
||||
|
||||
|
@ -522,11 +607,13 @@ begin
|
|||
//save
|
||||
if (start<>0) then
|
||||
begin
|
||||
hash:=MurmurHash64A(Pointer(start),__end-start,$010CA1C0DE);
|
||||
|
||||
count:=0;
|
||||
curr:=Pointer(start);
|
||||
|
||||
prev:=nil;
|
||||
link_prev:=nil_link;
|
||||
|
||||
//get count
|
||||
while (QWORD(curr)<__end) do
|
||||
begin
|
||||
|
@ -538,32 +625,6 @@ begin
|
|||
Assert(false);
|
||||
end;
|
||||
|
||||
Inc(count);
|
||||
curr:=clabel^.next;
|
||||
end;
|
||||
|
||||
clabel:=ctx.get_label(Pointer(start));
|
||||
|
||||
jcode:=blob^.new_chunk(count);
|
||||
|
||||
jcode^.start:=start;
|
||||
jcode^.__end:=__end;
|
||||
jcode^.dest :=QWORD(blob^.base)+clabel^.link_curr.offset;
|
||||
jcode^.hash :=hash ;
|
||||
|
||||
table:=@jcode^.table;
|
||||
|
||||
count:=0;
|
||||
curr:=Pointer(start);
|
||||
|
||||
prev:=nil;
|
||||
link_prev:=nil_link;
|
||||
|
||||
//get table
|
||||
while (QWORD(curr)<__end) do
|
||||
begin
|
||||
clabel:=ctx.get_label(curr);
|
||||
|
||||
next:=clabel^.next;
|
||||
|
||||
link_curr:=clabel^.link_curr;
|
||||
|
@ -573,34 +634,15 @@ begin
|
|||
begin
|
||||
if (link_prev.offset<>link_curr.offset) then
|
||||
begin
|
||||
Writeln(':',HexStr(curr),'..',HexStr(next),' prev:',HexStr(prev));
|
||||
Writeln('table:',HexStr(link_prev.offset,8),'<>',HexStr(link_next.offset,8));
|
||||
//devide chunk
|
||||
|
||||
print_disassemble(blob^.base+link_prev.offset,link_next.offset-link_prev.offset);
|
||||
build_chunk(ctx,blob,start,QWORD(curr),count);
|
||||
|
||||
Assert(False);
|
||||
start:=QWORD(curr);
|
||||
count:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
original:=QWORD(next)-QWORD(curr);
|
||||
recompil:=link_next.offset-link_curr.offset;
|
||||
|
||||
if (original>255) or (recompil>255) then
|
||||
begin
|
||||
Writeln('0x',HexStr(curr));
|
||||
Writeln(original,':',recompil);
|
||||
Assert(False);
|
||||
end;
|
||||
|
||||
table[count].original:=Byte(original);
|
||||
table[count].recompil:=Byte(recompil);
|
||||
|
||||
{
|
||||
writeln('|0x',HexStr(curr),'..',HexStr(next),
|
||||
':0x',HexStr(link_curr.offset,8),'..',HexStr(link_next.offset,8),
|
||||
':',count);
|
||||
}
|
||||
|
||||
prev:=curr;
|
||||
link_prev:=link_next;
|
||||
|
||||
|
@ -608,10 +650,8 @@ begin
|
|||
curr:=next;
|
||||
end;
|
||||
|
||||
//writeln('[0x',HexStr(start,16),':0x',HexStr(__end,16),':',count);
|
||||
build_chunk(ctx,blob,start,__end,count);
|
||||
|
||||
jcode:=nil;
|
||||
table:=nil;
|
||||
end;
|
||||
//new
|
||||
start:=chunk^.start;
|
||||
|
|
Loading…
Reference in New Issue