|
@@ -30,95 +30,127 @@ unit cpupara;
|
|
|
|
|
|
uses
|
|
|
globtype,
|
|
|
- cpubase,
|
|
|
+ cpubase,cgbase,
|
|
|
symconst,symbase,symtype,symdef,
|
|
|
paramgr;
|
|
|
|
|
|
type
|
|
|
- { Returns the location for the nr-st 32 Bit int parameter
|
|
|
- if every parameter before is an 32 Bit int parameter as well
|
|
|
- and if the calling conventions for the helper routines of the
|
|
|
- rtl are used.
|
|
|
- }
|
|
|
tx86_64paramanager = class(tparamanager)
|
|
|
+ private
|
|
|
+ procedure create_funcret_paraloc_info(p : tabstractprocdef; side: tcallercallee);
|
|
|
+ public
|
|
|
function getintparaloc(calloption : tproccalloption; nr : longint) : tparalocation;override;
|
|
|
+ function get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;override;
|
|
|
+ function get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;override;
|
|
|
+ function get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;override;
|
|
|
function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
|
|
|
end;
|
|
|
|
|
|
implementation
|
|
|
|
|
|
uses
|
|
|
- verbose,
|
|
|
- cpuinfo,cgbase,systems,
|
|
|
+ cutils,verbose,
|
|
|
+ cpuinfo,systems,
|
|
|
defutil;
|
|
|
|
|
|
const
|
|
|
paraintsupregs : array[0..5] of tsuperregister = (RS_RDI,RS_RSI,RS_RDX,RS_RCX,RS_R8,RS_R9);
|
|
|
parammsupregs : array[0..7] of tsuperregister = (RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3,RS_XMM4,RS_XMM5,RS_XMM6,RS_XMM7);
|
|
|
|
|
|
- function getparaloc(p : tdef) : tcgloc;
|
|
|
+ procedure getvalueparaloc(p : tdef;var loc_lo,loc_hi:tcgloc);
|
|
|
+ begin
|
|
|
+ loc_lo:=LOC_INVALID;
|
|
|
+ loc_hi:=LOC_INVALID;
|
|
|
+ case p.deftype of
|
|
|
+ orddef:
|
|
|
+ begin
|
|
|
+ loc_lo:=LOC_REGISTER;
|
|
|
+ {$warning TODO 128bit also needs lochigh}
|
|
|
+ end;
|
|
|
+ floatdef:
|
|
|
+ begin
|
|
|
+ case tfloatdef(p).typ of
|
|
|
+ s80real:
|
|
|
+ loc_lo:=LOC_REFERENCE;
|
|
|
+ s32real,
|
|
|
+ s64real,
|
|
|
+ s64comp,
|
|
|
+ s64currency :
|
|
|
+ loc_lo:=LOC_MMREGISTER;
|
|
|
+ s128real:
|
|
|
+ begin
|
|
|
+ loc_lo:=LOC_MMREGISTER;
|
|
|
+ loc_hi:=LOC_MMREGISTER;
|
|
|
+ {$warning TODO float 128bit needs SSEUP lochigh}
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ recorddef:
|
|
|
+ begin
|
|
|
+ if p.size<=16 then
|
|
|
+ begin
|
|
|
+ {$warning TODO location depends on the fields}
|
|
|
+ loc_lo:=LOC_REFERENCE;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ loc_lo:=LOC_REFERENCE;
|
|
|
+ end;
|
|
|
+ objectdef:
|
|
|
+ begin
|
|
|
+ if is_object(p) then
|
|
|
+ loc_lo:=LOC_REFERENCE
|
|
|
+ else
|
|
|
+ loc_lo:=LOC_REGISTER;
|
|
|
+ end;
|
|
|
+ arraydef:
|
|
|
+ loc_lo:=LOC_REFERENCE;
|
|
|
+ variantdef:
|
|
|
+ loc_lo:=LOC_REFERENCE;
|
|
|
+ stringdef:
|
|
|
+ if is_shortstring(p) or is_longstring(p) then
|
|
|
+ loc_lo:=LOC_REFERENCE
|
|
|
+ else
|
|
|
+ loc_lo:=LOC_REGISTER;
|
|
|
+ setdef:
|
|
|
+ if is_smallset(p) then
|
|
|
+ loc_lo:=LOC_REGISTER
|
|
|
+ else
|
|
|
+ loc_lo:=LOC_REFERENCE;
|
|
|
+ procvardef:
|
|
|
+ begin
|
|
|
+ { This is a record < 16 bytes }
|
|
|
+ if (po_methodpointer in tprocvardef(p).procoptions) then
|
|
|
+ begin
|
|
|
+ loc_lo:=LOC_REGISTER;
|
|
|
+ loc_hi:=LOC_REGISTER;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ loc_lo:=LOC_REGISTER;
|
|
|
+ end;
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ { default for pointers,enums,etc }
|
|
|
+ loc_lo:=LOC_REGISTER;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+
|
|
|
|
|
|
+ function tx86_64paramanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
|
|
|
begin
|
|
|
- { Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
|
|
|
- if push_addr_param for the def is true
|
|
|
- }
|
|
|
- // !!!!! Fix aggregate types
|
|
|
- case p.deftype of
|
|
|
- orddef:
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- floatdef:
|
|
|
- case tfloatdef(p).typ of
|
|
|
- s80real:
|
|
|
- getparaloc:=LOC_REFERENCE;
|
|
|
- s32real,
|
|
|
- s64real,
|
|
|
- s64comp,
|
|
|
- s64currency,
|
|
|
- s128real:
|
|
|
- getparaloc:=LOC_MMREGISTER;
|
|
|
- end;
|
|
|
- enumdef:
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- pointerdef:
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- formaldef:
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- classrefdef:
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- recorddef:
|
|
|
- getparaloc:=LOC_REFERENCE;
|
|
|
- objectdef:
|
|
|
- if is_object(p) then
|
|
|
- getparaloc:=LOC_REFERENCE
|
|
|
- else
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- stringdef:
|
|
|
- if is_shortstring(p) or is_longstring(p) then
|
|
|
- getparaloc:=LOC_REFERENCE
|
|
|
- else
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- procvardef:
|
|
|
- if (po_methodpointer in tprocvardef(p).procoptions) then
|
|
|
- getparaloc:=LOC_REFERENCE
|
|
|
- else
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- filedef:
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- arraydef:
|
|
|
- getparaloc:=LOC_REFERENCE;
|
|
|
- setdef:
|
|
|
- if is_smallset(p) then
|
|
|
- getparaloc:=LOC_REGISTER
|
|
|
- else
|
|
|
- getparaloc:=LOC_REFERENCE;
|
|
|
- variantdef:
|
|
|
- getparaloc:=LOC_REFERENCE;
|
|
|
- { avoid problems with errornous definitions }
|
|
|
- errordef:
|
|
|
- getparaloc:=LOC_REGISTER;
|
|
|
- else
|
|
|
- internalerror(2002071001);
|
|
|
- end;
|
|
|
+ result:=[RS_RAX,RS_RCX,RS_RDX,RS_RSI,RS_RDI,RS_R8,RS_R9,RS_R10,RS_R11];
|
|
|
+ end;
|
|
|
+
|
|
|
+
|
|
|
+ function tx86_64paramanager.get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;
|
|
|
+ begin
|
|
|
+ result:=[RS_XMM0..RS_XMM15];
|
|
|
+ end;
|
|
|
+
|
|
|
+
|
|
|
+ function tx86_64paramanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
|
|
|
+ begin
|
|
|
+ result:=[RS_ST0..RS_ST7];
|
|
|
end;
|
|
|
|
|
|
|
|
@@ -142,6 +174,34 @@ unit cpupara;
|
|
|
end;
|
|
|
|
|
|
|
|
|
+ procedure tx86_64paramanager.create_funcret_paraloc_info(p : tabstractprocdef; side: tcallercallee);
|
|
|
+ var
|
|
|
+ paraloc : tparalocation;
|
|
|
+ begin
|
|
|
+ { Function return }
|
|
|
+ fillchar(paraloc,sizeof(tparalocation),0);
|
|
|
+ paraloc.size:=def_cgsize(p.rettype.def);
|
|
|
+ { Return in FPU register? }
|
|
|
+ if is_extended(p.rettype.def) then
|
|
|
+ begin
|
|
|
+ paraloc.loc:=LOC_FPUREGISTER;
|
|
|
+ paraloc.register:=NR_FPU_RESULT_REG;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ { Return in register? }
|
|
|
+ if not ret_in_param(p.rettype.def,p.proccalloption) then
|
|
|
+ begin
|
|
|
+ paraloc.loc:=LOC_REGISTER;
|
|
|
+ paraloc.register:=NR_FUNCTION_RETURN_REG;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ paraloc.loc:=LOC_REFERENCE;
|
|
|
+ end;
|
|
|
+ p.funcret_paraloc[side]:=paraloc;
|
|
|
+ end;
|
|
|
+
|
|
|
+
|
|
|
function tx86_64paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
|
|
|
var
|
|
|
hp : tparaitem;
|
|
@@ -163,61 +223,108 @@ unit cpupara;
|
|
|
begin
|
|
|
pushaddr:=push_addr_param(hp.paratyp,hp.paratype.def,p.proccalloption);
|
|
|
if pushaddr then
|
|
|
- paraloc.size:=OS_ADDR
|
|
|
+ begin
|
|
|
+ paraloc.size:=OS_ADDR;
|
|
|
+ paraloc.loc:=LOC_REGISTER;
|
|
|
+ paraloc.lochigh:=LOC_INVALID;
|
|
|
+ end
|
|
|
else
|
|
|
- paraloc.size:=def_cgsize(hp.paratype.def);
|
|
|
+ begin
|
|
|
+ paraloc.size:=def_cgsize(hp.paratype.def);
|
|
|
+ getvalueparaloc(hp.paratype.def,paraloc.loc,paraloc.lochigh);
|
|
|
+ end;
|
|
|
paraloc.alignment:=paraalign;
|
|
|
- if (intparareg<=high(paraintsupregs)) and
|
|
|
- not(
|
|
|
- ((hp.paratype.def.deftype in [floatdef,recorddef,arraydef]) and
|
|
|
- (not pushaddr))
|
|
|
- ) then
|
|
|
+ { Location low }
|
|
|
+ if (paraloc.loc=LOC_REGISTER) and
|
|
|
+ (intparareg<=high(paraintsupregs)) then
|
|
|
begin
|
|
|
- paraloc.loc:=LOC_REGISTER;
|
|
|
- if paraloc.size=OS_NO then
|
|
|
+ if (paraloc.size=OS_NO) or (paraloc.lochigh<>LOC_INVALID) then
|
|
|
subreg:=R_SUBWHOLE
|
|
|
else
|
|
|
subreg:=cgsize2subreg(paraloc.size);
|
|
|
- paraloc.alignment:=paraalign;
|
|
|
paraloc.register:=newreg(R_INTREGISTER,paraintsupregs[intparareg],subreg);
|
|
|
inc(intparareg);
|
|
|
end
|
|
|
- else if (mmparareg<=high(parammsupregs)) then
|
|
|
+ else
|
|
|
+ if (paraloc.loc=LOC_MMREGISTER) and
|
|
|
+ (mmparareg<=high(parammsupregs)) then
|
|
|
begin
|
|
|
+ paraloc.register:=newreg(R_MMREGISTER,parammsupregs[mmparareg],R_SUBNONE);
|
|
|
+ inc(mmparareg);
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
paraloc.loc:=LOC_REFERENCE;
|
|
|
+ paraloc.lochigh:=LOC_INVALID;
|
|
|
if side=callerside then
|
|
|
paraloc.reference.index:=NR_STACK_POINTER_REG
|
|
|
else
|
|
|
paraloc.reference.index:=NR_FRAME_POINTER_REG;
|
|
|
l:=push_size(hp.paratyp,hp.paratype.def,p.proccalloption);
|
|
|
- // varalign:=size_2_align(l);
|
|
|
+ varalign:=size_2_align(l);
|
|
|
paraloc.reference.offset:=parasize;
|
|
|
- // varalign:=used_align(varalign,paraalign,paraalign);
|
|
|
- // parasize:=align(parasize+l,varalign);
|
|
|
+ varalign:=used_align(varalign,paraalign,paraalign);
|
|
|
+ parasize:=align(parasize+l,varalign);
|
|
|
+ end;
|
|
|
+ { Location High if required }
|
|
|
+ if (paraloc.lochigh<>LOC_INVALID) then
|
|
|
+ begin
|
|
|
+ if (paraloc.lochigh=LOC_REGISTER) and
|
|
|
+ (intparareg<=high(paraintsupregs)) then
|
|
|
+ begin
|
|
|
+ paraloc.registerhigh:=newreg(R_INTREGISTER,paraintsupregs[intparareg],R_SUBWHOLE);
|
|
|
+ inc(intparareg);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ if (paraloc.lochigh=LOC_MMREGISTER) and
|
|
|
+ (mmparareg<=high(parammsupregs)) then
|
|
|
+ begin
|
|
|
+ paraloc.registerhigh:=newreg(R_MMREGISTER,parammsupregs[mmparareg],R_SUBNONE);
|
|
|
+ inc(mmparareg);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ { Release when location low has already registers
|
|
|
+ assigned }
|
|
|
+ if paraloc.loc=LOC_REGISTER then
|
|
|
+ dec(intparareg);
|
|
|
+ if paraloc.loc=LOC_MMREGISTER then
|
|
|
+ dec(mmparareg);
|
|
|
+ { Overwrite with LOC_REFERENCE }
|
|
|
+ paraloc.loc:=LOC_REFERENCE;
|
|
|
+ paraloc.lochigh:=LOC_INVALID;
|
|
|
+ fillchar(paraloc.reference,sizeof(paraloc.reference),0);
|
|
|
+ if side=callerside then
|
|
|
+ paraloc.reference.index:=NR_STACK_POINTER_REG
|
|
|
+ else
|
|
|
+ paraloc.reference.index:=NR_FRAME_POINTER_REG;
|
|
|
+ l:=push_size(hp.paratyp,hp.paratype.def,p.proccalloption);
|
|
|
+ varalign:=size_2_align(l);
|
|
|
+ paraloc.reference.offset:=parasize;
|
|
|
+ varalign:=used_align(varalign,paraalign,paraalign);
|
|
|
+ parasize:=align(parasize+l,varalign);
|
|
|
+ end;
|
|
|
end;
|
|
|
hp.paraloc[side]:=paraloc;
|
|
|
hp:=tparaitem(hp.next);
|
|
|
end;
|
|
|
- { Register parameters are assigned from left-to-right, adapt offset
|
|
|
- for calleeside to be reversed }
|
|
|
- hp:=tparaitem(p.para.first);
|
|
|
- while assigned(hp) do
|
|
|
+ { Register parameters are assigned from left-to-right, but the
|
|
|
+ offsets on the stack are right-to-left. There is no need
|
|
|
+ to reverse the offset, only adapt the calleeside with the
|
|
|
+ start offset of the first param on the stack }
|
|
|
+ if side=calleeside then
|
|
|
begin
|
|
|
- if (hp.paraloc[side].loc=LOC_REFERENCE) then
|
|
|
+ hp:=tparaitem(p.para.first);
|
|
|
+ while assigned(hp) do
|
|
|
begin
|
|
|
- l:=push_size(hp.paratyp,hp.paratype.def,p.proccalloption);
|
|
|
- // varalign:=used_align(size_2_align(l),paraalign,paraalign);
|
|
|
- // l:=align(l,varalign);
|
|
|
- hp.paraloc[side].reference.offset:=parasize-hp.paraloc[side].reference.offset-l;
|
|
|
- if side=calleeside then
|
|
|
+ if (hp.paraloc[side].loc=LOC_REFERENCE) then
|
|
|
inc(hp.paraloc[side].reference.offset,target_info.first_parm_offset);
|
|
|
+ hp:=tparaitem(hp.next);
|
|
|
end;
|
|
|
- hp:=tparaitem(hp.next);
|
|
|
end;
|
|
|
- { We need to return the size allocated }
|
|
|
+ { Create Function result paraloc }
|
|
|
+ create_funcret_paraloc_info(p,side);
|
|
|
+ { We need to return the size allocated on the stack }
|
|
|
result:=parasize;
|
|
|
end;
|
|
|
|
|
@@ -227,7 +334,10 @@ begin
|
|
|
end.
|
|
|
{
|
|
|
$Log$
|
|
|
- Revision 1.6 2004-01-14 23:39:05 florian
|
|
|
+ Revision 1.7 2004-02-04 22:01:13 peter
|
|
|
+ * first try to get cpupara working for x86_64
|
|
|
+
|
|
|
+ Revision 1.6 2004/01/14 23:39:05 florian
|
|
|
* another bunch of x86-64 fixes mainly calling convention and
|
|
|
assembler reader related
|
|
|
|