From b870a6eff542c42f9c9f123fc01eb93caeca9f6b Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 27 Feb 2011 21:05:53 +0000 Subject: [PATCH] * started to fix parameter passing * fixed entry/exit code generation git-svn-id: branches/avr@17041 - --- compiler/avr/cgcpu.pas | 25 ++++++++++++++----------- compiler/avr/cpubase.pas | 10 ++++++---- compiler/avr/cpupara.pas | 20 ++++++++++---------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/compiler/avr/cgcpu.pas b/compiler/avr/cgcpu.pas index 90f773c69f..89d8c25309 100644 --- a/compiler/avr/cgcpu.pas +++ b/compiler/avr/cgcpu.pas @@ -87,8 +87,8 @@ unit cgcpu; procedure g_overflowcheck(list: TAsmList; const l: tlocation; def: tdef); override; -// procedure g_save_registers(list : TAsmList);override; -// procedure g_restore_registers(list : TAsmList);override; + procedure g_save_registers(list : TAsmList);override; + procedure g_restore_registers(list : TAsmList);override; procedure a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel); procedure fixref(list : TAsmList;var ref : treference); @@ -379,9 +379,6 @@ unit cgcpu; case op of OP_ADD: begin - if src<>dst then - a_load_reg_reg(list,size,size,src,dst); - list.concat(taicpu.op_reg_reg(A_ADD,dst,src)); if size in [OS_S16,OS_16,OS_S32,OS_32,OS_S64,OS_64] then begin @@ -397,9 +394,6 @@ unit cgcpu; OP_SUB: begin - if src<>dst then - a_load_reg_reg(list,size,size,src,dst); - list.concat(taicpu.op_reg_reg(A_SUB,dst,src)); if size in [OS_S16,OS_16,OS_S32,OS_32,OS_S64,OS_64] then begin @@ -492,9 +486,6 @@ unit cgcpu; OP_AND,OP_OR,OP_XOR: begin - if src<>dst then - a_load_reg_reg(list,size,size,src,dst); - for i:=1 to tcgsize2size[size] do begin list.concat(taicpu.op_reg_reg(topcg2asmop[op],dst,src)); @@ -1220,6 +1211,18 @@ unit cgcpu; end; + procedure tcgavr.g_save_registers(list: TAsmList); + begin + { this is done by the entry code } + end; + + + procedure tcgavr.g_restore_registers(list: TAsmList); + begin + { this is done by the exit code } + end; + + procedure tcgavr.a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel); var ai : taicpu; diff --git a/compiler/avr/cpubase.pas b/compiler/avr/cpubase.pas index d2feb00a0b..798d68a0be 100644 --- a/compiler/avr/cpubase.pas +++ b/compiler/avr/cpubase.pas @@ -259,8 +259,8 @@ unit cpubase; NR_STACK_POINTER_REG = NR_R13; RS_STACK_POINTER_REG = RS_R13; { Frame pointer register } - RS_FRAME_POINTER_REG = RS_R11; - NR_FRAME_POINTER_REG = NR_R11; + RS_FRAME_POINTER_REG = RS_R28; + NR_FRAME_POINTER_REG = NR_R28; { Register for addressing absolute data in a position independant way, such as in PIC code. The exact meaning is ABI specific. For further information look at GCC source : PIC_OFFSET_TABLE_REGNUM @@ -306,8 +306,10 @@ unit cpubase; This value can be deduced from the CALLED_USED_REGISTERS array in the GCC source. } - saved_standard_registers : array[0..6] of tsuperregister = - (RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,RS_R9,RS_R10); + { on avr, gen_entry/gen_exit code saves/restores registers, so + we don't need this array } + saved_standard_registers : array[0..0] of tsuperregister = + (RS_INVALID); { Required parameter alignment when calling a routine declared as stdcall and cdecl. The alignment value should be the one defined by GCC or the target ABI. diff --git a/compiler/avr/cpupara.pas b/compiler/avr/cpupara.pas index 57d84ffb89..2dfcc63389 100644 --- a/compiler/avr/cpupara.pas +++ b/compiler/avr/cpupara.pas @@ -84,17 +84,17 @@ unit cpupara; begin size:=OS_INT; { the four first parameters are passed into registers } - if nr<=4 then + if nr<=9 then begin loc:=LOC_REGISTER; - register:=newreg(R_INTREGISTER,RS_R0+nr-1,R_SUBWHOLE); + register:=newreg(R_INTREGISTER,RS_R25-(nr-1)*2,R_SUBWHOLE); end else begin { the other parameters are passed on the stack } loc:=LOC_REFERENCE; reference.index:=NR_STACK_POINTER_REG; - reference.offset:=(nr-5)*4; + reference.offset:=(nr-10)*2; end; end; end; @@ -200,7 +200,7 @@ unit cpupara; procedure tavrparamanager.init_values(var curintreg, curfloatreg, curmmreg: tsuperregister; var cur_stack_offset: aword); begin - curintreg:=RS_R0; + curintreg:=RS_R25; curfloatreg:=RS_INVALID; curmmreg:=RS_INVALID; cur_stack_offset:=0; @@ -225,7 +225,7 @@ unit cpupara; begin { In case of po_delphi_nested_cc, the parent frame pointer is always passed on the stack. } - if (nextintreg<=RS_R3) and + if (nextintreg>RS_R8) and (not(vo_is_parentfp in hp.varoptions) or not(po_delphi_nested_cc in p.procoptions)) then begin @@ -238,7 +238,7 @@ unit cpupara; paraloc^.loc:=LOC_REFERENCE; paraloc^.reference.index:=NR_STACK_POINTER_REG; paraloc^.reference.offset:=stack_offset; - inc(stack_offset,4); + dec(stack_offset,2); end; end; @@ -265,7 +265,7 @@ unit cpupara; paraloc:=hp.paraloc[side].add_location; { hack: the paraloc must be valid, but is not actually used } paraloc^.loc:=LOC_REGISTER; - paraloc^.register:=NR_R0; + paraloc^.register:=NR_R25; paraloc^.size:=OS_ADDR; break; end; @@ -333,11 +333,11 @@ unit cpupara; begin { this is not abi compliant why? (FK) } - if nextintreg<=RS_R3 then + if nextintreg>=RS_R8 then begin paraloc^.loc:=LOC_REGISTER; paraloc^.register:=newreg(R_INTREGISTER,nextintreg,R_SUBWHOLE); - inc(nextintreg); + dec(nextintreg); end else begin @@ -374,7 +374,7 @@ unit cpupara; if paraloc^.loc=LOC_REFERENCE then begin paraloc^.reference.index:=NR_FRAME_POINTER_REG; - inc(paraloc^.reference.offset,4); + inc(paraloc^.reference.offset,2); end; end; dec(paralen,tcgsize2size[paraloc^.size]);