From 0fdc62e0f79fa3a4fbd52526ba4a800390bce2cf Mon Sep 17 00:00:00 2001 From: nickysn Date: Thu, 3 Sep 2015 21:44:16 +0000 Subject: [PATCH] + initialize DS with the current unit's data segment in the function entry code generated in the huge memory model git-svn-id: trunk@31500 - --- compiler/cgbase.pas | 1 + compiler/i8086/cgcpu.pas | 6 +++++- compiler/x86/agx86nsm.pas | 8 ++++++++ compiler/x86/cgx86.pas | 12 ++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/compiler/cgbase.pas b/compiler/cgbase.pas index 95ac045500..e00ea8e2a0 100644 --- a/compiler/cgbase.pas +++ b/compiler/cgbase.pas @@ -101,6 +101,7 @@ interface {$ENDIF} {$IFDEF i8086} ,addr_dgroup // the data segment group + ,addr_fardataseg // the far data segment of the current pascal module (unit or program) ,addr_seg // used for getting the segment of an object, e.g. 'mov ax, SEG symbol' {$ENDIF} {$IFDEF AARCH64} diff --git a/compiler/i8086/cgcpu.pas b/compiler/i8086/cgcpu.pas index f427b174b4..c636dba17b 100644 --- a/compiler/i8086/cgcpu.pas +++ b/compiler/i8086/cgcpu.pas @@ -1776,7 +1776,11 @@ unit cgcpu; cg.a_op_const_reg(list,OP_ADD,OS_ADDR,stacksize,current_procinfo.framepointer); end else - generate_leave(list); + begin + if current_settings.x86memorymodel=mm_huge then + list.concat(Taicpu.Op_reg(A_POP,S_W,NR_DS)); + generate_leave(list); + end; list.concat(tai_regalloc.dealloc(current_procinfo.framepointer,nil)); end; diff --git a/compiler/x86/agx86nsm.pas b/compiler/x86/agx86nsm.pas index 8ac7617fb3..b3cb644b2a 100644 --- a/compiler/x86/agx86nsm.pas +++ b/compiler/x86/agx86nsm.pas @@ -387,6 +387,10 @@ interface begin AsmWrite('DGROUP'); end + else if o.ref^.refaddr=addr_fardataseg then + begin + AsmWrite(current_module.modulename^+'_DATA'); + end {$endif i8086} else begin @@ -603,14 +607,18 @@ interface var i: Integer; begin +{$ifdef i8086} if target_info.system=system_i8086_msdos then begin + if current_settings.x86memorymodel=mm_huge then + WriteSection(sec_data,'',2); AsmLn; AsmWrite('GROUP DGROUP'); for i:=0 to FSectionsInDGROUP.Count-1 do AsmWrite(' '+FSectionsInDGROUP.NameOfIndex(i)); AsmLn; end; +{$endif i8086} end; procedure TX86NasmAssembler.WriteTree(p:TAsmList); diff --git a/compiler/x86/cgx86.pas b/compiler/x86/cgx86.pas index 6145b9d505..59f52e1926 100644 --- a/compiler/x86/cgx86.pas +++ b/compiler/x86/cgx86.pas @@ -2847,6 +2847,7 @@ unit cgx86; regsize: longint; {$ifdef i8086} dgroup: treference; + fardataseg: treference; {$endif i8086} procedure push_regs; @@ -2975,6 +2976,17 @@ unit cgx86; current_procinfo.final_localsize:=localsize; end; +{$ifdef i8086} + if current_settings.x86memorymodel=mm_huge then + begin + list.concat(Taicpu.op_reg(A_PUSH,S_W,NR_DS)); + reference_reset(fardataseg,0); + fardataseg.refaddr:=addr_fardataseg; + list.concat(Taicpu.Op_ref_reg(A_MOV,S_W,fardataseg,NR_AX)); + list.concat(Taicpu.Op_reg_reg(A_MOV,S_W,NR_AX,NR_DS)); + end; +{$endif i8086} + {$ifdef i386} if (not paramanager.use_fixed_stack) and (current_procinfo.framepointer<>NR_STACK_POINTER_REG) and