* x86: Cleaned out addr_far,addr_far_ref used to encode far calls/jumps. NASM (and FPC x86 assembler based on it) already have opsize=S_FAR for this purpose.

git-svn-id: trunk@27037 -
This commit is contained in:
sergei 2014-03-08 22:54:43 +00:00
parent 06451dd9ab
commit 9c54cdc85d
5 changed files with 25 additions and 40 deletions

View File

@ -99,8 +99,6 @@ interface
{$ENDIF} {$ENDIF}
{$IFDEF i8086} {$IFDEF i8086}
,addr_dgroup // the data segment group ,addr_dgroup // the data segment group
,addr_far // used for emitting 'call/jmp far label' instructions
,addr_far_ref // used for emitting 'call far [reference]' instructions
,addr_seg // used for getting the segment of an object, e.g. 'mov ax, SEG symbol' ,addr_seg // used for getting the segment of an object, e.g. 'mov ax, SEG symbol'
{$ENDIF} {$ENDIF}
); );

View File

@ -192,15 +192,12 @@ unit cgcpu;
weak: boolean); weak: boolean);
var var
sym : tasmsymbol; sym : tasmsymbol;
r : treference;
begin begin
if not(weak) then if not(weak) then
sym:=current_asmdata.RefAsmSymbol(s) sym:=current_asmdata.RefAsmSymbol(s)
else else
sym:=current_asmdata.WeakRefAsmSymbol(s); sym:=current_asmdata.WeakRefAsmSymbol(s);
reference_reset_symbol(r,sym,0,sizeof(pint)); list.concat(taicpu.op_sym(A_CALL,S_FAR,sym));
r.refaddr:=addr_far;
list.concat(taicpu.op_ref(A_CALL,S_NO,r));
end; end;
@ -216,12 +213,9 @@ unit cgcpu;
procedure tcg8086.a_call_name_static_far(list: TAsmList; const s: string); procedure tcg8086.a_call_name_static_far(list: TAsmList; const s: string);
var var
sym : tasmsymbol; sym : tasmsymbol;
r : treference;
begin begin
sym:=current_asmdata.RefAsmSymbol(s); sym:=current_asmdata.RefAsmSymbol(s);
reference_reset_symbol(r,sym,0,sizeof(pint)); list.concat(taicpu.op_sym(A_CALL,S_FAR,sym));
r.refaddr:=addr_far;
list.concat(taicpu.op_ref(A_CALL,S_NO,r));
end; end;
@ -251,8 +245,7 @@ unit cgcpu;
a_load_reg_ref(list,OS_32,OS_32,reg,href); a_load_reg_ref(list,OS_32,OS_32,reg,href);
cg.getcpuregister(list,NR_BX); cg.getcpuregister(list,NR_BX);
cg.getcpuregister(list,NR_SI); cg.getcpuregister(list,NR_SI);
href.refaddr:=addr_far_ref; list.concat(taicpu.op_ref(A_CALL,S_FAR,href));
list.concat(taicpu.op_ref(A_CALL,S_NO,href));
tg.ungettemp(list,href); tg.ungettemp(list,href);
end; end;
@ -2193,11 +2186,7 @@ unit cgcpu;
lab:=current_asmdata.RefAsmSymbol(procdef.mangledname); lab:=current_asmdata.RefAsmSymbol(procdef.mangledname);
if current_settings.x86memorymodel in x86_far_code_models then if current_settings.x86memorymodel in x86_far_code_models then
begin list.concat(taicpu.op_sym(A_JMP,S_FAR,lab))
reference_reset_symbol(href,lab,0,sizeof(pint));
href.refaddr:=addr_far;
list.concat(taicpu.op_ref(A_JMP,S_NO,href));
end
else else
list.concat(taicpu.op_sym(A_JMP,S_NO,lab)); list.concat(taicpu.op_sym(A_JMP,S_NO,lab));
end; end;

View File

@ -116,8 +116,9 @@ implementation
procedure ti8086callnode.do_call_ref(ref: treference); procedure ti8086callnode.do_call_ref(ref: treference);
begin begin
if current_settings.x86memorymodel in x86_far_code_models then if current_settings.x86memorymodel in x86_far_code_models then
ref.refaddr:=addr_far_ref; current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_CALL,S_FAR,ref))
current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_CALL,S_NO,ref)); else
current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_CALL,S_NO,ref));
end; end;

View File

@ -40,7 +40,7 @@ interface
function CodeSectionName: string; function CodeSectionName: string;
procedure WriteReference(var ref : treference); procedure WriteReference(var ref : treference);
procedure WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean); procedure WriteOper(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean);
procedure WriteOper_jmp(const o:toper; op : tasmop); procedure WriteOper_jmp(const o:toper; ai : taicpu);
procedure WriteSection(atype:TAsmSectiontype;const aname:string); procedure WriteSection(atype:TAsmSectiontype;const aname:string);
public public
procedure WriteTree(p:TAsmList);override; procedure WriteTree(p:TAsmList);override;
@ -428,9 +428,7 @@ interface
asmwrite('dword '); asmwrite('dword ');
{$endif i386} {$endif i386}
{$ifdef i8086} {$ifdef i8086}
if o.ref^.refaddr=addr_far then if o.ref^.refaddr=addr_seg then
asmwrite('far ')
else if o.ref^.refaddr=addr_seg then
asmwrite('SEG ') asmwrite('SEG ')
else else
asmwrite('word '); asmwrite('word ');
@ -454,39 +452,39 @@ interface
end; end;
procedure TX86NasmAssembler.WriteOper_jmp(const o:toper; op : tasmop); procedure TX86NasmAssembler.WriteOper_jmp(const o:toper; ai : taicpu);
begin begin
case o.typ of case o.typ of
top_reg : top_reg :
AsmWrite(nasm_regname(o.reg)); AsmWrite(nasm_regname(o.reg));
top_ref : top_ref :
if o.ref^.refaddr in [addr_no{$ifdef i8086},addr_far_ref{$endif}] then if o.ref^.refaddr=addr_no then
begin begin
{$ifdef i8086} if ai.opsize=S_FAR then
if o.ref^.refaddr=addr_far_ref then
AsmWrite('far '); AsmWrite('far ');
{$endif i8086}
WriteReference(o.ref^); WriteReference(o.ref^);
end end
else else
begin begin
if ai.opsize=S_FAR then
AsmWrite('far ')
else
begin
{ NEAR forces NASM to emit near jumps, which are 386+ } { NEAR forces NASM to emit near jumps, which are 386+ }
{$ifndef i8086} {$ifndef i8086}
if not( if not(
(op=A_JCXZ) or (op=A_JECXZ) or (ai.opcode=A_JCXZ) or (ai.opcode=A_JECXZ) or
{$ifdef x86_64} {$ifdef x86_64}
(op=A_JRCXZ) or (ai.opcode=A_JRCXZ) or
{$endif x86_64} {$endif x86_64}
(op=A_LOOP) or (op=A_LOOPE) or (ai.opcode=A_LOOP) or (ai.opcode=A_LOOPE) or
(op=A_LOOPNE) or (op=A_LOOPNZ) or (ai.opcode=A_LOOPNE) or (ai.opcode=A_LOOPNZ) or
(op=A_LOOPZ) (ai.opcode=A_LOOPZ)
) then ) then
AsmWrite('NEAR '); AsmWrite('NEAR ');
{$endif i8086} {$endif i8086}
{$ifdef i8086} end;
if o.ref^.refaddr=addr_far then
AsmWrite('far ');
{$endif i8086}
AsmWrite(o.ref^.symbol.name); AsmWrite(o.ref^.symbol.name);
if SmartAsm then if SmartAsm then
AddSymbol(o.ref^.symbol.name,false); AddSymbol(o.ref^.symbol.name,false);
@ -1057,7 +1055,7 @@ interface
if is_calljmp(fixed_opcode) then if is_calljmp(fixed_opcode) then
begin begin
AsmWrite(#9); AsmWrite(#9);
WriteOper_jmp(taicpu(hp).oper[0]^,fixed_opcode); WriteOper_jmp(taicpu(hp).oper[0]^,taicpu(hp));
end end
else else
begin begin

View File

@ -2135,8 +2135,7 @@ Unit Rax86int;
if (instr.opcode=A_CALL) and (typ=OPR_SYMBOL) and (symbol<>nil) and (symbol.typ<>AT_DATA) then if (instr.opcode=A_CALL) and (typ=OPR_SYMBOL) and (symbol<>nil) and (symbol.typ<>AT_DATA) then
if current_settings.x86memorymodel in x86_far_code_models then if current_settings.x86memorymodel in x86_far_code_models then
begin begin
instr.operands[i].InitRef; instr.opsize:=S_FAR;
ref.refaddr:=addr_far;
end; end;
{$endif i8086} {$endif i8086}
end; end;