Browse Source

* Xtensa: proper code generation for unit initialization

git-svn-id: trunk@44381 -
florian 5 years ago
parent
commit
db71a9428a
1 changed files with 27 additions and 17 deletions
  1. 27 17
      compiler/xtensa/ncpuutil.pas

+ 27 - 17
compiler/xtensa/ncpuutil.pas

@@ -54,7 +54,7 @@ implementation
 
 
   class procedure txtensanodeutils.insert_init_final_table(entries:tfplist);
   class procedure txtensanodeutils.insert_init_final_table(entries:tfplist);
     var
     var
-      op : TAsmOp;
+      callop, retop: TAsmOp;
       initList, finalList, header: TAsmList;
       initList, finalList, header: TAsmList;
       entry : pinitfinalentry;
       entry : pinitfinalentry;
       i : longint;
       i : longint;
@@ -62,30 +62,40 @@ implementation
       initList:=TAsmList.create;
       initList:=TAsmList.create;
       finalList:=TAsmList.create;
       finalList:=TAsmList.create;
 
 
-      for i:=0 to entries.count-1 do
-         begin
-           entry:=pinitfinalentry(entries[i]);
-           if entry^.finifunc<>'' then
-             finalList.Concat(taicpu.op_sym(A_CALL0,current_asmdata.RefAsmSymbol(entry^.finifunc,AT_FUNCTION)));
-           if entry^.initfunc<>'' then
-             initList.Concat(taicpu.op_sym(A_CALL0,current_asmdata.RefAsmSymbol(entry^.initfunc,AT_FUNCTION)));
-         end;
+      initList.Concat(tai_align.Create(target_info.alignment.procalign));
+      finalList.Concat(tai_align.Create(target_info.alignment.procalign));
 
 
       case target_info.abi of
       case target_info.abi of
-        abi_xtensa_call0:
-          begin
-            initList.Concat(taicpu.op_none(A_RET));
-            finalList.Concat(taicpu.op_none(A_RET));
-          end;
+//        abi_xtensa_call0:
+//          begin
+//            initList.Concat(taicpu.op_none(A_RET));
+//            finalList.Concat(taicpu.op_none(A_RET));
+//            callop:=A_CALL0;
+//            retop:=A_RET;
+//          end;
         abi_xtensa_windowed:
         abi_xtensa_windowed:
           begin
           begin
-            initList.Concat(taicpu.op_none(A_RETW));
-            finalList.Concat(taicpu.op_none(A_RETW));
+            initList.Concat(taicpu.op_reg_const(A_ENTRY,NR_A1,16));
+            finalList.Concat(taicpu.op_reg_const(A_ENTRY,NR_A1,16));
+            callop:=A_CALL4;
+            retop:=A_RETW;
           end;
           end;
         else
         else
-          Internalerror(2020031410);
+          Internalerror(2020031501);
       end;
       end;
 
 
+      for i:=0 to entries.count-1 do
+        begin
+          entry:=pinitfinalentry(entries[i]);
+          if entry^.finifunc<>'' then
+            finalList.Concat(taicpu.op_sym(callop,current_asmdata.RefAsmSymbol(entry^.finifunc,AT_FUNCTION)));
+          if entry^.initfunc<>'' then
+            initList.Concat(taicpu.op_sym(callop,current_asmdata.RefAsmSymbol(entry^.initfunc,AT_FUNCTION)));
+        end;
+
+      initList.Concat(taicpu.op_none(retop));
+      finalList.Concat(taicpu.op_none(retop));
+
       header:=TAsmList.create;
       header:=TAsmList.create;
       new_section(header, sec_code, 'FPC_INIT_FUNC_TABLE', 1);
       new_section(header, sec_code, 'FPC_INIT_FUNC_TABLE', 1);
       header.concat(tai_symbol.Createname_global('FPC_INIT_FUNC_TABLE',AT_FUNCTION,0,voidcodepointertype));
       header.concat(tai_symbol.Createname_global('FPC_INIT_FUNC_TABLE',AT_FUNCTION,0,voidcodepointertype));