From d89aeeadafe93eb2d2a41fdfd2ae21d213cb8153 Mon Sep 17 00:00:00 2001 From: sergei Date: Mon, 23 May 2011 20:43:50 +0000 Subject: [PATCH] x86 assembler: * Adjust rip-relative offsets using values known from calcsize, instead of reinterpreting the tail of instruction. This is simpler and remains the same regardless of particular codes used in opcode table. * Reduced maxinfolen to 8. - 'jmp imm64' and 64-bit versions of 'in' do not exist, removed. git-svn-id: trunk@17546 - --- compiler/i386/i386tab.inc | 6 +++--- compiler/x86/aasmcpu.pas | 15 ++++----------- compiler/x86/x86ins.dat | 7 ++++--- compiler/x86_64/x8664tab.inc | 6 +++--- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/compiler/i386/i386tab.inc b/compiler/i386/i386tab.inc index 52de213db9..c3a0c44933 100644 --- a/compiler/i386/i386tab.inc +++ b/compiler/i386/i386tab.inc @@ -2369,7 +2369,7 @@ ( opcode : A_IN; ops : 2; - optypes : (ot_reg_ax or ot_bits32 or ot_bits64,ot_immediate,ot_none); + optypes : (ot_reg_ax or ot_bits32,ot_immediate,ot_none); code : #208#1#229#21; flags : if_8086 or if_sb ), @@ -2383,7 +2383,7 @@ ( opcode : A_IN; ops : 2; - optypes : (ot_reg_ax or ot_bits32 or ot_bits64,ot_reg_dx,ot_none); + optypes : (ot_reg_ax or ot_bits32,ot_reg_dx,ot_none); code : #208#1#237; flags : if_8086 ), @@ -2530,7 +2530,7 @@ ( opcode : A_JMP; ops : 1; - optypes : (ot_immediate or ot_bits16 or ot_bits32 or ot_bits64,ot_none,ot_none); + optypes : (ot_immediate or ot_bits16 or ot_bits32,ot_none,ot_none); code : #208#1#233#52; flags : if_8086 or if_pass2 ), diff --git a/compiler/x86/aasmcpu.pas b/compiler/x86/aasmcpu.pas index fe1254453f..bc802f6332 100644 --- a/compiler/x86/aasmcpu.pas +++ b/compiler/x86/aasmcpu.pas @@ -172,7 +172,7 @@ interface {$else x86_64} instabentries = {$i i386nop.inc} {$endif x86_64} - maxinfolen = 11; + maxinfolen = 8; MaxInsChanges = 3; { Max things a instruction can change } type @@ -2358,17 +2358,10 @@ implementation if oper[opidx]^.ref^.base=NR_RIP then begin currabsreloc:=RELOC_RELATIVE; - { Adjust reloc value depending of immediate operand size, - but not if offset is specified by literal constant } + { Adjust reloc value by number of bytes following the displacement, + but not if displacement is specified by literal constant } if Assigned(currsym) then - case Ord(codes^) of - 12,13,14,16,17,18,20,21,22: - Dec(currval, 1); - 24,25,26: - Dec(currval, 2); - 32,33,34,172,173,174: - Dec(currval, 4); - end; + Dec(currval,InsEnd-objdata.CurrObjSec.Size-ea_data.bytes); end else {$endif x86_64} diff --git a/compiler/x86/x86ins.dat b/compiler/x86/x86ins.dat index ab6e0f3337..c6fa0d3019 100644 --- a/compiler/x86/x86ins.dat +++ b/compiler/x86/x86ins.dat @@ -792,12 +792,13 @@ reg16,imm8 \324\1\x6B\100\15 286 reg16,imm \324\1\x69\100\31 286,SW rm8 \1\xF6\205 8086 +; 64-bit variant does not exist [IN,inX] (Ch_Wop2, Ch_Rop1, Ch_None) reg_al,imm \1\xE4\25 8086,SB -reg_ax|32|64,imm \320\1\xE5\25 8086,SB +reg_ax|32,imm \320\1\xE5\25 8086,SB reg_al,reg_dx \1\xEC 8086 -reg_ax|32|64,reg_dx \320\1\xED 8086 +reg_ax|32,reg_dx \320\1\xED 8086 [INC,incX] (Ch_Mop1, Ch_WFlags, Ch_None) @@ -876,7 +877,7 @@ imm \1\xE3\50 X86_64 [JMP,jmpX] (Ch_ROp1, Ch_None, Ch_None) imm8 \1\xEB\50 8086,PASS2 -imm16|32|64 \320\1\xE9\64 8086,PASS2 +imm16|32 \320\1\xE9\64 8086,PASS2 rm16|32|64 \320\1\xFF\204 8086 imm|short \1\xEB\50 8086,PASS2 imm|near \320\1\xE9\64 8086,ND,PASS2 diff --git a/compiler/x86_64/x8664tab.inc b/compiler/x86_64/x8664tab.inc index 419f0ad705..daa82bacaf 100644 --- a/compiler/x86_64/x8664tab.inc +++ b/compiler/x86_64/x8664tab.inc @@ -2306,7 +2306,7 @@ ( opcode : A_IN; ops : 2; - optypes : (ot_reg_ax or ot_bits32 or ot_bits64,ot_immediate,ot_none); + optypes : (ot_reg_ax or ot_bits32,ot_immediate,ot_none); code : #208#1#229#21; flags : if_8086 or if_sb ), @@ -2320,7 +2320,7 @@ ( opcode : A_IN; ops : 2; - optypes : (ot_reg_ax or ot_bits32 or ot_bits64,ot_reg_dx,ot_none); + optypes : (ot_reg_ax or ot_bits32,ot_reg_dx,ot_none); code : #208#1#237; flags : if_8086 ), @@ -2453,7 +2453,7 @@ ( opcode : A_JMP; ops : 1; - optypes : (ot_immediate or ot_bits16 or ot_bits32 or ot_bits64,ot_none,ot_none); + optypes : (ot_immediate or ot_bits16 or ot_bits32,ot_none,ot_none); code : #208#1#233#52; flags : if_8086 or if_pass2 ),