From c2df0f23006ec371479ce58e37e5f1c86878db31 Mon Sep 17 00:00:00 2001
From: florian <florian@freepascal.org>
Date: Sun, 19 Apr 2020 08:41:32 +0000
Subject: [PATCH]   * Xtensa: handle localsize > 32760

git-svn-id: trunk@44840 -
---
 compiler/xtensa/cgcpu.pas     | 18 +++++++++++++++++-
 compiler/xtensa/xtensaatt.inc |  1 +
 compiler/xtensa/xtensaop.inc  |  1 +
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/compiler/xtensa/cgcpu.pas b/compiler/xtensa/cgcpu.pas
index ab10146006..942039966c 100644
--- a/compiler/xtensa/cgcpu.pas
+++ b/compiler/xtensa/cgcpu.pas
@@ -619,6 +619,7 @@ implementation
          regoffset : LongInt;
          stack_parameters : Boolean;
          registerarea : PtrInt;
+         l : TAsmLabel;
       begin
         LocalSize:=align(LocalSize,4);
         stack_parameters:=current_procinfo.procdef.stack_tainting_parameter(calleeside);
@@ -705,7 +706,22 @@ implementation
                       localsize:=align(localsize,current_settings.alignment.localalignmax);
                     end;
 
-                  list.concat(taicpu.op_reg_const(A_ENTRY,NR_STACK_POINTER_REG,localsize));
+                  if localsize>32760 then
+                    begin
+                      list.concat(taicpu.op_reg_const(A_ENTRY,NR_STACK_POINTER_REG,32));
+
+                      reference_reset(ref,4,[]);
+                      current_asmdata.getjumplabel(l);
+                      cg.a_label(current_procinfo.aktlocaldata,l);
+                      current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(longint(localsize-32)));
+                      ref.symbol:=l;
+                      list.concat(taicpu.op_reg_ref(A_L32R,NR_A8,ref));
+
+                      list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_A8,NR_STACK_POINTER_REG,NR_A8));
+                      list.concat(taicpu.op_reg_reg(A_MOVSP,NR_STACK_POINTER_REG,NR_A8));
+                    end
+                  else
+                    list.concat(taicpu.op_reg_const(A_ENTRY,NR_STACK_POINTER_REG,localsize));
                 end;
               else
                 Internalerror(2020031401);
diff --git a/compiler/xtensa/xtensaatt.inc b/compiler/xtensa/xtensaatt.inc
index b16a695f0a..044e3d2d31 100644
--- a/compiler/xtensa/xtensaatt.inc
+++ b/compiler/xtensa/xtensaatt.inc
@@ -28,6 +28,7 @@
 'j',
 'j.l',
 'mov',
+'movsp',
 'mov.s',
 'movnez',
 'movi',
diff --git a/compiler/xtensa/xtensaop.inc b/compiler/xtensa/xtensaop.inc
index fb04d74bae..943f82a69b 100644
--- a/compiler/xtensa/xtensaop.inc
+++ b/compiler/xtensa/xtensaop.inc
@@ -28,6 +28,7 @@ A_LSI,
 A_J,
 A_J_L,
 A_MOV,
+A_MOVSP,
 A_MOV_S,
 A_MOVNEZ,
 A_MOVI,