{ Copyright (c) 1998-2002 by Florian Klaempfl and David Zhang Calling conventions for the MIPSEL This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *****************************************************************************} unit cpupara; {$i fpcdefs.inc} interface uses globtype, cclasses, aasmtai, cpubase,cpuinfo, symconst,symbase,symsym,symtype,symdef,paramgr,parabase,cgbase; const MIPS_MAX_OFFSET = 20; MIPS_MAX_REGISTERS_USED_IN_CALL = 6; MIPS_FIRST_REGISTER_USED_IN_CALL = RS_R4; type tparasupregs = array[0..MIPS_MAX_REGISTERS_USED_IN_CALL-1] of tsuperregister; tparasupregsused = array[0..MIPS_MAX_REGISTERS_USED_IN_CALL-1] of boolean; tparasupregsoffset = array[0..MIPS_MAX_REGISTERS_USED_IN_CALL-1] of longint; pparasupregs = ^tparasupregs; const paraoutsupregs : tparasupregs = (RS_R4, RS_R5, RS_R6, RS_R7, RS_R8, RS_R9); parainsupregs : tparasupregs = (RS_R4, RS_R5, RS_R6, RS_R7, RS_R8, RS_R9); type TMIPSParaManager=class(TParaManager) var param_offset:array[0..MIPS_MAX_OFFSET] of ^Aint; intparareg, parasize : longint; function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override; function get_volatile_registers_int(calloption : tproccalloption):TCpuRegisterSet;override; function get_volatile_registers_fpu(calloption : tproccalloption):TCpuRegisterSet;override; {Returns a structure giving the information on the storage of the parameter (which must be an integer parameter) @param(nr Parameter number of routine, starting from 1)} procedure getintparaloc(calloption : tproccalloption; nr : longint;var cgpara : TCGPara);override; function create_paraloc_info(p : TAbstractProcDef; side: tcallercallee):longint;override; function create_varargs_paraloc_info(p : TAbstractProcDef; varargspara:tvarargsparalist):longint;override; function get_funcretloc(p : tabstractprocdef; side: tcallercallee; def: tdef): tcgpara;override; private procedure create_funcretloc_info(p : tabstractprocdef; side: tcallercallee); procedure create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee; paras: tparalist); end; implementation uses cutils,verbose,systems, defutil, cpupi, procinfo, cgutils,cgobj; function TMIPSParaManager.get_volatile_registers_int(calloption : tproccalloption):TCpuRegisterSet; begin result:=[RS_R1..RS_R15,RS_R24..RS_R25,RS_R31]; end; function TMIPSParaManager.get_volatile_registers_fpu(calloption : tproccalloption):TCpuRegisterSet; begin result:=[RS_F0..RS_F19,RS_F31]; end; procedure TMIPSParaManager.GetIntParaLoc(calloption : tproccalloption; nr : longint;var cgpara : tcgpara); var paraloc : pcgparalocation; begin if nr<1 then InternalError(2002100806); cgpara.reset; cgpara.size:=OS_INT; cgpara.intsize:=tcgsize2size[OS_INT]; cgpara.alignment:=std_param_align; paraloc:=cgpara.add_location; with paraloc^ do begin { The six first parameters are passed into registers } {MIPS first four} dec(nr); if nr0 do begin paraloc:=hp.paraloc[side].add_location; { Floats are passed in int registers, We can allocate at maximum 32 bits per register } if paracgsize in [OS_64,OS_S64,OS_F32,OS_F64] then paraloc^.size:=OS_32 else paraloc^.size:=paracgsize; { ret in param? } if vo_is_funcret in hp.varoptions then begin { This should be the first parameter } if assigned(current_procinfo) then begin TMIPSProcInfo(current_procinfo).register_used[0]:=true; TMIPSProcInfo(current_procinfo).register_offset[0]:=0; end; //if (intparareg<>1) then // Comment(V_Warning,'intparareg should be one for funcret in TMipsParaManager.create_paraloc_info_intern'); if side=callerside then begin paraloc^.loc:=LOC_REGISTER; paraloc^.register:=newreg(R_INTREGISTER,hparasupregs^[0],R_SUBWHOLE); end else begin paraloc^.loc:=LOC_REFERENCE; paraloc^.reference.index := NR_FRAME_POINTER_REG; paraloc^.reference.offset:=0; if i<=MIPS_MAX_OFFSET then param_offset[i] := @paraloc^.reference.offset; end; inc(parasize,align(tcgsize2size[paraloc^.size],sizeof(aint))); end { In case of po_delphi_nested_cc, the parent frame pointer is always passed on the stack. } else if (intparareg<=high(tparasupregs)) and (not(vo_is_parentfp in hp.varoptions) or not(po_delphi_nested_cc in p.procoptions)) then begin if assigned(current_procinfo) then begin TMIPSProcInfo(current_procinfo).register_used[intparareg]:=true; TMIPSProcInfo(current_procinfo).register_offset[intparareg]:=intparareg*4; end; if side=callerside then begin paraloc^.loc:=LOC_REGISTER; paraloc^.register:=newreg(R_INTREGISTER,hparasupregs^[intparareg],R_SUBWHOLE); end else begin paraloc^.loc:=LOC_REFERENCE; //if assigned(current_procinfo) then // paraloc^.reference.index := current_procinfo.framepointer //else paraloc^.reference.index := NR_FRAME_POINTER_REG; paraloc^.reference.offset:=intparareg*sizeof(aint); end; inc(intparareg); inc(parasize,align(tcgsize2size[paraloc^.size],sizeof(aint))); end else begin paraloc^.loc:=LOC_REFERENCE; if side=callerside then begin paraloc^.reference.index := {NR_R17;//}NR_STACK_POINTER_REG; paraloc^.reference.offset:=parasize; end else begin //if assigned(current_procinfo) then // paraloc^.reference.index := current_procinfo.framepointer //else paraloc^.reference.index := {NR_R18;//}NR_FRAME_POINTER_REG; paraloc^.reference.offset:=parasize; if i<=MIPS_MAX_OFFSET then param_offset[i] := @paraloc^.reference.offset; end; { Parameters are aligned at 4 bytes } inc(parasize,align(tcgsize2size[paraloc^.size],sizeof(aint))); end; dec(paralen,tcgsize2size[paraloc^.size]); end; end; { for i:=0 to paras.count-1 do begin if (side = calleeside) and (param_offset[i] <> nil) then param_offset[i]^ := param_offset[i]^ + parasize - 8; end; } end; function TMIPSParaManager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint; begin intparareg:=0; parasize:=0; { Create Function result paraloc } create_funcretloc_info(p,callerside); { calculate the registers for the normal parameters } create_paraloc_info_intern(p,callerside,p.paras); { append the varargs } create_paraloc_info_intern(p,callerside,varargspara); result:=parasize; end; function TMIPSParaManager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint; begin intparareg:=0; parasize:=0; { Create Function result paraloc } create_funcretloc_info(p,side); create_paraloc_info_intern(p,side,p.paras); { We need to return the size allocated on the stack } result:=parasize; end; begin ParaManager:=TMIPSParaManager.create; end.