Sfoglia il codice sorgente

* started to fix parameter passing
* fixed entry/exit code generation

git-svn-id: branches/avr@17041 -

florian 14 anni fa
parent
commit
b870a6eff5
3 ha cambiato i file con 30 aggiunte e 25 eliminazioni
  1. 14 11
      compiler/avr/cgcpu.pas
  2. 6 4
      compiler/avr/cpubase.pas
  3. 10 10
      compiler/avr/cpupara.pas

+ 14 - 11
compiler/avr/cgcpu.pas

@@ -87,8 +87,8 @@ unit cgcpu;
 
 
         procedure g_overflowcheck(list: TAsmList; const l: tlocation; def: tdef); override;
         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 a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
         procedure fixref(list : TAsmList;var ref : treference);
         procedure fixref(list : TAsmList;var ref : treference);
@@ -379,9 +379,6 @@ unit cgcpu;
          case op of
          case op of
            OP_ADD:
            OP_ADD:
              begin
              begin
-               if src<>dst then
-                 a_load_reg_reg(list,size,size,src,dst);
-
                list.concat(taicpu.op_reg_reg(A_ADD,dst,src));
                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
                if size in [OS_S16,OS_16,OS_S32,OS_32,OS_S64,OS_64] then
                  begin
                  begin
@@ -397,9 +394,6 @@ unit cgcpu;
 
 
            OP_SUB:
            OP_SUB:
              begin
              begin
-               if src<>dst then
-                 a_load_reg_reg(list,size,size,src,dst);
-
                list.concat(taicpu.op_reg_reg(A_SUB,dst,src));
                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
                if size in [OS_S16,OS_16,OS_S32,OS_32,OS_S64,OS_64] then
                  begin
                  begin
@@ -492,9 +486,6 @@ unit cgcpu;
 
 
            OP_AND,OP_OR,OP_XOR:
            OP_AND,OP_OR,OP_XOR:
              begin
              begin
-               if src<>dst then
-                 a_load_reg_reg(list,size,size,src,dst);
-
                 for i:=1 to tcgsize2size[size] do
                 for i:=1 to tcgsize2size[size] do
                   begin
                   begin
                     list.concat(taicpu.op_reg_reg(topcg2asmop[op],dst,src));
                     list.concat(taicpu.op_reg_reg(topcg2asmop[op],dst,src));
@@ -1220,6 +1211,18 @@ unit cgcpu;
       end;
       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);
     procedure tcgavr.a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
       var
       var
         ai : taicpu;
         ai : taicpu;

+ 6 - 4
compiler/avr/cpubase.pas

@@ -259,8 +259,8 @@ unit cpubase;
       NR_STACK_POINTER_REG = NR_R13;
       NR_STACK_POINTER_REG = NR_R13;
       RS_STACK_POINTER_REG = RS_R13;
       RS_STACK_POINTER_REG = RS_R13;
       { Frame pointer register }
       { 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,
       { Register for addressing absolute data in a position independant way,
         such as in PIC code. The exact meaning is ABI specific. For
         such as in PIC code. The exact meaning is ABI specific. For
         further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
         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
         This value can be deduced from the CALLED_USED_REGISTERS array in the
         GCC source.
         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
       { Required parameter alignment when calling a routine declared as
         stdcall and cdecl. The alignment value should be the one defined
         stdcall and cdecl. The alignment value should be the one defined
         by GCC or the target ABI.
         by GCC or the target ABI.

+ 10 - 10
compiler/avr/cpupara.pas

@@ -84,17 +84,17 @@ unit cpupara;
           begin
           begin
             size:=OS_INT;
             size:=OS_INT;
             { the four first parameters are passed into registers }
             { the four first parameters are passed into registers }
-            if nr<=4 then
+            if nr<=9 then
               begin
               begin
                 loc:=LOC_REGISTER;
                 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
               end
             else
             else
               begin
               begin
                 { the other parameters are passed on the stack }
                 { the other parameters are passed on the stack }
                 loc:=LOC_REFERENCE;
                 loc:=LOC_REFERENCE;
                 reference.index:=NR_STACK_POINTER_REG;
                 reference.index:=NR_STACK_POINTER_REG;
-                reference.offset:=(nr-5)*4;
+                reference.offset:=(nr-10)*2;
               end;
               end;
           end;
           end;
       end;
       end;
@@ -200,7 +200,7 @@ unit cpupara;
 
 
     procedure tavrparamanager.init_values(var curintreg, curfloatreg, curmmreg: tsuperregister; var cur_stack_offset: aword);
     procedure tavrparamanager.init_values(var curintreg, curfloatreg, curmmreg: tsuperregister; var cur_stack_offset: aword);
       begin
       begin
-        curintreg:=RS_R0;
+        curintreg:=RS_R25;
         curfloatreg:=RS_INVALID;
         curfloatreg:=RS_INVALID;
         curmmreg:=RS_INVALID;
         curmmreg:=RS_INVALID;
         cur_stack_offset:=0;
         cur_stack_offset:=0;
@@ -225,7 +225,7 @@ unit cpupara;
         begin
         begin
           { In case of po_delphi_nested_cc, the parent frame pointer
           { In case of po_delphi_nested_cc, the parent frame pointer
             is always passed on the stack. }
             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(vo_is_parentfp in hp.varoptions) or
                not(po_delphi_nested_cc in p.procoptions)) then
                not(po_delphi_nested_cc in p.procoptions)) then
              begin
              begin
@@ -238,7 +238,7 @@ unit cpupara;
                paraloc^.loc:=LOC_REFERENCE;
                paraloc^.loc:=LOC_REFERENCE;
                paraloc^.reference.index:=NR_STACK_POINTER_REG;
                paraloc^.reference.index:=NR_STACK_POINTER_REG;
                paraloc^.reference.offset:=stack_offset;
                paraloc^.reference.offset:=stack_offset;
-               inc(stack_offset,4);
+               dec(stack_offset,2);
             end;
             end;
         end;
         end;
 
 
@@ -265,7 +265,7 @@ unit cpupara;
                 paraloc:=hp.paraloc[side].add_location;
                 paraloc:=hp.paraloc[side].add_location;
                 { hack: the paraloc must be valid, but is not actually used }
                 { hack: the paraloc must be valid, but is not actually used }
                 paraloc^.loc:=LOC_REGISTER;
                 paraloc^.loc:=LOC_REGISTER;
-                paraloc^.register:=NR_R0;
+                paraloc^.register:=NR_R25;
                 paraloc^.size:=OS_ADDR;
                 paraloc^.size:=OS_ADDR;
                 break;
                 break;
               end;
               end;
@@ -333,11 +333,11 @@ unit cpupara;
                       begin
                       begin
                         { this is not abi compliant
                         { this is not abi compliant
                           why? (FK) }
                           why? (FK) }
-                        if nextintreg<=RS_R3 then
+                        if nextintreg>=RS_R8 then
                           begin
                           begin
                             paraloc^.loc:=LOC_REGISTER;
                             paraloc^.loc:=LOC_REGISTER;
                             paraloc^.register:=newreg(R_INTREGISTER,nextintreg,R_SUBWHOLE);
                             paraloc^.register:=newreg(R_INTREGISTER,nextintreg,R_SUBWHOLE);
-                            inc(nextintreg);
+                            dec(nextintreg);
                           end
                           end
                         else
                         else
                           begin
                           begin
@@ -374,7 +374,7 @@ unit cpupara;
                      if paraloc^.loc=LOC_REFERENCE then
                      if paraloc^.loc=LOC_REFERENCE then
                        begin
                        begin
                          paraloc^.reference.index:=NR_FRAME_POINTER_REG;
                          paraloc^.reference.index:=NR_FRAME_POINTER_REG;
-                         inc(paraloc^.reference.offset,4);
+                         inc(paraloc^.reference.offset,2);
                        end;
                        end;
                    end;
                    end;
                  dec(paralen,tcgsize2size[paraloc^.size]);
                  dec(paralen,tcgsize2size[paraloc^.size]);